NVidia Gameworks
  • Main Page
  • Classes
  • Files
  • File List
  • File Members

NvUI.h

Go to the documentation of this file.
00001 // TAGRELEASE: PUBLIC
00002 
00003 #ifndef _NV_UI_H
00004 #define _NV_UI_H
00005 
00006 #include <NvFoundation.h>
00007 
00008 #include <NvUI/NvGestureEvent.h>
00009 #include "NvUI/NvPackedColor.h"
00010 #include "NV/NvVector.h"
00011 
00012 #include <string.h>
00013 #include <string>
00014 #include <map>
00015 
00016 // fwd decl of BFText class.
00017 class BFText;
00018 
00057 #define INHERIT_FROM(c) typedef c INHERITED;
00058 
00060 typedef uint64_t               NvUST; // U64 unadjusted system time value
00062 #define UST2SECS(t)     ((double)(((double)(t)) / 1.0e9));
00063 
00064 #define SECS2UST(t)     ((NvUST)(((double)(t)) * 1.0e9));
00065 
00066  
00076 typedef enum {
00077     nvuiEventNotHandled     = 0x000, 
00078     nvuiEventHandled        = 0x001, 
00080     nvuiEventWantsHover     = 0x010, 
00081     nvuiEventHandledHover   = nvuiEventHandled | nvuiEventWantsHover,  
00083     nvuiEventWantsFocus     = 0x020, 
00084     nvuiEventHandledFocus   = nvuiEventHandled | nvuiEventWantsFocus,  
00086     nvuiEventHadReaction    = 0x100, 
00087     nvuiEventHandledReaction = nvuiEventHandled | nvuiEventHadReaction,  
00088     nvuiEventHandledFocusReaction = nvuiEventHandled | nvuiEventWantsFocus | nvuiEventHadReaction, 
00089     nvuiEventNoReaction    = ~nvuiEventHadReaction, 
00090 } NvUIEventResponse;
00091 
00092 
00094 #define NV_PURE_VIRTUAL     0
00095 
00097 struct NvReactFlag {
00098     enum Enum { 
00099         NONE =           0x00, 
00100         FORCE_UPDATE =   0x01, 
00102         CLEAR_STATE =    0x02, 
00104     };
00105 };
00106 
00115 typedef struct
00116 {
00117     uint32_t uid;   
00118     uint32_t code;  
00119     uint32_t state; 
00121     NvGestureKind::Enum causeKind; 
00122     uint8_t causeIndex; 
00123     NvReactFlag::Enum flags; 
00125     float fval;   
00126     uint32_t ival;   
00128 } NvUIReaction;
00129 
00130 
00131 //=============================================================================
00132 //=============================================================================
00133 // !!!!TBD should have m_ prefixed this stuff. 
00141 class NvUIDrawState
00142 {
00143 public:
00144     NvUST   time; 
00145     int32_t   width; 
00146     int32_t   height; 
00147     int32_t   designWidth; 
00148     int32_t   designHeight; 
00149     float alpha; 
00150     float rotation; 
00153     NvUIDrawState(NvUST inTime, int32_t inWidth, int32_t inHeight, int32_t inDesignWidth=0, int32_t inDesignHeight=0)
00154         : time(inTime), width(inWidth), height(inHeight),
00155             designWidth(inDesignWidth), designHeight(inDesignHeight),
00156             alpha(1.0f), rotation(0.0f)
00157     {
00158     }    
00159 };
00160         
00161 
00162 //=============================================================================
00163 //=============================================================================
00170 class NvUIRect
00171 {
00172 public:    
00173     float left; 
00174     float top; 
00175     float width; 
00176     float height; 
00177     float zdepth; 
00180     NvUIRect()
00181         : left(0), top(0), width(0), height(0), zdepth(0)
00182         { /* empty */ };
00183         
00191     NvUIRect(float l, float t, float w, float h, float z=0.0f)
00192         : left(l), top(t), width(w), height(h), zdepth(z)
00193         { /* empty */ };
00194 
00196     virtual ~NvUIRect();
00197 
00205     virtual void Set(float l, float t, float w, float h, float z=0.0f)
00206         {
00207             left = l;
00208             top = t;
00209             width = w;
00210             height = h;
00211             zdepth = z;
00212         };
00213 
00223     virtual bool Inside(float x, float y, float mx=0, float my=0)
00224         {
00225             if (x >= left-mx && x <= left+width+mx)
00226                 if (y >= top-my && y <= top+height+my)
00227                     return true;
00228             return false;
00229         }
00230 
00231     friend class NvUIElement;
00232 };
00233 
00234 
00235 // fwd decl container, as elements hold their parent whenever possible.
00236 class NvUIContainer;
00237 
00238 //=============================================================================
00239 // >>> ABSTRACT BASE CLASS <<<
00240 //=============================================================================
00246 class NvUIElement
00247 {
00248 protected:
00249     uint32_t m_uiuid;           
00252     bool m_isVisible;           
00253     NvUIRect m_rect;            
00254     float m_alpha;              
00255     uint32_t m_slideFocusGroup; 
00259     NvUIContainer *m_parent;    
00260 //  bool m_isPressed;  // if needed to track 'direct manipulation focus', i.e., who got the press-down initially.
00261 
00262 public:
00264     NvUIElement()
00265         : m_uiuid(ms_uiuid_next++)
00266         , m_isVisible(true)
00267         , m_rect()
00268         , m_alpha(1.0f)
00269         , m_slideFocusGroup(0)
00270         , m_parent(NULL)
00271         , m_currDrawState(0)
00272         , m_prevDrawState(0)
00273         , m_maxDrawState(0)
00274         , m_llnext(NULL)
00275         , m_llprev(NULL)
00276         { /* empty */ };
00277     
00279     virtual ~NvUIElement();
00280 
00283     virtual void Draw(const NvUIDrawState &drawState) = NV_PURE_VIRTUAL; 
00284 
00291     virtual NvUIEventResponse HandleEvent(const NvGestureEvent &ev, NvUST timeUST, NvUIElement *hasFocus)
00292         {
00293            return nvuiEventNotHandled;
00294         }
00295 
00299     virtual NvUIEventResponse HandleReaction(const NvUIReaction& react)
00300         {
00301            return nvuiEventNotHandled;
00302         }
00303 
00307     virtual void SetOrigin(float x, float y)
00308         { // unless overridden, just drop into the m_rect top/left.
00309             m_rect.left = x;
00310             m_rect.top = y;
00311         }
00312 
00315     virtual void SetDimensions(float w, float h)
00316         {
00317             m_rect.width = w;
00318             m_rect.height = h;
00319         }
00320 
00322     virtual void SetDepth(float z)
00323         {
00324             m_rect.zdepth = z;
00325         }
00326     
00328     virtual bool HasDepth()
00329         {
00330             return (m_rect.zdepth > 0);
00331         }
00332     
00334     virtual void GetScreenRect(NvUIRect& rect)
00335         {
00336             rect = m_rect;
00337         }
00338 
00340         virtual float GetWidth()
00341                 {
00342                         return m_rect.width;
00343                 }
00344     
00346         virtual float GetHeight()
00347                 {
00348                         return m_rect.height;
00349                 }
00350       
00352     virtual void SetVisibility(bool show) // virtual for customization.
00353         {
00354             m_isVisible = show;
00355         }
00356 
00358     virtual bool GetVisibility() // virtual for customization.
00359         {
00360             return(m_isVisible);
00361         }
00362 
00364     virtual void SetAlpha(float a) // virtual for customization.
00365         {
00366             m_alpha = a;
00367         }
00368 
00370     virtual float GetAlpha()
00371         {
00372             return m_alpha;
00373         }
00374 
00376     static const NvUIReaction& GetReaction()
00377         {
00378             return ms_reaction;
00379         }
00380 
00383     static NvUIReaction& GetReactionEdit(bool clear=true)
00384         {
00385             if (clear)
00386                 memset(&ms_reaction, 0, sizeof(ms_reaction));
00387             return ms_reaction;
00388         }
00389 
00391     virtual void GotFocus()
00392         {
00393         }
00394 
00396     virtual void LostFocus()
00397         {
00398         }
00399 
00401     virtual NvUIContainer* GetParent() { return m_parent; };
00403     virtual void SetParent(NvUIContainer* p) { m_parent = p; };
00404     
00406     virtual uint32_t GetSlideFocusGroup() { return m_slideFocusGroup; };
00408     virtual void SetSlideFocusGroup(uint32_t group) { m_slideFocusGroup = group; };
00409 
00411     static uint32_t GetActiveSlideFocusGroup() { return ms_activeSlideFocusGroup; };
00413     static void SetActiveSlideFocusGroup(uint32_t group) { ms_activeSlideFocusGroup = group; };
00414 
00416     uint32_t GetUID()
00417         {
00418             return m_uiuid;
00419         }
00420 
00422     virtual bool Hit(float x, float y)
00423         {
00424             return (m_rect.Inside(x, y, 0, 0));
00425         }
00426 
00428     static void SystemResChange(int32_t w, int32_t h);
00429 
00432     inline uint32_t GetDrawState()
00433         {
00434             return m_currDrawState;
00435         }
00436 
00439     virtual void SetDrawState(uint32_t n) // must be virtual so we can catch it
00440         {
00441             if (n<=m_maxDrawState)
00442                 m_currDrawState = n;
00443         }
00444         
00447     inline void SetDrawStatePrev()
00448         {
00449             SetDrawState(m_prevDrawState);
00450         }
00451         
00454     inline uint32_t GetPrevDrawState()
00455         {
00456             return m_prevDrawState;
00457         }
00458 
00461     inline void SetPrevDrawState(uint32_t n)
00462         {
00463             if (n<=m_maxDrawState)
00464                 m_prevDrawState = n;
00465         }
00466 
00469     inline uint32_t GetMaxDrawState()
00470         {
00471             return m_maxDrawState;
00472         }
00473 
00476      inline void SetMaxDrawState(uint32_t n)
00477         {
00478             m_maxDrawState = n;
00479         }
00480 
00481 private:
00482     uint32_t m_currDrawState; 
00483     uint32_t m_prevDrawState; 
00484     uint32_t m_maxDrawState; 
00486     static NvUIReaction ms_reaction; 
00489     static uint32_t ms_uiuid_next; 
00490     static int32_t ms_designWidth; 
00491     static int32_t ms_designHeight; 
00492     static uint32_t ms_activeSlideFocusGroup;  
00494     // declare container as friend so it can access the internal LL variables,
00495     // until we otherwise reimplement container storage as a std::vector or map or the like.
00496     friend class NvUIContainer;
00497     class NvUIElement *m_llnext, *m_llprev; 
00498 };
00499 
00500 
00501 //=============================================================================
00502 //=============================================================================
00509 class NvUIProxy : public NvUIElement
00510 {
00511 private:
00512     INHERIT_FROM(NvUIElement);
00513         NvUIElement *m_proxy;
00514     
00515 public:
00516     NvUIProxy(NvUIElement *el)
00517         : m_proxy(el) // we own the proxy now.
00518         { /* empty */ };
00519     
00520     virtual ~NvUIProxy()
00521         {
00522                 delete m_proxy; // since we owned it.
00523         }
00524 
00525     // --- OVERRIDE VIRTUALS TO PROXIED OBJECT ---
00526         virtual void Draw(const NvUIDrawState &drawState)
00527         { m_proxy->Draw(drawState); }
00528     virtual NvUIEventResponse HandleEvent(const NvGestureEvent &ev, NvUST timeUST, NvUIElement *hasFocus)
00529         { return m_proxy->HandleEvent(ev, timeUST, (hasFocus==this)?m_proxy:hasFocus); }
00530         virtual NvUIEventResponse HandleReaction(const NvUIReaction& react)
00531         { return m_proxy->HandleReaction(react); }
00532 
00533         virtual void SetOrigin(float x, float y)
00534         { m_proxy->SetOrigin(x,y); }
00535     virtual void SetDimensions(float w, float h)
00536         { m_proxy->SetDimensions(w,h); }
00537     virtual void SetDepth(float z)
00538         { m_proxy->SetDepth(z); }   
00539     virtual bool HasDepth()
00540         { return m_proxy->HasDepth(); }
00541 
00542     virtual void GetScreenRect(NvUIRect& rect)
00543         { m_proxy->GetScreenRect(rect); }
00544         virtual float GetWidth()
00545         { return m_proxy->GetWidth(); }
00546         virtual float GetHeight()
00547         { return m_proxy->GetHeight(); }
00548       
00549     virtual void SetVisibility(bool show)
00550         { m_proxy->SetVisibility(show); }
00551     virtual bool GetVisibility()
00552         { return m_proxy->GetVisibility(); }
00553 
00554     virtual void SetAlpha(float a)
00555         { m_proxy->SetAlpha(a); }
00556     virtual float GetAlpha()
00557         { return m_proxy->GetAlpha(); }
00558 
00559     virtual void GotFocus()
00560         { m_proxy->GotFocus(); }
00561     virtual void LostFocus()
00562         { m_proxy->LostFocus(); }
00563     
00564     virtual uint32_t GetSlideFocusGroup()
00565         { return m_proxy->GetSlideFocusGroup(); }
00566 
00568     uint32_t GetUID()
00569         { return m_proxy->GetUID(); }
00570 
00571     virtual bool Hit(float x, float y)
00572         { return m_proxy->Hit(x,y); }
00573 
00574     //=============================================================================
00575         // !!!!TBD
00576     //inline uint32_t GetDrawState()
00577     virtual void SetDrawState(uint32_t n)
00578         { m_proxy->SetDrawState(n); }
00579     //inline void SetDrawStatePrev();
00580     //inline uint32_t GetPrevDrawState();
00581     //inline void SetPrevDrawState(uint32_t n);
00582     //inline uint32_t GetMaxDrawState();
00583     //inline void SetMaxDrawState(uint32_t n);
00584 };
00585 
00586 
00587 //=============================================================================
00588 //=============================================================================
00589 class NvGLSLProgram;
00591 class NvGraphicShader
00592 {
00593 public:
00594     NvGLSLProgram *m_program; 
00595     //int32_t m_shader; // now stored inside program
00596     int32_t m_positionIndex; 
00597     int32_t m_uvIndex;  
00598     int32_t m_matrixIndex; 
00599     int32_t m_alphaIndex; 
00600     int32_t m_colorIndex; 
00603     virtual void Load(const char* vs, const char* fs);
00604 };
00605 
00606 
00607 //=============================================================================
00608 //=============================================================================
00613 class NvUITexture
00614 {
00615 private:
00616     // !!!!TBD TODO change this over to a std::map or hash table.
00617     NvUITexture *m_llnext; 
00618     static const int32_t NV_UITEX_HASHMAX = 19; 
00619     static NvUITexture *ms_texTable[NV_UITEX_HASHMAX]; 
00621 protected:
00622     std::string m_filename; 
00623     uint32_t m_glID; 
00624     int32_t m_width; 
00625     int32_t m_height; 
00626     bool m_validTex; 
00627     bool m_hasAlpha; 
00628     bool m_ownsID; 
00629     uint32_t m_refcount;  // !!!!TBD TODO use a real ref system?
00630     bool m_cached; 
00632 private:
00634     static uint32_t CalculateNameHash(const std::string& texname);
00636     bool DerefTexture(); 
00637 
00638 public:
00640     NvUITexture(const std::string& texname, bool noMips=true);
00642     NvUITexture(const uint32_t texID, bool alpha,
00643                 int32_t srcw, int32_t srch, bool ownsID = false, bool isCubeMap = false);
00645     virtual ~NvUITexture();
00646     
00648     inline int32_t GetWidth() { return m_width; };
00650     inline int32_t GetHeight() { return m_height; };
00652     inline uint32_t GetGLTex() { return m_glID; };
00654     inline bool GetHasAlpha() { return m_hasAlpha; };
00655 #if later
00656     inline uint32_t GetGLTarget() { return m_isCubeMap ? GL_TEXTURE_CUBE_MAP:GL_TEXTURE_2D; };
00657 #endif
00658     
00660     void AddRef() { m_refcount++; }; // that one is easy.
00662     void DelRef(); // this one is trickier...
00663 
00668     static NvUITexture *CacheTexture(const std::string& texname, bool noMips=true);
00669 };
00670 
00671 
00672 //=============================================================================
00673 // The base, static visual element class.
00674 //=============================================================================
00684 class NvUIGraphic : public NvUIElement
00685 {
00686 private:
00687     INHERIT_FROM(NvUIElement);
00688 
00689 protected:
00690     NvUITexture *m_tex; 
00691     bool m_scale; 
00692     bool m_vFlip; 
00693     NvPackedColor m_color;  // !!!!TBD
00694     
00695 public:
00703     NvUIGraphic(const std::string& texname, float dstw=0, float dsth=0);
00714     NvUIGraphic(uint32_t texId, bool alpha, // dynamic/fbo/ext texture.
00715                     uint32_t srcw, uint32_t srch,
00716                     float dstw=0, float dsth=0); 
00724     NvUIGraphic(NvUITexture* tex, float dstw=0, float dsth=0);
00725     virtual ~NvUIGraphic();
00733     virtual bool LoadTexture(const std::string& texname, bool resetDimensions=true);
00735     void SetTexture(NvUITexture *tex);
00737     void SetTextureID(const uint32_t texID, bool alpha,
00738                         uint32_t srcw, uint32_t srch);    
00739 
00741     void SetTextureFiltering(uint32_t minFilter, uint32_t magFilter);
00742 
00743         //virtual void SetDimensions(float w, float h); // no need to override atm.
00744 
00746     virtual void Draw(const NvUIDrawState &drawState); // leaf, needs to implement!
00747 
00751     virtual void SetColor(NvPackedColor color);
00752     
00754     void FlushTexture(); // made public in case needed.
00755     
00756     // !!!!TBD might need to override for subgraphic.
00758     uint32_t GetTexWidth() { return (m_tex?m_tex->GetWidth():0); };
00760     uint32_t GetTexHeight() { return (m_tex?m_tex->GetHeight():0); };
00762     int32_t GetTexID() { return (m_tex?m_tex->GetGLTex():-1); };
00763 
00765     void FlipVertical(bool flipped = true)
00766     {
00767         m_vFlip = flipped;
00768     };
00769 
00770 private:
00771     bool StaticInit();
00772     void StaticCleanup();
00773     void PrivateInit(void);
00774 
00775     static uint32_t ms_vbo; 
00776     static uint32_t ms_vboFlip; 
00777     static uint32_t ms_ibo; 
00779     static float s_pixelToClipMatrix[4][4];
00780     static float s_pixelScaleFactorX;
00781     static float s_pixelScaleFactorY;
00782     static int32_t s_pixelXLast;
00783     static int32_t s_pixelYLast;
00784     static float s_graphicWidth, s_graphicHeight;
00785 };
00786 
00787 
00788 //=============================================================================
00789 //=============================================================================
00791 class NvGraphicFrameShader : public NvGraphicShader
00792 {
00793 private:
00794     INHERIT_FROM(NvGraphicShader);
00795 
00796 public:
00797     uint32_t m_borderIndex;
00798     uint32_t m_thicknessIndex;
00799     uint32_t m_texBorderIndex;
00800 
00804     virtual void Load(const char* vs, const char* fs);
00805 };
00806 
00807 //=============================================================================
00808 // STATIC visual element
00809 //=============================================================================
00822 class NvUIGraphicFrame : public NvUIGraphic
00823 {
00824 private:
00825     INHERIT_FROM(NvUIGraphic);
00826 
00827 protected:
00828     nv::vec2<float> m_texBorder; 
00829     nv::vec2<float> m_borderThickness; 
00830     bool m_drawCenter; 
00832 public:
00834     NvUIGraphicFrame(const std::string& texname, float texBorder);
00836     NvUIGraphicFrame(const std::string& texname, float texBorderX, float texBorderY);
00838     NvUIGraphicFrame(NvUITexture *uiTex, float border);
00840     virtual ~NvUIGraphicFrame();
00841 
00847     virtual bool LoadTexture(const std::string& texname, bool resetDimensions=true);
00848 
00850     void SetBorderThickness(float thickness);
00852     void SetBorderThickness(float width, float height);
00854     void GetBorderThickness(float *x, float *y);
00856     void SetDrawCenter(bool m_drawCenter);
00857 
00859     virtual void Draw(const NvUIDrawState &drawState); // Override parent class drawing
00860 
00861 private:
00862     bool StaticInit();
00863     void StaticCleanup();
00864 };
00865 
00866 //=============================================================================
00867 //=============================================================================
00878 struct NvUIFontFamily {
00879     enum Enum
00880     {
00881         DEFAULT = 0, 
00882         SANS = DEFAULT, 
00883         MONO = 1, 
00884         COUNT // should get set to right value...
00885     };
00886 };
00887 
00895 struct NvUITextAlign {
00896     enum Enum {
00897         LEFT = 0, 
00898         RIGHT = 1, 
00899         CENTER = 2, 
00900         TOP  = 0, 
00901         BOTTOM = 1 
00902     };
00903 };
00904 
00905 //=============================================================================
00906 // STATIC visual element
00907 //=============================================================================
00916 class NvUIText : public NvUIElement
00917 {
00918 private:
00919     INHERIT_FROM(NvUIElement);
00920 
00921 protected:
00922     BFText *m_bftext; 
00923     float m_size; 
00924     NvPackedColor m_color; 
00925     bool m_wrap; 
00927 public:
00934     NvUIText(const char* str, NvUIFontFamily::Enum font, float size, NvUITextAlign::Enum halign);
00935     virtual ~NvUIText();
00936     
00938     static uint8_t GetFontID(NvUIFontFamily::Enum font);
00940     static bool StaticInit(float width=1280, float height=720);
00942     static void StaticCleanup();
00943     
00945     void SetAlignment(NvUITextAlign::Enum halign);
00947     virtual void SetAlpha(float alpha);
00949     void SetColor(const NvPackedColor& color);
00951     void SetShadow(char offset, NvPackedColor color=NV_PC_PREDEF_BLACK);
00970     void SetTextBox(float width, float height, uint32_t lines, uint32_t dots);
00971 
00973     virtual void SetDimensions(float w, float h);
00974 
00976     virtual void Draw(const NvUIDrawState &drawState); // leaf, needs to implement!
00977 
00979     void SetString(const char* in);
00981     void SetFontSize(float size);
00983     float GetFontSize() { return m_size; }
00984 
00985 //    virtual void GetString(char *string, uint32_t buflen); // copies out to a buffer.
00986 
00988     float GetStringPixelWidth();
00989 
00992     void SetDrawnChars(int32_t count);
00993 };
00994 
00995 
00996 //=============================================================================
00997 //=============================================================================
01003 struct NvUIButtonState {
01004     enum Enum {
01005         ACTIVE=0, 
01006         SELECTED, 
01007         INACTIVE, 
01008         MAX
01009     };
01010 };
01011 
01017 struct NvUIButtonType {
01018     enum Enum {
01019         PUSH,    
01020         RADIO,   
01021         CHECK,   
01022     };
01023 };
01024 
01025 //=============================================================================
01026 //=============================================================================
01045 class NvUIButton : public NvUIElement
01046 {
01047 private:
01048     INHERIT_FROM(NvUIElement);
01049 
01050 protected:
01051     NvUIElement *m_visrep[NvUIButtonState::MAX]; 
01052         NvUIText *m_title; 
01053     NvUIButtonType::Enum m_type; 
01055         uint32_t m_action; 
01056     uint32_t m_subcode; 
01058         NvGestureUID m_reactGestureUID;  
01059     NvGestureUID m_failedHitUID; 
01060     bool m_wasHit; 
01062     float m_hitMarginWide; 
01063     float m_hitMarginTall; 
01065     bool m_stickyClick; 
01067 public:
01082     NvUIButton(NvUIButtonType::Enum btntype, uint32_t actionCode, NvUIElement *visrep[NvUIButtonState::MAX],
01083         const char *title=NULL, float pt=0, bool shadowed=false); // visrep has w/h set already.
01094     NvUIButton(NvUIButtonType::Enum btntype, uint32_t actionCode, NvUIElement *visrep,
01095         const char *title=NULL, float pt=0, bool shadowed=false); // visrep has w/h set already.
01104         NvUIButton(NvUIButtonType::Enum btntype, uint32_t actionCode, NvUIRect &size,
01105         const char *title, float pt, bool shadowed=false);
01107     virtual ~NvUIButton();
01108 
01117         virtual void SetTitle(const char *title, float ptsize, bool shadowed=false);
01119     virtual void SetTitleColor(const NvPackedColor& c);
01120 
01122     virtual void SetHitMargin(float hitwide, float hittall);
01123 
01125     virtual void Draw(const NvUIDrawState &drawState); // visual, must implement
01127     virtual void SetOrigin(float x, float y);
01128 
01130     virtual NvUIEventResponse HandleEvent(const NvGestureEvent &ev, NvUST timeUST, NvUIElement *hasFocus); // interactive, must override.
01138     virtual NvUIEventResponse HandleReaction(const NvUIReaction& react); // interactive, must override.
01139 
01140 //    bool WasHit() { return m_wasHit; };
01141 
01143     virtual void LostFocus();
01144     
01146     uint32_t GetActionCode() { return m_action; };
01147 
01149         void SetSubCode(uint32_t c) { m_subcode = c; };
01151     uint32_t GetSubCode() { return m_subcode; };
01152 
01154     void SetStickyClick(bool b) { m_stickyClick = b; };
01155 
01157     void ConsumeGesture(const NvGestureEvent& ev) { m_reactGestureUID = ev.uid; }
01158 
01159 private:
01160     void PrivateInit(NvUIButtonType::Enum btntype, uint32_t actionCode);
01161 
01162 #ifdef BTN_SUPPORTS_HOVER
01163         bool m_wantsHover;
01164         bool m_wasHover;
01165 #endif
01166 };
01167 
01168 
01169 //=============================================================================
01170 //=============================================================================
01171 #if later
01172 
01173 struct NvUIContainerFlags {
01174     enum Enum {
01175         NONE =          0x00,
01176         CLIPCHILDREN =  0x01, 
01177     };
01178 };
01179 #endif
01180 
01181 
01182 //=============================================================================
01183 //=============================================================================
01216 class NvUIContainer : public NvUIElement
01217 {
01218 private:
01219     INHERIT_FROM(NvUIElement);
01220 
01221 protected:
01223     NvUIGraphic *m_background; 
01227     bool m_consumeClicks;
01234     NvUIElement *m_childrenHead; 
01239     NvUIElement *m_childrenTail;
01241     uint32_t m_numChildren; 
01245     NvUIElement *m_focusedChild; 
01247     NvUIElement *m_popup; 
01248     //NvUIContainerFlags::Enum m_flags; /**< Flags as defined by NvUIContainerFlags. */
01249 
01250 public:
01254     NvUIContainer(float width, float height, NvUIGraphic *bg=NULL);
01256     virtual ~NvUIContainer();
01257     
01259     void SetBackground(NvUIGraphic *bg)
01260     {
01261         m_background = bg;
01262     };
01264         void SetConsumeClicks(bool b)
01265         {
01266                 m_consumeClicks = b;
01267         };
01268 
01270     virtual void Add(NvUIElement *el, float desiredleft, float desiredtop);
01272     virtual bool Remove(NvUIElement *child);
01273 
01275     virtual void AddPopup(NvUIElement *el);
01277     virtual void RemovePopup(NvUIElement *el);
01278 
01280     virtual void SetOrigin(float x, float y);
01283     virtual void SetDimensions(float w, float h);
01284 
01297     virtual NvUIEventResponse HandleEvent(const NvGestureEvent &ev, NvUST timeUST, NvUIElement *hasFocus);
01299     virtual void Draw(const NvUIDrawState &drawState);
01300 
01305     virtual NvUIEventResponse HandleReaction(const NvUIReaction& react);
01306 
01309     virtual void HandleReshape(float w, float h)
01310     {
01311         // TODO
01312     };
01313 
01315     virtual void LostFocus();
01317     virtual bool MakeChildFrontmost(NvUIElement *child);
01318     
01320     NvUIElement *GetFocusedChild()
01321         {
01322             return m_focusedChild;
01323         };
01325     virtual uint32_t GetSlideFocusGroup()
01326         {
01327             if (m_focusedChild)
01328                 return m_focusedChild->GetSlideFocusGroup();
01329             return NvUIElement::GetSlideFocusGroup(); // in case inherited does something...
01330         };
01331 
01332 private:
01333     /* this internal/private method is what handles actually adding a
01334         child element to our linked list and setting back pointer. */
01335     virtual void Add(NvUIElement *el);
01336 };
01337 
01338 
01339 //=============================================================================
01340 //=============================================================================
01348 class NvUIWindow : public NvUIContainer
01349 {
01350 private:
01351     INHERIT_FROM(NvUIContainer);
01352 
01353 public:
01358     NvUIWindow(float width, float height)
01359     : NvUIContainer(width, height)
01360     {
01361         // !!!!TBD TODO error handling.
01362         NvUIText::StaticInit(width, height);
01363     };
01364 
01368     virtual ~NvUIWindow()
01369     {
01370         NvUIText::StaticCleanup();
01371     }
01372 
01375     virtual NvUIEventResponse HandleEvent(const NvGestureEvent &ev, NvUST timeUST, NvUIElement *hasFocus)
01376     {
01377         // !!!!TBD note we ignore hasFocus, and just pass in the window as the top level focus holder.
01378             NvUIEventResponse r = INHERITED::HandleEvent(ev, timeUST, this);
01379         return r;
01380     }
01381 
01385     virtual void HandleReshape(float w, float h)
01386     {
01387         // !!!!!TBD TODO !!!!!TBD TODO
01388         // resize container, notify contents
01389         // update UIText/BitFont of view size change as needed.
01390     }
01391 };
01392 
01393 
01394 //=============================================================================
01395 //=============================================================================
01416 class NvUIValueBar : public NvUIElement
01417 {
01418 private:
01419     INHERIT_FROM(NvUIElement);
01420 
01421 protected:
01422     float m_value;                  
01423     float m_maxValue;               
01424     float m_minValue;               
01425     bool m_integral;                
01426     bool m_useRawBorders;           
01427     bool m_flipDirection;           
01428     NvUIGraphicFrame *m_emptyFrame; 
01429     NvUIGraphicFrame *m_fullFrame;  
01431 public:
01438     NvUIValueBar(NvUIGraphicFrame *emptybar, NvUIGraphicFrame *fullbar,
01439                     bool useRawBorders=false, bool flipDir=false);
01441     virtual ~NvUIValueBar();
01442 
01444     virtual void SetDimensions(float w, float h);
01446     virtual void SetOrigin(float x, float y);
01447 
01449     void SetIntegral(bool isint);
01451     bool GetIntegral();
01452 
01454     virtual void SetAlpha(float a);
01455 
01457     virtual void SetValue(float value);
01459     void SetMaxValue(float value);
01461     void SetMinValue(float value);
01462 
01464     float GetValue();
01466     float GetMaxValue();
01468     float GetMinValue();
01469     
01470     //NvUIGraphicFrame *GetActiveFrame() { return m_active; };
01471 
01473     virtual void Draw(const NvUIDrawState &drawState);
01474 
01475 protected:
01477     void UpdateBar();
01478 };
01479 
01480 
01481 //=============================================================================
01482 //=============================================================================
01503 class NvUISlider : public NvUIValueBar
01504 {
01505 private:
01506     INHERIT_FROM(NvUIValueBar);
01507 
01508 protected:
01509     NvUIGraphic *m_thumb; 
01510     bool m_wasHit; 
01514     float m_startValue; 
01515     float m_stepValue; 
01517     uint32_t m_action; 
01518     bool m_smooth; 
01520     NvUIText *m_output; 
01521         bool m_ownsOutput; 
01523 public:
01531     NvUISlider(NvUIGraphicFrame *emptybar, NvUIGraphicFrame *fullbar, NvUIGraphic *thumb, uint32_t actionCode);
01533     virtual ~NvUISlider();
01534 
01536     virtual NvUIEventResponse HandleEvent(const NvGestureEvent &ev, NvUST timeUST, NvUIElement *hasFocus); // interactive, must override
01538     virtual NvUIEventResponse HandleReaction(const NvUIReaction& react); // interactive, must override
01539 
01541     virtual void SetDimensions(float w, float h);
01543     virtual void SetOrigin(float x, float y);
01545     virtual void SetAlpha(float a);
01546 
01548     virtual void SetValue(float value);
01549 
01551     virtual void SetHitMargin(float hitwide, float hittall);
01552 
01554     virtual void Draw(const NvUIDrawState &drawState);
01555 
01557         void SetOutput(NvUIText *out, bool owns=false);
01558 
01565     void SetSmoothScrolling(bool smooth) { m_smooth = smooth; }
01566 
01571     void SetStepValue(float step) { m_stepValue = step; }
01572 
01574         uint32_t GetActionCode() { return m_action; }
01575 
01576 private:
01578     void SetValueReal(float value); // This function does the real work. This is because
01579                                     // when we are sliding the slider manually, we don't
01580                                     // want "external" SetValues to influence the position
01581                                     // of the thumb.
01583     void PositionThumb();
01584 
01585     float m_hitMarginWide; 
01586     float m_hitMarginTall; 
01587 };
01588 
01589 
01590 //=============================================================================
01591 //=============================================================================
01592 class NvUIPopup;
01608 class NvUIPopupMenu : public NvUIContainer
01609 {
01610 private:
01611     INHERIT_FROM(NvUIContainer);
01612     NvUIPopup *m_myButton; 
01614 public:
01624     NvUIPopupMenu(NvUIPopup *btn, float width, float height, NvUIGraphic *bg=NULL);
01626     virtual ~NvUIPopupMenu();
01636     virtual NvUIEventResponse HandleEvent(const NvGestureEvent &ev, NvUST timeUST, NvUIElement *hasFocus);
01637 };
01638 
01639 
01640 //======================================================================
01641 //======================================================================
01657 class NvUIPopup : public NvUIButton
01658 {
01659 private:
01660     INHERIT_FROM(NvUIButton);
01661     NvUIPopupMenu *m_menu; 
01662     NvUIButton *m_popper; 
01663     uint32_t m_itemCount; 
01664     float m_lineHeight; 
01665     float m_nextItemTop; 
01666     uint32_t m_padTop; 
01667     uint32_t m_padBottom; 
01668     std::string m_titlePre; 
01669     typedef std::map<uint32_t, std::string> ItemValueName; 
01670     ItemValueName m_itemNames; 
01672 public:
01682     NvUIPopup(uint32_t actionCode, NvUIElement *visrep[NvUIButtonState::MAX],
01683                 NvUIGraphicFrame *popupFrame, NvUIButton *popper,
01684                 const char *title=NULL, float pt=0, bool shadowed=false);
01686     virtual ~NvUIPopup();
01687 
01693     void AddItem(NvUIElement *el, const char *name, uint32_t value);
01694 
01696     void SetActiveItemValue(uint32_t value);
01697 
01709     virtual NvUIEventResponse HandleEvent(const NvGestureEvent &ev, NvUST timeUST, NvUIElement *hasFocus);
01720         virtual NvUIEventResponse HandleReaction(const NvUIReaction& react);
01721 
01723     virtual void Draw(const NvUIDrawState &ds);
01725     virtual void SetDrawState(uint32_t n);
01730     virtual void SetOrigin(float x, float y);
01731 
01732 protected:
01734     void PopupStart();
01736     void PopupFinish();
01737 
01738 private:
01740     void UpdateTitleValue(uint32_t value);
01741 
01742     friend class NvUIPopupMenu;
01743 };
01744 
01745 #endif
Generated on Sat Mar 8 14:58:36 2014 for NVIDIA GameWorks OpenGL App Framework and Libraries by Doxygen
©2014 NVIDIA Corporation.