00001
00034 #include "llviewerprecompiledheaders.h"
00035
00036 #include "llfloatereditui.h"
00037
00038 #include "lluiconstants.h"
00039 #include "llbutton.h"
00040 #include "lllineeditor.h"
00041 #include "llspinctrl.h"
00042 #include "lltextbox.h"
00043
00044 LLFloaterEditUI* LLFloaterEditUI::sInstance = NULL;
00045
00046 void LLFloaterEditUI::navigateHierarchyButtonPressed(void* data)
00047 {
00048 LLView* view = LLView::sEditingUIView;
00049 if( !view ) return;
00050 LLView* parent = view->getParent();
00051 const LLView::child_list_t* viewChildren = view->getChildList();
00052 const LLView::child_list_t* parentChildren = parent->getChildList();
00053
00054 std::list<LLView*>::const_iterator itor;
00055 std::list<LLView*>::size_type idx;
00056 std::list<LLView*>::size_type sidx;
00057 for(idx = 0,itor = parentChildren->begin();itor!=parentChildren->end();itor++,idx++){
00058 if((*itor)==view)break;
00059 }
00060 switch((intptr_t)data)
00061 {
00062 case 0 :
00063 view = view->getParent();
00064 break;
00065 case 1 :
00066 view = viewChildren->begin()!=viewChildren->end() ? (*viewChildren->begin()) : NULL;
00067 break;
00068 case 2 :
00069 {
00070 if(idx==0)
00071 idx = parentChildren->size()-1;
00072 else
00073 idx--;
00074 if( (long) idx < 0 || idx >= parentChildren->size())break;
00075 for(sidx = 0,itor = parentChildren->begin();itor!=parentChildren->end();itor++,sidx++){
00076 if(sidx == idx)
00077 {
00078 view = (*itor);
00079 break;
00080 }
00081 }
00082 }
00083 break;
00084 case 3 :
00085 {
00086 if(idx==parentChildren->size()-1)
00087 idx = 0;
00088 else
00089 idx++;
00090 if( (long) idx < 0 || idx >= parentChildren->size())break;
00091 for(sidx = 0,itor = parentChildren->begin();itor!=parentChildren->end();itor++,sidx++){
00092 if(sidx == idx)
00093 {
00094 view = (*itor);
00095 break;
00096 }
00097 }
00098 }
00099 break;
00100 }
00101 if (view)
00102 {
00103 sEditingUIView = view;
00104 sInstance->refresh();
00105 }
00106 }
00107
00108 LLFloaterEditUI::LLFloaterEditUI()
00109 : LLFloater("floater_ui_editor", LLRect(0, 200, 200, 0), "Edit User Interface"),
00110 mLastView(NULL),
00111 mLabelLine(NULL),
00112 mWidthSpin(NULL),
00113 mHeightSpin(NULL)
00114 {
00115 LLView::sEditingUI = TRUE;
00116
00117 S32 x = HPAD;
00118 S32 y = getRect().getHeight() - LINE - LINE - VPAD;
00119 const S32 R1 = HPAD + 40;
00120
00121 LLLineEditor* line = NULL;
00122 LLSpinCtrl* spin = NULL;
00123 LLTextBox* text = NULL;
00124
00125 LLButton* button = NULL;
00126
00127
00128 text = new LLTextBox("Selected UI Widget:", LLRect(x, y+16, x+100, y));
00129 addChild(text);
00130 y -= VPAD + 16;
00131
00132 text = new LLTextBox("Label:", LLRect(x, y+16, x+40, y));
00133 addChild(text);
00134 x = R1;
00135
00136 line = new LLLineEditor("label_line", LLRect(x, y+20, x+100, y),
00137 "",
00138 NULL,
00139 254,
00140 onCommitLabel,
00141 NULL,
00142 NULL,
00143 this);
00144 addChild(line);
00145 mLabelLine = line;
00146
00147 x = HPAD;
00148 y -= VPAD + 20;
00149
00150 spin = new LLSpinCtrl("height_spin", LLRect(x, y+20, x+100, y),
00151 "Height:", LLFontGL::sSansSerifSmall,
00152 onCommitHeight,
00153 this,
00154 0.f,
00155 2.f,
00156 1000.f,
00157 1.f);
00158 spin->setPrecision(0);
00159 addChild(spin);
00160 mHeightSpin = spin;
00161
00162 y -= VPAD + 20;
00163
00164 spin = new LLSpinCtrl("width_spin", LLRect(x, y+20, x+100, y),
00165 "Width:", LLFontGL::sSansSerifSmall,
00166 onCommitWidth,
00167 this,
00168 0.f,
00169 2.f,
00170 1000.f,
00171 1.f);
00172 spin->setPrecision(0);
00173 addChild(spin);
00174 mWidthSpin = spin;
00175
00176 y -= VPAD + 20;
00177
00178 text = new LLTextBox("XML Name:", LLRect(x, y+16, x+60, y));
00179 addChild(text);
00180 x+=60;
00181 text = new LLTextBox("xml_name", LLRect(x, y+16, x+100, y));
00182 addChild(text);
00183 x-=50;
00184
00185 y -= VPAD + 20;
00186
00187 x += 40;
00188 button = new LLButton("up",LLRect(x, y+16, x+32, y));
00189 addChild(button);
00190 x -= 40;
00191 y -= VPAD + 20;
00192 button = new LLButton("<<",LLRect(x, y+16, x+32, y));
00193 addChild(button);
00194 x += 40;
00195 button = new LLButton("rfrsh",LLRect(x, y+16, x+32, y));
00196 addChild(button);
00197 x += 40;
00198 button = new LLButton(">>",LLRect(x, y+16, x+32, y));
00199 addChild(button);
00200 x -= 40;
00201 y -= VPAD + 20;
00202 button = new LLButton("dn",LLRect(x, y+16, x+32, y));
00203 addChild(button);
00204
00205 childSetAction("up",navigateHierarchyButtonPressed,(void*)0);
00206 childSetAction("dn",navigateHierarchyButtonPressed,(void*)1);
00207 childSetAction("<<",navigateHierarchyButtonPressed,(void*)2);
00208 childSetAction(">>",navigateHierarchyButtonPressed,(void*)3);
00209 childSetAction("rfrsh",navigateHierarchyButtonPressed,(void*)4);
00210 sInstance = this;
00211 }
00212
00213
00214 LLFloaterEditUI::~LLFloaterEditUI()
00215 {
00216 LLView::sEditingUI = FALSE;
00217 LLView::sEditingUIView = NULL;
00218 sInstance = NULL;
00219 }
00220
00221
00222 void LLFloaterEditUI::draw()
00223 {
00224 refresh();
00225 LLFloater::draw();
00226 }
00227
00228 void LLFloaterEditUI::refresh()
00229 {
00230 LLView* view = LLView::sEditingUIView;
00231
00232
00233 if (view == mLastView) return;
00234
00235
00236 if (!view)
00237 {
00238 mLastView = NULL;
00239 mLabelLine->setText(LLString::null);
00240 mLabelLine->setEnabled(FALSE);
00241 mWidthSpin->set(0.f);
00242 mWidthSpin->setEnabled(FALSE);
00243 mHeightSpin->set(0.f);
00244 mHeightSpin->setEnabled(FALSE);
00245 return;
00246 }
00247
00248
00249 LLView* parent = view->getParent();
00250 while (parent)
00251 {
00252 if (parent == this)
00253 {
00254
00255 LLView::sEditingUIView = mLastView;
00256 return;
00257 }
00258 parent = parent->getParent();
00259 }
00260
00261 refreshCore();
00262
00263 mLastView = view;
00264 }
00265
00266 void LLFloaterEditUI::refreshCore()
00267 {
00268 LLView* view = LLView::sEditingUIView;
00269
00270 LLRect r = view->getRect();
00271 F32 width = (F32)r.getWidth();
00272 F32 height = (F32)r.getHeight();
00273 mWidthSpin->set(width);
00274 mHeightSpin->set(height);
00275
00276 EWidgetType widget_type = view->getWidgetType();
00277 switch (widget_type)
00278 {
00279 default:
00280 case WIDGET_TYPE_VIEW:
00281 refreshView(view);
00282 break;
00283 case WIDGET_TYPE_BUTTON:
00284 refreshButton(view);
00285 break;
00286 case WIDGET_TYPE_CHECKBOX:
00287 case WIDGET_TYPE_COLOR_SWATCH:
00288 case WIDGET_TYPE_COMBO_BOX:
00289 case WIDGET_TYPE_LINE_EDITOR:
00290 case WIDGET_TYPE_SCROLL_LIST:
00291 case WIDGET_TYPE_NAME_LIST:
00292 case WIDGET_TYPE_SLIDER:
00293 case WIDGET_TYPE_VOLUME_SLIDER:
00294 case WIDGET_TYPE_SPINNER:
00295 case WIDGET_TYPE_TEXT_EDITOR:
00296 case WIDGET_TYPE_TEXTURE_PICKER:
00297 case WIDGET_TYPE_TEXT_BOX:
00298 case WIDGET_TYPE_RADIO_GROUP:
00299 case WIDGET_TYPE_ICON:
00300 refreshView(view);
00301 break;
00302 }
00303 }
00304
00305 void LLFloaterEditUI::refreshView(LLView* view)
00306 {
00307 mLabelLine->setEnabled(FALSE);
00308 mLabelLine->setText(LLString::null);
00309 childSetText("xml_name",view->getName());
00310 }
00311
00312 void LLFloaterEditUI::refreshButton(LLView* view)
00313 {
00314 LLButton* btn = (LLButton*)view;
00315 LLString label = btn->getLabelUnselected();
00316 mLabelLine->setEnabled(TRUE);
00317 mLabelLine->setText(label);
00318 childSetText("xml_name",view->getName());
00319 }
00320
00321
00322 void LLFloaterEditUI::show(void*)
00323 {
00324 LLFloaterEditUI* self = new LLFloaterEditUI();
00325 self->center();
00326 self->open();
00327 }
00328
00329
00330 BOOL LLFloaterEditUI::handleKey(KEY key, MASK mask)
00331 {
00332 if (!LLView::sEditingUIView) return FALSE;
00333
00334 S32 step = 2;
00335 BOOL handled = FALSE;
00336 LLRect r = LLView::sEditingUIView->getRect();
00337
00338 if (mask == MASK_NONE)
00339 {
00340 if (key == KEY_RIGHT)
00341 {
00342 r.translate(step,0);
00343 handled = TRUE;
00344 }
00345 else if (key == KEY_LEFT)
00346 {
00347 r.translate(-step,0);
00348 handled = TRUE;
00349 }
00350 else if (key == KEY_UP)
00351 {
00352 r.translate(0,step);
00353 handled = TRUE;
00354 }
00355 else if (key == KEY_DOWN)
00356 {
00357 r.translate(0,-step);
00358 handled = TRUE;
00359 }
00360 }
00361 else if (mask == MASK_SHIFT)
00362 {
00363 if (key == KEY_RIGHT)
00364 {
00365 r.mRight += step;
00366 handled = TRUE;
00367 }
00368 else if (key == KEY_LEFT)
00369 {
00370 r.mRight -= step;
00371 handled = TRUE;
00372 }
00373 else if (key == KEY_UP)
00374 {
00375 r.mTop += step;
00376 handled = TRUE;
00377 }
00378 else if (key == KEY_DOWN)
00379 {
00380 r.mTop -= step;
00381 handled = TRUE;
00382 }
00383 }
00384
00385 if (handled)
00386 {
00387 LLView::sEditingUIView->reshape(r.getWidth(), r.getHeight());
00388 LLView::sEditingUIView->setRect(r);
00389 if (sInstance) sInstance->refreshCore();
00390 }
00391
00392 return handled;
00393 }
00394
00395
00396 void LLFloaterEditUI::onCommitLabel(LLUICtrl* ctrl, void* data)
00397 {
00398 LLView* view = LLView::sEditingUIView;
00399 if (!view) return;
00400
00401 LLLineEditor* line = (LLLineEditor*)ctrl;
00402 const LLString& text = line->getText();
00403 if (view->getWidgetType() == WIDGET_TYPE_BUTTON)
00404 {
00405 LLButton* btn = (LLButton*)view;
00406 btn->setLabelUnselected(text);
00407 btn->setLabelSelected(text);
00408 }
00409 }
00410
00411
00412 void LLFloaterEditUI::onCommitHeight(LLUICtrl* ctrl, void* data)
00413 {
00414 LLView* view = LLView::sEditingUIView;
00415 if (!view) return;
00416
00417 LLSpinCtrl* spin = (LLSpinCtrl*)ctrl;
00418 F32 height = spin->get();
00419 LLRect r = view->getRect();
00420 r.mTop = r.mBottom + (S32)height;
00421 view->reshape(r.getWidth(), r.getHeight());
00422 view->setRect(r);
00423 }
00424
00425
00426 void LLFloaterEditUI::onCommitWidth(LLUICtrl* ctrl, void* data)
00427 {
00428 LLView* view = LLView::sEditingUIView;
00429 if (!view) return;
00430
00431 LLSpinCtrl* spin = (LLSpinCtrl*)ctrl;
00432 F32 width = spin->get();
00433 LLRect r = view->getRect();
00434 r.mRight = r.mLeft + (S32)width;
00435 view->reshape(r.getWidth(), r.getHeight());
00436 view->setRect(r);
00437 }