llui.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711
  1. /**
  2. * @file llui.h
  3. * @brief General static UI services definitions.
  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. #ifndef LL_LLUI_H
  33. #define LL_LLUI_H
  34. #include <stack>
  35. #include "llcontrol.h"
  36. #include "llcoord.h"
  37. #include "llgltexture.h"
  38. #include "llpointer.h"
  39. #include "llrefcount.h"
  40. #include "llrenderutils.h"
  41. #include "llsd.h"
  42. #include "llcolor4.h"
  43. class LLImageProviderInterface;
  44. class LLColor4;
  45. class LLHtmlHelp;
  46. class LLUIImage;
  47. class LLVector2;
  48. class LLVector3;
  49. class LLView;
  50. class LLWindow;
  51. typedef LLPointer<LLUIImage> LLUIImagePtr;
  52. // Reasons for drags to be denied. Ordered by priority for multi-drag.
  53. enum EAcceptance
  54. {
  55. ACCEPT_POSTPONED, // We are asynchronously determining acceptance
  56. ACCEPT_NO, // Uninformative, general purpose denial.
  57. ACCEPT_NO_LOCKED, // Operation would be valid, but perms forbid it.
  58. ACCEPT_YES_COPY_SINGLE, // We will take a copy of a single item
  59. ACCEPT_YES_SINGLE, // It is OK to drag and drop single item here.
  60. ACCEPT_YES_COPY_MULTI, // Wewill take a copy of multiple items
  61. ACCEPT_YES_MULTI // It is OK to drag and drop multiple items here.
  62. };
  63. enum EAddPosition
  64. {
  65. ADD_TOP,
  66. ADD_SORTED,
  67. ADD_BOTTOM
  68. };
  69. // Used to hide the flashing text cursor when window doesn't have focus.
  70. extern bool gShowTextEditCursor;
  71. void make_ui_sound(const char* name, bool force = false);
  72. // UI-specific rendering functions that cannot go into llrenderutils.h since
  73. // their implementation needs llui stuff
  74. void gl_rect_2d_offset_local(S32 left, S32 top, S32 right, S32 bottom,
  75. S32 pixel_offset = 0, bool filled = true);
  76. LL_INLINE void gl_rect_2d_offset_local(const LLRect& rect,
  77. S32 pixel_offset = 0,
  78. bool filled = true)
  79. {
  80. gl_rect_2d_offset_local(rect.mLeft, rect.mTop, rect.mRight, rect.mBottom,
  81. pixel_offset, filled);
  82. }
  83. LL_INLINE void gl_rect_2d_offset_local(S32 left, S32 top,
  84. S32 right, S32 bottom,
  85. const LLColor4& color,
  86. S32 pixel_offset = 0,
  87. bool filled = true)
  88. {
  89. gGL.color4fv(color.mV);
  90. gl_rect_2d_offset_local(left, top, right, bottom, pixel_offset, filled);
  91. }
  92. void gl_line_3d(const LLVector3& start, const LLVector3& end,
  93. const LLColor4& color, F32 phase = 0.f);
  94. void gl_rect_2d_checkerboard(const LLRect& rect);
  95. //
  96. // Classes
  97. //
  98. typedef void (*LLUIAudioCallback)(const LLUUID& uuid);
  99. // Purely static class (singleton, for no valid reason, in LL's code).
  100. class LLUI
  101. {
  102. LLUI() = delete;
  103. ~LLUI() = delete;
  104. protected:
  105. LOG_CLASS(LLUI);
  106. public:
  107. static void initClass(LLControlGroup* config,
  108. LLControlGroup* ignores,
  109. LLControlGroup* colors,
  110. LLImageProviderInterface* image_provider,
  111. LLUIAudioCallback audio_callback = NULL,
  112. const LLVector2* scale_factor = NULL,
  113. const std::string& language = LLStringUtil::null);
  114. static void cleanupClass();
  115. static void pushMatrix();
  116. static void popMatrix();
  117. static void loadIdentity();
  118. static void translate(F32 x, F32 y, F32 z = 0.0f);
  119. // Return the ISO639 language name ("en", "ko", etc.) for the viewer UI.
  120. // http://www.loc.gov/standards/iso639-2/php/code_list.php
  121. static std::string getLanguage();
  122. // Helper functions (should probably move free standing rendering helper
  123. // functions here)
  124. static std::string locateSkin(const std::string& filename);
  125. static void setCursorPositionScreen(S32 x, S32 y);
  126. static void setCursorPositionLocal(const LLView* viewp, S32 x, S32 y);
  127. static void getCursorPositionLocal(const LLView* viewp, S32* x, S32* y);
  128. static void setLineWidth(F32 width);
  129. static LLUIImagePtr getUIImageByID(const LLUUID& image_id);
  130. static LLUIImagePtr getUIImage(const std::string& name);
  131. static LLVector2 getWindowSize();
  132. static void screenPointToGL(S32 screen_x, S32 screen_y, S32* gl_x, S32* gl_y);
  133. static void glPointToScreen(S32 gl_x, S32 gl_y, S32* screen_x, S32* screen_y);
  134. static void screenRectToGL(const LLRect& screen, LLRect* gl);
  135. static void glRectToScreen(const LLRect& gl, LLRect* screen);
  136. static void setHtmlHelp(LLHtmlHelp* html_help);
  137. // The two following methods shall only be called from LLUISingleton, to
  138. // register and unregister the singleton instances, in a type-agnostic way,
  139. // and allow them to be destroyed cleanly on viewer exit. HB
  140. static void addSingletonInstance(LLView* instancep);
  141. static void removeSingletonInstance(LLView* instancep);
  142. // Called on viewer exit, to destroy all UI singleton instances. HB
  143. static void deleteSingletonInstances();
  144. private:
  145. static void connectRefreshSettingsSafe(const char* name);
  146. static void refreshSettings();
  147. private:
  148. // This set contains all the addresses of the UI singletons that have been
  149. // created during the viewer session; it is used to destroy all these
  150. // instances on viewer exit. Note that all singleton instances are derived
  151. // from a LLView, which is the parent class for all UI sub-classes. HB
  152. static fast_hset<LLView*> sSingletonInstances;
  153. public:
  154. static LLControlGroup* sConfigGroup;
  155. static LLControlGroup* sIgnoresGroup;
  156. static LLControlGroup* sColorsGroup;
  157. static LLImageProviderInterface* sImageProvider;
  158. static LLUIAudioCallback sAudioCallback;
  159. static LLVector2 sGLScaleFactor;
  160. static LLHtmlHelp* sHtmlHelp;
  161. static LLColor4 sAlertBoxColor;
  162. static LLColor4 sAlertCautionBoxColor;
  163. static LLColor4 sAlertCautionTextColor;
  164. static LLColor4 sAlertTextColor;
  165. static LLColor4 sButtonFlashBgColor;
  166. static LLColor4 sButtonImageColor;
  167. static LLColor4 sButtonLabelColor;
  168. static LLColor4 sButtonLabelDisabledColor;
  169. static LLColor4 sButtonLabelSelectedColor;
  170. static LLColor4 sButtonLabelSelectedDisabledColor;
  171. static LLColor4 sColorDropShadow;
  172. static LLColor4 sDefaultBackgroundColor;
  173. static LLColor4 sDefaultHighlightDark;
  174. static LLColor4 sDefaultHighlightLight;
  175. static LLColor4 sDefaultShadowDark;
  176. static LLColor4 sDefaultShadowLight;
  177. static LLColor4 sFloaterButtonImageColor;
  178. static LLColor4 sFloaterFocusBorderColor;
  179. static LLColor4 sFloaterUnfocusBorderColor;
  180. static LLColor4 sFocusBackgroundColor;
  181. static LLColor4 sHTMLLinkColor;
  182. static LLColor4 sLabelDisabledColor;
  183. static LLColor4 sLabelSelectedColor;
  184. static LLColor4 sLabelTextColor;
  185. static LLColor4 sLoginProgressBarBgColor;
  186. static LLColor4 sMenuDefaultBgColor;
  187. static LLColor4 sMultiSliderThumbCenterColor;
  188. static LLColor4 sMultiSliderThumbCenterSelectedColor;
  189. static LLColor4 sMultiSliderTrackColor;
  190. static LLColor4 sMultiSliderTriangleColor;
  191. static LLColor4 sPieMenuBgColor;
  192. static LLColor4 sPieMenuLineColor;
  193. static LLColor4 sPieMenuSelectedColor;
  194. static LLColor4 sScrollbarThumbColor;
  195. static LLColor4 sScrollbarTrackColor;
  196. static LLColor4 sScrollBgReadOnlyColor;
  197. static LLColor4 sScrollBGStripeColor;
  198. static LLColor4 sScrollBgWriteableColor;
  199. static LLColor4 sScrollDisabledColor;
  200. static LLColor4 sScrollHighlightedColor;
  201. static LLColor4 sScrollSelectedBGColor;
  202. static LLColor4 sScrollSelectedFGColor;
  203. static LLColor4 sScrollUnselectedColor;
  204. static LLColor4 sSliderThumbCenterColor;
  205. static LLColor4 sSliderThumbOutlineColor;
  206. static LLColor4 sSliderTrackColor;
  207. static LLColor4 sTextBgFocusColor;
  208. static LLColor4 sTextBgReadOnlyColor;
  209. static LLColor4 sTextBgWriteableColor;
  210. static LLColor4 sTextCursorColor;
  211. static LLColor4 sTextDefaultColor;
  212. static LLColor4 sTextEmbeddedItemColor;
  213. static LLColor4 sTextEmbeddedItemReadOnlyColor;
  214. static LLColor4 sTextFgColor;
  215. static LLColor4 sTextFgReadOnlyColor;
  216. static LLColor4 sTextFgTentativeColor;
  217. static LLColor4 sTitleBarFocusColor;
  218. static LLColor4 sTrackColor;
  219. static LLColor4 sDisabledTrackColor;
  220. static S32 sButtonFlashCount;
  221. static F32 sButtonFlashRate;
  222. static F32 sColumnHeaderDropDownDelay;
  223. static S32 sDropShadowButton;
  224. static S32 sDropShadowFloater;
  225. static S32 sDropShadowTooltip;
  226. static F32 sMenuAccessKeyTime;
  227. static F32 sPieMenuLineWidth;
  228. static S32 sSnapMargin;
  229. static F32 sTypeAheadTimeout;
  230. static bool sShowXUINames;
  231. static bool sConsoleBoxPerMessage;
  232. static bool sDisableMessagesSpacing;
  233. static bool sTabToTextFieldsOnly;
  234. static bool sUseAltKeyForMenus;
  235. };
  236. // FactoryPolicy is a static class that controls the creation and lookup of UI
  237. // elements such as floaters. The key parameter is used to provide a unique
  238. // identifier and/or associated construction parameters for a given UI
  239. // instance.
  240. //
  241. // Specialize this traits for different types, or provide a class with an
  242. // identical interface in the place of the traits parameter.
  243. //
  244. // For example:
  245. //
  246. // template <>
  247. // class FactoryPolicy<MyClass> /* FactoryPolicy specialized for MyClass */
  248. // {
  249. // public:
  250. // static MyClass* findInstance(const LLSD& key = LLSD())
  251. // {
  252. // // return instance of MyClass associated with key
  253. // }
  254. //
  255. // static MyClass* createInstance(const LLSD& key = LLSD())
  256. // {
  257. // // create new instance of MyClass using key for
  258. // // construction parameters
  259. // }
  260. // }
  261. //
  262. // class MyClass : public LLUIFactory<MyClass>
  263. // {
  264. // // uses FactoryPolicy<MyClass> by default
  265. // }
  266. template <class T>
  267. class FactoryPolicy
  268. {
  269. public:
  270. // Basic factory methods, unimplemented, provide specialisation
  271. static T* findInstance(const LLSD& key);
  272. static T* createInstance(const LLSD& key);
  273. };
  274. // VisibilityPolicy controls the visibility of UI elements, such as floaters.
  275. // The key parameter is used to store the unique identifier of a given UI instance
  276. //
  277. // Specialize this traits for different types, or duplicate this interface for
  278. // specific instances (see above).
  279. template <class T>
  280. class VisibilityPolicy
  281. {
  282. public:
  283. // visibility methods, unimplemented, provide specialisation
  284. static bool visible(T* instance, const LLSD& key);
  285. static void show(T* instance, const LLSD& key);
  286. static void hide(T* instance, const LLSD& key);
  287. };
  288. // Manages generation of UI elements by LLSD, such that (generally) there is a
  289. // unique instance per distinct LLSD parameter. Class T is the instance type
  290. // being managed, and the FACTORY_POLICY and VISIBILITY_POLICY. Classes provide
  291. // static methods for creating, accessing, showing and hiding the associated
  292. // element T.
  293. template <class T,
  294. class FACTORY_POLICY = FactoryPolicy<T>,
  295. class VISIBILITY_POLICY = VisibilityPolicy<T> >
  296. class LLUIFactory
  297. {
  298. public:
  299. // Give names to the template parameters so derived classes can refer to
  300. // them except this does not work in gcc
  301. typedef FACTORY_POLICY factory_policy_t;
  302. typedef VISIBILITY_POLICY visibility_policy_t;
  303. LLUIFactory() = default;
  304. virtual ~LLUIFactory() = default;
  305. // Default show and hide methods
  306. static T* showInstance(const LLSD& key = LLSD())
  307. {
  308. T* instance = getInstance(key);
  309. if (instance != NULL)
  310. {
  311. VISIBILITY_POLICY::show(instance, key);
  312. }
  313. return instance;
  314. }
  315. static void hideInstance(const LLSD& key = LLSD())
  316. {
  317. T* instance = FACTORY_POLICY::findInstance(key);
  318. if (instance != NULL)
  319. {
  320. VISIBILITY_POLICY::hide(instance, key);
  321. }
  322. }
  323. static void toggleInstance(const LLSD& key = LLSD())
  324. {
  325. if (instanceVisible(key))
  326. {
  327. hideInstance(key);
  328. }
  329. else
  330. {
  331. showInstance(key);
  332. }
  333. }
  334. static bool instanceVisible(const LLSD& key = LLSD())
  335. {
  336. T* instance = FACTORY_POLICY::findInstance(key);
  337. return instance != NULL && VISIBILITY_POLICY::visible(instance, key);
  338. }
  339. static T* getInstance(const LLSD& key = LLSD())
  340. {
  341. T* instance = FACTORY_POLICY::findInstance(key);
  342. if (instance == NULL)
  343. {
  344. instance = FACTORY_POLICY::createInstance(key);
  345. }
  346. return instance;
  347. }
  348. };
  349. // Creates a UI singleton by ignoring the identifying parameter and always
  350. // generating the same instance via the LLUIFactory interface. Note that since
  351. // UI elements can be destroyed by their hierarchy, this singleton pattern uses
  352. // a static pointer to an instance that will be re-created as needed.
  353. //
  354. // Usage Pattern:
  355. //
  356. // class LLFloaterFoo : public LLFloater, public LLUISingleton<LLFloaterFoo>
  357. // {
  358. // friend class LLUISingleton<LLFloaterFoo>;
  359. // private:
  360. // LLFloaterFoo(const LLSD& key);
  361. // };
  362. //
  363. // Note that LLUISingleton takes an option VisibilityPolicy parameter that
  364. // defines how showInstance(), hideInstance(), etc. work.
  365. template <class T, class VISIBILITY_POLICY = VisibilityPolicy<T> >
  366. class LLUISingleton : public LLUIFactory<T,
  367. LLUISingleton<T, VISIBILITY_POLICY>,
  368. VISIBILITY_POLICY>
  369. {
  370. protected:
  371. // T must derive from LLUISingleton<T>
  372. LL_INLINE LLUISingleton()
  373. {
  374. sInstance = static_cast<T*>(this);
  375. LLUI::addSingletonInstance(sInstance);
  376. }
  377. LL_INLINE ~LLUISingleton()
  378. {
  379. LLUI::removeSingletonInstance(sInstance);
  380. sInstance = NULL;
  381. }
  382. public:
  383. LL_INLINE static T* findInstance(const LLSD& key = LLSD())
  384. {
  385. return sInstance;
  386. }
  387. LL_INLINE static T* createInstance(const LLSD& key = LLSD())
  388. {
  389. if (!sInstance)
  390. {
  391. sInstance = new T(key);
  392. }
  393. return sInstance;
  394. }
  395. private:
  396. static T* sInstance;
  397. };
  398. template <class T, class U> T* LLUISingleton<T, U>::sInstance = NULL;
  399. class LLScreenClipRect
  400. {
  401. public:
  402. LLScreenClipRect(const LLRect& rect, bool enabled = true);
  403. virtual ~LLScreenClipRect();
  404. private:
  405. static void pushClipRect(const LLRect& rect);
  406. static void popClipRect();
  407. static void updateScissorRegion();
  408. private:
  409. LLGLState mScissorState;
  410. bool mEnabled;
  411. static std::stack<LLRect> sClipRectStack;
  412. };
  413. class LLLocalClipRect : public LLScreenClipRect
  414. {
  415. public:
  416. LLLocalClipRect(const LLRect& rect, bool enabled = true);
  417. };
  418. class LLUIImage : public LLRefCount
  419. {
  420. protected:
  421. LOG_CLASS(LLUIImage);
  422. public:
  423. LLUIImage(const std::string& name, LLPointer<LLGLTexture> image);
  424. void setClipRegion(const LLRectf& region);
  425. void setScaleRegion(const LLRectf& region);
  426. LLPointer<LLGLTexture> getImage() { return mImage; }
  427. const LLPointer<LLGLTexture>& getImage() const { return mImage; }
  428. void draw(S32 x, S32 y, S32 width, S32 height,
  429. const LLColor4& color = UI_VERTEX_COLOR) const;
  430. void draw(S32 x, S32 y, const LLColor4& color = UI_VERTEX_COLOR) const;
  431. void draw(const LLRect& rect,
  432. const LLColor4& color = UI_VERTEX_COLOR) const
  433. {
  434. draw(rect.mLeft, rect.mBottom, rect.getWidth(), rect.getHeight(),
  435. color);
  436. }
  437. void drawSolid(S32 x, S32 y, S32 width, S32 height,
  438. const LLColor4& color) const;
  439. void drawSolid(const LLRect& rect, const LLColor4& color) const
  440. {
  441. drawSolid(rect.mLeft, rect.mBottom, rect.getWidth(), rect.getHeight(),
  442. color);
  443. }
  444. void drawSolid(S32 x, S32 y, const LLColor4& color) const
  445. {
  446. drawSolid(x, y, mImage->getWidth(0), mImage->getHeight(0), color);
  447. }
  448. void drawBorder(S32 x, S32 y, S32 width, S32 height, const LLColor4& color,
  449. S32 border_width) const;
  450. void drawBorder(const LLRect& rect, const LLColor4& color,
  451. S32 border_width) const
  452. {
  453. drawBorder(rect.mLeft, rect.mBottom, rect.getWidth(), rect.getHeight(),
  454. color, border_width);
  455. }
  456. void drawBorder(S32 x, S32 y, const LLColor4& color,
  457. S32 border_width) const
  458. {
  459. drawBorder(x, y, mImage->getWidth(0), mImage->getHeight(0), color,
  460. border_width);
  461. }
  462. const std::string& getName() const { return mName; }
  463. S32 getWidth() const;
  464. S32 getHeight() const;
  465. // Returns dimensions of underlying textures, which might not be equal to
  466. // UI image portion
  467. S32 getTextureWidth() const;
  468. S32 getTextureHeight() const;
  469. // Used to load static UI image pointers. Must be called once the texture
  470. // fetcher has been fully initialized. Called from llviewertexturelist.cpp.
  471. static void initClass();
  472. // Used to cleanup static UI image pointers on viewer shutdown. Called from
  473. // llviewertexturelist.cpp.
  474. static void cleanupClass();
  475. public:
  476. static LLUIImagePtr sRoundedSquare;
  477. static S32 sRoundedSquareWidth;
  478. static S32 sRoundedSquareHeight;
  479. protected:
  480. std::string mName;
  481. LLRectf mScaleRegion;
  482. LLRectf mClipRegion;
  483. LLPointer<LLGLTexture> mImage;
  484. bool mUniformScaling;
  485. bool mNoClip;
  486. };
  487. // RN: maybe this needs to moved elsewhere ?
  488. class LLImageProviderInterface
  489. {
  490. public:
  491. LLImageProviderInterface() = default;
  492. virtual ~LLImageProviderInterface() = default;
  493. virtual LLUIImagePtr getUIImage(const std::string& name) = 0;
  494. virtual LLUIImagePtr getUIImageByID(const LLUUID& id) = 0;
  495. virtual void cleanUp() = 0;
  496. };
  497. template <typename DERIVED>
  498. class LLParamBlock
  499. {
  500. protected:
  501. LLParamBlock() { sBlock = (DERIVED*)this; }
  502. typedef typename boost::add_const<DERIVED>::type Tconst;
  503. template <typename T>
  504. class LLMandatoryParam
  505. {
  506. public:
  507. typedef typename boost::add_const<T>::type T_const;
  508. LLMandatoryParam(T_const initial_val)
  509. : mVal(initial_val),
  510. mBlock(sBlock)
  511. {
  512. }
  513. LLMandatoryParam(const LLMandatoryParam<T>& other)
  514. : mVal(other.mVal)
  515. {
  516. }
  517. DERIVED& operator()(T_const set_value) { mVal = set_value; return *mBlock; }
  518. operator T() const { return mVal; }
  519. T operator=(T_const set_value) { mVal = set_value; return mVal; }
  520. private:
  521. T mVal;
  522. DERIVED* mBlock;
  523. };
  524. template <typename T>
  525. class LLOptionalParam
  526. {
  527. public:
  528. typedef typename boost::add_const<T>::type T_const;
  529. LLOptionalParam(T_const initial_val)
  530. : mVal(initial_val),
  531. mBlock(sBlock)
  532. {
  533. }
  534. LLOptionalParam()
  535. : mBlock(sBlock)
  536. {
  537. }
  538. LLOptionalParam(const LLOptionalParam<T>& other)
  539. : mVal(other.mVal)
  540. {
  541. }
  542. DERIVED& operator()(T_const set_value) { mVal = set_value; return *mBlock; }
  543. operator T() const { return mVal; }
  544. T operator=(T_const set_value) { mVal = set_value; return mVal; }
  545. private:
  546. T mVal;
  547. DERIVED* mBlock;
  548. };
  549. // specialization that requires initialization for reference types
  550. template <typename T>
  551. class LLOptionalParam <T&>
  552. {
  553. public:
  554. typedef typename boost::add_const<T&>::type T_const;
  555. LLOptionalParam(T_const initial_val)
  556. : mVal(initial_val), mBlock(sBlock)
  557. {
  558. }
  559. LLOptionalParam(const LLOptionalParam<T&>& other)
  560. : mVal(other.mVal)
  561. {
  562. }
  563. DERIVED& operator ()(T_const set_value) { mVal = set_value; return *mBlock; }
  564. operator T&() const { return mVal; }
  565. T& operator=(T_const set_value) { mVal = set_value; return mVal; }
  566. private:
  567. T& mVal;
  568. DERIVED* mBlock;
  569. };
  570. // specialization that initializes pointer params to NULL
  571. template<typename T>
  572. class LLOptionalParam<T*>
  573. {
  574. public:
  575. typedef typename boost::add_const<T*>::type T_const;
  576. LLOptionalParam(T_const initial_val)
  577. : mVal(initial_val),
  578. mBlock(sBlock)
  579. {
  580. }
  581. LLOptionalParam()
  582. : mVal(NULL),
  583. mBlock(sBlock)
  584. {
  585. }
  586. LLOptionalParam(const LLOptionalParam<T*>& other)
  587. : mVal(other.mVal)
  588. {
  589. }
  590. DERIVED& operator ()(T_const set_value) { mVal = set_value; return *mBlock; }
  591. operator T*() const { return mVal; }
  592. T* operator=(T_const set_value) { mVal = set_value; return mVal; }
  593. private:
  594. T* mVal;
  595. DERIVED* mBlock;
  596. };
  597. static DERIVED* sBlock;
  598. };
  599. template <typename T> T* LLParamBlock<T>::sBlock = NULL;
  600. extern LLGLSLShader gSolidColorProgram;
  601. extern LLGLSLShader gUIProgram;
  602. // UI constants. Formerly in the now removed lluiconstants.h
  603. constexpr S32 VPAD = 4; // Vertical padding
  604. constexpr S32 HPAD = 4; // Horizontal padding
  605. // Spacing for small font lines of text, like LLTextBoxes
  606. constexpr S32 LINE = 16;
  607. #endif