llui.cpp 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894
  1. /**
  2. * @file llui.cpp
  3. * @brief General static UI services implementation
  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. // Utilities functions the user interface needs
  33. #include "linden_common.h"
  34. #include <stack>
  35. #include "llui.h"
  36. #include "llcontrol.h"
  37. #include "llconsole.h"
  38. #include "lldir.h"
  39. #include "lllineeditor.h"
  40. #include "llwindow.h"
  41. #include "llvector2.h"
  42. #include "llcolor4.h"
  43. //
  44. // Globals
  45. //
  46. const LLColor4 UI_VERTEX_COLOR(1.f, 1.f, 1.f, 1.f);
  47. // Used to hide the flashing text cursor when window doesn't have focus.
  48. bool gShowTextEditCursor = true;
  49. LLControlGroup* LLUI::sConfigGroup = NULL;
  50. LLControlGroup* LLUI::sIgnoresGroup = NULL;
  51. LLControlGroup* LLUI::sColorsGroup = NULL;
  52. LLImageProviderInterface* LLUI::sImageProvider = NULL;
  53. LLUIAudioCallback LLUI::sAudioCallback = NULL;
  54. LLVector2 LLUI::sGLScaleFactor(1.f, 1.f);
  55. LLHtmlHelp* LLUI::sHtmlHelp = NULL;
  56. bool LLUI::sShowXUINames = false;
  57. std::stack<LLRect> LLScreenClipRect::sClipRectStack;
  58. LLUIImagePtr LLUIImage::sRoundedSquare;
  59. S32 LLUIImage::sRoundedSquareWidth;
  60. S32 LLUIImage::sRoundedSquareHeight;
  61. S32 LLUI::sButtonFlashCount = 10;
  62. F32 LLUI::sButtonFlashRate = 2.0f;
  63. F32 LLUI::sColumnHeaderDropDownDelay = 0.3f;
  64. bool LLUI::sConsoleBoxPerMessage = false;
  65. bool LLUI::sDisableMessagesSpacing = true;
  66. S32 LLUI::sDropShadowButton = 2;
  67. S32 LLUI::sDropShadowFloater = 5;
  68. S32 LLUI::sDropShadowTooltip = 4;
  69. F32 LLUI::sMenuAccessKeyTime = 0.25f;
  70. F32 LLUI::sPieMenuLineWidth = 2.5f;
  71. S32 LLUI::sSnapMargin = 10;
  72. F32 LLUI::sTypeAheadTimeout = 1.5f;
  73. bool LLUI::sTabToTextFieldsOnly = false;
  74. bool LLUI::sUseAltKeyForMenus = false;
  75. fast_hset<LLView*> LLUI::sSingletonInstances;
  76. LLColor4 LLUI::sAlertBoxColor;
  77. LLColor4 LLUI::sAlertCautionBoxColor;
  78. LLColor4 LLUI::sAlertCautionTextColor;
  79. LLColor4 LLUI::sAlertTextColor;
  80. LLColor4 LLUI::sButtonFlashBgColor;
  81. LLColor4 LLUI::sButtonImageColor;
  82. LLColor4 LLUI::sButtonLabelColor;
  83. LLColor4 LLUI::sButtonLabelDisabledColor;
  84. LLColor4 LLUI::sButtonLabelSelectedColor;
  85. LLColor4 LLUI::sButtonLabelSelectedDisabledColor;
  86. LLColor4 LLUI::sColorDropShadow;
  87. LLColor4 LLUI::sDefaultBackgroundColor;
  88. LLColor4 LLUI::sDefaultHighlightDark;
  89. LLColor4 LLUI::sDefaultHighlightLight;
  90. LLColor4 LLUI::sDefaultShadowDark;
  91. LLColor4 LLUI::sDefaultShadowLight;
  92. LLColor4 LLUI::sFloaterButtonImageColor;
  93. LLColor4 LLUI::sFloaterFocusBorderColor;
  94. LLColor4 LLUI::sFloaterUnfocusBorderColor;
  95. LLColor4 LLUI::sFocusBackgroundColor;
  96. LLColor4 LLUI::sHTMLLinkColor;
  97. LLColor4 LLUI::sLabelDisabledColor;
  98. LLColor4 LLUI::sLabelSelectedColor;
  99. LLColor4 LLUI::sLabelTextColor;
  100. LLColor4 LLUI::sLoginProgressBarBgColor;
  101. LLColor4 LLUI::sMenuDefaultBgColor;
  102. LLColor4 LLUI::sMultiSliderThumbCenterColor;
  103. LLColor4 LLUI::sMultiSliderThumbCenterSelectedColor;
  104. LLColor4 LLUI::sMultiSliderTrackColor;
  105. LLColor4 LLUI::sMultiSliderTriangleColor;
  106. LLColor4 LLUI::sPieMenuBgColor;
  107. LLColor4 LLUI::sPieMenuLineColor;
  108. LLColor4 LLUI::sPieMenuSelectedColor;
  109. LLColor4 LLUI::sScrollbarThumbColor;
  110. LLColor4 LLUI::sScrollbarTrackColor;
  111. LLColor4 LLUI::sScrollBgReadOnlyColor;
  112. LLColor4 LLUI::sScrollBGStripeColor;
  113. LLColor4 LLUI::sScrollBgWriteableColor;
  114. LLColor4 LLUI::sScrollDisabledColor;
  115. LLColor4 LLUI::sScrollHighlightedColor;
  116. LLColor4 LLUI::sScrollSelectedBGColor;
  117. LLColor4 LLUI::sScrollSelectedFGColor;
  118. LLColor4 LLUI::sScrollUnselectedColor;
  119. LLColor4 LLUI::sSliderThumbCenterColor;
  120. LLColor4 LLUI::sSliderThumbOutlineColor;
  121. LLColor4 LLUI::sSliderTrackColor;
  122. LLColor4 LLUI::sTextBgFocusColor;
  123. LLColor4 LLUI::sTextBgReadOnlyColor;
  124. LLColor4 LLUI::sTextBgWriteableColor;
  125. LLColor4 LLUI::sTextCursorColor;
  126. LLColor4 LLUI::sTextDefaultColor;
  127. LLColor4 LLUI::sTextEmbeddedItemColor;
  128. LLColor4 LLUI::sTextEmbeddedItemReadOnlyColor;
  129. LLColor4 LLUI::sTextFgColor;
  130. LLColor4 LLUI::sTextFgReadOnlyColor;
  131. LLColor4 LLUI::sTextFgTentativeColor;
  132. LLColor4 LLUI::sTitleBarFocusColor;
  133. LLColor4 LLUI::sTrackColor;
  134. LLColor4 LLUI::sDisabledTrackColor;
  135. //
  136. // Functions
  137. //
  138. void make_ui_sound(const char* namep, bool force)
  139. {
  140. std::string name = ll_safe_string(namep);
  141. if (!LLUI::sConfigGroup->controlExists(name.c_str()))
  142. {
  143. llwarns << "tried to make UI sound for unknown sound name: " << name
  144. << llendl;
  145. return;
  146. }
  147. std::string flagname = name + "Enable";
  148. if (force || !LLUI::sConfigGroup->controlExists(flagname.c_str()) ||
  149. LLUI::sConfigGroup->getBool(flagname.c_str()))
  150. {
  151. LLUUID uuid(LLUI::sConfigGroup->getString(name.c_str()));
  152. if (uuid.isNull())
  153. {
  154. if (LLUI::sConfigGroup->getString(name.c_str()) == LLUUID::null.asString())
  155. {
  156. LL_DEBUGS("UISounds") << "UI sound name: " << name
  157. << " triggered but silent (null uuid)"
  158. << LL_ENDL;
  159. }
  160. else
  161. {
  162. llwarns << "UI sound named: " << name
  163. << " does not translate into a valid uuid" << llendl;
  164. }
  165. }
  166. else if (LLUI::sAudioCallback != NULL)
  167. {
  168. LL_DEBUGS("UISounds") << "UI sound name: " << name << LL_ENDL;
  169. LLUI::sAudioCallback(uuid);
  170. }
  171. }
  172. }
  173. ///////////////////////////////////////////////////////////////////////////////
  174. // UI-specific rendering functions that cannot go into llrenderutils.cpp
  175. // since they refer to llui stuff
  176. void gl_rect_2d_offset_local(S32 left, S32 top, S32 right, S32 bottom,
  177. S32 pixel_offset, bool filled)
  178. {
  179. gGL.pushUIMatrix();
  180. left += LLFontGL::sCurOrigin.mX;
  181. right += LLFontGL::sCurOrigin.mX;
  182. bottom += LLFontGL::sCurOrigin.mY;
  183. top += LLFontGL::sCurOrigin.mY;
  184. gGL.loadUIIdentity();
  185. gl_rect_2d(llfloor((F32)left * LLUI::sGLScaleFactor.mV[VX]) - pixel_offset,
  186. llfloor((F32)top * LLUI::sGLScaleFactor.mV[VY]) + pixel_offset,
  187. llfloor((F32)right * LLUI::sGLScaleFactor.mV[VX]) + pixel_offset,
  188. llfloor((F32)bottom * LLUI::sGLScaleFactor.mV[VY]) - pixel_offset,
  189. filled);
  190. gGL.popUIMatrix();
  191. }
  192. void gl_line_3d(const LLVector3& start, const LLVector3& end,
  193. const LLColor4& color, F32 phase)
  194. {
  195. phase = fmod(phase, 1.f);
  196. gGL.color4f(color.mV[VRED], color.mV[VGREEN], color.mV[VBLUE],
  197. color.mV[VALPHA]);
  198. gGL.flush();
  199. gGL.lineWidth(2.5f);
  200. gGL.begin(LLRender::LINES);
  201. {
  202. gGL.vertex3fv(start.mV);
  203. gGL.vertex3fv(end.mV);
  204. }
  205. gGL.end();
  206. LLUI::setLineWidth(1.f);
  207. }
  208. // Draw gray and white checkerboard with black border
  209. void gl_rect_2d_checkerboard(const LLRect& rect)
  210. {
  211. LLTexUnit* unit0 = gGL.getTexUnit(0);
  212. // Polygon stipple is deprecated, use the checker.png texture
  213. static LLUIImagePtr img = LLUI::getUIImage("checker.png");
  214. unit0->bind(img->getImage());
  215. unit0->setTextureAddressMode(LLTexUnit::TAM_WRAP);
  216. unit0->setTextureFilteringOption(LLTexUnit::TFO_POINT);
  217. F32 width = rect.getWidth();
  218. F32 height = rect.getHeight();
  219. F32 scaler = width <= 32.f || height <= 32.f ? 1.f / 16.f : 1.f / 32.f;
  220. LLRectf uv_rect(0.f, 0.f, scaler * width, scaler * height);
  221. gl_draw_scaled_image(rect.mLeft, rect.mBottom, rect.getWidth(),
  222. rect.getHeight(), img->getImage(), LLColor4::white,
  223. uv_rect);
  224. }
  225. ///////////////////////////////////////////////////////////////////////////////
  226. // LLUI class
  227. ///////////////////////////////////////////////////////////////////////////////
  228. //static
  229. bool show_xui_names_cb(const LLSD& newvalue)
  230. {
  231. LLUI::sShowXUINames = newvalue.asBoolean();
  232. return true;
  233. }
  234. //static
  235. void LLUI::initClass(LLControlGroup* config,
  236. LLControlGroup* ignores,
  237. LLControlGroup* colors,
  238. LLImageProviderInterface* image_provider,
  239. LLUIAudioCallback audio_callback,
  240. const LLVector2* scale_factor,
  241. const std::string& language)
  242. {
  243. sConfigGroup = config;
  244. sIgnoresGroup = ignores;
  245. sColorsGroup = colors;
  246. if (sConfigGroup == NULL || sIgnoresGroup == NULL || sColorsGroup == NULL)
  247. {
  248. llerrs << "Failure to initialize configuration groups" << llendl;
  249. }
  250. sImageProvider = image_provider;
  251. sAudioCallback = audio_callback;
  252. sGLScaleFactor = scale_factor ? *scale_factor : LLVector2(1.f, 1.f);
  253. sShowXUINames = sConfigGroup->getBool("ShowXUINames");
  254. LLControlVariable* controlp = sConfigGroup->getControl("ShowXUINames");
  255. if (controlp)
  256. {
  257. controlp->getSignal()->connect(boost::bind(&show_xui_names_cb, _2));
  258. }
  259. connectRefreshSettingsSafe("ButtonFlashCount");
  260. connectRefreshSettingsSafe("ButtonFlashRate");
  261. connectRefreshSettingsSafe("ColumnHeaderDropDownDelay");
  262. connectRefreshSettingsSafe("ConsoleBoxPerMessage");
  263. connectRefreshSettingsSafe("DisableMessagesSpacing");
  264. connectRefreshSettingsSafe("DropShadowButton");
  265. connectRefreshSettingsSafe("DropShadowFloater");
  266. connectRefreshSettingsSafe("DropShadowTooltip");
  267. connectRefreshSettingsSafe("HTMLLinkColor");
  268. connectRefreshSettingsSafe("MenuAccessKeyTime");
  269. connectRefreshSettingsSafe("PieMenuLineWidth");
  270. connectRefreshSettingsSafe("SnapMargin");
  271. connectRefreshSettingsSafe("TabToTextFieldsOnly");
  272. connectRefreshSettingsSafe("TypeAheadTimeout");
  273. connectRefreshSettingsSafe("UseAltKeyForMenus");
  274. connectRefreshSettingsSafe("ColorDropShadow");
  275. connectRefreshSettingsSafe("AlertBoxColor");
  276. connectRefreshSettingsSafe("AlertCautionBoxColor");
  277. connectRefreshSettingsSafe("AlertCautionTextColor");
  278. connectRefreshSettingsSafe("AlertTextColor");
  279. connectRefreshSettingsSafe("ButtonFlashBgColor");
  280. connectRefreshSettingsSafe("ButtonImageColor");
  281. connectRefreshSettingsSafe("ButtonLabelColor");
  282. connectRefreshSettingsSafe("ButtonLabelDisabledColor");
  283. connectRefreshSettingsSafe("ButtonLabelSelectedColor");
  284. connectRefreshSettingsSafe("ButtonLabelSelectedDisabledColor");
  285. connectRefreshSettingsSafe("ColorDropShadow");
  286. connectRefreshSettingsSafe("DefaultBackgroundColor");
  287. connectRefreshSettingsSafe("DefaultHighlightDark");
  288. connectRefreshSettingsSafe("DefaultHighlightLight");
  289. connectRefreshSettingsSafe("DefaultShadowDark");
  290. connectRefreshSettingsSafe("DefaultShadowLight");
  291. connectRefreshSettingsSafe("FloaterButtonImageColor");
  292. connectRefreshSettingsSafe("FloaterFocusBorderColor");
  293. connectRefreshSettingsSafe("FloaterUnfocusBorderColor");
  294. connectRefreshSettingsSafe("FocusBackgroundColor");
  295. connectRefreshSettingsSafe("LabelDisabledColor");
  296. connectRefreshSettingsSafe("LabelSelectedColor");
  297. connectRefreshSettingsSafe("LabelTextColor");
  298. connectRefreshSettingsSafe("LoginProgressBarBgColor");
  299. connectRefreshSettingsSafe("MenuDefaultBgColor");
  300. connectRefreshSettingsSafe("MultiSliderThumbCenterColor");
  301. connectRefreshSettingsSafe("MultiSliderThumbCenterSelectedColor");
  302. connectRefreshSettingsSafe("MultiSliderTrackColor");
  303. connectRefreshSettingsSafe("MultiSliderTriangleColor");
  304. connectRefreshSettingsSafe("PieMenuBgColor");
  305. connectRefreshSettingsSafe("PieMenuLineColor");
  306. connectRefreshSettingsSafe("PieMenuSelectedColor");
  307. connectRefreshSettingsSafe("ScrollbarThumbColor");
  308. connectRefreshSettingsSafe("ScrollbarTrackColor");
  309. connectRefreshSettingsSafe("ScrollBgReadOnlyColor");
  310. connectRefreshSettingsSafe("ScrollBGStripeColor");
  311. connectRefreshSettingsSafe("ScrollBgWriteableColor");
  312. connectRefreshSettingsSafe("ScrollDisabledColor");
  313. connectRefreshSettingsSafe("ScrollHighlightedColor");
  314. connectRefreshSettingsSafe("ScrollSelectedBGColor");
  315. connectRefreshSettingsSafe("ScrollSelectedFGColor");
  316. connectRefreshSettingsSafe("ScrollUnselectedColor");
  317. connectRefreshSettingsSafe("SliderThumbCenterColor");
  318. connectRefreshSettingsSafe("SliderThumbOutlineColor");
  319. connectRefreshSettingsSafe("SliderTrackColor");
  320. connectRefreshSettingsSafe("TextBgFocusColor");
  321. connectRefreshSettingsSafe("TextBgReadOnlyColor");
  322. connectRefreshSettingsSafe("TextBgWriteableColor");
  323. connectRefreshSettingsSafe("TextCursorColor");
  324. connectRefreshSettingsSafe("TextDefaultColor");
  325. connectRefreshSettingsSafe("TextEmbeddedItemColor");
  326. connectRefreshSettingsSafe("TextEmbeddedItemReadOnlyColor");
  327. connectRefreshSettingsSafe("TextFgColor");
  328. connectRefreshSettingsSafe("TextFgReadOnlyColor");
  329. connectRefreshSettingsSafe("TextFgTentativeColor");
  330. connectRefreshSettingsSafe("TitleBarFocusColor");
  331. connectRefreshSettingsSafe("TrackColor");
  332. connectRefreshSettingsSafe("DisabledTrackColor");
  333. connectRefreshSettingsSafe("ConsoleBackground");
  334. connectRefreshSettingsSafe("ConsoleBackgroundOpacity");
  335. refreshSettings();
  336. }
  337. //static
  338. void LLUI::connectRefreshSettingsSafe(const char* name)
  339. {
  340. LLControlVariable* controlp = sConfigGroup->getControl(name);
  341. if (!controlp)
  342. {
  343. controlp = sColorsGroup->getControl(name);
  344. }
  345. if (!controlp)
  346. {
  347. llwarns << "Setting name not found: " << name << llendl;
  348. return;
  349. }
  350. controlp->getSignal()->connect(boost::bind(&LLUI::refreshSettings));
  351. }
  352. //static
  353. void LLUI::refreshSettings()
  354. {
  355. sButtonFlashCount = sConfigGroup->getS32("ButtonFlashCount");
  356. sButtonFlashRate = sConfigGroup->getF32("ButtonFlashRate");
  357. sColumnHeaderDropDownDelay =
  358. sConfigGroup->getF32("ColumnHeaderDropDownDelay");
  359. sConsoleBoxPerMessage = sConfigGroup->getBool("ConsoleBoxPerMessage");
  360. sDisableMessagesSpacing = sConfigGroup->getBool("DisableMessagesSpacing");
  361. sDropShadowButton = sConfigGroup->getS32("DropShadowButton");
  362. sDropShadowFloater = sConfigGroup->getS32("DropShadowFloater");
  363. sDropShadowTooltip = sConfigGroup->getS32("DropShadowTooltip");
  364. sHTMLLinkColor = LLUI::sConfigGroup->getColor4("HTMLLinkColor");
  365. sMenuAccessKeyTime = sConfigGroup->getF32("MenuAccessKeyTime");
  366. sPieMenuLineWidth = sConfigGroup->getF32("PieMenuLineWidth");
  367. sSnapMargin = sConfigGroup->getS32("SnapMargin");
  368. sTabToTextFieldsOnly = sConfigGroup->getBool("TabToTextFieldsOnly");
  369. sTypeAheadTimeout = sConfigGroup->getF32("TypeAheadTimeout");
  370. sUseAltKeyForMenus = sConfigGroup->getBool("UseAltKeyForMenus");
  371. LLFontGL::sShadowColor = sColorsGroup->getColor("ColorDropShadow");
  372. // We do the conversion here, once and for all, for speed
  373. LLFontGL::sShadowColorU = LLColor4U(LLFontGL::sShadowColor);
  374. sAlertBoxColor = sColorsGroup->getColor("AlertBoxColor");
  375. sAlertCautionBoxColor = sColorsGroup->getColor("AlertCautionBoxColor");
  376. sAlertCautionTextColor = sColorsGroup->getColor("AlertCautionTextColor");
  377. sAlertTextColor = sColorsGroup->getColor("AlertTextColor");
  378. sButtonFlashBgColor = sColorsGroup->getColor("ButtonFlashBgColor");
  379. sButtonImageColor = sColorsGroup->getColor("ButtonImageColor");
  380. sButtonLabelColor = sColorsGroup->getColor("ButtonLabelColor");
  381. sButtonLabelDisabledColor =
  382. sColorsGroup->getColor("ButtonLabelDisabledColor");
  383. sButtonLabelSelectedColor =
  384. sColorsGroup->getColor("ButtonLabelSelectedColor");
  385. sButtonLabelSelectedDisabledColor =
  386. sColorsGroup->getColor("ButtonLabelSelectedDisabledColor");
  387. sColorDropShadow = sColorsGroup->getColor("ColorDropShadow");
  388. sDefaultBackgroundColor = sColorsGroup->getColor("DefaultBackgroundColor");
  389. sDefaultHighlightDark = sColorsGroup->getColor("DefaultHighlightDark");
  390. sDefaultHighlightLight = sColorsGroup->getColor("DefaultHighlightLight");
  391. sDefaultShadowDark = sColorsGroup->getColor("DefaultShadowDark");
  392. sDefaultShadowLight = sColorsGroup->getColor("DefaultShadowLight");
  393. sFloaterButtonImageColor =
  394. sColorsGroup->getColor("FloaterButtonImageColor");
  395. sFloaterFocusBorderColor =
  396. sColorsGroup->getColor("FloaterFocusBorderColor");
  397. sFloaterUnfocusBorderColor =
  398. sColorsGroup->getColor("FloaterUnfocusBorderColor");
  399. sFocusBackgroundColor = sColorsGroup->getColor("FocusBackgroundColor");
  400. sLabelDisabledColor = sColorsGroup->getColor("LabelDisabledColor");
  401. sLabelSelectedColor = sColorsGroup->getColor("LabelSelectedColor");
  402. sLabelTextColor = sColorsGroup->getColor("LabelTextColor");
  403. sLoginProgressBarBgColor =
  404. sColorsGroup->getColor("LoginProgressBarBgColor");
  405. sMenuDefaultBgColor = sColorsGroup->getColor("MenuDefaultBgColor");
  406. sMultiSliderThumbCenterColor =
  407. sColorsGroup->getColor("MultiSliderThumbCenterColor");
  408. sMultiSliderThumbCenterSelectedColor =
  409. sColorsGroup->getColor("MultiSliderThumbCenterSelectedColor");
  410. sMultiSliderTrackColor = sColorsGroup->getColor("MultiSliderTrackColor");
  411. sMultiSliderTriangleColor =
  412. sColorsGroup->getColor("MultiSliderTriangleColor");
  413. sPieMenuBgColor = sColorsGroup->getColor("PieMenuBgColor");
  414. sPieMenuLineColor = sColorsGroup->getColor("PieMenuLineColor");
  415. sPieMenuSelectedColor = sColorsGroup->getColor("PieMenuSelectedColor");
  416. sScrollbarThumbColor = sColorsGroup->getColor("ScrollbarThumbColor");
  417. sScrollbarTrackColor = sColorsGroup->getColor("ScrollbarTrackColor");
  418. sScrollBgReadOnlyColor = sColorsGroup->getColor("ScrollBgReadOnlyColor");
  419. sScrollBGStripeColor = sColorsGroup->getColor("ScrollBGStripeColor");
  420. sScrollBgWriteableColor = sColorsGroup->getColor("ScrollBgWriteableColor");
  421. sScrollDisabledColor = sColorsGroup->getColor("ScrollDisabledColor");
  422. sScrollHighlightedColor = sColorsGroup->getColor("ScrollHighlightedColor");
  423. sScrollSelectedBGColor = sColorsGroup->getColor("ScrollSelectedBGColor");
  424. sScrollSelectedFGColor = sColorsGroup->getColor("ScrollSelectedFGColor");
  425. sScrollUnselectedColor = sColorsGroup->getColor("ScrollUnselectedColor");
  426. sSliderThumbCenterColor = sColorsGroup->getColor("SliderThumbCenterColor");
  427. sSliderThumbOutlineColor =
  428. sColorsGroup->getColor("SliderThumbOutlineColor");
  429. sSliderTrackColor = sColorsGroup->getColor("SliderTrackColor");
  430. sTextBgFocusColor = sColorsGroup->getColor("TextBgFocusColor");
  431. sTextBgReadOnlyColor = sColorsGroup->getColor("TextBgReadOnlyColor");
  432. sTextBgWriteableColor = sColorsGroup->getColor("TextBgWriteableColor");
  433. sTextCursorColor = sColorsGroup->getColor("TextCursorColor");
  434. sTextDefaultColor = sColorsGroup->getColor("TextDefaultColor");
  435. sTextEmbeddedItemColor = sColorsGroup->getColor("TextEmbeddedItemColor");
  436. sTextEmbeddedItemReadOnlyColor =
  437. sColorsGroup->getColor("TextEmbeddedItemReadOnlyColor");
  438. sTextFgColor = sColorsGroup->getColor("TextFgColor");
  439. sTextFgReadOnlyColor = sColorsGroup->getColor("TextFgReadOnlyColor");
  440. sTextFgTentativeColor = sColorsGroup->getColor("TextFgTentativeColor");
  441. sTitleBarFocusColor = sColorsGroup->getColor("TitleBarFocusColor");
  442. sTrackColor = sColorsGroup->getColor("TrackColor");
  443. sDisabledTrackColor = sColorsGroup->getColor("DisabledTrackColor");
  444. LLConsole::setBackground(sColorsGroup->getColor("ConsoleBackground"),
  445. llclamp(sConfigGroup->getF32("ConsoleBackgroundOpacity"),
  446. 0.f, 1.f));
  447. }
  448. //static
  449. void LLUI::cleanupClass()
  450. {
  451. sImageProvider->cleanUp();
  452. LLLineEditor::cleanupLineEditor();
  453. }
  454. //static
  455. void LLUI::translate(F32 x, F32 y, F32 z)
  456. {
  457. gGL.translateUI(x, y, z);
  458. LLFontGL::sCurOrigin.mX += (S32) x;
  459. LLFontGL::sCurOrigin.mY += (S32) y;
  460. LLFontGL::sCurDepth += z;
  461. }
  462. //static
  463. void LLUI::pushMatrix()
  464. {
  465. gGL.pushUIMatrix();
  466. LLFontGL::sOriginStack.emplace_back(LLFontGL::sCurOrigin,
  467. LLFontGL::sCurDepth);
  468. }
  469. //static
  470. void LLUI::popMatrix()
  471. {
  472. gGL.popUIMatrix();
  473. LLFontGL::sCurOrigin = LLFontGL::sOriginStack.back().first;
  474. LLFontGL::sCurDepth = LLFontGL::sOriginStack.back().second;
  475. LLFontGL::sOriginStack.pop_back();
  476. }
  477. //static
  478. void LLUI::loadIdentity()
  479. {
  480. gGL.loadUIIdentity();
  481. LLFontGL::sCurOrigin.mX = 0;
  482. LLFontGL::sCurOrigin.mY = 0;
  483. LLFontGL::sCurDepth = 0.f;
  484. }
  485. //static
  486. void LLUI::setLineWidth(F32 width)
  487. {
  488. gGL.flush();
  489. gGL.lineWidth(width *
  490. lerp(sGLScaleFactor.mV[VX], sGLScaleFactor.mV[VY], 0.5f));
  491. }
  492. //static
  493. void LLUI::setCursorPositionScreen(S32 x, S32 y)
  494. {
  495. if (!gWindowp) return;
  496. #if LL_DARWIN
  497. F32 sys_size_factor = gWindowp->getSystemUISize();
  498. S32 screen_x = ll_round((F32)x * sGLScaleFactor.mV[VX] / sys_size_factor);
  499. S32 screen_y = ll_round((F32)y * sGLScaleFactor.mV[VY] / sys_size_factor);
  500. #else
  501. S32 screen_x = ll_round((F32)x * sGLScaleFactor.mV[VX]);
  502. S32 screen_y = ll_round((F32)y * sGLScaleFactor.mV[VY]);
  503. #endif
  504. LLCoordWindow window_point;
  505. gWindowp->convertCoords(LLCoordGL(screen_x, screen_y), &window_point);
  506. gWindowp->setCursorPosition(window_point);
  507. }
  508. //static
  509. void LLUI::setCursorPositionLocal(const LLView* viewp, S32 x, S32 y)
  510. {
  511. S32 screen_x, screen_y;
  512. viewp->localPointToScreen(x, y, &screen_x, &screen_y);
  513. setCursorPositionScreen(screen_x, screen_y);
  514. }
  515. //static
  516. void LLUI::getCursorPositionLocal(const LLView* viewp, S32* x, S32* y)
  517. {
  518. if (!gWindowp) return;
  519. LLCoordWindow cursor_pos_window;
  520. gWindowp->getCursorPosition(&cursor_pos_window);
  521. LLCoordGL cursor_pos_gl;
  522. gWindowp->convertCoords(cursor_pos_window, &cursor_pos_gl);
  523. cursor_pos_gl.mX = ll_round((F32)cursor_pos_gl.mX / LLUI::sGLScaleFactor.mV[VX]);
  524. cursor_pos_gl.mY = ll_round((F32)cursor_pos_gl.mY / LLUI::sGLScaleFactor.mV[VY]);
  525. viewp->screenPointToLocal(cursor_pos_gl.mX, cursor_pos_gl.mY, x, y);
  526. }
  527. //static
  528. std::string LLUI::getLanguage()
  529. {
  530. std::string language = "en-us";
  531. if (sConfigGroup)
  532. {
  533. language = sConfigGroup->getString("Language");
  534. if (language.empty() || language == "default")
  535. {
  536. language = sConfigGroup->getString("SystemLanguage");
  537. }
  538. if (language.empty() || language == "default")
  539. {
  540. language = "en-us";
  541. }
  542. }
  543. return language;
  544. }
  545. //static
  546. std::string LLUI::locateSkin(const std::string& filename)
  547. {
  548. std::string found_file = filename;
  549. if (!LLFile::exists(found_file))
  550. {
  551. // Should be CUSTOM_SKINS ?
  552. found_file = gDirUtil.getFullPath(LL_PATH_USER_SETTINGS, filename);
  553. }
  554. if (sConfigGroup && sConfigGroup->controlExists("Language"))
  555. {
  556. if (!LLFile::exists(found_file))
  557. {
  558. std::string localization = getLanguage();
  559. std::string local_skin = "xui" LL_DIR_DELIM_STR;
  560. local_skin += localization;
  561. local_skin += LL_DIR_DELIM_STR;
  562. local_skin += filename;
  563. found_file = gDirUtil.findSkinnedFilename(local_skin);
  564. }
  565. }
  566. if (!LLFile::exists(found_file))
  567. {
  568. std::string local_skin = "xui" LL_DIR_DELIM_STR "en-us" LL_DIR_DELIM_STR;
  569. local_skin += filename;
  570. found_file = gDirUtil.findSkinnedFilename(local_skin);
  571. }
  572. if (!LLFile::exists(found_file))
  573. {
  574. found_file = gDirUtil.getFullPath(LL_PATH_APP_SETTINGS, filename);
  575. }
  576. return found_file;
  577. }
  578. //static
  579. LLVector2 LLUI::getWindowSize()
  580. {
  581. LLCoordWindow window_rect;
  582. gWindowp->getSize(&window_rect);
  583. return LLVector2(window_rect.mX / sGLScaleFactor.mV[VX],
  584. window_rect.mY / sGLScaleFactor.mV[VY]);
  585. }
  586. //static
  587. void LLUI::screenPointToGL(S32 screen_x, S32 screen_y, S32* gl_x, S32* gl_y)
  588. {
  589. *gl_x = ll_round((F32)screen_x * sGLScaleFactor.mV[VX]);
  590. *gl_y = ll_round((F32)screen_y * sGLScaleFactor.mV[VY]);
  591. }
  592. //static
  593. void LLUI::glPointToScreen(S32 gl_x, S32 gl_y, S32* screen_x, S32* screen_y)
  594. {
  595. *screen_x = ll_round((F32)gl_x / sGLScaleFactor.mV[VX]);
  596. *screen_y = ll_round((F32)gl_y / sGLScaleFactor.mV[VY]);
  597. }
  598. //static
  599. void LLUI::screenRectToGL(const LLRect& screen, LLRect* gl)
  600. {
  601. screenPointToGL(screen.mLeft, screen.mTop, &gl->mLeft, &gl->mTop);
  602. screenPointToGL(screen.mRight, screen.mBottom, &gl->mRight, &gl->mBottom);
  603. }
  604. //static
  605. void LLUI::glRectToScreen(const LLRect& gl, LLRect *screen)
  606. {
  607. glPointToScreen(gl.mLeft, gl.mTop, &screen->mLeft, &screen->mTop);
  608. glPointToScreen(gl.mRight, gl.mBottom, &screen->mRight, &screen->mBottom);
  609. }
  610. //static
  611. LLUIImagePtr LLUI::getUIImageByID(const LLUUID& image_id)
  612. {
  613. if (!sImageProvider)
  614. {
  615. return NULL;
  616. }
  617. return sImageProvider->getUIImageByID(image_id);
  618. }
  619. //static
  620. LLUIImagePtr LLUI::getUIImage(const std::string& name)
  621. {
  622. if (!sImageProvider || name.empty())
  623. {
  624. return NULL;
  625. }
  626. return sImageProvider->getUIImage(name);
  627. }
  628. //static
  629. void LLUI::setHtmlHelp(LLHtmlHelp* html_help)
  630. {
  631. LLUI::sHtmlHelp = html_help;
  632. }
  633. //static
  634. void LLUI::addSingletonInstance(LLView* instancep)
  635. {
  636. sSingletonInstances.insert(instancep);
  637. }
  638. //static
  639. void LLUI::removeSingletonInstance(LLView* instancep)
  640. {
  641. sSingletonInstances.erase(instancep);
  642. }
  643. //static
  644. void LLUI::deleteSingletonInstances()
  645. {
  646. llinfos << "Destroying UI singletons..." << llendl;
  647. while (!sSingletonInstances.empty())
  648. {
  649. // The LLUISingleton destructor will automatically remove its address
  650. // from sSingletonInstances by calling removeSingletonInstance(). HB
  651. delete *sSingletonInstances.begin();
  652. }
  653. llinfos << "UI singletons destroyed." << llendl;
  654. }
  655. ///////////////////////////////////////////////////////////////////////////////
  656. // LLScreenClipRect class
  657. ///////////////////////////////////////////////////////////////////////////////
  658. LLScreenClipRect::LLScreenClipRect(const LLRect& rect, bool enabled)
  659. : mScissorState(GL_SCISSOR_TEST),
  660. mEnabled(enabled)
  661. {
  662. if (mEnabled)
  663. {
  664. pushClipRect(rect);
  665. }
  666. mScissorState.setEnabled(!sClipRectStack.empty());
  667. updateScissorRegion();
  668. }
  669. LLScreenClipRect::~LLScreenClipRect()
  670. {
  671. if (mEnabled)
  672. {
  673. popClipRect();
  674. }
  675. updateScissorRegion();
  676. }
  677. //static
  678. void LLScreenClipRect::pushClipRect(const LLRect& rect)
  679. {
  680. LLRect combined_clip_rect = rect;
  681. if (!sClipRectStack.empty())
  682. {
  683. LLRect top = sClipRectStack.top();
  684. combined_clip_rect.intersectWith(top);
  685. }
  686. sClipRectStack.push(combined_clip_rect);
  687. }
  688. //static
  689. void LLScreenClipRect::popClipRect()
  690. {
  691. sClipRectStack.pop();
  692. }
  693. //static
  694. void LLScreenClipRect::updateScissorRegion()
  695. {
  696. if (sClipRectStack.empty()) return;
  697. LLRect rect = sClipRectStack.top();
  698. S32 x, y , w, h;
  699. x = llfloor(rect.mLeft * LLUI::sGLScaleFactor.mV[VX]);
  700. y = llfloor(rect.mBottom * LLUI::sGLScaleFactor.mV[VY]);
  701. w = llmax(0, llceil(rect.getWidth() * LLUI::sGLScaleFactor.mV[VX])) + 1;
  702. h = llmax(0, llceil(rect.getHeight() * LLUI::sGLScaleFactor.mV[VY])) + 1;
  703. glScissor(x, y, w, h);
  704. stop_glerror();
  705. }
  706. LLLocalClipRect::LLLocalClipRect(const LLRect &rect, bool enabled)
  707. : LLScreenClipRect(LLRect(rect.mLeft + LLFontGL::sCurOrigin.mX,
  708. rect.mTop + LLFontGL::sCurOrigin.mY,
  709. rect.mRight + LLFontGL::sCurOrigin.mX,
  710. rect.mBottom + LLFontGL::sCurOrigin.mY),
  711. enabled)
  712. {
  713. }
  714. ///////////////////////////////////////////////////////////////////////////////
  715. // LLUIImage class
  716. ///////////////////////////////////////////////////////////////////////////////
  717. //static
  718. void LLUIImage::initClass()
  719. {
  720. sRoundedSquare = LLUI::getUIImage("rounded_square.tga");
  721. if (sRoundedSquare.isNull())
  722. {
  723. llerrs << "Failure to find rounded_square.tga" << llendl;
  724. }
  725. sRoundedSquareWidth = sRoundedSquare->getTextureWidth();
  726. sRoundedSquareHeight = sRoundedSquare->getTextureHeight();
  727. }
  728. //static
  729. void LLUIImage::cleanupClass()
  730. {
  731. sRoundedSquare = NULL;
  732. }
  733. LLUIImage::LLUIImage(const std::string& name, LLPointer<LLGLTexture> image)
  734. : mName(name),
  735. mImage(image),
  736. mScaleRegion(0.f, 1.f, 1.f, 0.f),
  737. mClipRegion(0.f, 1.f, 1.f, 0.f),
  738. mUniformScaling(true),
  739. mNoClip(true)
  740. {
  741. }
  742. void LLUIImage::setClipRegion(const LLRectf& region)
  743. {
  744. mClipRegion = region;
  745. mNoClip = mClipRegion.mLeft == 0.f && mClipRegion.mRight == 1.f &&
  746. mClipRegion.mBottom == 0.f && mClipRegion.mTop == 1.f;
  747. }
  748. void LLUIImage::setScaleRegion(const LLRectf& region)
  749. {
  750. mScaleRegion = region;
  751. mUniformScaling = mScaleRegion.mLeft == 0.f && mScaleRegion.mRight == 1.f &&
  752. mScaleRegion.mBottom == 0.f && mScaleRegion.mTop == 1.f;
  753. }
  754. // *TODO: move drawing implementation inside class
  755. void LLUIImage::draw(S32 x, S32 y, const LLColor4& color) const
  756. {
  757. #if 0
  758. gl_draw_scaled_image(x, y, getWidth(), getHeight(), mImage, color,
  759. mClipRegion);
  760. #endif
  761. gl_draw_image(x, y, mImage, color, mClipRegion);
  762. }
  763. void LLUIImage::draw(S32 x, S32 y, S32 width, S32 height,
  764. const LLColor4& color) const
  765. {
  766. if (mUniformScaling)
  767. {
  768. gl_draw_scaled_image(x, y, width, height, mImage, color, mClipRegion);
  769. }
  770. else
  771. {
  772. gl_draw_scaled_image_with_border(x, y, width, height, mImage, color,
  773. false, mClipRegion, mScaleRegion);
  774. }
  775. }
  776. void LLUIImage::drawSolid(S32 x, S32 y, S32 width, S32 height,
  777. const LLColor4& color) const
  778. {
  779. gl_draw_scaled_image_with_border(x, y, width, height, mImage, color, true,
  780. mClipRegion, mScaleRegion);
  781. }
  782. void LLUIImage::drawBorder(S32 x, S32 y, S32 width, S32 height,
  783. const LLColor4& color, S32 border_width) const
  784. {
  785. LLRect border_rect;
  786. border_rect.setOriginAndSize(x, y, width, height);
  787. border_rect.stretch(border_width, border_width);
  788. drawSolid(border_rect, color);
  789. }
  790. S32 LLUIImage::getWidth() const
  791. {
  792. // return clipped dimensions of actual image area
  793. return ll_roundp((F32)mImage->getWidth(0) * mClipRegion.getWidth());
  794. }
  795. S32 LLUIImage::getHeight() const
  796. {
  797. // return clipped dimensions of actual image area
  798. return ll_roundp((F32)mImage->getHeight(0) * mClipRegion.getHeight());
  799. }
  800. S32 LLUIImage::getTextureWidth() const
  801. {
  802. return mImage->getWidth(0);
  803. }
  804. S32 LLUIImage::getTextureHeight() const
  805. {
  806. return mImage->getHeight(0);
  807. }