00001
00002
00003 #ifndef NV_TWEAKBAR_H
00004 #define NV_TWEAKBAR_H
00005
00006 #include "NvUI/NvUI.h"
00007 #include "NvUI/NvTweakVar.h"
00008
00020 template<class T>
00021 struct NvTweakEnum
00022 {
00026 #define TWEAKENUM_ARRAYSIZE(a) (sizeof(a)/sizeof(a[0]))
00027
00028 const char *m_name;
00029 T m_value;
00031 operator T&() { return m_value;}
00032 operator const T&() const { return m_value;}
00034 operator char *() { return m_name;}
00035 operator const char *() const { return m_name;}
00036 };
00037
00043 class NvTweakVarUIProxyBase : public NvUIProxy
00044 {
00045 protected:
00047 INHERIT_FROM(NvUIProxy);
00049 bool m_readonly;
00050
00051 public:
00053 NvTweakVarUIProxyBase(NvUIElement *el)
00054 : INHERITED(el)
00055 , m_readonly(false)
00056 { }
00057
00058
00059
00061 virtual NvUIEventResponse HandleEvent(const NvGestureEvent &ev, NvUST timeUST, NvUIElement *hasFocus)
00062 {
00063 if (m_readonly)
00064 return nvuiEventNotHandled;
00065 return INHERITED::HandleEvent(ev, timeUST, hasFocus);
00066 }
00067
00069 virtual NvUIEventResponse HandleReaction(const NvUIReaction& react)
00070 {
00071 if (m_readonly)
00072 return nvuiEventNotHandled;
00073 return INHERITED::HandleReaction(react);
00074 }
00075 };
00076
00077
00083 template<class T>
00084 class NvTweakVarUI : public NvTweakVarUIProxyBase
00085 {
00086 protected:
00088 INHERIT_FROM(NvTweakVarUIProxyBase);
00089
00090
00091 NvTweakVarUI() {}
00092 NvTweakVarUI& operator=( const NvTweakVarUI& v) {}
00093 NvTweakVarUI( const NvTweakVarUI& v){}
00096 NvTweakVar<T> &m_tvar;
00098 public:
00103 NvTweakVarUI(NvTweakVar<T> &tvar, NvUIElement *el, uint32_t actionCode=0)
00104 : INHERITED(el)
00105 , m_tvar(tvar)
00106 {
00107 m_tvar.setActionCode(actionCode);
00108 };
00109
00113 virtual NvUIEventResponse HandleReaction(const NvUIReaction& react);
00114 };
00115
00121 template<class T>
00122 class NvTweakEnumUI : public NvTweakVarUI<T>
00123 {
00124 protected:
00126 INHERIT_FROM(NvTweakVarUI<T>);
00129 T m_enumval;
00131 public:
00136 NvTweakEnumUI(NvTweakVar<T> &tvar, T eval, NvUIElement *el, uint32_t actionCode=0)
00137 : INHERITED(tvar, el, actionCode)
00138 , m_enumval(eval)
00139 {
00140 };
00141
00146 virtual NvUIEventResponse HandleEvent(const NvGestureEvent &ev, NvUST timeUST, NvUIElement *hasFocus);
00147
00154 virtual NvUIEventResponse HandleReaction(const NvUIReaction& react);
00155 };
00156
00160 #define TWEAKBAR_ACTIONCODE_BASE 0x43210000
00161
00167 class NvTweakBar : public NvUIContainer
00168 {
00169 private:
00170 INHERIT_FROM(NvUIContainer);
00171
00172 float m_lastElX;
00173 float m_lastElY;
00174 float m_xInset;
00175 float m_widthPadFactor;
00176 float m_padHeight;
00177 uint32_t m_lastActionCode;
00178 uint32_t m_defaultRows;
00179 bool m_textShadows;
00180 bool m_compactLayout;
00181
00182 float m_subgroupLastY;
00183 float m_subgroupMaxY;
00184 NvUIContainer *m_subgroupContainer;
00185 NvTweakVarBase *m_subgroupSwitchVar;
00186
00187 NvPackedColor m_labelColor;
00188 NvPackedColor m_valueColor;
00189
00190 NvUIPopup *MakeStdPopup(const char* name, NvTweakVar<uint32_t> &refvar, NvTweakEnum<uint32_t> values[], uint32_t valueCount, uint32_t actionCode=0);
00191 NvUIButton *MakeStdButton(const char* name, bool val, NvUIButtonType::Enum type=NvUIButtonType::CHECK, uint32_t code=0, uint32_t subcode=0);
00192 NvUISlider *MakeStdSlider(const char* name, float val, float min, float max, float step=0, bool integral=false, uint32_t code=0);
00193
00194 void AddElement(NvUIElement *te, bool autoSpace=true);
00195
00196 public:
00202 static NvTweakBar *CreateTweakBar(NvUIWindow *window);
00203
00212 NvTweakBar(float width, float height);
00213
00218 virtual ~NvTweakBar();
00219
00221 inline float GetDefaultLineHeight() { return GetHeight()/m_defaultRows; }
00223 inline float GetDefaultLineWidth() { return (GetWidth() - (2 * m_widthPadFactor * GetWidth()) - m_xInset); }
00227 inline float GetStartOffY() { return GetDefaultLineHeight()*0.5f; }
00228
00232 virtual NvUIEventResponse HandleReaction(const NvUIReaction& react);
00233
00238 virtual void HandleReshape(float w, float h);
00239
00243 virtual void Draw(const NvUIDrawState &drawState);
00244
00251 void syncValues();
00252
00257 void setCompactLayout(bool compact) { m_compactLayout = compact; }
00258
00262 void textShadows(bool b) { m_textShadows = b; }
00263
00270 void subgroupStart();
00273 void subgroupEnd();
00274
00311 void subgroupSwitchStart(NvTweakVarBase *var);
00316 void subgroupSwitchCase(bool val);
00321 void subgroupSwitchCase(float val);
00326 void subgroupSwitchCase(uint32_t val);
00329 void subgroupSwitchEnd();
00330
00333 private:
00334
00337 void subgroupSwitchCase(NvUIContainer *c);
00340 void subgroupClose();
00341
00342 public:
00343
00349 void addPadding();
00350
00351
00353 void addLabel(const char *title, bool bold=false);
00354
00355
00356
00357
00366 NvTweakVarBase* addValue(const char *name, bool &var, bool pushButton=false, uint32_t actionCode=0);
00374 NvTweakVarBase* addButton(const char* name, uint32_t actionCode);
00375
00376
00381 NvTweakVarBase* addValue(const char *name, float &var, float min, float max, float step=0, uint32_t actionCode=0);
00386 NvTweakVarBase* addValue(const char *name, uint32_t &var, uint32_t min, uint32_t max, uint32_t step=0, uint32_t actionCode=0);
00387
00388
00396 NvTweakVarBase* addEnum(const char *name, uint32_t &var, NvTweakEnum<uint32_t> values[], uint32_t valueCount, uint32_t actionCode=0);
00397
00403 NvTweakVarBase* addMenu(const char *name, uint32_t &var, NvTweakEnum<uint32_t> values[], uint32_t valueCount, uint32_t actionCode=0);
00405 };
00406
00407 #endif //NV_TWEAKBAR_H