lldebugmessagebox.cpp

Go to the documentation of this file.
00001 
00032 #include "llviewerprecompiledheaders.h"
00033 
00034 #include "lldebugmessagebox.h"
00035 
00036 #include "llresmgr.h"
00037 #include "llfontgl.h"
00038 #include "llbutton.h"
00039 #include "llsliderctrl.h"
00040 #include "llcheckboxctrl.h"
00041 #include "lltextbox.h"
00042 #include "llcallbacklist.h"
00043 #include "lllineeditor.h"
00044 #include "llfocusmgr.h"
00045 
00049 
00050 std::map<LLString, LLDebugVarMessageBox*> LLDebugVarMessageBox::sInstances;
00051 
00052 LLDebugVarMessageBox::LLDebugVarMessageBox(const std::string& title, EDebugVarType var_type, void *var) : 
00053         LLFloater("msg box", LLRect(10,160,400,10), title),
00054         mVarType(var_type), mVarData(var), mAnimate(FALSE)
00055 {
00056         switch(var_type)
00057         {
00058         case VAR_TYPE_F32:
00059           mSlider1 = new LLSliderCtrl("slider 1", LLRect(20,130,190,110), title, NULL, 70, 130, TRUE, TRUE, FALSE, NULL, NULL, *((F32*)var), -100.f, 100.f, 0.1f, NULL);
00060                 mSlider1->setPrecision(3);
00061                 addChild(mSlider1);
00062                 mSlider2 = NULL;
00063                 mSlider3 = NULL;
00064                 break;
00065         case VAR_TYPE_S32:
00066                 mSlider1 = new LLSliderCtrl("slider 1", LLRect(20,100,190,80), title, NULL, 70, 130, TRUE, TRUE, FALSE, NULL, NULL, (F32)*((S32*)var), -255.f, 255.f, 1.f, NULL);
00067                 mSlider1->setPrecision(0);
00068                 addChild(mSlider1);
00069                 mSlider2 = NULL;
00070                 mSlider3 = NULL;
00071                 break;
00072         case VAR_TYPE_VEC3:
00073                 mSlider1 = new LLSliderCtrl("slider 1", LLRect(20,130,190,110), "x: ", NULL, 70, 130, TRUE, TRUE, FALSE, NULL, NULL, ((LLVector3*)var)->mV[VX], -100.f, 100.f, 0.1f, NULL);
00074                 mSlider1->setPrecision(3);
00075                 mSlider2 = new LLSliderCtrl("slider 2", LLRect(20,100,190,80), "y: ", NULL, 70, 130, TRUE, TRUE, FALSE, NULL, NULL, ((LLVector3*)var)->mV[VY], -100.f, 100.f, 0.1f, NULL);
00076                 mSlider2->setPrecision(3);
00077                 mSlider3 = new LLSliderCtrl("slider 3", LLRect(20,70,190,50), "z: ", NULL, 70, 130, TRUE, TRUE, FALSE, NULL, NULL, ((LLVector3*)var)->mV[VZ], -100.f, 100.f, 0.1f, NULL);
00078                 mSlider3->setPrecision(3);
00079                 addChild(mSlider1);
00080                 addChild(mSlider2);
00081                 addChild(mSlider3);
00082                 break;
00083         default:
00084                 llwarns << "Unhandled var type " << var_type << llendl;
00085                 break;
00086         }
00087 
00088         mAnimateButton = new LLButton("Animate", LLRect(20, 45, 180, 25), "", onAnimateClicked, this);
00089         addChild(mAnimateButton);
00090 
00091         mText = new LLTextBox("value", LLRect(20,20,190,0));
00092         addChild(mText);
00093 
00094         //disable hitting enter closes dialog
00095         setDefaultBtn();
00096 }
00097 
00098 LLDebugVarMessageBox::~LLDebugVarMessageBox()
00099 {
00100         sInstances.erase(mTitle);
00101 }
00102 
00103 void LLDebugVarMessageBox::show(const std::string& title, F32 *var, F32 max_value, F32 increment)
00104 {
00105 #ifndef LL_RELEASE_FOR_DOWNLOAD
00106         LLDebugVarMessageBox* box = show(title, VAR_TYPE_F32, (void*)var);
00107         max_value = llabs(max_value);
00108         box->mSlider1->setMaxValue(max_value);
00109         box->mSlider1->setMinValue(-max_value);
00110         box->mSlider1->setIncrement(increment);
00111         if (!gFocusMgr.childHasKeyboardFocus(box))
00112         {
00113                 box->mSlider1->setValue(*var);
00114         }
00115         box->mSlider1->setCommitCallback(slider_changed);
00116         box->mSlider1->setCallbackUserData(box);
00117 #endif
00118 }
00119 
00120 void LLDebugVarMessageBox::show(const std::string& title, S32 *var, S32 max_value, S32 increment)
00121 {
00122 #ifndef LL_RELEASE_FOR_DOWNLOAD
00123         LLDebugVarMessageBox* box = show(title, VAR_TYPE_S32, (void*)var);
00124         F32 max_val = llabs((F32)max_value);
00125         box->mSlider1->setMaxValue(max_val);
00126         box->mSlider1->setMinValue(-max_val);
00127         box->mSlider1->setIncrement((F32)increment);
00128         if (!gFocusMgr.childHasKeyboardFocus(box))
00129         {
00130                 box->mSlider1->setValue((F32)*var);
00131         }
00132         box->mSlider1->setCommitCallback(slider_changed);
00133         box->mSlider1->setCallbackUserData(box);
00134 #endif
00135 }
00136 
00137 void LLDebugVarMessageBox::show(const std::string& title, LLVector3 *var, LLVector3 max_value, LLVector3 increment)
00138 {
00139 #ifndef LL_RELEASE_FOR_DOWNLOAD
00140         LLDebugVarMessageBox* box = show(title, VAR_TYPE_VEC3, (LLVector3*)var);
00141         max_value.abs();
00142         box->mSlider1->setMaxValue(max_value.mV[VX]);
00143         box->mSlider1->setMinValue(-max_value.mV[VX]);
00144         box->mSlider1->setIncrement(increment.mV[VX]);
00145         box->mSlider1->setCommitCallback(slider_changed);
00146         box->mSlider1->setCallbackUserData(box);
00147 
00148         box->mSlider2->setMaxValue(max_value.mV[VX]);
00149         box->mSlider2->setMinValue(-max_value.mV[VX]);
00150         box->mSlider2->setIncrement(increment.mV[VX]);
00151         box->mSlider2->setCommitCallback(slider_changed);
00152         box->mSlider2->setCallbackUserData(box);
00153 
00154         box->mSlider3->setMaxValue(max_value.mV[VX]);
00155         box->mSlider3->setMinValue(-max_value.mV[VX]);
00156         box->mSlider3->setIncrement(increment.mV[VX]);
00157         box->mSlider3->setCommitCallback(slider_changed);
00158         box->mSlider3->setCallbackUserData(box);
00159 #endif
00160 }
00161 
00162 LLDebugVarMessageBox* LLDebugVarMessageBox::show(const std::string& title, EDebugVarType var_type, void *var)
00163 {
00164         LLString title_string(title);
00165 
00166         LLDebugVarMessageBox *box = sInstances[title_string];
00167         if (!box)
00168         {
00169                 box = new LLDebugVarMessageBox(title, var_type, var);
00170                 sInstances[title_string] = box;
00171                 gFloaterView->addChild(box);
00172                 box->reshape(200,150);
00173                 box->open();             /*Flawfinder: ignore*/
00174                 box->mTitle = title_string;
00175         }
00176 
00177         return box;
00178 }
00179 
00180 void LLDebugVarMessageBox::slider_changed(LLUICtrl* ctrl, void* user_data)
00181 {
00182         LLDebugVarMessageBox *msg_box = (LLDebugVarMessageBox*)user_data;
00183         if (!msg_box || !msg_box->mVarData) return;
00184 
00185         switch(msg_box->mVarType)
00186         {
00187         case VAR_TYPE_F32:
00188                 *((F32*)msg_box->mVarData) = (F32)msg_box->mSlider1->getValue().asReal();
00189                 break;
00190         case VAR_TYPE_S32:
00191                 *((S32*)msg_box->mVarData) = (S32)msg_box->mSlider1->getValue().asInteger();
00192                 break;
00193         case VAR_TYPE_VEC3:
00194         {
00195                 LLVector3* vec_p = (LLVector3*)msg_box->mVarData;
00196                 vec_p->setVec((F32)msg_box->mSlider1->getValue().asReal(), 
00197                         (F32)msg_box->mSlider2->getValue().asReal(), 
00198                         (F32)msg_box->mSlider3->getValue().asReal());
00199                 break;
00200         }
00201         default:
00202                 llwarns << "Unhandled var type " << msg_box->mVarType << llendl;
00203                 break;
00204         }
00205 }
00206 
00207 void LLDebugVarMessageBox::onAnimateClicked(void* user_data)
00208 {
00209         LLDebugVarMessageBox* msg_boxp = (LLDebugVarMessageBox*)user_data;
00210         msg_boxp->mAnimate = !msg_boxp->mAnimate;
00211         msg_boxp->mAnimateButton->setToggleState(msg_boxp->mAnimate);
00212 }
00213 
00214 void LLDebugVarMessageBox::onClose(bool app_quitting)
00215 {
00216         setVisible(FALSE);
00217 }
00218 
00219 void LLDebugVarMessageBox::draw()
00220 {
00221         LLString text;
00222         switch(mVarType)
00223         {
00224           case VAR_TYPE_F32:
00225                 text = llformat("%.3f", *((F32*)mVarData));
00226                 break;
00227           case VAR_TYPE_S32:
00228                 text = llformat("%d", *((S32*)mVarData));
00229                 break;
00230           case VAR_TYPE_VEC3:
00231           {
00232                   LLVector3* vec_p = (LLVector3*)mVarData;
00233                   text= llformat("%.3f %.3f %.3f", vec_p->mV[VX], vec_p->mV[VY], vec_p->mV[VZ]);
00234                   break;
00235           }
00236           default:
00237                 llwarns << "Unhandled var type " << mVarType << llendl;
00238                 break;
00239         }
00240         mText->setText(text);
00241 
00242         if(mAnimate)
00243         {
00244                 if (mSlider1)
00245                 {
00246                         F32 animated_val = clamp_rescale(fmodf((F32)LLFrameTimer::getElapsedSeconds() / 5.f, 1.f), 0.f, 1.f, 0.f, mSlider1->getMaxValue());
00247                         mSlider1->setValue(animated_val);
00248                         slider_changed(mSlider1, this);
00249                         if (mSlider2)
00250                         {
00251                                 mSlider2->setValue(animated_val);
00252                                 slider_changed(mSlider2, this);
00253                         }
00254                         if (mSlider3)
00255                         {
00256                                 mSlider3->setValue(animated_val);
00257                                 slider_changed(mSlider3, this);
00258                         }
00259                 }
00260         }
00261         LLFloater::draw();
00262 }

Generated on Thu Jul 1 06:08:24 2010 for Second Life Viewer by  doxygen 1.4.7