PageRenderTime 687ms CodeModel.GetById 152ms app.highlight 376ms RepoModel.GetById 145ms app.codeStats 0ms

/indra/newview/llfloatersettingsdebug.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 439 lines | 372 code | 32 blank | 35 comment | 41 complexity | 61e267d8c9c97026ee2025bb3dd8157b MD5 | raw file
  1/** 
  2 * @file llfloatersettingsdebug.cpp
  3 * @brief floater for debugging internal viewer settings
  4 *
  5 * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#include "llviewerprecompiledheaders.h"
 28#include "llfloatersettingsdebug.h"
 29#include "llfloater.h"
 30#include "lluictrlfactory.h"
 31//#include "llfirstuse.h"
 32#include "llcombobox.h"
 33#include "llspinctrl.h"
 34#include "llcolorswatch.h"
 35#include "llviewercontrol.h"
 36#include "lltexteditor.h"
 37
 38
 39LLFloaterSettingsDebug::LLFloaterSettingsDebug(const LLSD& key) 
 40:	LLFloater(key)
 41{
 42	mCommitCallbackRegistrar.add("SettingSelect",	boost::bind(&LLFloaterSettingsDebug::onSettingSelect, this,_1));
 43	mCommitCallbackRegistrar.add("CommitSettings",	boost::bind(&LLFloaterSettingsDebug::onCommitSettings, this));
 44	mCommitCallbackRegistrar.add("ClickDefault",	boost::bind(&LLFloaterSettingsDebug::onClickDefault, this));
 45
 46}
 47
 48LLFloaterSettingsDebug::~LLFloaterSettingsDebug()
 49{}
 50
 51BOOL LLFloaterSettingsDebug::postBuild()
 52{
 53	LLComboBox* settings_combo = getChild<LLComboBox>("settings_combo");
 54
 55	struct f : public LLControlGroup::ApplyFunctor
 56	{
 57		LLComboBox* combo;
 58		f(LLComboBox* c) : combo(c) {}
 59		virtual void apply(const std::string& name, LLControlVariable* control)
 60		{
 61			if (!control->isHiddenFromSettingsEditor())
 62			{
 63				combo->add(name, (void*)control);
 64			}
 65		}
 66	} func(settings_combo);
 67
 68	std::string key = getKey().asString();
 69	if (key == "all" || key == "base")
 70	{
 71		gSavedSettings.applyToAll(&func);
 72	}
 73	if (key == "all" || key == "account")
 74	{
 75		gSavedPerAccountSettings.applyToAll(&func);
 76	}
 77
 78	settings_combo->sortByName();
 79	settings_combo->updateSelection();
 80	mComment = getChild<LLTextEditor>("comment_text");
 81	return TRUE;
 82}
 83
 84void LLFloaterSettingsDebug::draw()
 85{
 86	LLComboBox* settings_combo = getChild<LLComboBox>("settings_combo");
 87	LLControlVariable* controlp = (LLControlVariable*)settings_combo->getCurrentUserdata();
 88	updateControl(controlp);
 89
 90	LLFloater::draw();
 91}
 92
 93//static 
 94void LLFloaterSettingsDebug::onSettingSelect(LLUICtrl* ctrl)
 95{
 96	LLComboBox* combo_box = (LLComboBox*)ctrl;
 97	LLControlVariable* controlp = (LLControlVariable*)combo_box->getCurrentUserdata();
 98
 99	updateControl(controlp);
100}
101
102void LLFloaterSettingsDebug::onCommitSettings()
103{
104	LLComboBox* settings_combo = getChild<LLComboBox>("settings_combo");
105	LLControlVariable* controlp = (LLControlVariable*)settings_combo->getCurrentUserdata();
106
107	if (!controlp)
108	{
109		return;
110	}
111
112	LLVector3 vector;
113	LLVector3d vectord;
114	LLRect rect;
115	LLColor4 col4;
116	LLColor3 col3;
117	LLColor4U col4U;
118	LLColor4 color_with_alpha;
119
120	switch(controlp->type())
121	{		
122	  case TYPE_U32:
123		controlp->set(getChild<LLUICtrl>("val_spinner_1")->getValue());
124		break;
125	  case TYPE_S32:
126		controlp->set(getChild<LLUICtrl>("val_spinner_1")->getValue());
127		break;
128	  case TYPE_F32:
129		controlp->set(LLSD(getChild<LLUICtrl>("val_spinner_1")->getValue().asReal()));
130		break;
131	  case TYPE_BOOLEAN:
132		controlp->set(getChild<LLUICtrl>("boolean_combo")->getValue());
133		break;
134	  case TYPE_STRING:
135		controlp->set(LLSD(getChild<LLUICtrl>("val_text")->getValue().asString()));
136		break;
137	  case TYPE_VEC3:
138		vector.mV[VX] = (F32)getChild<LLUICtrl>("val_spinner_1")->getValue().asReal();
139		vector.mV[VY] = (F32)getChild<LLUICtrl>("val_spinner_2")->getValue().asReal();
140		vector.mV[VZ] = (F32)getChild<LLUICtrl>("val_spinner_3")->getValue().asReal();
141		controlp->set(vector.getValue());
142		break;
143	  case TYPE_VEC3D:
144		vectord.mdV[VX] = getChild<LLUICtrl>("val_spinner_1")->getValue().asReal();
145		vectord.mdV[VY] = getChild<LLUICtrl>("val_spinner_2")->getValue().asReal();
146		vectord.mdV[VZ] = getChild<LLUICtrl>("val_spinner_3")->getValue().asReal();
147		controlp->set(vectord.getValue());
148		break;
149	  case TYPE_RECT:
150		rect.mLeft = getChild<LLUICtrl>("val_spinner_1")->getValue().asInteger();
151		rect.mRight = getChild<LLUICtrl>("val_spinner_2")->getValue().asInteger();
152		rect.mBottom = getChild<LLUICtrl>("val_spinner_3")->getValue().asInteger();
153		rect.mTop = getChild<LLUICtrl>("val_spinner_4")->getValue().asInteger();
154		controlp->set(rect.getValue());
155		break;
156	  case TYPE_COL4:
157		col3.setValue(getChild<LLUICtrl>("val_color_swatch")->getValue());
158		col4 = LLColor4(col3, (F32)getChild<LLUICtrl>("val_spinner_4")->getValue().asReal());
159		controlp->set(col4.getValue());
160		break;
161	  case TYPE_COL3:
162		controlp->set(getChild<LLUICtrl>("val_color_swatch")->getValue());
163		//col3.mV[VRED] = (F32)floaterp->getChild<LLUICtrl>("val_spinner_1")->getValue().asC();
164		//col3.mV[VGREEN] = (F32)floaterp->getChild<LLUICtrl>("val_spinner_2")->getValue().asReal();
165		//col3.mV[VBLUE] = (F32)floaterp->getChild<LLUICtrl>("val_spinner_3")->getValue().asReal();
166		//controlp->set(col3.getValue());
167		break;
168	  default:
169		break;
170	}
171}
172
173// static
174void LLFloaterSettingsDebug::onClickDefault()
175{
176	LLComboBox* settings_combo = getChild<LLComboBox>("settings_combo");
177	LLControlVariable* controlp = (LLControlVariable*)settings_combo->getCurrentUserdata();
178
179	if (controlp)
180	{
181		controlp->resetToDefault(true);
182		updateControl(controlp);
183	}
184}
185
186// we've switched controls, or doing per-frame update, so update spinners, etc.
187void LLFloaterSettingsDebug::updateControl(LLControlVariable* controlp)
188{
189	LLSpinCtrl* spinner1 = getChild<LLSpinCtrl>("val_spinner_1");
190	LLSpinCtrl* spinner2 = getChild<LLSpinCtrl>("val_spinner_2");
191	LLSpinCtrl* spinner3 = getChild<LLSpinCtrl>("val_spinner_3");
192	LLSpinCtrl* spinner4 = getChild<LLSpinCtrl>("val_spinner_4");
193	LLColorSwatchCtrl* color_swatch = getChild<LLColorSwatchCtrl>("val_color_swatch");
194
195	if (!spinner1 || !spinner2 || !spinner3 || !spinner4 || !color_swatch)
196	{
197		llwarns << "Could not find all desired controls by name"
198			<< llendl;
199		return;
200	}
201
202	spinner1->setVisible(FALSE);
203	spinner2->setVisible(FALSE);
204	spinner3->setVisible(FALSE);
205	spinner4->setVisible(FALSE);
206	color_swatch->setVisible(FALSE);
207	getChildView("val_text")->setVisible( FALSE);
208	mComment->setText(LLStringUtil::null);
209
210	if (controlp)
211	{
212		eControlType type = controlp->type();
213
214		//hide combo box only for non booleans, otherwise this will result in the combo box closing every frame
215		getChildView("boolean_combo")->setVisible( type == TYPE_BOOLEAN);
216		
217
218		mComment->setText(controlp->getComment());
219		spinner1->setMaxValue(F32_MAX);
220		spinner2->setMaxValue(F32_MAX);
221		spinner3->setMaxValue(F32_MAX);
222		spinner4->setMaxValue(F32_MAX);
223		spinner1->setMinValue(-F32_MAX);
224		spinner2->setMinValue(-F32_MAX);
225		spinner3->setMinValue(-F32_MAX);
226		spinner4->setMinValue(-F32_MAX);
227		if (!spinner1->hasFocus())
228		{
229			spinner1->setIncrement(0.1f);
230		}
231		if (!spinner2->hasFocus())
232		{
233			spinner2->setIncrement(0.1f);
234		}
235		if (!spinner3->hasFocus())
236		{
237			spinner3->setIncrement(0.1f);
238		}
239		if (!spinner4->hasFocus())
240		{
241			spinner4->setIncrement(0.1f);
242		}
243
244		LLSD sd = controlp->get();
245		switch(type)
246		{
247		  case TYPE_U32:
248			spinner1->setVisible(TRUE);
249			spinner1->setLabel(std::string("value")); // Debug, don't translate
250			if (!spinner1->hasFocus())
251			{
252				spinner1->setValue(sd);
253				spinner1->setMinValue((F32)U32_MIN);
254				spinner1->setMaxValue((F32)U32_MAX);
255				spinner1->setIncrement(1.f);
256				spinner1->setPrecision(0);
257			}
258			break;
259		  case TYPE_S32:
260			spinner1->setVisible(TRUE);
261			spinner1->setLabel(std::string("value")); // Debug, don't translate
262			if (!spinner1->hasFocus())
263			{
264				spinner1->setValue(sd);
265				spinner1->setMinValue((F32)S32_MIN);
266				spinner1->setMaxValue((F32)S32_MAX);
267				spinner1->setIncrement(1.f);
268				spinner1->setPrecision(0);
269			}
270			break;
271		  case TYPE_F32:
272			spinner1->setVisible(TRUE);
273			spinner1->setLabel(std::string("value")); // Debug, don't translate
274			if (!spinner1->hasFocus())
275			{
276				spinner1->setPrecision(3);
277				spinner1->setValue(sd);
278			}
279			break;
280		  case TYPE_BOOLEAN:
281			if (!getChild<LLUICtrl>("boolean_combo")->hasFocus())
282			{
283				if (sd.asBoolean())
284				{
285					getChild<LLUICtrl>("boolean_combo")->setValue(LLSD("true"));
286				}
287				else
288				{
289					getChild<LLUICtrl>("boolean_combo")->setValue(LLSD(""));
290				}
291			}
292			break;
293		  case TYPE_STRING:
294			getChildView("val_text")->setVisible( TRUE);
295			if (!getChild<LLUICtrl>("val_text")->hasFocus())
296			{
297				getChild<LLUICtrl>("val_text")->setValue(sd);
298			}
299			break;
300		  case TYPE_VEC3:
301		  {
302			LLVector3 v;
303			v.setValue(sd);
304			spinner1->setVisible(TRUE);
305			spinner1->setLabel(std::string("X"));
306			spinner2->setVisible(TRUE);
307			spinner2->setLabel(std::string("Y"));
308			spinner3->setVisible(TRUE);
309			spinner3->setLabel(std::string("Z"));
310			if (!spinner1->hasFocus())
311			{
312				spinner1->setPrecision(3);
313				spinner1->setValue(v[VX]);
314			}
315			if (!spinner2->hasFocus())
316			{
317				spinner2->setPrecision(3);
318				spinner2->setValue(v[VY]);
319			}
320			if (!spinner3->hasFocus())
321			{
322				spinner3->setPrecision(3);
323				spinner3->setValue(v[VZ]);
324			}
325			break;
326		  }
327		  case TYPE_VEC3D:
328		  {
329			LLVector3d v;
330			v.setValue(sd);
331			spinner1->setVisible(TRUE);
332			spinner1->setLabel(std::string("X"));
333			spinner2->setVisible(TRUE);
334			spinner2->setLabel(std::string("Y"));
335			spinner3->setVisible(TRUE);
336			spinner3->setLabel(std::string("Z"));
337			if (!spinner1->hasFocus())
338			{
339				spinner1->setPrecision(3);
340				spinner1->setValue(v[VX]);
341			}
342			if (!spinner2->hasFocus())
343			{
344				spinner2->setPrecision(3);
345				spinner2->setValue(v[VY]);
346			}
347			if (!spinner3->hasFocus())
348			{
349				spinner3->setPrecision(3);
350				spinner3->setValue(v[VZ]);
351			}
352			break;
353		  }
354		  case TYPE_RECT:
355		  {
356			LLRect r;
357			r.setValue(sd);
358			spinner1->setVisible(TRUE);
359			spinner1->setLabel(std::string("Left"));
360			spinner2->setVisible(TRUE);
361			spinner2->setLabel(std::string("Right"));
362			spinner3->setVisible(TRUE);
363			spinner3->setLabel(std::string("Bottom"));
364			spinner4->setVisible(TRUE);
365			spinner4->setLabel(std::string("Top"));
366			if (!spinner1->hasFocus())
367			{
368				spinner1->setPrecision(0);
369				spinner1->setValue(r.mLeft);
370			}
371			if (!spinner2->hasFocus())
372			{
373				spinner2->setPrecision(0);
374				spinner2->setValue(r.mRight);
375			}
376			if (!spinner3->hasFocus())
377			{
378				spinner3->setPrecision(0);
379				spinner3->setValue(r.mBottom);
380			}
381			if (!spinner4->hasFocus())
382			{
383				spinner4->setPrecision(0);
384				spinner4->setValue(r.mTop);
385			}
386
387			spinner1->setMinValue((F32)S32_MIN);
388			spinner1->setMaxValue((F32)S32_MAX);
389			spinner1->setIncrement(1.f);
390
391			spinner2->setMinValue((F32)S32_MIN);
392			spinner2->setMaxValue((F32)S32_MAX);
393			spinner2->setIncrement(1.f);
394
395			spinner3->setMinValue((F32)S32_MIN);
396			spinner3->setMaxValue((F32)S32_MAX);
397			spinner3->setIncrement(1.f);
398
399			spinner4->setMinValue((F32)S32_MIN);
400			spinner4->setMaxValue((F32)S32_MAX);
401			spinner4->setIncrement(1.f);
402			break;
403		  }
404		  case TYPE_COL4:
405		  {
406			LLColor4 clr;
407			clr.setValue(sd);
408			color_swatch->setVisible(TRUE);
409			// only set if changed so color picker doesn't update
410			if(clr != LLColor4(color_swatch->getValue()))
411			{
412				color_swatch->set(LLColor4(sd), TRUE, FALSE);
413			}
414			spinner4->setVisible(TRUE);
415			spinner4->setLabel(std::string("Alpha"));
416			if (!spinner4->hasFocus())
417			{
418				spinner4->setPrecision(3);
419				spinner4->setMinValue(0.0);
420				spinner4->setMaxValue(1.f);
421				spinner4->setValue(clr.mV[VALPHA]);
422			}
423			break;
424		  }
425		  case TYPE_COL3:
426		  {
427			LLColor3 clr;
428			clr.setValue(sd);
429			color_swatch->setVisible(TRUE);
430			color_swatch->setValue(sd);
431			break;
432		  }
433		  default:
434			mComment->setText(std::string("unknown"));
435			break;
436		}
437	}
438
439}