Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

UpDownButton.h

Go to the documentation of this file.
00001 /*
00002  * UpDownButton to be used in combination with other widgets.
00003  * For example combining it with a TextField to create an UpDownNumber
00004  */
00005 
00006 #ifndef OglGui_UpDownButton_h
00007 #define OglGui_UpDownButton_h
00008 
00009 #ifndef OglGui_DirectionButton_h
00010 #include "OglGui/DirectionButton.h"
00011 #endif
00012 
00013 #ifndef OglGui_UpDownButtonListener_h
00014 #include "OglGui/UpDownButtonListener.h"
00015 #endif
00016 
00017 // RvB: I could store the buttons in a vector in their own class
00018 // and make a DirectionSetter interface that performs the actions
00019 // over all DirectionButtons in the vector.
00020 //
00021 // Class DirectionButtonSet -> holder of the buttons with setting functions
00022 // Dan UpDownButton en future LeftRightButton als extension hiervan.
00023 
00024 namespace OglGui
00025 {
00026 
00027 class UpDownButton : public Window, ButtonListener
00028 {
00029 public:
00030 
00031     UpDownButton(Window* parent, int x, int y, int width, int height,
00032                  bool leftRight=false, int margin=0) :
00033         Window(parent, x, y, width, height)
00034     {
00035         Init(width, height, leftRight, margin);
00036     }
00037 
00038     UpDownButton(Window* parent, int width, int height,
00039                  bool leftRight=false, int margin=0) :
00040         Window(parent, width, height)
00041     {
00042         Init(width, height, leftRight, margin);
00043     }
00044 
00045     void
00046     SetUpDownButtonListener(UpDownButtonListener* listener, void* userData = 0)
00047     {
00048         mListener = listener;
00049         mListenerData = userData;
00050     }
00051     void
00052     SetUpDownButtonListener(UpDownButtonListener* listener, int userData)
00053     {
00054         SetUpDownButtonListener(listener, (void *) userData);
00055     }
00056 
00057     virtual void ButtonSelectionEvent(Button *src, void* userData)
00058     {
00059         if (!mListener)
00060             return;
00061         mListener->UpDownButtonSelectionEvent(this, userData==(void*)1, mListenerData);
00062     }
00063 
00064     DirectionButton* UpButton() const
00065     {
00066         return mUpButton;
00067     }
00068 
00069     DirectionButton* DownButton() const
00070     {
00071         return mDownButton;
00072     }
00073 
00074     virtual void MouseFunc(INT msg, INT but, INT state, INT x, INT y)
00075     {
00076         Window::MouseFunc(msg, but, state, x, y);
00077         if (msg == oglMouseWheelUp)
00078             mUpButton->DoButtonSelectionEvent(); 
00079         if (msg == oglMouseWheelDown)
00080             mDownButton->DoButtonSelectionEvent(); 
00081     }
00082 
00083     /*
00084     virtual void KeyboardFunc( INT c, INT state )
00085     {
00086         Window::KeyboardFunc(c, state);
00087         GetParent()->KeyboardFunc(c, state);
00088     }
00089     */
00090 
00091     void SetRepeatMode(bool mode)
00092     {
00093         mUpButton->SetRepeatMode(mode);
00094         mDownButton->SetRepeatMode(mode);
00095     }
00096 
00097     void SetDirectionFeedback(bool mode, ULONG feedbackCol=0xff606060)
00098     {
00099         mUpButton->SetDirectionFeedback(mode, feedbackCol);
00100         mDownButton->SetDirectionFeedback(mode, feedbackCol);
00101     }
00102 
00103     void SetClosed(bool mode=true)
00104     {
00105         mUpButton->SetClosed(mode);
00106         mDownButton->SetClosed(mode);
00107     }
00108 
00109     void SetFilled(bool mode=true)
00110     {
00111         mUpButton->SetFilled(mode);
00112         mDownButton->SetFilled(mode);
00113     }
00114 
00115     void SetFixedArrowSize(int sz)
00116     {
00117         mUpButton->SetFixedArrowSize(sz);
00118         mDownButton->SetFixedArrowSize(sz);
00119     }
00120 
00121     void AdjustRoundness(float r0, float r1, float r2, float r3,
00122                          bool childAdjust=true, int margin=0)
00123     {
00124         Window::SetRoundness(r0, r1, r2, r3);
00125         if (childAdjust && !mLeftRight)
00126         {
00127             mUpButton->SetRoundness(r0-margin, r1-margin, FRETAIN, FRETAIN);
00128             mDownButton->SetRoundness(FRETAIN, FRETAIN, r2-margin, r3-margin);
00129         }
00130         if (childAdjust && mLeftRight)
00131         {
00132             mUpButton->SetRoundness(FRETAIN, r1-margin, r2-margin, FRETAIN);
00133             mDownButton->SetRoundness(r0-margin, FRETAIN, FRETAIN, r3-margin);
00134         }
00135     }
00136 
00137 
00138 private :
00139 
00140     void
00141     Init(int w, int h, bool leftRight, int margin)
00142     {
00143         int     m = margin;
00144 
00145         if (m >= w/2)
00146             m = w/2-1;
00147         if (m >= h/2)
00148             m = h/2-1;
00149 
00150         mLeftRight = leftRight;
00151         mListener = 0;
00152 
00153         if (!leftRight)
00154         {
00155             mUpButton = new DirectionButton(this, m, h/2, w-2*m, h/2-m, 1.0f);
00156             mDownButton = new DirectionButton(this, m, m, w-2*m, h/2-m, 3.0f);
00157         }
00158         else
00159         {
00160             mUpButton = new DirectionButton(this, w/2, m, w/2-m, h-2*m, 0.0f);
00161             mDownButton = new DirectionButton(this, m, m, w/2-m, h-2*m, 2.0f);
00162         }
00163 
00164         mUpButton->SetButtonListener(this, (void*)1);
00165         mDownButton->SetButtonListener(this, (void*)-1);
00166 
00167         // If user indicated a margin than provide suitable default border
00168         if (margin > 0)
00169             SetBorderType((margin<3) ? BEV_LINE : BEV_ETCHED);
00170 
00171         SetDirectionFeedback(true);
00172 
00173         ScaleChildren(0,true);
00174 
00175         // Prevent others setting scaling as we allready scale
00176         mUpButton->SetAllowScaling(false);
00177         mDownButton->SetAllowScaling(false);
00178 
00179         // To prevent the margin becoming bigger when scaling
00180         if (margin>0)
00181         {
00182             if (!leftRight)
00183             {
00184                 mUpButton->ConnectTo(this, T2T | R2R | L2L | TPARENT);
00185                 mDownButton->ConnectTo(this, B2B | R2R | L2L | TPARENT);
00186             }
00187             else
00188             {
00189                 mUpButton->ConnectTo(this, B2B | T2T | R2R | TPARENT);
00190                 mDownButton->ConnectTo(this, B2B | T2T | L2L | TPARENT);
00191             }
00192         }
00193     }
00194     DirectionButton*      mUpButton;
00195     DirectionButton*      mDownButton;
00196     UpDownButtonListener* mListener;
00197     void*                 mListenerData;
00198     bool                  mLeftRight;
00199 
00200 };
00201 
00202 } // namespace OglGui
00203 
00204 #endif UpDownButton_h

Generated on Fri Mar 19 09:31:40 2010 for ImpalaSrc by  doxygen 1.5.1