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

CheckBox.h

Go to the documentation of this file.
00001 //345678901234567890123456789012345678901234567890123456789012345678901234567890
00002 // Author: Richard van Balen
00003 #ifndef OglGui_CheckBox_h
00004 #define OglGui_CheckBox_h
00005 
00006 #ifndef OglGui_StaticText_h
00007 #include "OglGui/StaticText.h"
00008 #endif
00009 
00010 #include "OglGui/CheckBoxListener.h"
00011 
00012 namespace OglGui
00013 {
00014 
00015 class CheckBox : public StaticText
00016 {
00017 public:
00018 
00019     CheckBox(Window* parent, int width, int height, strconst label,
00020              bool selected=false, int borderType = 0) :
00021         StaticText(parent, width, height, label, false)
00022     {
00023         Init(selected, borderType);
00024     }
00025     CheckBox(Window* parent, int x, int y, int width, int height,
00026              strconst label, bool selected=false, int borderType = 0) :
00027         StaticText(parent, x, y, width, height, label, false)
00028     {
00029         Init(selected, borderType);
00030     }
00031 
00032     void SetCheckBoxListener(CheckBoxListener* listener, void* listenerData = 0)
00033     {
00034         mCheckBoxListener = listener;
00035         mCheckBoxListenerData = listenerData;
00036     }
00037     void SetCheckBoxListener(CheckBoxListener* listener, int listenerData)
00038     {
00039         SetCheckBoxListener(listener, (void*) listenerData);
00040     }
00041 
00042     void PublishSelection()
00043     {
00044         if (!mCheckBoxListener)
00045             return;
00046         mCheckBoxListener->CheckBoxEvent(this,mSelected,mCheckBoxListenerData);
00047     }
00048 
00049     void DoSelect(bool flag=true)
00050     {
00051         mSelected = flag;
00052         PublishSelection();
00053     }
00054 
00055     void SetSelected(bool flag=true)
00056     {
00057         mSelected = flag;
00058     }
00059 
00060     bool GetSelected() const
00061     {
00062         return mSelected;
00063     }
00064 
00065     void SetBoxFrameType(int frameType)
00066     {
00067         mBoxFrameType = frameType;
00068     }
00069 
00070     int GetBoxFrameType() const
00071     {
00072         return mBoxFrameType;
00073     }
00074 
00075     void SetRoundedCheck(bool rounded=true)
00076     {
00077         mRoundedCheck = rounded;
00078     }
00079 
00080     bool GetRoundedCheck() const
00081     {
00082         return mRoundedCheck;
00083     }
00084 
00085     void SetEnabled(bool flag=true)
00086     {
00087         SetState((flag) ? 1 : 0);
00088     }
00089 
00090     // specialization of base classes
00091 
00092     virtual void DisplayFunc()
00093     {
00094         Window::DisplayFunc();
00095 
00096         OGC oldOGC;
00097         OGCSave(&oldOGC);
00098 
00099         SetLineWidth(1);
00100 
00101         // draw the check
00102         int box = mOglWnd->height;
00103         int ins = 2;
00104 
00105         if (mBoxFrameType) ins += 3;
00106 
00107         SetLineColors(oglBLACK, oglGREY, oglWHITE, oglGREY);
00108         SetFillColors(oglWHITE, oglLIGHTGREY, oglDARKGREY, oglLIGHTGREY, 0);
00109         if (!GetState())
00110             SetFillColors(oglLIGHTGREY, oglLIGHTGREY, oglLIGHTGREY,
00111                           oglLIGHTGREY, 0);
00112 
00113         //if (mSelected || (GetBorderType() == 0 && GetState() == 2))
00114         //    SetFillColors(oglWHITE, 0xff60a060, 0xff004000, 0xff60a060, 0);
00115 
00116         if (mRoundedCheck)
00117         {
00118             FillRoundRect(ins, ins, box - 2*ins, box - 2*ins, 500);
00119             DrawRoundRect(ins+2, ins+2, box - 2*ins-4, box - 2*ins-4, 500);
00120         }
00121         else if (mSelected || (GetBorderType() == 0 && GetState() == 2))
00122             FillRectangle(ins, ins, box - 2*ins, box - 2*ins);
00123 
00124         if (mBoxFrameType)
00125         {
00126             ins -= 3;
00127             DrawBorderType(mBoxFrameType, ins, ins, box - 2*ins,
00128                            box - 2*ins,0,0,0,0);
00129         }
00130         if (mSelected){
00131             int sx = box/2;
00132             int sy = box/3;
00133             SetSolidLineColor(oglGREEN);
00134             DrawLine(sx, sy, sx - box/6, sy + box/5);
00135             DrawLine(sx, sy, sx + box/4, sy + (2*box)/3 - 2);
00136         }
00137 
00138         // draw the string content
00139         AlignString(box, 0);
00140 
00141         OGCRestore(&oldOGC);
00142    }
00143 
00144     virtual void MouseFunc(INT msg, INT but, INT state, INT x, INT y)
00145     {
00146         if (!GetState()) return;
00147 
00148         Window::MouseFunc(msg, but, state, x, y);
00149 
00150         if (state & oglModifierKey)
00151             return;
00152 
00153         if ((msg == oglMouseDown) && (but == oglLeftButton)) 
00154         {
00155             mSelected = !mSelected;
00156             PublishSelection();
00157         }
00158     }
00159 
00160 private:
00161 
00162     void
00163     Init(bool selected, int borderType)
00164     {
00165         SetBorderType(borderType);
00166         SetBorderFillShaded(2);
00167         SetBorderFillOpacity(0.5f);
00168         mDoStateFeedback = true;
00169         mBoxFrameType = 0;
00170         mRoundedCheck = true;
00171         mSelected = selected;
00172         mCheckBoxListener = 0;
00173         mCheckBoxListenerData = 0;
00174 
00175         SetDisableOGLViewKeys(true);
00176         SetDisableOGLViewMouse(true);
00177     }
00178 
00179     CheckBoxListener*     mCheckBoxListener;
00180     void*                 mCheckBoxListenerData;
00181     bool                  mSelected;
00182     bool                  mRoundedCheck;
00183     int                   mBoxFrameType;
00184 };
00185 
00186 } // namespace OglGui
00187 #endif

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