diff options
author | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
commit | 38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch) | |
tree | adca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/newview/lldebugmessagebox.cpp | |
parent | README.txt (diff) | |
download | meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2 meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz |
Second Life viewer sources 1.13.2.12
Diffstat (limited to 'linden/indra/newview/lldebugmessagebox.cpp')
-rw-r--r-- | linden/indra/newview/lldebugmessagebox.cpp | 245 |
1 files changed, 245 insertions, 0 deletions
diff --git a/linden/indra/newview/lldebugmessagebox.cpp b/linden/indra/newview/lldebugmessagebox.cpp new file mode 100644 index 0000000..46dffdf --- /dev/null +++ b/linden/indra/newview/lldebugmessagebox.cpp | |||
@@ -0,0 +1,245 @@ | |||
1 | /** | ||
2 | * @file lldebugmessagebox.cpp | ||
3 | * @brief Implementation of a simple, non-modal message box. | ||
4 | * | ||
5 | * Copyright (c) 2002-2007, Linden Research, Inc. | ||
6 | * | ||
7 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
8 | * to you under the terms of the GNU General Public License, version 2.0 | ||
9 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
10 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
11 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
12 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
13 | * | ||
14 | * There are special exceptions to the terms and conditions of the GPL as | ||
15 | * it is applied to this Source Code. View the full text of the exception | ||
16 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
17 | * online at http://secondlife.com/developers/opensource/flossexception | ||
18 | * | ||
19 | * By copying, modifying or distributing this software, you acknowledge | ||
20 | * that you have read and understood your obligations described above, | ||
21 | * and agree to abide by those obligations. | ||
22 | * | ||
23 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
24 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
25 | * COMPLETENESS OR PERFORMANCE. | ||
26 | */ | ||
27 | |||
28 | #include "llviewerprecompiledheaders.h" | ||
29 | |||
30 | #include "lldebugmessagebox.h" | ||
31 | |||
32 | #include "llresmgr.h" | ||
33 | #include "llfontgl.h" | ||
34 | #include "llbutton.h" | ||
35 | #include "llsliderctrl.h" | ||
36 | #include "llcheckboxctrl.h" | ||
37 | #include "lltextbox.h" | ||
38 | #include "llcallbacklist.h" | ||
39 | #include "lllineeditor.h" | ||
40 | #include "llfocusmgr.h" | ||
41 | |||
42 | ///---------------------------------------------------------------------------- | ||
43 | /// Class LLDebugVarMessageBox | ||
44 | ///---------------------------------------------------------------------------- | ||
45 | |||
46 | std::map<LLString, LLDebugVarMessageBox*> LLDebugVarMessageBox::sInstances; | ||
47 | |||
48 | LLDebugVarMessageBox::LLDebugVarMessageBox(const std::string& title, EDebugVarType var_type, void *var) : | ||
49 | LLFloater("msg box", LLRect(10,160,400,10), title), | ||
50 | mVarType(var_type), mVarData(var), mAnimate(FALSE) | ||
51 | { | ||
52 | switch(var_type) | ||
53 | { | ||
54 | case VAR_TYPE_F32: | ||
55 | mSlider1 = new LLSliderCtrl("slider 1", LLRect(20,130,190,110), title, NULL, 70, 130, TRUE, TRUE, NULL, NULL, *((F32*)var), -100.f, 100.f, 0.1f, NULL); | ||
56 | mSlider1->setPrecision(3); | ||
57 | addChild(mSlider1); | ||
58 | mSlider2 = NULL; | ||
59 | mSlider3 = NULL; | ||
60 | break; | ||
61 | case VAR_TYPE_S32: | ||
62 | mSlider1 = new LLSliderCtrl("slider 1", LLRect(20,100,190,80), title, NULL, 70, 130, TRUE, TRUE, NULL, NULL, (F32)*((S32*)var), -255.f, 255.f, 1.f, NULL); | ||
63 | mSlider1->setPrecision(0); | ||
64 | addChild(mSlider1); | ||
65 | mSlider2 = NULL; | ||
66 | mSlider3 = NULL; | ||
67 | break; | ||
68 | case VAR_TYPE_VEC3: | ||
69 | mSlider1 = new LLSliderCtrl("slider 1", LLRect(20,130,190,110), "x: ", NULL, 70, 130, TRUE, TRUE, NULL, NULL, ((LLVector3*)var)->mV[VX], -100.f, 100.f, 0.1f, NULL); | ||
70 | mSlider1->setPrecision(3); | ||
71 | mSlider2 = new LLSliderCtrl("slider 2", LLRect(20,100,190,80), "y: ", NULL, 70, 130, TRUE, TRUE, NULL, NULL, ((LLVector3*)var)->mV[VY], -100.f, 100.f, 0.1f, NULL); | ||
72 | mSlider2->setPrecision(3); | ||
73 | mSlider3 = new LLSliderCtrl("slider 3", LLRect(20,70,190,50), "z: ", NULL, 70, 130, TRUE, TRUE, NULL, NULL, ((LLVector3*)var)->mV[VZ], -100.f, 100.f, 0.1f, NULL); | ||
74 | mSlider3->setPrecision(3); | ||
75 | addChild(mSlider1); | ||
76 | addChild(mSlider2); | ||
77 | addChild(mSlider3); | ||
78 | break; | ||
79 | } | ||
80 | |||
81 | mAnimateButton = new LLButton("Animate", LLRect(20, 45, 180, 25), "", onAnimateClicked, this); | ||
82 | addChild(mAnimateButton); | ||
83 | |||
84 | mText = new LLTextBox("value", LLRect(20,20,190,0)); | ||
85 | addChild(mText); | ||
86 | |||
87 | //disable hitting enter closes dialog | ||
88 | setDefaultBtn(); | ||
89 | } | ||
90 | |||
91 | LLDebugVarMessageBox::~LLDebugVarMessageBox() | ||
92 | { | ||
93 | sInstances.erase(mTitle); | ||
94 | } | ||
95 | |||
96 | void LLDebugVarMessageBox::show(const std::string& title, F32 *var, F32 max_value, F32 increment) | ||
97 | { | ||
98 | #ifndef LL_RELEASE_FOR_DOWNLOAD | ||
99 | LLDebugVarMessageBox* box = show(title, VAR_TYPE_F32, (void*)var); | ||
100 | max_value = llabs(max_value); | ||
101 | box->mSlider1->setMaxValue(max_value); | ||
102 | box->mSlider1->setMinValue(-max_value); | ||
103 | box->mSlider1->setIncrement(increment); | ||
104 | if (!gFocusMgr.childHasKeyboardFocus(box)) | ||
105 | { | ||
106 | box->mSlider1->setValue(*var); | ||
107 | } | ||
108 | box->mSlider1->setCommitCallback(slider_changed); | ||
109 | box->mSlider1->setCallbackUserData(box); | ||
110 | #endif | ||
111 | } | ||
112 | |||
113 | void LLDebugVarMessageBox::show(const std::string& title, S32 *var, S32 max_value, S32 increment) | ||
114 | { | ||
115 | #ifndef LL_RELEASE_FOR_DOWNLOAD | ||
116 | LLDebugVarMessageBox* box = show(title, VAR_TYPE_S32, (void*)var); | ||
117 | F32 max_val = llabs((F32)max_value); | ||
118 | box->mSlider1->setMaxValue(max_val); | ||
119 | box->mSlider1->setMinValue(-max_val); | ||
120 | box->mSlider1->setIncrement((F32)increment); | ||
121 | if (!gFocusMgr.childHasKeyboardFocus(box)) | ||
122 | { | ||
123 | box->mSlider1->setValue((F32)*var); | ||
124 | } | ||
125 | box->mSlider1->setCommitCallback(slider_changed); | ||
126 | box->mSlider1->setCallbackUserData(box); | ||
127 | #endif | ||
128 | } | ||
129 | |||
130 | void LLDebugVarMessageBox::show(const std::string& title, LLVector3 *var, LLVector3 max_value, LLVector3 increment) | ||
131 | { | ||
132 | #ifndef LL_RELEASE_FOR_DOWNLOAD | ||
133 | LLDebugVarMessageBox* box = show(title, VAR_TYPE_VEC3, (LLVector3*)var); | ||
134 | max_value.abs(); | ||
135 | box->mSlider1->setMaxValue(max_value.mV[VX]); | ||
136 | box->mSlider1->setMinValue(-max_value.mV[VX]); | ||
137 | box->mSlider1->setIncrement(increment.mV[VX]); | ||
138 | box->mSlider1->setCommitCallback(slider_changed); | ||
139 | box->mSlider1->setCallbackUserData(box); | ||
140 | |||
141 | box->mSlider2->setMaxValue(max_value.mV[VX]); | ||
142 | box->mSlider2->setMinValue(-max_value.mV[VX]); | ||
143 | box->mSlider2->setIncrement(increment.mV[VX]); | ||
144 | box->mSlider2->setCommitCallback(slider_changed); | ||
145 | box->mSlider2->setCallbackUserData(box); | ||
146 | |||
147 | box->mSlider3->setMaxValue(max_value.mV[VX]); | ||
148 | box->mSlider3->setMinValue(-max_value.mV[VX]); | ||
149 | box->mSlider3->setIncrement(increment.mV[VX]); | ||
150 | box->mSlider3->setCommitCallback(slider_changed); | ||
151 | box->mSlider3->setCallbackUserData(box); | ||
152 | #endif | ||
153 | } | ||
154 | |||
155 | LLDebugVarMessageBox* LLDebugVarMessageBox::show(const std::string& title, EDebugVarType var_type, void *var) | ||
156 | { | ||
157 | LLString title_string(title); | ||
158 | |||
159 | LLDebugVarMessageBox *box = sInstances[title_string]; | ||
160 | if (!box) | ||
161 | { | ||
162 | box = new LLDebugVarMessageBox(title, var_type, var); | ||
163 | sInstances[title_string] = box; | ||
164 | gFloaterView->addChild(box); | ||
165 | box->reshape(200,150); | ||
166 | box->open(); | ||
167 | box->mTitle = title_string; | ||
168 | } | ||
169 | |||
170 | return box; | ||
171 | } | ||
172 | |||
173 | void LLDebugVarMessageBox::slider_changed(LLUICtrl* ctrl, void* user_data) | ||
174 | { | ||
175 | LLDebugVarMessageBox *msg_box = (LLDebugVarMessageBox*)user_data; | ||
176 | if (!msg_box || !msg_box->mVarData) return; | ||
177 | |||
178 | switch(msg_box->mVarType) | ||
179 | { | ||
180 | case VAR_TYPE_F32: | ||
181 | *((F32*)msg_box->mVarData) = (F32)msg_box->mSlider1->getValue().asReal(); | ||
182 | break; | ||
183 | case VAR_TYPE_S32: | ||
184 | *((S32*)msg_box->mVarData) = (S32)msg_box->mSlider1->getValue().asInteger(); | ||
185 | break; | ||
186 | case VAR_TYPE_VEC3: | ||
187 | LLVector3* vec_p = (LLVector3*)msg_box->mVarData; | ||
188 | vec_p->setVec((F32)msg_box->mSlider1->getValue().asReal(), | ||
189 | (F32)msg_box->mSlider2->getValue().asReal(), | ||
190 | (F32)msg_box->mSlider3->getValue().asReal()); | ||
191 | break; | ||
192 | } | ||
193 | } | ||
194 | |||
195 | void LLDebugVarMessageBox::onAnimateClicked(void* user_data) | ||
196 | { | ||
197 | LLDebugVarMessageBox* msg_boxp = (LLDebugVarMessageBox*)user_data; | ||
198 | msg_boxp->mAnimate = !msg_boxp->mAnimate; | ||
199 | msg_boxp->mAnimateButton->setToggleState(msg_boxp->mAnimate); | ||
200 | } | ||
201 | |||
202 | void LLDebugVarMessageBox::onClose(bool app_quitting) | ||
203 | { | ||
204 | setVisible(FALSE); | ||
205 | } | ||
206 | |||
207 | void LLDebugVarMessageBox::draw() | ||
208 | { | ||
209 | char text[128]; | ||
210 | switch(mVarType) | ||
211 | { | ||
212 | case VAR_TYPE_F32: | ||
213 | sprintf(text, "%.3f", *((F32*)mVarData)); | ||
214 | break; | ||
215 | case VAR_TYPE_S32: | ||
216 | sprintf(text, "%d", *((S32*)mVarData)); | ||
217 | break; | ||
218 | case VAR_TYPE_VEC3: | ||
219 | LLVector3* vec_p = (LLVector3*)mVarData; | ||
220 | sprintf(text, "%.3f %.3f %.3f", vec_p->mV[VX], vec_p->mV[VY], vec_p->mV[VZ]); | ||
221 | break; | ||
222 | } | ||
223 | mText->setText(text); | ||
224 | |||
225 | if(mAnimate) | ||
226 | { | ||
227 | F32 animated_val = clamp_rescale(fmodf((F32)LLFrameTimer::getElapsedSeconds() / 5.f, 1.f), 0.f, 1.f, 0.f, mSlider1->getMaxValue()); | ||
228 | if (mSlider1) | ||
229 | { | ||
230 | mSlider1->setValue(animated_val); | ||
231 | slider_changed(mSlider1, this); | ||
232 | } | ||
233 | if (mSlider2) | ||
234 | { | ||
235 | mSlider2->setValue(animated_val); | ||
236 | slider_changed(mSlider2, this); | ||
237 | } | ||
238 | if (mSlider3) | ||
239 | { | ||
240 | mSlider3->setValue(animated_val); | ||
241 | slider_changed(mSlider3, this); | ||
242 | } | ||
243 | } | ||
244 | LLFloater::draw(); | ||
245 | } | ||