diff options
author | Jacek Antonelli | 2009-04-30 13:04:20 -0500 |
---|---|---|
committer | Jacek Antonelli | 2009-04-30 13:07:16 -0500 |
commit | ca8149ca6d157eb4b5fc8ba0e5ba3a6e56f72e7e (patch) | |
tree | 8348301d0ac44a524f1819b777686bf086907d76 /linden/indra/llui/llui.h | |
parent | Second Life viewer sources 1.22.11 (diff) | |
download | meta-impy-ca8149ca6d157eb4b5fc8ba0e5ba3a6e56f72e7e.zip meta-impy-ca8149ca6d157eb4b5fc8ba0e5ba3a6e56f72e7e.tar.gz meta-impy-ca8149ca6d157eb4b5fc8ba0e5ba3a6e56f72e7e.tar.bz2 meta-impy-ca8149ca6d157eb4b5fc8ba0e5ba3a6e56f72e7e.tar.xz |
Second Life viewer sources 1.23.0-RC
Diffstat (limited to 'linden/indra/llui/llui.h')
-rw-r--r-- | linden/indra/llui/llui.h | 241 |
1 files changed, 240 insertions, 1 deletions
diff --git a/linden/indra/llui/llui.h b/linden/indra/llui/llui.h index 1e731f1..ebcc730 100644 --- a/linden/indra/llui/llui.h +++ b/linden/indra/llui/llui.h | |||
@@ -17,7 +17,8 @@ | |||
17 | * There are special exceptions to the terms and conditions of the GPL as | 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 | 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 | 19 | * in the file doc/FLOSS-exception.txt in this software distribution, or |
20 | * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception | 20 | * online at |
21 | * http://secondlifegrid.net/programs/open_source/licensing/flossexception | ||
21 | * | 22 | * |
22 | * By copying, modifying or distributing this software, you acknowledge | 23 | * By copying, modifying or distributing this software, you acknowledge |
23 | * that you have read and understood your obligations described above, | 24 | * that you have read and understood your obligations described above, |
@@ -42,6 +43,7 @@ | |||
42 | #include "llgl.h" // *TODO: break this dependency | 43 | #include "llgl.h" // *TODO: break this dependency |
43 | #include <stack> | 44 | #include <stack> |
44 | //#include "llimagegl.h" | 45 | //#include "llimagegl.h" |
46 | #include <boost/signal.hpp> | ||
45 | 47 | ||
46 | // LLUIFactory | 48 | // LLUIFactory |
47 | #include "llsd.h" | 49 | #include "llsd.h" |
@@ -150,11 +152,13 @@ typedef void (*LLUIAudioCallback)(const LLUUID& uuid); | |||
150 | 152 | ||
151 | class LLUI | 153 | class LLUI |
152 | { | 154 | { |
155 | LOG_CLASS(LLUI); | ||
153 | public: | 156 | public: |
154 | // | 157 | // |
155 | // Methods | 158 | // Methods |
156 | // | 159 | // |
157 | static void initClass(LLControlGroup* config, | 160 | static void initClass(LLControlGroup* config, |
161 | LLControlGroup* ignores, | ||
158 | LLControlGroup* colors, | 162 | LLControlGroup* colors, |
159 | LLImageProviderInterface* image_provider, | 163 | LLImageProviderInterface* image_provider, |
160 | LLUIAudioCallback audio_callback = NULL, | 164 | LLUIAudioCallback audio_callback = NULL, |
@@ -175,6 +179,7 @@ public: | |||
175 | static std::string locateSkin(const std::string& filename); | 179 | static std::string locateSkin(const std::string& filename); |
176 | static void setCursorPositionScreen(S32 x, S32 y); | 180 | static void setCursorPositionScreen(S32 x, S32 y); |
177 | static void setCursorPositionLocal(const LLView* viewp, S32 x, S32 y); | 181 | static void setCursorPositionLocal(const LLView* viewp, S32 x, S32 y); |
182 | static void getCursorPositionLocal(const LLView* viewp, S32 *x, S32 *y); | ||
178 | static void setScaleFactor(const LLVector2& scale_factor); | 183 | static void setScaleFactor(const LLVector2& scale_factor); |
179 | static void setLineWidth(F32 width); | 184 | static void setLineWidth(F32 width); |
180 | static LLUIImage* getUIImage(const std::string& name); | 185 | static LLUIImage* getUIImage(const std::string& name); |
@@ -189,6 +194,7 @@ public: | |||
189 | // Data | 194 | // Data |
190 | // | 195 | // |
191 | static LLControlGroup* sConfigGroup; | 196 | static LLControlGroup* sConfigGroup; |
197 | static LLControlGroup* sIgnoresGroup; | ||
192 | static LLControlGroup* sColorsGroup; | 198 | static LLControlGroup* sColorsGroup; |
193 | static LLImageProviderInterface* sImageProvider; | 199 | static LLImageProviderInterface* sImageProvider; |
194 | static LLUIAudioCallback sAudioCallback; | 200 | static LLUIAudioCallback sAudioCallback; |
@@ -596,4 +602,237 @@ public: | |||
596 | virtual void cleanUp() = 0; | 602 | virtual void cleanUp() = 0; |
597 | }; | 603 | }; |
598 | 604 | ||
605 | // This mix-in class adds support for tracking all instances of the specificed class parameter T | ||
606 | // The (optional) key associates a value of type KEY with a given instance of T, for quick lookup | ||
607 | // If KEY is not provided, then instances are stored in a simple list | ||
608 | template<typename T, typename KEY = T*> | ||
609 | class LLInstanceTracker : boost::noncopyable | ||
610 | { | ||
611 | public: | ||
612 | typedef typename std::map<KEY, T*>::iterator instance_iter; | ||
613 | typedef typename std::map<KEY, T*>::const_iterator instance_const_iter; | ||
614 | |||
615 | static T* getInstance(KEY k) { instance_iter found = sInstances.find(k); return (found == sInstances.end()) ? NULL : found->second; } | ||
616 | |||
617 | static instance_iter beginInstances() { return sInstances.begin(); } | ||
618 | static instance_iter endInstances() { return sInstances.end(); } | ||
619 | static S32 instanceCount() { return sInstances.size(); } | ||
620 | protected: | ||
621 | LLInstanceTracker(KEY key) { add(key); } | ||
622 | virtual ~LLInstanceTracker() { remove(); } | ||
623 | virtual void setKey(KEY key) { remove(); add(key); } | ||
624 | virtual const KEY& getKey() const { return mKey; } | ||
625 | |||
626 | private: | ||
627 | void add(KEY key) | ||
628 | { | ||
629 | mKey = key; | ||
630 | sInstances[key] = static_cast<T*>(this); | ||
631 | } | ||
632 | void remove() { sInstances.erase(mKey); } | ||
633 | |||
634 | private: | ||
635 | |||
636 | KEY mKey; | ||
637 | static std::map<KEY, T*> sInstances; | ||
638 | }; | ||
639 | |||
640 | template<typename T> | ||
641 | class LLInstanceTracker<T, T*> : boost::noncopyable | ||
642 | { | ||
643 | public: | ||
644 | typedef typename std::set<T*>::iterator instance_iter; | ||
645 | typedef typename std::set<T*>::const_iterator instance_const_iter; | ||
646 | |||
647 | static instance_iter instancesBegin() { return sInstances.begin(); } | ||
648 | static instance_iter instancesEnd() { return sInstances.end(); } | ||
649 | static S32 instanceCount() { return sInstances.size(); } | ||
650 | |||
651 | protected: | ||
652 | LLInstanceTracker() { sInstances.insert(static_cast<T*>(this)); } | ||
653 | virtual ~LLInstanceTracker() { sInstances.erase(static_cast<T*>(this)); } | ||
654 | |||
655 | static std::set<T*> sInstances; | ||
656 | }; | ||
657 | |||
658 | template <typename T, typename KEY> std::map<KEY, T*> LLInstanceTracker<T, KEY>::sInstances; | ||
659 | template <typename T> std::set<T*> LLInstanceTracker<T, T*>::sInstances; | ||
660 | |||
661 | class LLCallbackRegistry | ||
662 | { | ||
663 | public: | ||
664 | typedef boost::signal<void()> callback_signal_t; | ||
665 | |||
666 | void registerCallback(const callback_signal_t::slot_type& slot) | ||
667 | { | ||
668 | mCallbacks.connect(slot); | ||
669 | } | ||
670 | |||
671 | void fireCallbacks() | ||
672 | { | ||
673 | mCallbacks(); | ||
674 | } | ||
675 | |||
676 | private: | ||
677 | callback_signal_t mCallbacks; | ||
678 | }; | ||
679 | |||
680 | class LLInitClassList : | ||
681 | public LLCallbackRegistry, | ||
682 | public LLSingleton<LLInitClassList> | ||
683 | { | ||
684 | friend class LLSingleton<LLInitClassList>; | ||
685 | private: | ||
686 | LLInitClassList() {} | ||
687 | }; | ||
688 | |||
689 | class LLDestroyClassList : | ||
690 | public LLCallbackRegistry, | ||
691 | public LLSingleton<LLDestroyClassList> | ||
692 | { | ||
693 | friend class LLSingleton<LLDestroyClassList>; | ||
694 | private: | ||
695 | LLDestroyClassList() {} | ||
696 | }; | ||
697 | |||
698 | template<typename T> | ||
699 | class LLRegisterWith | ||
700 | { | ||
701 | public: | ||
702 | LLRegisterWith(boost::function<void ()> func) | ||
703 | { | ||
704 | T::instance().registerCallback(func); | ||
705 | } | ||
706 | |||
707 | // this avoids a MSVC bug where non-referenced static members are "optimized" away | ||
708 | // even if their constructors have side effects | ||
709 | void reference() | ||
710 | { | ||
711 | S32 dummy; | ||
712 | dummy = 0; | ||
713 | } | ||
714 | }; | ||
715 | |||
716 | template<typename T> | ||
717 | class LLInitClass | ||
718 | { | ||
719 | public: | ||
720 | LLInitClass() { sRegister.reference(); } | ||
721 | |||
722 | static LLRegisterWith<LLInitClassList> sRegister; | ||
723 | private: | ||
724 | |||
725 | static void initClass() | ||
726 | { | ||
727 | llerrs << "No static initClass() method defined for " << typeid(T).name() << llendl; | ||
728 | } | ||
729 | }; | ||
730 | |||
731 | template<typename T> | ||
732 | class LLDestroyClass | ||
733 | { | ||
734 | public: | ||
735 | LLDestroyClass() { sRegister.reference(); } | ||
736 | |||
737 | static LLRegisterWith<LLDestroyClassList> sRegister; | ||
738 | private: | ||
739 | |||
740 | static void destroyClass() | ||
741 | { | ||
742 | llerrs << "No static destroyClass() method defined for " << typeid(T).name() << llendl; | ||
743 | } | ||
744 | }; | ||
745 | |||
746 | template <typename T> LLRegisterWith<LLInitClassList> LLInitClass<T>::sRegister(&T::initClass); | ||
747 | template <typename T> LLRegisterWith<LLDestroyClassList> LLDestroyClass<T>::sRegister(&T::destroyClass); | ||
748 | |||
749 | |||
750 | template <typename DERIVED> | ||
751 | class LLParamBlock | ||
752 | { | ||
753 | protected: | ||
754 | LLParamBlock() { sBlock = (DERIVED*)this; } | ||
755 | |||
756 | typedef typename boost::add_const<DERIVED>::type Tconst; | ||
757 | |||
758 | template <typename T> | ||
759 | class LLMandatoryParam | ||
760 | { | ||
761 | public: | ||
762 | typedef typename boost::add_const<T>::type T_const; | ||
763 | |||
764 | LLMandatoryParam(T_const initial_val) : mVal(initial_val), mBlock(sBlock) {} | ||
765 | LLMandatoryParam(const LLMandatoryParam<T>& other) : mVal(other.mVal) {} | ||
766 | |||
767 | DERIVED& operator ()(T_const set_value) { mVal = set_value; return *mBlock; } | ||
768 | operator T() const { return mVal; } | ||
769 | T operator=(T_const set_value) { mVal = set_value; return mVal; } | ||
770 | |||
771 | private: | ||
772 | T mVal; | ||
773 | DERIVED* mBlock; | ||
774 | }; | ||
775 | |||
776 | template <typename T> | ||
777 | class LLOptionalParam | ||
778 | { | ||
779 | public: | ||
780 | typedef typename boost::add_const<T>::type T_const; | ||
781 | |||
782 | LLOptionalParam(T_const initial_val) : mVal(initial_val), mBlock(sBlock) {} | ||
783 | LLOptionalParam() : mBlock(sBlock) {} | ||
784 | LLOptionalParam(const LLOptionalParam<T>& other) : mVal(other.mVal) {} | ||
785 | |||
786 | DERIVED& operator ()(T_const set_value) { mVal = set_value; return *mBlock; } | ||
787 | operator T() const { return mVal; } | ||
788 | T operator=(T_const set_value) { mVal = set_value; return mVal; } | ||
789 | |||
790 | private: | ||
791 | T mVal; | ||
792 | DERIVED* mBlock; | ||
793 | }; | ||
794 | |||
795 | // specialization that requires initialization for reference types | ||
796 | template <typename T> | ||
797 | class LLOptionalParam <T&> | ||
798 | { | ||
799 | public: | ||
800 | typedef typename boost::add_const<T&>::type T_const; | ||
801 | |||
802 | LLOptionalParam(T_const initial_val) : mVal(initial_val), mBlock(sBlock) {} | ||
803 | LLOptionalParam(const LLOptionalParam<T&>& other) : mVal(other.mVal) {} | ||
804 | |||
805 | DERIVED& operator ()(T_const set_value) { mVal = set_value; return *mBlock; } | ||
806 | operator T&() const { return mVal; } | ||
807 | T& operator=(T_const set_value) { mVal = set_value; return mVal; } | ||
808 | |||
809 | private: | ||
810 | T& mVal; | ||
811 | DERIVED* mBlock; | ||
812 | }; | ||
813 | |||
814 | // specialization that initializes pointer params to NULL | ||
815 | template<typename T> | ||
816 | class LLOptionalParam<T*> | ||
817 | { | ||
818 | public: | ||
819 | typedef typename boost::add_const<T*>::type T_const; | ||
820 | |||
821 | LLOptionalParam(T_const initial_val) : mVal(initial_val), mBlock(sBlock) {} | ||
822 | LLOptionalParam() : mVal((T*)NULL), mBlock(sBlock) {} | ||
823 | LLOptionalParam(const LLOptionalParam<T*>& other) : mVal(other.mVal) {} | ||
824 | |||
825 | DERIVED& operator ()(T_const set_value) { mVal = set_value; return *mBlock; } | ||
826 | operator T*() const { return mVal; } | ||
827 | T* operator=(T_const set_value) { mVal = set_value; return mVal; } | ||
828 | private: | ||
829 | T* mVal; | ||
830 | DERIVED* mBlock; | ||
831 | }; | ||
832 | |||
833 | static DERIVED* sBlock; | ||
834 | }; | ||
835 | |||
836 | template <typename T> T* LLParamBlock<T>::sBlock = NULL; | ||
837 | |||
599 | #endif | 838 | #endif |