123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711 |
- /**
- * @file llui.h
- * @brief General static UI services definitions.
- *
- * $LicenseInfo:firstyear=2001&license=viewergpl$
- *
- * Copyright (c) 2001-2009, Linden Research, Inc.
- *
- * Second Life Viewer Source Code
- * The source code in this file ("Source Code") is provided by Linden Lab
- * to you under the terms of the GNU General Public License, version 2.0
- * ("GPL"), unless you have obtained a separate licensing agreement
- * ("Other License"), formally executed by you and Linden Lab. Terms of
- * the GPL can be found in doc/GPL-license.txt in this distribution, or
- * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
- *
- * There are special exceptions to the terms and conditions of the GPL as
- * it is applied to this Source Code. View the full text of the exception
- * in the file doc/FLOSS-exception.txt in this software distribution, or
- * online at
- * http://secondlifegrid.net/programs/open_source/licensing/flossexception
- *
- * By copying, modifying or distributing this software, you acknowledge
- * that you have read and understood your obligations described above,
- * and agree to abide by those obligations.
- *
- * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
- * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
- * COMPLETENESS OR PERFORMANCE.
- * $/LicenseInfo$
- */
- #ifndef LL_LLUI_H
- #define LL_LLUI_H
- #include <stack>
- #include "llcontrol.h"
- #include "llcoord.h"
- #include "llgltexture.h"
- #include "llpointer.h"
- #include "llrefcount.h"
- #include "llrenderutils.h"
- #include "llsd.h"
- #include "llcolor4.h"
- class LLImageProviderInterface;
- class LLColor4;
- class LLHtmlHelp;
- class LLUIImage;
- class LLVector2;
- class LLVector3;
- class LLView;
- class LLWindow;
- typedef LLPointer<LLUIImage> LLUIImagePtr;
- // Reasons for drags to be denied. Ordered by priority for multi-drag.
- enum EAcceptance
- {
- ACCEPT_POSTPONED, // We are asynchronously determining acceptance
- ACCEPT_NO, // Uninformative, general purpose denial.
- ACCEPT_NO_LOCKED, // Operation would be valid, but perms forbid it.
- ACCEPT_YES_COPY_SINGLE, // We will take a copy of a single item
- ACCEPT_YES_SINGLE, // It is OK to drag and drop single item here.
- ACCEPT_YES_COPY_MULTI, // Wewill take a copy of multiple items
- ACCEPT_YES_MULTI // It is OK to drag and drop multiple items here.
- };
- enum EAddPosition
- {
- ADD_TOP,
- ADD_SORTED,
- ADD_BOTTOM
- };
- // Used to hide the flashing text cursor when window doesn't have focus.
- extern bool gShowTextEditCursor;
- void make_ui_sound(const char* name, bool force = false);
- // UI-specific rendering functions that cannot go into llrenderutils.h since
- // their implementation needs llui stuff
- void gl_rect_2d_offset_local(S32 left, S32 top, S32 right, S32 bottom,
- S32 pixel_offset = 0, bool filled = true);
- LL_INLINE void gl_rect_2d_offset_local(const LLRect& rect,
- S32 pixel_offset = 0,
- bool filled = true)
- {
- gl_rect_2d_offset_local(rect.mLeft, rect.mTop, rect.mRight, rect.mBottom,
- pixel_offset, filled);
- }
- LL_INLINE void gl_rect_2d_offset_local(S32 left, S32 top,
- S32 right, S32 bottom,
- const LLColor4& color,
- S32 pixel_offset = 0,
- bool filled = true)
- {
- gGL.color4fv(color.mV);
- gl_rect_2d_offset_local(left, top, right, bottom, pixel_offset, filled);
- }
- void gl_line_3d(const LLVector3& start, const LLVector3& end,
- const LLColor4& color, F32 phase = 0.f);
- void gl_rect_2d_checkerboard(const LLRect& rect);
- //
- // Classes
- //
- typedef void (*LLUIAudioCallback)(const LLUUID& uuid);
- // Purely static class (singleton, for no valid reason, in LL's code).
- class LLUI
- {
- LLUI() = delete;
- ~LLUI() = delete;
- protected:
- LOG_CLASS(LLUI);
- public:
- static void initClass(LLControlGroup* config,
- LLControlGroup* ignores,
- LLControlGroup* colors,
- LLImageProviderInterface* image_provider,
- LLUIAudioCallback audio_callback = NULL,
- const LLVector2* scale_factor = NULL,
- const std::string& language = LLStringUtil::null);
- static void cleanupClass();
- static void pushMatrix();
- static void popMatrix();
- static void loadIdentity();
- static void translate(F32 x, F32 y, F32 z = 0.0f);
- // Return the ISO639 language name ("en", "ko", etc.) for the viewer UI.
- // http://www.loc.gov/standards/iso639-2/php/code_list.php
- static std::string getLanguage();
- // Helper functions (should probably move free standing rendering helper
- // functions here)
- static std::string locateSkin(const std::string& filename);
- static void setCursorPositionScreen(S32 x, S32 y);
- static void setCursorPositionLocal(const LLView* viewp, S32 x, S32 y);
- static void getCursorPositionLocal(const LLView* viewp, S32* x, S32* y);
- static void setLineWidth(F32 width);
- static LLUIImagePtr getUIImageByID(const LLUUID& image_id);
- static LLUIImagePtr getUIImage(const std::string& name);
- static LLVector2 getWindowSize();
- static void screenPointToGL(S32 screen_x, S32 screen_y, S32* gl_x, S32* gl_y);
- static void glPointToScreen(S32 gl_x, S32 gl_y, S32* screen_x, S32* screen_y);
- static void screenRectToGL(const LLRect& screen, LLRect* gl);
- static void glRectToScreen(const LLRect& gl, LLRect* screen);
- static void setHtmlHelp(LLHtmlHelp* html_help);
- // The two following methods shall only be called from LLUISingleton, to
- // register and unregister the singleton instances, in a type-agnostic way,
- // and allow them to be destroyed cleanly on viewer exit. HB
- static void addSingletonInstance(LLView* instancep);
- static void removeSingletonInstance(LLView* instancep);
- // Called on viewer exit, to destroy all UI singleton instances. HB
- static void deleteSingletonInstances();
- private:
- static void connectRefreshSettingsSafe(const char* name);
- static void refreshSettings();
- private:
- // This set contains all the addresses of the UI singletons that have been
- // created during the viewer session; it is used to destroy all these
- // instances on viewer exit. Note that all singleton instances are derived
- // from a LLView, which is the parent class for all UI sub-classes. HB
- static fast_hset<LLView*> sSingletonInstances;
- public:
- static LLControlGroup* sConfigGroup;
- static LLControlGroup* sIgnoresGroup;
- static LLControlGroup* sColorsGroup;
- static LLImageProviderInterface* sImageProvider;
- static LLUIAudioCallback sAudioCallback;
- static LLVector2 sGLScaleFactor;
- static LLHtmlHelp* sHtmlHelp;
- static LLColor4 sAlertBoxColor;
- static LLColor4 sAlertCautionBoxColor;
- static LLColor4 sAlertCautionTextColor;
- static LLColor4 sAlertTextColor;
- static LLColor4 sButtonFlashBgColor;
- static LLColor4 sButtonImageColor;
- static LLColor4 sButtonLabelColor;
- static LLColor4 sButtonLabelDisabledColor;
- static LLColor4 sButtonLabelSelectedColor;
- static LLColor4 sButtonLabelSelectedDisabledColor;
- static LLColor4 sColorDropShadow;
- static LLColor4 sDefaultBackgroundColor;
- static LLColor4 sDefaultHighlightDark;
- static LLColor4 sDefaultHighlightLight;
- static LLColor4 sDefaultShadowDark;
- static LLColor4 sDefaultShadowLight;
- static LLColor4 sFloaterButtonImageColor;
- static LLColor4 sFloaterFocusBorderColor;
- static LLColor4 sFloaterUnfocusBorderColor;
- static LLColor4 sFocusBackgroundColor;
- static LLColor4 sHTMLLinkColor;
- static LLColor4 sLabelDisabledColor;
- static LLColor4 sLabelSelectedColor;
- static LLColor4 sLabelTextColor;
- static LLColor4 sLoginProgressBarBgColor;
- static LLColor4 sMenuDefaultBgColor;
- static LLColor4 sMultiSliderThumbCenterColor;
- static LLColor4 sMultiSliderThumbCenterSelectedColor;
- static LLColor4 sMultiSliderTrackColor;
- static LLColor4 sMultiSliderTriangleColor;
- static LLColor4 sPieMenuBgColor;
- static LLColor4 sPieMenuLineColor;
- static LLColor4 sPieMenuSelectedColor;
- static LLColor4 sScrollbarThumbColor;
- static LLColor4 sScrollbarTrackColor;
- static LLColor4 sScrollBgReadOnlyColor;
- static LLColor4 sScrollBGStripeColor;
- static LLColor4 sScrollBgWriteableColor;
- static LLColor4 sScrollDisabledColor;
- static LLColor4 sScrollHighlightedColor;
- static LLColor4 sScrollSelectedBGColor;
- static LLColor4 sScrollSelectedFGColor;
- static LLColor4 sScrollUnselectedColor;
- static LLColor4 sSliderThumbCenterColor;
- static LLColor4 sSliderThumbOutlineColor;
- static LLColor4 sSliderTrackColor;
- static LLColor4 sTextBgFocusColor;
- static LLColor4 sTextBgReadOnlyColor;
- static LLColor4 sTextBgWriteableColor;
- static LLColor4 sTextCursorColor;
- static LLColor4 sTextDefaultColor;
- static LLColor4 sTextEmbeddedItemColor;
- static LLColor4 sTextEmbeddedItemReadOnlyColor;
- static LLColor4 sTextFgColor;
- static LLColor4 sTextFgReadOnlyColor;
- static LLColor4 sTextFgTentativeColor;
- static LLColor4 sTitleBarFocusColor;
- static LLColor4 sTrackColor;
- static LLColor4 sDisabledTrackColor;
- static S32 sButtonFlashCount;
- static F32 sButtonFlashRate;
- static F32 sColumnHeaderDropDownDelay;
- static S32 sDropShadowButton;
- static S32 sDropShadowFloater;
- static S32 sDropShadowTooltip;
- static F32 sMenuAccessKeyTime;
- static F32 sPieMenuLineWidth;
- static S32 sSnapMargin;
- static F32 sTypeAheadTimeout;
- static bool sShowXUINames;
- static bool sConsoleBoxPerMessage;
- static bool sDisableMessagesSpacing;
- static bool sTabToTextFieldsOnly;
- static bool sUseAltKeyForMenus;
- };
- // FactoryPolicy is a static class that controls the creation and lookup of UI
- // elements such as floaters. The key parameter is used to provide a unique
- // identifier and/or associated construction parameters for a given UI
- // instance.
- //
- // Specialize this traits for different types, or provide a class with an
- // identical interface in the place of the traits parameter.
- //
- // For example:
- //
- // template <>
- // class FactoryPolicy<MyClass> /* FactoryPolicy specialized for MyClass */
- // {
- // public:
- // static MyClass* findInstance(const LLSD& key = LLSD())
- // {
- // // return instance of MyClass associated with key
- // }
- //
- // static MyClass* createInstance(const LLSD& key = LLSD())
- // {
- // // create new instance of MyClass using key for
- // // construction parameters
- // }
- // }
- //
- // class MyClass : public LLUIFactory<MyClass>
- // {
- // // uses FactoryPolicy<MyClass> by default
- // }
- template <class T>
- class FactoryPolicy
- {
- public:
- // Basic factory methods, unimplemented, provide specialisation
- static T* findInstance(const LLSD& key);
- static T* createInstance(const LLSD& key);
- };
- // VisibilityPolicy controls the visibility of UI elements, such as floaters.
- // The key parameter is used to store the unique identifier of a given UI instance
- //
- // Specialize this traits for different types, or duplicate this interface for
- // specific instances (see above).
- template <class T>
- class VisibilityPolicy
- {
- public:
- // visibility methods, unimplemented, provide specialisation
- static bool visible(T* instance, const LLSD& key);
- static void show(T* instance, const LLSD& key);
- static void hide(T* instance, const LLSD& key);
- };
- // Manages generation of UI elements by LLSD, such that (generally) there is a
- // unique instance per distinct LLSD parameter. Class T is the instance type
- // being managed, and the FACTORY_POLICY and VISIBILITY_POLICY. Classes provide
- // static methods for creating, accessing, showing and hiding the associated
- // element T.
- template <class T,
- class FACTORY_POLICY = FactoryPolicy<T>,
- class VISIBILITY_POLICY = VisibilityPolicy<T> >
- class LLUIFactory
- {
- public:
- // Give names to the template parameters so derived classes can refer to
- // them except this does not work in gcc
- typedef FACTORY_POLICY factory_policy_t;
- typedef VISIBILITY_POLICY visibility_policy_t;
- LLUIFactory() = default;
- virtual ~LLUIFactory() = default;
- // Default show and hide methods
- static T* showInstance(const LLSD& key = LLSD())
- {
- T* instance = getInstance(key);
- if (instance != NULL)
- {
- VISIBILITY_POLICY::show(instance, key);
- }
- return instance;
- }
- static void hideInstance(const LLSD& key = LLSD())
- {
- T* instance = FACTORY_POLICY::findInstance(key);
- if (instance != NULL)
- {
- VISIBILITY_POLICY::hide(instance, key);
- }
- }
- static void toggleInstance(const LLSD& key = LLSD())
- {
- if (instanceVisible(key))
- {
- hideInstance(key);
- }
- else
- {
- showInstance(key);
- }
- }
- static bool instanceVisible(const LLSD& key = LLSD())
- {
- T* instance = FACTORY_POLICY::findInstance(key);
- return instance != NULL && VISIBILITY_POLICY::visible(instance, key);
- }
- static T* getInstance(const LLSD& key = LLSD())
- {
- T* instance = FACTORY_POLICY::findInstance(key);
- if (instance == NULL)
- {
- instance = FACTORY_POLICY::createInstance(key);
- }
- return instance;
- }
- };
- // Creates a UI singleton by ignoring the identifying parameter and always
- // generating the same instance via the LLUIFactory interface. Note that since
- // UI elements can be destroyed by their hierarchy, this singleton pattern uses
- // a static pointer to an instance that will be re-created as needed.
- //
- // Usage Pattern:
- //
- // class LLFloaterFoo : public LLFloater, public LLUISingleton<LLFloaterFoo>
- // {
- // friend class LLUISingleton<LLFloaterFoo>;
- // private:
- // LLFloaterFoo(const LLSD& key);
- // };
- //
- // Note that LLUISingleton takes an option VisibilityPolicy parameter that
- // defines how showInstance(), hideInstance(), etc. work.
- template <class T, class VISIBILITY_POLICY = VisibilityPolicy<T> >
- class LLUISingleton : public LLUIFactory<T,
- LLUISingleton<T, VISIBILITY_POLICY>,
- VISIBILITY_POLICY>
- {
- protected:
- // T must derive from LLUISingleton<T>
- LL_INLINE LLUISingleton()
- {
- sInstance = static_cast<T*>(this);
- LLUI::addSingletonInstance(sInstance);
- }
- LL_INLINE ~LLUISingleton()
- {
- LLUI::removeSingletonInstance(sInstance);
- sInstance = NULL;
- }
- public:
- LL_INLINE static T* findInstance(const LLSD& key = LLSD())
- {
- return sInstance;
- }
- LL_INLINE static T* createInstance(const LLSD& key = LLSD())
- {
- if (!sInstance)
- {
- sInstance = new T(key);
- }
- return sInstance;
- }
- private:
- static T* sInstance;
- };
- template <class T, class U> T* LLUISingleton<T, U>::sInstance = NULL;
- class LLScreenClipRect
- {
- public:
- LLScreenClipRect(const LLRect& rect, bool enabled = true);
- virtual ~LLScreenClipRect();
- private:
- static void pushClipRect(const LLRect& rect);
- static void popClipRect();
- static void updateScissorRegion();
- private:
- LLGLState mScissorState;
- bool mEnabled;
- static std::stack<LLRect> sClipRectStack;
- };
- class LLLocalClipRect : public LLScreenClipRect
- {
- public:
- LLLocalClipRect(const LLRect& rect, bool enabled = true);
- };
- class LLUIImage : public LLRefCount
- {
- protected:
- LOG_CLASS(LLUIImage);
- public:
- LLUIImage(const std::string& name, LLPointer<LLGLTexture> image);
- void setClipRegion(const LLRectf& region);
- void setScaleRegion(const LLRectf& region);
- LLPointer<LLGLTexture> getImage() { return mImage; }
- const LLPointer<LLGLTexture>& getImage() const { return mImage; }
- void draw(S32 x, S32 y, S32 width, S32 height,
- const LLColor4& color = UI_VERTEX_COLOR) const;
- void draw(S32 x, S32 y, const LLColor4& color = UI_VERTEX_COLOR) const;
- void draw(const LLRect& rect,
- const LLColor4& color = UI_VERTEX_COLOR) const
- {
- draw(rect.mLeft, rect.mBottom, rect.getWidth(), rect.getHeight(),
- color);
- }
- void drawSolid(S32 x, S32 y, S32 width, S32 height,
- const LLColor4& color) const;
- void drawSolid(const LLRect& rect, const LLColor4& color) const
- {
- drawSolid(rect.mLeft, rect.mBottom, rect.getWidth(), rect.getHeight(),
- color);
- }
- void drawSolid(S32 x, S32 y, const LLColor4& color) const
- {
- drawSolid(x, y, mImage->getWidth(0), mImage->getHeight(0), color);
- }
- void drawBorder(S32 x, S32 y, S32 width, S32 height, const LLColor4& color,
- S32 border_width) const;
- void drawBorder(const LLRect& rect, const LLColor4& color,
- S32 border_width) const
- {
- drawBorder(rect.mLeft, rect.mBottom, rect.getWidth(), rect.getHeight(),
- color, border_width);
- }
- void drawBorder(S32 x, S32 y, const LLColor4& color,
- S32 border_width) const
- {
- drawBorder(x, y, mImage->getWidth(0), mImage->getHeight(0), color,
- border_width);
- }
- const std::string& getName() const { return mName; }
- S32 getWidth() const;
- S32 getHeight() const;
- // Returns dimensions of underlying textures, which might not be equal to
- // UI image portion
- S32 getTextureWidth() const;
- S32 getTextureHeight() const;
- // Used to load static UI image pointers. Must be called once the texture
- // fetcher has been fully initialized. Called from llviewertexturelist.cpp.
- static void initClass();
- // Used to cleanup static UI image pointers on viewer shutdown. Called from
- // llviewertexturelist.cpp.
- static void cleanupClass();
- public:
- static LLUIImagePtr sRoundedSquare;
- static S32 sRoundedSquareWidth;
- static S32 sRoundedSquareHeight;
- protected:
- std::string mName;
- LLRectf mScaleRegion;
- LLRectf mClipRegion;
- LLPointer<LLGLTexture> mImage;
- bool mUniformScaling;
- bool mNoClip;
- };
- // RN: maybe this needs to moved elsewhere ?
- class LLImageProviderInterface
- {
- public:
- LLImageProviderInterface() = default;
- virtual ~LLImageProviderInterface() = default;
- virtual LLUIImagePtr getUIImage(const std::string& name) = 0;
- virtual LLUIImagePtr getUIImageByID(const LLUUID& id) = 0;
- virtual void cleanUp() = 0;
- };
- template <typename DERIVED>
- class LLParamBlock
- {
- protected:
- LLParamBlock() { sBlock = (DERIVED*)this; }
- typedef typename boost::add_const<DERIVED>::type Tconst;
- template <typename T>
- class LLMandatoryParam
- {
- public:
- typedef typename boost::add_const<T>::type T_const;
- LLMandatoryParam(T_const initial_val)
- : mVal(initial_val),
- mBlock(sBlock)
- {
- }
- LLMandatoryParam(const LLMandatoryParam<T>& other)
- : mVal(other.mVal)
- {
- }
- DERIVED& operator()(T_const set_value) { mVal = set_value; return *mBlock; }
- operator T() const { return mVal; }
- T operator=(T_const set_value) { mVal = set_value; return mVal; }
- private:
- T mVal;
- DERIVED* mBlock;
- };
- template <typename T>
- class LLOptionalParam
- {
- public:
- typedef typename boost::add_const<T>::type T_const;
- LLOptionalParam(T_const initial_val)
- : mVal(initial_val),
- mBlock(sBlock)
- {
- }
- LLOptionalParam()
- : mBlock(sBlock)
- {
- }
- LLOptionalParam(const LLOptionalParam<T>& other)
- : mVal(other.mVal)
- {
- }
- DERIVED& operator()(T_const set_value) { mVal = set_value; return *mBlock; }
- operator T() const { return mVal; }
- T operator=(T_const set_value) { mVal = set_value; return mVal; }
- private:
- T mVal;
- DERIVED* mBlock;
- };
- // specialization that requires initialization for reference types
- template <typename T>
- class LLOptionalParam <T&>
- {
- public:
- typedef typename boost::add_const<T&>::type T_const;
- LLOptionalParam(T_const initial_val)
- : mVal(initial_val), mBlock(sBlock)
- {
- }
- LLOptionalParam(const LLOptionalParam<T&>& other)
- : mVal(other.mVal)
- {
- }
- DERIVED& operator ()(T_const set_value) { mVal = set_value; return *mBlock; }
- operator T&() const { return mVal; }
- T& operator=(T_const set_value) { mVal = set_value; return mVal; }
- private:
- T& mVal;
- DERIVED* mBlock;
- };
- // specialization that initializes pointer params to NULL
- template<typename T>
- class LLOptionalParam<T*>
- {
- public:
- typedef typename boost::add_const<T*>::type T_const;
- LLOptionalParam(T_const initial_val)
- : mVal(initial_val),
- mBlock(sBlock)
- {
- }
- LLOptionalParam()
- : mVal(NULL),
- mBlock(sBlock)
- {
- }
- LLOptionalParam(const LLOptionalParam<T*>& other)
- : mVal(other.mVal)
- {
- }
- DERIVED& operator ()(T_const set_value) { mVal = set_value; return *mBlock; }
- operator T*() const { return mVal; }
- T* operator=(T_const set_value) { mVal = set_value; return mVal; }
- private:
- T* mVal;
- DERIVED* mBlock;
- };
- static DERIVED* sBlock;
- };
- template <typename T> T* LLParamBlock<T>::sBlock = NULL;
- extern LLGLSLShader gSolidColorProgram;
- extern LLGLSLShader gUIProgram;
- // UI constants. Formerly in the now removed lluiconstants.h
- constexpr S32 VPAD = 4; // Vertical padding
- constexpr S32 HPAD = 4; // Horizontal padding
- // Spacing for small font lines of text, like LLTextBoxes
- constexpr S32 LINE = 16;
- #endif
|