llfloaterdebugsettings.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  1. /**
  2. * @file llfloaterdebugsettings.cpp
  3. * @brief floater for debugging internal viewer settings
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #include "llviewerprecompiledheaders.h"
  33. #include "llfloaterdebugsettings.h"
  34. #include "llcombobox.h"
  35. #include "lllineeditor.h"
  36. #include "llspinctrl.h"
  37. #include "lltexteditor.h"
  38. #include "lluictrlfactory.h"
  39. #include "llcolorswatch.h"
  40. //MK
  41. #include "mkrlinterface.h"
  42. //mk
  43. #include "llviewercontrol.h"
  44. LLFloaterDebugSettings::LLFloaterDebugSettings(const LLSD&)
  45. {
  46. LLUICtrlFactory::getInstance()->buildFloater(this,
  47. "floater_settings_debug.xml");
  48. }
  49. bool LLFloaterDebugSettings::postBuild()
  50. {
  51. mComboNames = getChild<LLComboBox>("settings_combo");
  52. struct f final : public LLControlGroup::ApplyFunctor
  53. {
  54. LLComboBox* combo;
  55. f(LLComboBox* c) : combo(c) {}
  56. void apply(const std::string& name, LLControlVariable* ctrl) override
  57. {
  58. if (!ctrl->isHiddenFromUser())
  59. {
  60. combo->add(name, (void*)ctrl);
  61. }
  62. }
  63. } func(mComboNames);
  64. gSavedSettings.applyToAll(&func);
  65. gSavedPerAccountSettings.applyToAll(&func);
  66. gColors.applyToAll(&func);
  67. mComboNames->sortByName();
  68. mComboNames->setCommitCallback(onSettingSelect);
  69. mComboNames->setCallbackUserData(this);
  70. mComboNames->selectFirstItem();
  71. childSetCommitCallback("val_spinner_1", onCommitSettings);
  72. childSetUserData("val_spinner_1", this);
  73. childSetCommitCallback("val_spinner_2", onCommitSettings);
  74. childSetUserData("val_spinner_2", this);
  75. childSetCommitCallback("val_spinner_3", onCommitSettings);
  76. childSetUserData("val_spinner_3", this);
  77. childSetCommitCallback("val_spinner_4", onCommitSettings);
  78. childSetUserData("val_spinner_4", this);
  79. childSetCommitCallback("val_text", onCommitSettings);
  80. childSetUserData("val_text", this);
  81. childSetCommitCallback("boolean_combo", onCommitSettings);
  82. childSetUserData("boolean_combo", this);
  83. childSetCommitCallback("color_swatch", onCommitSettings);
  84. childSetUserData("color_swatch", this);
  85. childSetAction("default_btn", onClickDefault, this);
  86. mComment = getChild<LLTextEditor>("comment_text");
  87. LLSearchEditor* search = getChild<LLSearchEditor>("control_search");
  88. search->setSearchCallback(onSearchEdit, this);
  89. return true;
  90. }
  91. void LLFloaterDebugSettings::draw()
  92. {
  93. updateControl((LLControlVariable*)mComboNames->getCurrentUserdata());
  94. LLFloater::draw();
  95. }
  96. //static
  97. void LLFloaterDebugSettings::onSettingSelect(LLUICtrl* ctrl, void* user_data)
  98. {
  99. LLFloaterDebugSettings* self = (LLFloaterDebugSettings*)user_data;
  100. LLComboBox* combo_box = (LLComboBox*)ctrl;
  101. if (self && ctrl)
  102. {
  103. LLControlVariable* controlp;
  104. controlp = (LLControlVariable*)combo_box->getCurrentUserdata();
  105. self->updateControl(controlp);
  106. }
  107. }
  108. //static
  109. void LLFloaterDebugSettings::onSearchEdit(const std::string& search_string,
  110. void* user_data)
  111. {
  112. static std::string filter;
  113. LLFloaterDebugSettings* self = (LLFloaterDebugSettings*)user_data;
  114. if (!self) return;
  115. filter = search_string;
  116. LLStringUtil::trim(filter);
  117. LLStringUtil::toLower(filter);
  118. struct f final : public LLControlGroup::ApplyFunctor
  119. {
  120. LLComboBox* combo;
  121. f(LLComboBox* c)
  122. : combo(c)
  123. {
  124. }
  125. void apply(const std::string& name, LLControlVariable* ctrl) override
  126. {
  127. if (!ctrl->isHiddenFromUser())
  128. {
  129. std::string setting_name = name;
  130. LLStringUtil::toLower(setting_name);
  131. if (filter.empty() ||
  132. setting_name.find(filter) != std::string::npos)
  133. {
  134. combo->add(name, (void*)ctrl);
  135. }
  136. }
  137. }
  138. } func(self->mComboNames);
  139. self->mComboNames->removeall();
  140. gSavedSettings.applyToAll(&func);
  141. gSavedPerAccountSettings.applyToAll(&func);
  142. gColors.applyToAll(&func);
  143. self->mComboNames->sortByName();
  144. self->mComboNames->selectFirstItem();
  145. }
  146. //MK
  147. // If the debug setting associated with controlp can be changed through RLV and
  148. // a setdebug restriction is active, return false. Else return true.
  149. bool canChangeSettingRLV(LLControlVariable* controlp)
  150. {
  151. if (!controlp || !gRLenabled || !gRLInterface.mContainsSetdebug)
  152. {
  153. return true;
  154. }
  155. std::string name = controlp->getName();
  156. LLStringUtil::toLower(name);
  157. std::string tmp;
  158. for (S32 i = 0, count = gRLInterface.mAllowedSetDebug.size();
  159. i < count; ++i)
  160. {
  161. tmp = gRLInterface.mAllowedSetDebug[i];
  162. LLStringUtil::toLower(tmp);
  163. if (tmp == name)
  164. {
  165. return false;
  166. }
  167. }
  168. return true;
  169. }
  170. //mk
  171. //static
  172. void LLFloaterDebugSettings::onCommitSettings(LLUICtrl* ctrl, void* user_data)
  173. {
  174. LLFloaterDebugSettings* self = (LLFloaterDebugSettings*)user_data;
  175. if (!self) return;
  176. LLControlVariable* controlp =
  177. (LLControlVariable*)self->mComboNames->getCurrentUserdata();
  178. if (!controlp) return;
  179. //MK
  180. // If this debug setting can be changed through RLV and a setdebug
  181. // restriction is active, ignore the change
  182. if (!canChangeSettingRLV(controlp))
  183. {
  184. return;
  185. }
  186. //mk
  187. LLVector3 vector;
  188. LLVector3d vectord;
  189. LLRect rect;
  190. LLColor4 col4;
  191. LLColor3 col3;
  192. LLColor4U col4U;
  193. LLColor4 color_with_alpha;
  194. switch (controlp->type())
  195. {
  196. case TYPE_U32:
  197. controlp->setValue(self->childGetValue("val_spinner_1"));
  198. break;
  199. case TYPE_S32:
  200. controlp->setValue(self->childGetValue("val_spinner_1"));
  201. break;
  202. case TYPE_F32:
  203. controlp->setValue(LLSD(self->childGetValue("val_spinner_1").asReal()));
  204. break;
  205. case TYPE_BOOLEAN:
  206. controlp->setValue(self->childGetValue("boolean_combo"));
  207. break;
  208. case TYPE_STRING:
  209. controlp->setValue(LLSD(self->childGetValue("val_text").asString()));
  210. break;
  211. case TYPE_VEC3:
  212. vector.mV[VX] = (F32)self->childGetValue("val_spinner_1").asReal();
  213. vector.mV[VY] = (F32)self->childGetValue("val_spinner_2").asReal();
  214. vector.mV[VZ] = (F32)self->childGetValue("val_spinner_3").asReal();
  215. controlp->setValue(vector.getValue());
  216. break;
  217. case TYPE_VEC3D:
  218. vectord.mdV[VX] = self->childGetValue("val_spinner_1").asReal();
  219. vectord.mdV[VY] = self->childGetValue("val_spinner_2").asReal();
  220. vectord.mdV[VZ] = self->childGetValue("val_spinner_3").asReal();
  221. controlp->setValue(vectord.getValue());
  222. break;
  223. case TYPE_RECT:
  224. rect.mLeft = self->childGetValue("val_spinner_1").asInteger();
  225. rect.mRight = self->childGetValue("val_spinner_2").asInteger();
  226. rect.mBottom = self->childGetValue("val_spinner_3").asInteger();
  227. rect.mTop = self->childGetValue("val_spinner_4").asInteger();
  228. controlp->setValue(rect.getValue());
  229. break;
  230. case TYPE_COL4:
  231. col3.setValue(self->childGetValue("color_swatch"));
  232. col4 = LLColor4(col3, (F32)self->childGetValue("val_spinner_4").asReal());
  233. controlp->setValue(col4.getValue());
  234. break;
  235. case TYPE_COL3:
  236. controlp->setValue(self->childGetValue("color_swatch"));
  237. #if 0
  238. col3.mV[VRED] = (F32)self->childGetValue("val_spinner_1").asC();
  239. col3.mV[VGREEN] = (F32)self->childGetValue("val_spinner_2").asReal();
  240. col3.mV[VBLUE] = (F32)self->childGetValue("val_spinner_3").asReal();
  241. controlp->setValue(col3.getValue());
  242. #endif
  243. break;
  244. case TYPE_COL4U:
  245. col3.setValue(self->childGetValue("color_swatch"));
  246. col4U.setVecScaleClamp(col3);
  247. col4U.mV[VALPHA] = self->childGetValue("val_spinner_4").asInteger();
  248. controlp->setValue(col4U.getValue());
  249. break;
  250. default:
  251. break;
  252. }
  253. }
  254. // static
  255. void LLFloaterDebugSettings::onClickDefault(void* user_data)
  256. {
  257. //MK
  258. // Do not allow Reset To Default when under @setdebug (that could give
  259. // funny results)
  260. if (gRLenabled && gRLInterface.mContainsSetdebug)
  261. {
  262. return;
  263. }
  264. //mk
  265. LLFloaterDebugSettings* self = (LLFloaterDebugSettings*)user_data;
  266. if (!self) return;
  267. LLComboBox* settings_combo = self->mComboNames;
  268. LLControlVariable* controlp;
  269. controlp = (LLControlVariable*)settings_combo->getCurrentUserdata();
  270. if (controlp)
  271. {
  272. controlp->resetToDefault(true);
  273. self->updateControl(controlp);
  274. }
  275. }
  276. // We have switched controls, or doing per-frame update, so update spinners,
  277. // etc.
  278. void LLFloaterDebugSettings::updateControl(LLControlVariable* controlp)
  279. {
  280. LLSpinCtrl* spinner1 = getChild<LLSpinCtrl>("val_spinner_1");
  281. LLSpinCtrl* spinner2 = getChild<LLSpinCtrl>("val_spinner_2");
  282. LLSpinCtrl* spinner3 = getChild<LLSpinCtrl>("val_spinner_3");
  283. LLSpinCtrl* spinner4 = getChild<LLSpinCtrl>("val_spinner_4");
  284. LLColorSwatchCtrl* color_swatch =
  285. getChild<LLColorSwatchCtrl>("color_swatch");
  286. spinner1->setVisible(false);
  287. spinner2->setVisible(false);
  288. spinner3->setVisible(false);
  289. spinner4->setVisible(false);
  290. color_swatch->setVisible(false);
  291. childSetVisible("val_text", false);
  292. mComment->setText(LLStringUtil::null);
  293. if (controlp)
  294. {
  295. eControlType type = controlp->type();
  296. // Hide combo box only for non booleans, otherwise this will result in
  297. // the combo box closing every frame
  298. childSetVisible("boolean_combo", type == TYPE_BOOLEAN);
  299. mComment->setText(controlp->getComment());
  300. spinner1->setMaxValue(F32_MAX);
  301. spinner2->setMaxValue(F32_MAX);
  302. spinner3->setMaxValue(F32_MAX);
  303. spinner4->setMaxValue(F32_MAX);
  304. spinner1->setMinValue(-F32_MAX);
  305. spinner2->setMinValue(-F32_MAX);
  306. spinner3->setMinValue(-F32_MAX);
  307. spinner4->setMinValue(-F32_MAX);
  308. if (!spinner1->hasFocus())
  309. {
  310. spinner1->setIncrement(0.1f);
  311. }
  312. if (!spinner2->hasFocus())
  313. {
  314. spinner2->setIncrement(0.1f);
  315. }
  316. if (!spinner3->hasFocus())
  317. {
  318. spinner3->setIncrement(0.1f);
  319. }
  320. if (!spinner4->hasFocus())
  321. {
  322. spinner4->setIncrement(0.1f);
  323. }
  324. LLSD sd = controlp->getValue();
  325. switch (type)
  326. {
  327. case TYPE_U32:
  328. spinner1->setVisible(true);
  329. spinner1->setLabel("value"); // Debug, don't translate
  330. if (!spinner1->hasFocus())
  331. {
  332. spinner1->setValue(sd);
  333. spinner1->setMinValue((F32)U32_MIN);
  334. spinner1->setMaxValue((F32)U32_MAX);
  335. spinner1->setIncrement(1.f);
  336. spinner1->setPrecision(0);
  337. }
  338. break;
  339. case TYPE_S32:
  340. spinner1->setVisible(true);
  341. spinner1->setLabel("value"); // Debug, don't translate
  342. if (!spinner1->hasFocus())
  343. {
  344. spinner1->setValue(sd);
  345. spinner1->setMinValue((F32)S32_MIN);
  346. spinner1->setMaxValue((F32)S32_MAX);
  347. spinner1->setIncrement(1.f);
  348. spinner1->setPrecision(0);
  349. }
  350. break;
  351. case TYPE_F32:
  352. spinner1->setVisible(true);
  353. spinner1->setLabel("value"); // Debug, don't translate
  354. if (!spinner1->hasFocus())
  355. {
  356. spinner1->setPrecision(5);
  357. spinner1->setValue(sd);
  358. }
  359. break;
  360. case TYPE_BOOLEAN:
  361. if (!childHasFocus("boolean_combo"))
  362. {
  363. if (sd.asBoolean())
  364. {
  365. childSetValue("boolean_combo", LLSD("true"));
  366. }
  367. else
  368. {
  369. childSetValue("boolean_combo", LLSD(""));
  370. }
  371. }
  372. break;
  373. case TYPE_STRING:
  374. childSetVisible("val_text", true);
  375. if (!childHasFocus("val_text"))
  376. {
  377. childSetValue("val_text", sd);
  378. }
  379. break;
  380. case TYPE_VEC3:
  381. {
  382. LLVector3 v;
  383. v.setValue(sd);
  384. spinner1->setVisible(true);
  385. spinner1->setLabel("X");
  386. spinner2->setVisible(true);
  387. spinner2->setLabel("Y");
  388. spinner3->setVisible(true);
  389. spinner3->setLabel("Z");
  390. if (!spinner1->hasFocus())
  391. {
  392. spinner1->setPrecision(3);
  393. spinner1->setValue(v[VX]);
  394. }
  395. if (!spinner2->hasFocus())
  396. {
  397. spinner2->setPrecision(3);
  398. spinner2->setValue(v[VY]);
  399. }
  400. if (!spinner3->hasFocus())
  401. {
  402. spinner3->setPrecision(3);
  403. spinner3->setValue(v[VZ]);
  404. }
  405. break;
  406. }
  407. case TYPE_VEC3D:
  408. {
  409. LLVector3d v;
  410. v.setValue(sd);
  411. spinner1->setVisible(true);
  412. spinner1->setLabel("X");
  413. spinner2->setVisible(true);
  414. spinner2->setLabel("Y");
  415. spinner3->setVisible(true);
  416. spinner3->setLabel("Z");
  417. if (!spinner1->hasFocus())
  418. {
  419. spinner1->setPrecision(3);
  420. spinner1->setValue(v[VX]);
  421. }
  422. if (!spinner2->hasFocus())
  423. {
  424. spinner2->setPrecision(3);
  425. spinner2->setValue(v[VY]);
  426. }
  427. if (!spinner3->hasFocus())
  428. {
  429. spinner3->setPrecision(3);
  430. spinner3->setValue(v[VZ]);
  431. }
  432. break;
  433. }
  434. case TYPE_RECT:
  435. {
  436. LLRect r;
  437. r.setValue(sd);
  438. spinner1->setVisible(true);
  439. spinner1->setLabel("Left");
  440. spinner2->setVisible(true);
  441. spinner2->setLabel("Right");
  442. spinner3->setVisible(true);
  443. spinner3->setLabel("Bottom");
  444. spinner4->setVisible(true);
  445. spinner4->setLabel("Top");
  446. if (!spinner1->hasFocus())
  447. {
  448. spinner1->setPrecision(0);
  449. spinner1->setValue(r.mLeft);
  450. }
  451. if (!spinner2->hasFocus())
  452. {
  453. spinner2->setPrecision(0);
  454. spinner2->setValue(r.mRight);
  455. }
  456. if (!spinner3->hasFocus())
  457. {
  458. spinner3->setPrecision(0);
  459. spinner3->setValue(r.mBottom);
  460. }
  461. if (!spinner4->hasFocus())
  462. {
  463. spinner4->setPrecision(0);
  464. spinner4->setValue(r.mTop);
  465. }
  466. spinner1->setMinValue((F32)S32_MIN);
  467. spinner1->setMaxValue((F32)S32_MAX);
  468. spinner1->setIncrement(1.f);
  469. spinner2->setMinValue((F32)S32_MIN);
  470. spinner2->setMaxValue((F32)S32_MAX);
  471. spinner2->setIncrement(1.f);
  472. spinner3->setMinValue((F32)S32_MIN);
  473. spinner3->setMaxValue((F32)S32_MAX);
  474. spinner3->setIncrement(1.f);
  475. spinner4->setMinValue((F32)S32_MIN);
  476. spinner4->setMaxValue((F32)S32_MAX);
  477. spinner4->setIncrement(1.f);
  478. break;
  479. }
  480. case TYPE_COL4:
  481. {
  482. LLColor4 clr;
  483. clr.setValue(sd);
  484. color_swatch->setVisible(true);
  485. // only set if changed so color picker doesn't update
  486. if (clr != LLColor4(color_swatch->getValue()))
  487. {
  488. color_swatch->set(LLColor4(sd), true, false);
  489. }
  490. spinner4->setVisible(true);
  491. spinner4->setLabel("Alpha");
  492. if (!spinner4->hasFocus())
  493. {
  494. spinner4->setPrecision(3);
  495. spinner4->setMinValue(0.0);
  496. spinner4->setMaxValue(1.f);
  497. spinner4->setValue(clr.mV[VALPHA]);
  498. }
  499. break;
  500. }
  501. case TYPE_COL3:
  502. {
  503. LLColor3 clr;
  504. clr.setValue(sd);
  505. color_swatch->setVisible(true);
  506. color_swatch->setValue(sd);
  507. break;
  508. }
  509. case TYPE_COL4U:
  510. {
  511. LLColor4U clr;
  512. clr.setValue(sd);
  513. color_swatch->setVisible(true);
  514. if (LLColor4(clr) != LLColor4(color_swatch->getValue()))
  515. {
  516. color_swatch->set(LLColor4(clr), true, false);
  517. }
  518. spinner4->setVisible(true);
  519. spinner4->setLabel("Alpha");
  520. if (!spinner4->hasFocus())
  521. {
  522. spinner4->setPrecision(0);
  523. spinner4->setValue(clr.mV[VALPHA]);
  524. }
  525. spinner4->setMinValue(0);
  526. spinner4->setMaxValue(255);
  527. spinner4->setIncrement(1.f);
  528. break;
  529. }
  530. default:
  531. mComment->setText("unknown");
  532. break;
  533. }
  534. }
  535. }