PageRenderTime 61ms CodeModel.GetById 22ms RepoModel.GetById 1ms 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
Possible License(s): LGPL-2.1
  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. #include "llviewerprecompiledheaders.h"
  27. #include "llfloatersettingsdebug.h"
  28. #include "llfloater.h"
  29. #include "lluictrlfactory.h"
  30. //#include "llfirstuse.h"
  31. #include "llcombobox.h"
  32. #include "llspinctrl.h"
  33. #include "llcolorswatch.h"
  34. #include "llviewercontrol.h"
  35. #include "lltexteditor.h"
  36. LLFloaterSettingsDebug::LLFloaterSettingsDebug(const LLSD& key)
  37. : LLFloater(key)
  38. {
  39. mCommitCallbackRegistrar.add("SettingSelect", boost::bind(&LLFloaterSettingsDebug::onSettingSelect, this,_1));
  40. mCommitCallbackRegistrar.add("CommitSettings", boost::bind(&LLFloaterSettingsDebug::onCommitSettings, this));
  41. mCommitCallbackRegistrar.add("ClickDefault", boost::bind(&LLFloaterSettingsDebug::onClickDefault, this));
  42. }
  43. LLFloaterSettingsDebug::~LLFloaterSettingsDebug()
  44. {}
  45. BOOL LLFloaterSettingsDebug::postBuild()
  46. {
  47. LLComboBox* settings_combo = getChild<LLComboBox>("settings_combo");
  48. struct f : public LLControlGroup::ApplyFunctor
  49. {
  50. LLComboBox* combo;
  51. f(LLComboBox* c) : combo(c) {}
  52. virtual void apply(const std::string& name, LLControlVariable* control)
  53. {
  54. if (!control->isHiddenFromSettingsEditor())
  55. {
  56. combo->add(name, (void*)control);
  57. }
  58. }
  59. } func(settings_combo);
  60. std::string key = getKey().asString();
  61. if (key == "all" || key == "base")
  62. {
  63. gSavedSettings.applyToAll(&func);
  64. }
  65. if (key == "all" || key == "account")
  66. {
  67. gSavedPerAccountSettings.applyToAll(&func);
  68. }
  69. settings_combo->sortByName();
  70. settings_combo->updateSelection();
  71. mComment = getChild<LLTextEditor>("comment_text");
  72. return TRUE;
  73. }
  74. void LLFloaterSettingsDebug::draw()
  75. {
  76. LLComboBox* settings_combo = getChild<LLComboBox>("settings_combo");
  77. LLControlVariable* controlp = (LLControlVariable*)settings_combo->getCurrentUserdata();
  78. updateControl(controlp);
  79. LLFloater::draw();
  80. }
  81. //static
  82. void LLFloaterSettingsDebug::onSettingSelect(LLUICtrl* ctrl)
  83. {
  84. LLComboBox* combo_box = (LLComboBox*)ctrl;
  85. LLControlVariable* controlp = (LLControlVariable*)combo_box->getCurrentUserdata();
  86. updateControl(controlp);
  87. }
  88. void LLFloaterSettingsDebug::onCommitSettings()
  89. {
  90. LLComboBox* settings_combo = getChild<LLComboBox>("settings_combo");
  91. LLControlVariable* controlp = (LLControlVariable*)settings_combo->getCurrentUserdata();
  92. if (!controlp)
  93. {
  94. return;
  95. }
  96. LLVector3 vector;
  97. LLVector3d vectord;
  98. LLRect rect;
  99. LLColor4 col4;
  100. LLColor3 col3;
  101. LLColor4U col4U;
  102. LLColor4 color_with_alpha;
  103. switch(controlp->type())
  104. {
  105. case TYPE_U32:
  106. controlp->set(getChild<LLUICtrl>("val_spinner_1")->getValue());
  107. break;
  108. case TYPE_S32:
  109. controlp->set(getChild<LLUICtrl>("val_spinner_1")->getValue());
  110. break;
  111. case TYPE_F32:
  112. controlp->set(LLSD(getChild<LLUICtrl>("val_spinner_1")->getValue().asReal()));
  113. break;
  114. case TYPE_BOOLEAN:
  115. controlp->set(getChild<LLUICtrl>("boolean_combo")->getValue());
  116. break;
  117. case TYPE_STRING:
  118. controlp->set(LLSD(getChild<LLUICtrl>("val_text")->getValue().asString()));
  119. break;
  120. case TYPE_VEC3:
  121. vector.mV[VX] = (F32)getChild<LLUICtrl>("val_spinner_1")->getValue().asReal();
  122. vector.mV[VY] = (F32)getChild<LLUICtrl>("val_spinner_2")->getValue().asReal();
  123. vector.mV[VZ] = (F32)getChild<LLUICtrl>("val_spinner_3")->getValue().asReal();
  124. controlp->set(vector.getValue());
  125. break;
  126. case TYPE_VEC3D:
  127. vectord.mdV[VX] = getChild<LLUICtrl>("val_spinner_1")->getValue().asReal();
  128. vectord.mdV[VY] = getChild<LLUICtrl>("val_spinner_2")->getValue().asReal();
  129. vectord.mdV[VZ] = getChild<LLUICtrl>("val_spinner_3")->getValue().asReal();
  130. controlp->set(vectord.getValue());
  131. break;
  132. case TYPE_RECT:
  133. rect.mLeft = getChild<LLUICtrl>("val_spinner_1")->getValue().asInteger();
  134. rect.mRight = getChild<LLUICtrl>("val_spinner_2")->getValue().asInteger();
  135. rect.mBottom = getChild<LLUICtrl>("val_spinner_3")->getValue().asInteger();
  136. rect.mTop = getChild<LLUICtrl>("val_spinner_4")->getValue().asInteger();
  137. controlp->set(rect.getValue());
  138. break;
  139. case TYPE_COL4:
  140. col3.setValue(getChild<LLUICtrl>("val_color_swatch")->getValue());
  141. col4 = LLColor4(col3, (F32)getChild<LLUICtrl>("val_spinner_4")->getValue().asReal());
  142. controlp->set(col4.getValue());
  143. break;
  144. case TYPE_COL3:
  145. controlp->set(getChild<LLUICtrl>("val_color_swatch")->getValue());
  146. //col3.mV[VRED] = (F32)floaterp->getChild<LLUICtrl>("val_spinner_1")->getValue().asC();
  147. //col3.mV[VGREEN] = (F32)floaterp->getChild<LLUICtrl>("val_spinner_2")->getValue().asReal();
  148. //col3.mV[VBLUE] = (F32)floaterp->getChild<LLUICtrl>("val_spinner_3")->getValue().asReal();
  149. //controlp->set(col3.getValue());
  150. break;
  151. default:
  152. break;
  153. }
  154. }
  155. // static
  156. void LLFloaterSettingsDebug::onClickDefault()
  157. {
  158. LLComboBox* settings_combo = getChild<LLComboBox>("settings_combo");
  159. LLControlVariable* controlp = (LLControlVariable*)settings_combo->getCurrentUserdata();
  160. if (controlp)
  161. {
  162. controlp->resetToDefault(true);
  163. updateControl(controlp);
  164. }
  165. }
  166. // we've switched controls, or doing per-frame update, so update spinners, etc.
  167. void LLFloaterSettingsDebug::updateControl(LLControlVariable* controlp)
  168. {
  169. LLSpinCtrl* spinner1 = getChild<LLSpinCtrl>("val_spinner_1");
  170. LLSpinCtrl* spinner2 = getChild<LLSpinCtrl>("val_spinner_2");
  171. LLSpinCtrl* spinner3 = getChild<LLSpinCtrl>("val_spinner_3");
  172. LLSpinCtrl* spinner4 = getChild<LLSpinCtrl>("val_spinner_4");
  173. LLColorSwatchCtrl* color_swatch = getChild<LLColorSwatchCtrl>("val_color_swatch");
  174. if (!spinner1 || !spinner2 || !spinner3 || !spinner4 || !color_swatch)
  175. {
  176. llwarns << "Could not find all desired controls by name"
  177. << llendl;
  178. return;
  179. }
  180. spinner1->setVisible(FALSE);
  181. spinner2->setVisible(FALSE);
  182. spinner3->setVisible(FALSE);
  183. spinner4->setVisible(FALSE);
  184. color_swatch->setVisible(FALSE);
  185. getChildView("val_text")->setVisible( FALSE);
  186. mComment->setText(LLStringUtil::null);
  187. if (controlp)
  188. {
  189. eControlType type = controlp->type();
  190. //hide combo box only for non booleans, otherwise this will result in the combo box closing every frame
  191. getChildView("boolean_combo")->setVisible( type == TYPE_BOOLEAN);
  192. mComment->setText(controlp->getComment());
  193. spinner1->setMaxValue(F32_MAX);
  194. spinner2->setMaxValue(F32_MAX);
  195. spinner3->setMaxValue(F32_MAX);
  196. spinner4->setMaxValue(F32_MAX);
  197. spinner1->setMinValue(-F32_MAX);
  198. spinner2->setMinValue(-F32_MAX);
  199. spinner3->setMinValue(-F32_MAX);
  200. spinner4->setMinValue(-F32_MAX);
  201. if (!spinner1->hasFocus())
  202. {
  203. spinner1->setIncrement(0.1f);
  204. }
  205. if (!spinner2->hasFocus())
  206. {
  207. spinner2->setIncrement(0.1f);
  208. }
  209. if (!spinner3->hasFocus())
  210. {
  211. spinner3->setIncrement(0.1f);
  212. }
  213. if (!spinner4->hasFocus())
  214. {
  215. spinner4->setIncrement(0.1f);
  216. }
  217. LLSD sd = controlp->get();
  218. switch(type)
  219. {
  220. case TYPE_U32:
  221. spinner1->setVisible(TRUE);
  222. spinner1->setLabel(std::string("value")); // Debug, don't translate
  223. if (!spinner1->hasFocus())
  224. {
  225. spinner1->setValue(sd);
  226. spinner1->setMinValue((F32)U32_MIN);
  227. spinner1->setMaxValue((F32)U32_MAX);
  228. spinner1->setIncrement(1.f);
  229. spinner1->setPrecision(0);
  230. }
  231. break;
  232. case TYPE_S32:
  233. spinner1->setVisible(TRUE);
  234. spinner1->setLabel(std::string("value")); // Debug, don't translate
  235. if (!spinner1->hasFocus())
  236. {
  237. spinner1->setValue(sd);
  238. spinner1->setMinValue((F32)S32_MIN);
  239. spinner1->setMaxValue((F32)S32_MAX);
  240. spinner1->setIncrement(1.f);
  241. spinner1->setPrecision(0);
  242. }
  243. break;
  244. case TYPE_F32:
  245. spinner1->setVisible(TRUE);
  246. spinner1->setLabel(std::string("value")); // Debug, don't translate
  247. if (!spinner1->hasFocus())
  248. {
  249. spinner1->setPrecision(3);
  250. spinner1->setValue(sd);
  251. }
  252. break;
  253. case TYPE_BOOLEAN:
  254. if (!getChild<LLUICtrl>("boolean_combo")->hasFocus())
  255. {
  256. if (sd.asBoolean())
  257. {
  258. getChild<LLUICtrl>("boolean_combo")->setValue(LLSD("true"));
  259. }
  260. else
  261. {
  262. getChild<LLUICtrl>("boolean_combo")->setValue(LLSD(""));
  263. }
  264. }
  265. break;
  266. case TYPE_STRING:
  267. getChildView("val_text")->setVisible( TRUE);
  268. if (!getChild<LLUICtrl>("val_text")->hasFocus())
  269. {
  270. getChild<LLUICtrl>("val_text")->setValue(sd);
  271. }
  272. break;
  273. case TYPE_VEC3:
  274. {
  275. LLVector3 v;
  276. v.setValue(sd);
  277. spinner1->setVisible(TRUE);
  278. spinner1->setLabel(std::string("X"));
  279. spinner2->setVisible(TRUE);
  280. spinner2->setLabel(std::string("Y"));
  281. spinner3->setVisible(TRUE);
  282. spinner3->setLabel(std::string("Z"));
  283. if (!spinner1->hasFocus())
  284. {
  285. spinner1->setPrecision(3);
  286. spinner1->setValue(v[VX]);
  287. }
  288. if (!spinner2->hasFocus())
  289. {
  290. spinner2->setPrecision(3);
  291. spinner2->setValue(v[VY]);
  292. }
  293. if (!spinner3->hasFocus())
  294. {
  295. spinner3->setPrecision(3);
  296. spinner3->setValue(v[VZ]);
  297. }
  298. break;
  299. }
  300. case TYPE_VEC3D:
  301. {
  302. LLVector3d 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_RECT:
  328. {
  329. LLRect r;
  330. r.setValue(sd);
  331. spinner1->setVisible(TRUE);
  332. spinner1->setLabel(std::string("Left"));
  333. spinner2->setVisible(TRUE);
  334. spinner2->setLabel(std::string("Right"));
  335. spinner3->setVisible(TRUE);
  336. spinner3->setLabel(std::string("Bottom"));
  337. spinner4->setVisible(TRUE);
  338. spinner4->setLabel(std::string("Top"));
  339. if (!spinner1->hasFocus())
  340. {
  341. spinner1->setPrecision(0);
  342. spinner1->setValue(r.mLeft);
  343. }
  344. if (!spinner2->hasFocus())
  345. {
  346. spinner2->setPrecision(0);
  347. spinner2->setValue(r.mRight);
  348. }
  349. if (!spinner3->hasFocus())
  350. {
  351. spinner3->setPrecision(0);
  352. spinner3->setValue(r.mBottom);
  353. }
  354. if (!spinner4->hasFocus())
  355. {
  356. spinner4->setPrecision(0);
  357. spinner4->setValue(r.mTop);
  358. }
  359. spinner1->setMinValue((F32)S32_MIN);
  360. spinner1->setMaxValue((F32)S32_MAX);
  361. spinner1->setIncrement(1.f);
  362. spinner2->setMinValue((F32)S32_MIN);
  363. spinner2->setMaxValue((F32)S32_MAX);
  364. spinner2->setIncrement(1.f);
  365. spinner3->setMinValue((F32)S32_MIN);
  366. spinner3->setMaxValue((F32)S32_MAX);
  367. spinner3->setIncrement(1.f);
  368. spinner4->setMinValue((F32)S32_MIN);
  369. spinner4->setMaxValue((F32)S32_MAX);
  370. spinner4->setIncrement(1.f);
  371. break;
  372. }
  373. case TYPE_COL4:
  374. {
  375. LLColor4 clr;
  376. clr.setValue(sd);
  377. color_swatch->setVisible(TRUE);
  378. // only set if changed so color picker doesn't update
  379. if(clr != LLColor4(color_swatch->getValue()))
  380. {
  381. color_swatch->set(LLColor4(sd), TRUE, FALSE);
  382. }
  383. spinner4->setVisible(TRUE);
  384. spinner4->setLabel(std::string("Alpha"));
  385. if (!spinner4->hasFocus())
  386. {
  387. spinner4->setPrecision(3);
  388. spinner4->setMinValue(0.0);
  389. spinner4->setMaxValue(1.f);
  390. spinner4->setValue(clr.mV[VALPHA]);
  391. }
  392. break;
  393. }
  394. case TYPE_COL3:
  395. {
  396. LLColor3 clr;
  397. clr.setValue(sd);
  398. color_swatch->setVisible(TRUE);
  399. color_swatch->setValue(sd);
  400. break;
  401. }
  402. default:
  403. mComment->setText(std::string("unknown"));
  404. break;
  405. }
  406. }
  407. }