llfloatereditui.cpp

Go to the documentation of this file.
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         //LLView::child_list_t::iterator
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       ://up
00063                         view = view->getParent();
00064                 break;
00065                 case    1       ://down
00066                         view = viewChildren->begin()!=viewChildren->end() ? (*viewChildren->begin()) : NULL;
00067                 break;
00068                 case    2       ://left
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       ://right
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 // virtual
00214 LLFloaterEditUI::~LLFloaterEditUI()
00215 {
00216         LLView::sEditingUI = FALSE;
00217         LLView::sEditingUIView = NULL;
00218         sInstance = NULL;
00219 }
00220 
00221 // virtual
00222 void LLFloaterEditUI::draw()
00223 {
00224         refresh();
00225         LLFloater::draw();
00226 }
00227 
00228 void LLFloaterEditUI::refresh()
00229 {
00230         LLView* view = LLView::sEditingUIView;
00231 
00232         // same selection
00233         if (view == mLastView) return;
00234 
00235         // user deselected
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         // HACK - don't allow widgets in this window to be selected
00249         LLView* parent = view->getParent();
00250         while (parent)
00251         {
00252                 if (parent == this)
00253                 {
00254                         // user selected one of our children, slam them back
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         LLButton* buttonp = dynamic_cast<LLButton*>(view);
00277         if (buttonp)
00278         {
00279                 refreshButton(view);
00280         }
00281         else
00282         {
00283                 refreshView(view);
00284         }
00285 }
00286 
00287 void LLFloaterEditUI::refreshView(LLView* view)
00288 {
00289         mLabelLine->setEnabled(FALSE);
00290         mLabelLine->setText(LLString::null);
00291         childSetText("xml_name",view->getName());
00292 }
00293 
00294 void LLFloaterEditUI::refreshButton(LLView* view)
00295 {
00296         LLButton* btn = (LLButton*)view;
00297         LLString label = btn->getLabelUnselected();
00298         mLabelLine->setEnabled(TRUE);
00299         mLabelLine->setText(label);
00300         childSetText("xml_name",view->getName());
00301 }
00302 
00303 // static
00304 void LLFloaterEditUI::show(void*)
00305 {
00306         LLFloaterEditUI* self = new LLFloaterEditUI();
00307         self->center();
00308         self->open();           /*Flawfinder: ignore*/
00309 }
00310 
00311 // static
00312 BOOL LLFloaterEditUI::processKeystroke(KEY key, MASK mask)
00313 {
00314         if (!LLView::sEditingUIView) return FALSE;
00315 
00316         S32 step = 2;
00317         BOOL handled = FALSE;
00318         LLRect r = LLView::sEditingUIView->getRect();
00319 
00320         if (mask == MASK_NONE)
00321         {
00322                 if (key == KEY_RIGHT)
00323                 {
00324                         r.translate(step,0);
00325                         handled = TRUE;
00326                 }
00327                 else if (key == KEY_LEFT)
00328                 {
00329                         r.translate(-step,0);
00330                         handled = TRUE;
00331                 }
00332                 else if (key == KEY_UP)
00333                 {
00334                         r.translate(0,step);
00335                         handled = TRUE;
00336                 }
00337                 else if (key == KEY_DOWN)
00338                 {
00339                         r.translate(0,-step);
00340                         handled = TRUE;
00341                 }
00342         }
00343         else if (mask == MASK_SHIFT)
00344         {
00345                 if (key == KEY_RIGHT)
00346                 {
00347                         r.mRight += step;
00348                         handled = TRUE;
00349                 }
00350                 else if (key == KEY_LEFT)
00351                 {
00352                         r.mRight -= step;
00353                         handled = TRUE;
00354                 }
00355                 else if (key == KEY_UP)
00356                 {
00357                         r.mTop += step;
00358                         handled = TRUE;
00359                 }
00360                 else if (key == KEY_DOWN)
00361                 {
00362                         r.mTop -= step;
00363                         handled = TRUE;
00364                 }
00365         }
00366 
00367         if (handled)
00368         {
00369                 LLView::sEditingUIView->reshape(r.getWidth(), r.getHeight());
00370                 LLView::sEditingUIView->setRect(r);
00371                 if (sInstance) sInstance->refreshCore();
00372         }
00373 
00374         return handled;
00375 }
00376 
00377 // static
00378 void LLFloaterEditUI::onCommitLabel(LLUICtrl* ctrl, void* data)
00379 {
00380         LLView* view = LLView::sEditingUIView;
00381         if (!view) return;
00382 
00383         LLLineEditor* line = (LLLineEditor*)ctrl;
00384         const LLString& text = line->getText();
00385         LLButton* btn = dynamic_cast<LLButton*>(view);
00386         if (btn)
00387         {
00388                 btn->setLabelUnselected(text);
00389                 btn->setLabelSelected(text);
00390         }
00391 }
00392 
00393 // static
00394 void LLFloaterEditUI::onCommitHeight(LLUICtrl* ctrl, void* data)
00395 {
00396         LLView* view = LLView::sEditingUIView;
00397         if (!view) return;
00398 
00399         LLSpinCtrl* spin = (LLSpinCtrl*)ctrl;
00400         F32 height = spin->get();
00401         LLRect r = view->getRect();
00402         r.mTop = r.mBottom + (S32)height;
00403         view->reshape(r.getWidth(), r.getHeight());
00404         view->setRect(r);
00405 }
00406 
00407 // static
00408 void LLFloaterEditUI::onCommitWidth(LLUICtrl* ctrl, void* data)
00409 {
00410         LLView* view = LLView::sEditingUIView;
00411         if (!view) return;
00412 
00413         LLSpinCtrl* spin = (LLSpinCtrl*)ctrl;
00414         F32 width = spin->get();
00415         LLRect r = view->getRect();
00416         r.mRight = r.mLeft + (S32)width;
00417         view->reshape(r.getWidth(), r.getHeight());
00418         view->setRect(r);
00419 }

Generated on Fri May 16 08:33:24 2008 for SecondLife by  doxygen 1.5.5