llviewercontrol.cpp

Go to the documentation of this file.
00001 
00033 #include "llviewerprecompiledheaders.h"
00034 
00035 #include "llviewercontrol.h"
00036 
00037 #include "indra_constants.h"
00038 
00039 #include "v3math.h"
00040 #include "v3dmath.h"
00041 #include "llrect.h"
00042 #include "v4color.h"
00043 #include "v4coloru.h"
00044 #include "v3color.h"
00045 
00046 #include "llfloater.h"
00047 #include "llvieweruictrlfactory.h"
00048 #include "llfirstuse.h"
00049 #include "llcombobox.h"
00050 #include "llspinctrl.h"
00051 #include "llcolorswatch.h"
00052 
00053 LLFloaterSettingsDebug* LLFloaterSettingsDebug::sInstance = NULL;
00054 
00055 LLControlGroup gSavedSettings;  // saved at end of session
00056 LLControlGroup gSavedPerAccountSettings; // saved at end of session
00057 LLControlGroup gViewerArt;              // read-only
00058 LLControlGroup gColors;                 // read-only
00059 LLControlGroup gCrashSettings;  // saved at end of session
00060 
00061 LLString gLastRunVersion;
00062 LLString gCurrentVersion;
00063 
00064 LLString gSettingsFileName;
00065 LLString gPerAccountSettingsFileName;
00066 
00067 LLFloaterSettingsDebug::LLFloaterSettingsDebug() : LLFloater("Configuration Editor")
00068 {
00069 }
00070 
00071 LLFloaterSettingsDebug::~LLFloaterSettingsDebug()
00072 {
00073         sInstance = NULL;
00074 }
00075 
00076 BOOL LLFloaterSettingsDebug::postBuild()
00077 {
00078         LLComboBox* settings_combo = LLUICtrlFactory::getComboBoxByName(this, "settings_combo");
00079 
00080         LLControlGroup::ctrl_name_table_t::iterator name_it;
00081         for(name_it = gSavedSettings.mNameTable.begin(); name_it != gSavedSettings.mNameTable.end(); ++name_it)
00082         {
00083                 settings_combo->add(name_it->first, (void*)name_it->second);
00084         }
00085         for(name_it = gSavedPerAccountSettings.mNameTable.begin(); name_it != gSavedPerAccountSettings.mNameTable.end(); ++name_it)
00086         {
00087                 settings_combo->add(name_it->first, (void*)name_it->second);
00088         }
00089         for(name_it = gColors.mNameTable.begin(); name_it != gColors.mNameTable.end(); ++name_it)
00090         {
00091                 settings_combo->add(name_it->first, (void*)name_it->second);
00092         }
00093         settings_combo->sortByName();
00094         settings_combo->setCommitCallback(onSettingSelect);
00095         settings_combo->setCallbackUserData(this);
00096         settings_combo->updateSelection();
00097 
00098         childSetCommitCallback("val_spinner_1", onCommitSettings);
00099         childSetUserData("val_spinner_1", this);
00100         childSetCommitCallback("val_spinner_2", onCommitSettings);
00101         childSetUserData("val_spinner_2", this);
00102         childSetCommitCallback("val_spinner_3", onCommitSettings);
00103         childSetUserData("val_spinner_3", this);
00104         childSetCommitCallback("val_spinner_4", onCommitSettings);
00105         childSetUserData("val_spinner_4", this);
00106         childSetCommitCallback("val_text", onCommitSettings);
00107         childSetUserData("val_text", this);
00108         childSetCommitCallback("boolean_combo", onCommitSettings);
00109         childSetUserData("boolean_combo", this);
00110         childSetCommitCallback("color_swatch", onCommitSettings);
00111         childSetUserData("color_swatch", this);
00112         childSetAction("default_btn", onClickDefault, this);
00113         mComment = (LLTextEditor*)getChildByName("comment_text");
00114         return TRUE;
00115 }
00116 
00117 void LLFloaterSettingsDebug::draw()
00118 {
00119         LLComboBox* settings_combo = (LLComboBox*)getChildByName("settings_combo");
00120         LLControlBase* controlp = (LLControlBase*)settings_combo->getCurrentUserdata();
00121         updateControl(controlp);
00122 
00123         LLFloater::draw();
00124 }
00125 
00126 //static
00127 void LLFloaterSettingsDebug::show(void*)
00128 {
00129         if (sInstance == NULL)
00130         {
00131                 sInstance = new LLFloaterSettingsDebug();
00132 
00133                 gUICtrlFactory->buildFloater(sInstance, "floater_settings_debug.xml");
00134         }
00135 
00136         sInstance->open();              /* Flawfinder: ignore */
00137 }
00138 
00139 //static 
00140 void LLFloaterSettingsDebug::onSettingSelect(LLUICtrl* ctrl, void* user_data)
00141 {
00142         LLFloaterSettingsDebug* floaterp = (LLFloaterSettingsDebug*)user_data;
00143         LLComboBox* combo_box = (LLComboBox*)ctrl;
00144         LLControlBase* controlp = (LLControlBase*)combo_box->getCurrentUserdata();
00145 
00146         floaterp->updateControl(controlp);
00147 }
00148 
00149 //static
00150 void LLFloaterSettingsDebug::onCommitSettings(LLUICtrl* ctrl, void* user_data)
00151 {
00152         LLFloaterSettingsDebug* floaterp = (LLFloaterSettingsDebug*)user_data;
00153 
00154         LLComboBox* settings_combo = (LLComboBox*)floaterp->getChildByName("settings_combo");
00155         LLControlBase* controlp = (LLControlBase*)settings_combo->getCurrentUserdata();
00156 
00157         LLVector3 vector;
00158         LLVector3d vectord;
00159         LLRect rect;
00160         LLColor4 col4;
00161         LLColor3 col3;
00162         LLColor4U col4U;
00163         LLColor4 color_with_alpha;
00164 
00165         switch(controlp->type())
00166         {               
00167           case TYPE_U32:
00168                 controlp->set(floaterp->childGetValue("val_spinner_1"));
00169                 break;
00170           case TYPE_S32:
00171                 controlp->set(floaterp->childGetValue("val_spinner_1"));
00172                 break;
00173           case TYPE_F32:
00174                 controlp->set(LLSD(floaterp->childGetValue("val_spinner_1").asReal()));
00175                 break;
00176           case TYPE_BOOLEAN:
00177                 controlp->set(floaterp->childGetValue("boolean_combo"));
00178                 break;
00179           case TYPE_STRING:
00180                 controlp->set(LLSD(floaterp->childGetValue("val_text").asString()));
00181                 break;
00182           case TYPE_VEC3:
00183                 vector.mV[VX] = (F32)floaterp->childGetValue("val_spinner_1").asReal();
00184                 vector.mV[VY] = (F32)floaterp->childGetValue("val_spinner_2").asReal();
00185                 vector.mV[VZ] = (F32)floaterp->childGetValue("val_spinner_3").asReal();
00186                 controlp->set(vector.getValue());
00187                 break;
00188           case TYPE_VEC3D:
00189                 vectord.mdV[VX] = floaterp->childGetValue("val_spinner_1").asReal();
00190                 vectord.mdV[VY] = floaterp->childGetValue("val_spinner_2").asReal();
00191                 vectord.mdV[VZ] = floaterp->childGetValue("val_spinner_3").asReal();
00192                 controlp->set(vectord.getValue());
00193                 break;
00194           case TYPE_RECT:
00195                 rect.mLeft = floaterp->childGetValue("val_spinner_1").asInteger();
00196                 rect.mRight = floaterp->childGetValue("val_spinner_2").asInteger();
00197                 rect.mBottom = floaterp->childGetValue("val_spinner_3").asInteger();
00198                 rect.mTop = floaterp->childGetValue("val_spinner_4").asInteger();
00199                 controlp->set(rect.getValue());
00200                 break;
00201           case TYPE_COL4:
00202                 col3.setValue(floaterp->childGetValue("color_swatch"));
00203                 col4 = LLColor4(col3, (F32)floaterp->childGetValue("val_spinner_4").asReal());
00204                 controlp->set(col4.getValue());
00205                 break;
00206           case TYPE_COL3:
00207                 controlp->set(floaterp->childGetValue("color_swatch"));
00208                 //col3.mV[VRED] = (F32)floaterp->childGetValue("val_spinner_1").asC();
00209                 //col3.mV[VGREEN] = (F32)floaterp->childGetValue("val_spinner_2").asReal();
00210                 //col3.mV[VBLUE] = (F32)floaterp->childGetValue("val_spinner_3").asReal();
00211                 //controlp->set(col3.getValue());
00212                 break;
00213           case TYPE_COL4U:
00214                 col3.setValue(floaterp->childGetValue("color_swatch"));
00215                 col4U.setVecScaleClamp(col3);
00216                 col4U.mV[VALPHA] = floaterp->childGetValue("val_spinner_4").asInteger();
00217                 controlp->set(col4U.getValue());
00218                 break;
00219           default:
00220                 break;
00221         }
00222 }
00223 
00224 // static
00225 void LLFloaterSettingsDebug::onClickDefault(void* user_data)
00226 {
00227         LLFloaterSettingsDebug* floaterp = (LLFloaterSettingsDebug*)user_data;
00228         LLComboBox* settings_combo = (LLComboBox*)floaterp->getChildByName("settings_combo");
00229         LLControlBase* controlp = (LLControlBase*)settings_combo->getCurrentUserdata();
00230 
00231         if (controlp)
00232         {
00233                 controlp->resetToDefault();
00234                 floaterp->updateControl(controlp);
00235         }
00236 }
00237 
00238 // we've switched controls, or doing per-frame update, so update spinners, etc.
00239 void LLFloaterSettingsDebug::updateControl(LLControlBase* controlp)
00240 {
00241         LLSpinCtrl* spinner1 = LLUICtrlFactory::getSpinnerByName(this, "val_spinner_1");
00242         LLSpinCtrl* spinner2 = LLUICtrlFactory::getSpinnerByName(this, "val_spinner_2");
00243         LLSpinCtrl* spinner3 = LLUICtrlFactory::getSpinnerByName(this, "val_spinner_3");
00244         LLSpinCtrl* spinner4 = LLUICtrlFactory::getSpinnerByName(this, "val_spinner_4");
00245         LLColorSwatchCtrl* color_swatch = LLUICtrlFactory::getColorSwatchByName(this, "color_swatch");
00246 
00247         if (!spinner1 || !spinner2 || !spinner3 || !spinner4 || !color_swatch)
00248         {
00249                 llwarns << "Could not find all desired controls by name"
00250                         << llendl;
00251                 return;
00252         }
00253 
00254         spinner1->setVisible(FALSE);
00255         spinner2->setVisible(FALSE);
00256         spinner3->setVisible(FALSE);
00257         spinner4->setVisible(FALSE);
00258         color_swatch->setVisible(FALSE);
00259         childSetVisible("val_text", FALSE);
00260         childSetVisible("boolean_combo", FALSE);
00261         mComment->setText(LLString::null);
00262 
00263         if (controlp)
00264         {
00265                 eControlType type = controlp->type();
00266                 mComment->setText(controlp->getComment());
00267                 spinner1->setMaxValue(F32_MAX);
00268                 spinner2->setMaxValue(F32_MAX);
00269                 spinner3->setMaxValue(F32_MAX);
00270                 spinner4->setMaxValue(F32_MAX);
00271                 spinner1->setMinValue(-F32_MAX);
00272                 spinner2->setMinValue(-F32_MAX);
00273                 spinner3->setMinValue(-F32_MAX);
00274                 spinner4->setMinValue(-F32_MAX);
00275                 if (!spinner1->hasFocus())
00276                 {
00277                         spinner1->setIncrement(0.1f);
00278                 }
00279                 if (!spinner2->hasFocus())
00280                 {
00281                         spinner2->setIncrement(0.1f);
00282                 }
00283                 if (!spinner3->hasFocus())
00284                 {
00285                         spinner3->setIncrement(0.1f);
00286                 }
00287                 if (!spinner4->hasFocus())
00288                 {
00289                         spinner4->setIncrement(0.1f);
00290                 }
00291 
00292                 LLSD sd = controlp->get();
00293                 switch(type)
00294                 {
00295                   case TYPE_U32:
00296                         spinner1->setVisible(TRUE);
00297                         spinner1->setLabel(LLString("value")); // Debug, don't translate
00298                         if (!spinner1->hasFocus())
00299                         {
00300                                 spinner1->setValue(sd);
00301                                 spinner1->setMinValue((F32)U32_MIN);
00302                                 spinner1->setMaxValue((F32)U32_MAX);
00303                                 spinner1->setIncrement(1.f);
00304                                 spinner1->setPrecision(0);
00305                         }
00306                         break;
00307                   case TYPE_S32:
00308                         spinner1->setVisible(TRUE);
00309                         spinner1->setLabel(LLString("value")); // Debug, don't translate
00310                         if (!spinner1->hasFocus())
00311                         {
00312                                 spinner1->setValue(sd);
00313                                 spinner1->setMinValue((F32)S32_MIN);
00314                                 spinner1->setMaxValue((F32)S32_MAX);
00315                                 spinner1->setIncrement(1.f);
00316                                 spinner1->setPrecision(0);
00317                         }
00318                         break;
00319                   case TYPE_F32:
00320                         spinner1->setVisible(TRUE);
00321                         spinner1->setLabel(LLString("value")); // Debug, don't translate
00322                         if (!spinner1->hasFocus())
00323                         {
00324                                 spinner1->setPrecision(3);
00325                                 spinner1->setValue(sd);
00326                         }
00327                         break;
00328                   case TYPE_BOOLEAN:
00329                         childSetVisible("boolean_combo", TRUE);
00330                         
00331                         if (!childHasFocus("boolean_combo"))
00332                         {
00333                                 if (sd.asBoolean())
00334                                 {
00335                                         childSetValue("boolean_combo", LLSD("true"));
00336                                 }
00337                                 else
00338                                 {
00339                                         childSetValue("boolean_combo", LLSD(""));
00340                                 }
00341                         }
00342                         break;
00343                   case TYPE_STRING:
00344                         childSetVisible("val_text", TRUE);
00345                         if (!childHasFocus("val_text"))
00346                         {
00347                                 childSetValue("val_text", sd);
00348                         }
00349                         break;
00350                   case TYPE_VEC3:
00351                   {
00352                         LLVector3 v;
00353                         v.setValue(sd);
00354                         spinner1->setVisible(TRUE);
00355                         spinner1->setLabel(LLString("X"));
00356                         spinner2->setVisible(TRUE);
00357                         spinner2->setLabel(LLString("Y"));
00358                         spinner3->setVisible(TRUE);
00359                         spinner3->setLabel(LLString("Z"));
00360                         if (!spinner1->hasFocus())
00361                         {
00362                                 spinner1->setPrecision(3);
00363                                 spinner1->setValue(v[VX]);
00364                         }
00365                         if (!spinner2->hasFocus())
00366                         {
00367                                 spinner2->setPrecision(3);
00368                                 spinner2->setValue(v[VY]);
00369                         }
00370                         if (!spinner3->hasFocus())
00371                         {
00372                                 spinner3->setPrecision(3);
00373                                 spinner3->setValue(v[VZ]);
00374                         }
00375                         break;
00376                   }
00377                   case TYPE_VEC3D:
00378                   {
00379                         LLVector3d v;
00380                         v.setValue(sd);
00381                         spinner1->setVisible(TRUE);
00382                         spinner1->setLabel(LLString("X"));
00383                         spinner2->setVisible(TRUE);
00384                         spinner2->setLabel(LLString("Y"));
00385                         spinner3->setVisible(TRUE);
00386                         spinner3->setLabel(LLString("Z"));
00387                         if (!spinner1->hasFocus())
00388                         {
00389                                 spinner1->setPrecision(3);
00390                                 spinner1->setValue(v[VX]);
00391                         }
00392                         if (!spinner2->hasFocus())
00393                         {
00394                                 spinner2->setPrecision(3);
00395                                 spinner2->setValue(v[VY]);
00396                         }
00397                         if (!spinner3->hasFocus())
00398                         {
00399                                 spinner3->setPrecision(3);
00400                                 spinner3->setValue(v[VZ]);
00401                         }
00402                         break;
00403                   }
00404                   case TYPE_RECT:
00405                   {
00406                         LLRect r;
00407                         r.setValue(sd);
00408                         spinner1->setVisible(TRUE);
00409                         spinner1->setLabel(LLString("Left"));
00410                         spinner2->setVisible(TRUE);
00411                         spinner2->setLabel(LLString("Right"));
00412                         spinner3->setVisible(TRUE);
00413                         spinner3->setLabel(LLString("Bottom"));
00414                         spinner4->setVisible(TRUE);
00415                         spinner4->setLabel(LLString("Top"));
00416                         if (!spinner1->hasFocus())
00417                         {
00418                                 spinner1->setPrecision(0);
00419                                 spinner1->setValue(r.mLeft);
00420                         }
00421                         if (!spinner2->hasFocus())
00422                         {
00423                                 spinner2->setPrecision(0);
00424                                 spinner2->setValue(r.mRight);
00425                         }
00426                         if (!spinner3->hasFocus())
00427                         {
00428                                 spinner3->setPrecision(0);
00429                                 spinner3->setValue(r.mBottom);
00430                         }
00431                         if (!spinner4->hasFocus())
00432                         {
00433                                 spinner4->setPrecision(0);
00434                                 spinner4->setValue(r.mTop);
00435                         }
00436 
00437                         spinner1->setMinValue((F32)S32_MIN);
00438                         spinner1->setMaxValue((F32)S32_MAX);
00439                         spinner1->setIncrement(1.f);
00440 
00441                         spinner2->setMinValue((F32)S32_MIN);
00442                         spinner2->setMaxValue((F32)S32_MAX);
00443                         spinner2->setIncrement(1.f);
00444 
00445                         spinner3->setMinValue((F32)S32_MIN);
00446                         spinner3->setMaxValue((F32)S32_MAX);
00447                         spinner3->setIncrement(1.f);
00448 
00449                         spinner4->setMinValue((F32)S32_MIN);
00450                         spinner4->setMaxValue((F32)S32_MAX);
00451                         spinner4->setIncrement(1.f);
00452                         break;
00453                   }
00454                   case TYPE_COL4:
00455                   {
00456                         LLColor4 clr;
00457                         clr.setValue(sd);
00458                         color_swatch->setVisible(TRUE);
00459                         // only set if changed so color picker doesn't update
00460                         if(clr != LLColor4(color_swatch->getValue()))
00461                         {
00462                                 color_swatch->set(LLColor4(sd), TRUE, FALSE);
00463                         }
00464                         spinner4->setVisible(TRUE);
00465                         spinner4->setLabel(LLString("Alpha"));
00466                         if (!spinner4->hasFocus())
00467                         {
00468                                 spinner4->setPrecision(3);
00469                                 spinner4->setMinValue(0.0);
00470                                 spinner4->setMaxValue(1.f);
00471                                 spinner4->setValue(clr.mV[VALPHA]);
00472                         }
00473                         break;
00474                   }
00475                   case TYPE_COL3:
00476                   {
00477                         LLColor3 clr;
00478                         clr.setValue(sd);
00479                         color_swatch->setVisible(TRUE);
00480                         color_swatch->setValue(sd);
00481                         break;
00482                   }
00483                   case TYPE_COL4U:
00484                   {
00485                         LLColor4U clr;
00486                         clr.setValue(sd);
00487                         color_swatch->setVisible(TRUE);
00488                         if(LLColor4(clr) != LLColor4(color_swatch->getValue()))
00489                         {
00490                                 color_swatch->set(LLColor4(clr), TRUE, FALSE);
00491                         }
00492                         spinner4->setVisible(TRUE);
00493                         spinner4->setLabel(LLString("Alpha"));
00494                         if(!spinner4->hasFocus())
00495                         {
00496                                 spinner4->setPrecision(0);
00497                                 spinner4->setValue(clr.mV[VALPHA]);
00498                         }
00499 
00500                         spinner4->setMinValue(0);
00501                         spinner4->setMaxValue(255);
00502                         spinner4->setIncrement(1.f);
00503 
00504                         break;
00505                   }
00506                   default:
00507                         mComment->setText(LLString("unknown"));
00508                         break;
00509                 }
00510         }
00511 
00512 }

Generated on Thu Jul 1 06:09:27 2010 for Second Life Viewer by  doxygen 1.4.7