arbeit
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

WidgetState.h

Go to the documentation of this file.
00001 //------------------------------------------------------------------------
00002 //
00003 //   Joe Kniss
00004 //     6-20-03
00005 //                   ________    ____   ___ 
00006 //                  |        \  /    | /  /
00007 //                  +---+     \/     |/  /
00008 //                  +--+|  |\    /|     < 
00009 //                  |  ||  | \  / |  |\  \ 
00010 //                  |      |  \/  |  | \  \ 
00011 //                   \_____|      |__|  \__\
00012 //                       Copyright  2003 
00013 //                      Joe Michael Kniss
00014 //                   <<< jmk@cs.utah.edu >>>
00015 //               "All Your Base are Belong to Us"
00016 //-------------------------------------------------------------------------
00017 
00018 // WidgetState.h
00019 
00020 #ifndef __WIDGET_STATE_DOT_H
00021 #define __WIDGET_STATE_DOT_H
00022 
00023 #include <signalGutz.h>
00024 #include <mathGutz.h>
00025 #include <smartptr.h>
00026 
00027 class WidgetItem;
00028 
00029 ///////////////////////////////////////////////////////////////////////////
00030 /// The Base interface for Widget State, this is things like colors, 
00031 ///  clipping planes, etc.  Remember at this level in the widget hierarchy
00032 ///  we don't know anything about openGL... so the specific implementations
00033 ///  of Widget States must exist elsewhere.
00034 ///////////////////////////////////////////////////////////////////////////
00035 class WidgetState : public gutz::Counted
00036 {
00037 public:
00038    HAS_SLOTS;
00039    virtual ~WidgetState() {}
00040 
00041    virtual WidgetState* clone() = 0;
00042 
00043    /////////////////////////////////////////////////
00044    ///@name Bind/Release
00045    /// Bind should enable any state that is applicable, release should undo
00046    ///  that, back to defaults.  A Concrete Class should implement
00047    ///  the bindWS() and releaseWS() for the specific platform (if applicable).
00048    ///@{
00049    inline void bind()    { bindWS(); }
00050    inline void release() { releaseWS(); }
00051    ///@}
00052    /////////////////////////////////////////////////
00053 
00054 protected:
00055    /////////////////////////////////////////////////
00056    /// implements bind()
00057    virtual void bindWS() = 0;
00058    /// implements release()
00059    virtual void releaseWS() = 0;
00060    /////////////////////////////////////////////////
00061 
00062    WidgetState() {}
00063    WidgetState(const WidgetState &ws) {}
00064    WidgetState &operator=(const WidgetState &ws) {}
00065    
00066 };
00067 typedef gutz::SmartPtr<WidgetState> WidgetStateSP;
00068 
00069 const gutz::vec4f defColor  = gutz::vec4f(.72165f, .91373f, .62353f, 1.0f);
00070 const gutz::vec4f defPicked = gutz::vec4f(.72165f, .62353f, .91373f, 1.0f);
00071 const gutz::vec4f defSecond = gutz::vec4f(1.0f,.99f, .97f, 1.0f);
00072 
00073 ///////////////////////////////////////////////////////////////////////////
00074 /// The basic Color Widget State.  Contains a primary (getColor()), 
00075 ///  secondary (getSecondary()), and picked (getPickedColor()) color.
00076 ///////////////////////////////////////////////////////////////////////////
00077 class ColorWState : public WidgetState {
00078 public:
00079    virtual ~ColorWState() {}
00080 
00081    ColorWState &operator=(const ColorWState &cws)
00082    {
00083       _color = cws._color;
00084       _pickedColor = cws._pickedColor;
00085       _second = cws._second;
00086    }
00087 
00088    WidgetState* clone() { return cloneColor(); }
00089    virtual ColorWState* cloneColor() = 0;
00090 
00091    /////////////////////////////////////////////////
00092    ///@name Colors
00093    ///@{
00094    void        setColor(const gutz::vec4f &c)        { _color = c; }
00095    gutz::vec4f getColor() const                      { return _color; }
00096    void        setPickedColor(const gutz::vec4f &pc) { _pickedColor = pc; }
00097    gutz::vec4f getPickedColor() const                { return _pickedColor; }
00098    void        setSecondary(const gutz::vec4f &sc)   { _second = sc; }
00099    gutz::vec4f getSecondary() const                  { return _second; }
00100    ///@}
00101    /////////////////////////////////////////////////
00102 
00103    /////////////////////////////////////////////////
00104    ///@name Set/Get Picked
00105    /// if _picked is true, you should use the picked color.
00106    /// setPicked() makes a very convenient slot ;)
00107    ///@{
00108    void setPicked(bool yes) { _picked = yes; }
00109    bool getPicked() const   { return _picked; }
00110    ///@}
00111    /////////////////////////////////////////////////
00112 
00113 protected:
00114    /// WidgetItem is a friend so that it can create one of these
00115    friend class WidgetItem;
00116 
00117    ColorWState(const gutz::vec4f color = defColor,
00118                const gutz::vec4f pickedColor = defPicked,
00119                const gutz::vec4f second = defSecond)
00120                : _color(color), _pickedColor(pickedColor), _second(second),
00121                  _picked(false)
00122    {}
00123    ColorWState(const ColorWState &cws)
00124       : _color(cws._color), _pickedColor(cws._pickedColor), _second(cws._second), 
00125         _picked(false)
00126    {}
00127 
00128    gutz::vec4f _color;
00129    gutz::vec4f _pickedColor;
00130    gutz::vec4f _second;
00131    bool        _picked;
00132 
00133 };
00134 typedef gutz::SmartPtr<ColorWState> ColorWStateSP;
00135 
00136 
00137 #endif
00138 
00139 

Send questions, comments, and bug reports to:
jmk