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

DirectionButton.h

Go to the documentation of this file.
00001 #ifndef OglGui_DirectionButton_h
00002 #define OglGui_DirectionButton_h
00003 
00004 #ifndef OglGui_Button_h
00005 #include "OglGui/Button.h"
00006 #endif
00007 
00008 namespace OglGui
00009 {
00010 
00011 class DirectionButton : public Button
00012 {
00013 public:
00014 
00015     DirectionButton(Window* parent, int x, int y, int width, int height,
00016                     float dir, int brdType=BEV_RAISED) :
00017         Button(parent, x, y, width, height, "", brdType, true)
00018     {
00019         Init(dir, 4);
00020     }
00021 
00022     DirectionButton(Window* parent, int width, int height, 
00023                     float dir, int brdType=BEV_RAISED) :
00024         Button(parent, width, height, "", brdType, true)
00025     {
00026         Init(dir, 4);
00027     }
00028 
00029     // To also allow functioning as txt button
00030     void SetDoDrawDir(bool mode)
00031     {
00032         mDoDrawDirection = mode;
00033     }
00034 
00035     void SetMargin(int margin)
00036     {
00037         mMargin = margin;
00038     }
00039 
00040     void SetDirection(int dir)
00041     {
00042         mDirection = dir;
00043     }
00044 
00045     void SetFixedArrowSize(int sz)
00046     {
00047         mFixedArrowSize = sz;
00048     }
00049 
00050     void SetClosed(bool mode)
00051     {
00052         mIsClosed = mode;
00053     }
00054 
00055     void SetFilled(bool mode)
00056     {
00057         mIsFilled = mode;
00058     }
00059 
00060     void SetDirectionFeedback(bool mode, ULONG col=0x606060)
00061     {
00062         mDirectionFeedback = mode;
00063         mFeedbackColor = col;
00064     }
00065 
00066     virtual void DisplayFunc()
00067     {
00068         float   coords[6];
00069         float   hW = WndWidth()/2.0f;
00070         float   hH = WndHeight()/2.0f;
00071         ULONG   col = mForeGroundColor;
00072         int     marginW = mMargin;
00073         int     marginH = mMargin;
00074         OGC     myOGC;
00075 
00076         Button::DisplayFunc();
00077 
00078         if (!mDoDrawDirection)   // Enable the user to choose text instead
00079             return;
00080 
00081         marginW = (int) ((marginW < hW/2) ? marginW : hW/2);
00082         marginH = (int) ((marginH < hH/2) ? marginH : hH/2);
00083 
00084         OGCSave(&myOGC);
00085         glPushMatrix();
00086 
00087         OGCSetPolyFillMode(theOGC,3);
00088 
00089         glTranslatef(hW+(IsPressed()?1:0), hH+(IsPressed()?-1:0), 0.0f);
00090         if ((mDirection%4) != 0)
00091             glRotatef(mDirection*90.0f, 0.0f, 0.0f, 1.0f);
00092 
00093         if (mDirection%2)
00094         {
00095             hH = hW;
00096             hW = WndHeight()/2.0f;
00097         }
00098         if (mFixedArrowSize>0)
00099         {
00100             hH = hW = mFixedArrowSize/2;
00101             marginH = marginW = 0;
00102         }
00103         coords[0] = -hW+marginH;
00104         coords[1] = -hH+marginW;
00105 
00106         coords[2] = hW-marginH;
00107         coords[3] = 0;
00108 
00109         coords[4] = -hW+marginH;
00110         coords[5] = hH-marginW;
00111 
00112         if (mIsFilled || (mDirectionFeedback && GetState()==2))
00113         {
00114             col = (mDirectionFeedback && GetState()==2) ?
00115                    mFeedbackColor : mForeGroundColor;
00116             if (!GetState())
00117                 col = oglLIGHTGREY;
00118             SetSolidFillColor(col);
00119             FillTriangles(coords,3);
00120         }
00121         else
00122         {
00123             if (!GetState())
00124                 col = oglLIGHTGREY;
00125             SetSolidLineColor(col);
00126             if (mIsClosed)
00127                 DrawTriangles(coords,3);
00128             else
00129                 DrawLineStrip(coords,3);
00130         }
00131 
00132         glPopMatrix();
00133         OGCRestore(&myOGC);
00134     }
00135 
00136 private :
00137 
00138     bool    mDoDrawDirection;
00139     bool    mIsFilled;
00140     bool    mIsClosed;
00141     bool    mDirectionFeedback;
00142     ULONG   mFeedbackColor;
00143     int     mDirection; // * 90
00144     int     mFixedArrowSize;
00145     int     mMargin;
00146 
00147     void Init(float dir, int margin)
00148     {
00149         mDoDrawDirection = true;
00150         mIsFilled = false;
00151         mIsClosed = true;
00152         mDirectionFeedback = false;
00153         mFeedbackColor = oglDARKGREY;
00154         mDirection = (int) dir;
00155         mMargin = margin;
00156         mFixedArrowSize = 0;
00157     }
00158 };
00159 
00160 } // namespace OglGui
00161 
00162 #endif

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