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

RadioGroup.h

Go to the documentation of this file.
00001 #ifndef OglGui_RadioGroup_h
00002 #define OglGui_RadioGroup_h
00003 
00004 #ifndef OglGui_RadioGroupListener_h
00005 #include "OglGui/RadioGroupListener.h"
00006 #endif
00007 
00008 #ifndef OglGui_Button_h
00009 #include "OglGui/Button.h"
00010 #endif
00011 
00012 namespace OglGui {
00013 
00014 class RadioGroup: public Window, ButtonListener
00015 {
00016 public:
00017 
00018     RadioGroup(int x, int y, int w, int h, int borderType=BEV_SUNKEN,
00019                bool isRect=true) :
00020         Window(x, y, w, h)
00021     {
00022         Init(borderType, isRect);
00023     }
00024     RadioGroup(Window* parent, int w, int h, int borderType=BEV_SUNKEN,
00025                bool isRect=true) :
00026         Window(parent, w, h)
00027     {
00028         Init(borderType, isRect);
00029     }
00030 
00031     RadioGroup(Window* parent, int x, int y, int w, int h,
00032                int borderType=BEV_SUNKEN, bool isRect=true) :
00033         Window(parent, x, y, w, h)
00034     {
00035                 Init(borderType, isRect);
00036     }
00037 
00038     void SetButtonDimensions(int w, int h)
00039     {
00040         mButtonWidth = w;
00041         mButtonHeight = h;
00042     }
00043 
00044     void Add(Window* parent, strconst text, int borderType = BEV_RAISED,
00045              bool isRect=false)
00046     {
00047         Button* rb = new Button(parent, mButtonWidth, mButtonHeight, text,
00048                                 borderType, isRect);
00049         Add(rb);
00050     }
00051 
00052     void Add(strconst text, int borderType = BEV_RAISED, bool isRect=false)
00053     {
00054         Button* rb = new Button(this, mButtonWidth, mButtonHeight, text,
00055                                 borderType, isRect);
00056         Add(rb);
00057     }
00058 
00059     void Add(Button* button)
00060     {
00061         button->SetButtonListener(this, (void*)mButtons.size());
00062         mButtons.push_back(button);
00063         if (mButtons.size() == 1)
00064             button->SetSelected(true);
00065     }
00066 
00067     void SetCurrentSelected()
00068     {
00069         for(int i=0 ; i<(int)mButtons.size() ; i++)
00070             mButtons[i]->SetSelected(i == mCurrent);
00071     }
00072 
00073     void ButtonSelectionEvent(Button *src, void* data)
00074     {
00075         int btn = (int)(long long)data;
00076         if (mListener)
00077             mListener->OnRadioButton(this, btn, mListenerData);
00078 
00079         if (data == (void*) mCurrent)
00080             return;
00081         if (data >= (void*)mButtons.size())
00082             return;
00083         mCurrent = (long long) data;
00084         SetCurrentSelected();
00085         //for(int i=0 ; i<(int)mButtons.size() ; i++)
00086         //    mButtons[i]->SetSelected(i == mCurrent);
00087 
00088         if (mListener)
00089             mListener->OnRadioChange(this, mCurrent, mListenerData);
00090     }
00091 
00092     void SetRadioListener(RadioGroupListener* l, void* userData=0)
00093     {
00094         mListener = l;
00095         mListenerData = userData;
00096     }
00097     void SetRadioListener(RadioGroupListener* l, int userData=0)
00098     {
00099         SetRadioListener(l, (void*) userData);
00100     }
00101 
00102     void SetDisabled(bool b)
00103     {
00104         for(int i=0 ; i<(int)mButtons.size() ; i++)
00105             mButtons[i]->SetState(b ? 0 : 1);
00106     }
00107 
00108     int GetActiveRadio()
00109     {
00110         return mCurrent;
00111     }
00112 
00113     void SetActiveRadio(int id)
00114     {
00115         if (id>=mButtons.size())
00116             return;
00117 
00118         mCurrent = id;
00119         SetCurrentSelected();
00120     }
00121 
00122     Button* GetButton(int i)
00123     {
00124         return mButtons[i];
00125     }
00126 
00127 protected:
00128 
00129     std::vector<Button*> mButtons; // maybe this is unnecessary
00130 
00131 private:
00132 
00133         void
00134     Init(int borderType, bool isRect)
00135         {
00136         mButtonWidth = 80;
00137         mButtonHeight = 20;
00138         mCurrent = 0;
00139         mListenerData = 0;
00140         mListener = 0;
00141         if (!isRect)
00142             SetRoundness(4, 4, 4, 4);
00143                 SetBorderType(borderType);
00144 
00145         SetDisableOGLViewKeys(true);
00146         SetDisableOGLViewMouse(true);
00147         }
00148 
00149     RadioGroupListener*   mListener;
00150     void*                 mListenerData;
00151     int                   mCurrent;
00152     int                   mButtonWidth;
00153     int                   mButtonHeight;
00154 };
00155 
00156 } // namespace OglGui
00157 
00158 #endif // RadioGroup_h

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