00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #if !defined(SJBUTTON_H_INCLUDED)
00012 #define SJBUTTON_H_INCLUDED
00013
00014 namespace sjgui{
00015 namespace SJGUI_USE_STYLE
00016 {
00017 extern CWnd::CSize def_button_size;
00018 }
00019
00057 template<class Tlabel,class Tbase>
00058 class CButtonCtrlTmpl : public Tbase
00059 {
00060 protected:
00061 bool m_yPushed;
00062
00066 Tlabel m_Label;
00067 int m_iNumStates;
00068 int m_iState;
00069 bool m_yChecked;
00070 public:
00071 virtual void OnKeyUp(int &iKey);
00072 virtual void OnKeyDown(int &iKey);
00073 public:
00074 CButtonCtrlTmpl();
00076 void SetNumStates(int i){assert(i>=1);m_iNumStates=i;}
00078 int GetNumStates(){return m_iNumStates;}
00080 int GetState(){return m_iState;}
00082 bool IsChecked(){return m_yChecked;}
00084 void GoToNextState(){m_iState=(m_iState+1)%m_iNumStates;}
00086 void SetChecked(bool b=true){m_yChecked=b;}
00088 void SetTextColor(GLfloat R,GLfloat G,GLfloat B){m_Label.SetColor(R,G,B);}
00090 void SetTextColor(GLfloat* pC){m_Label.SetColor(pC);}
00092 GLfloat* GetTextColor(){return m_Label.GetColor();}
00094 void SetLabel(const char* pc){m_Label.SetText(pc);}
00096 int GetTextLen(){return m_Label.GetTextLen();}
00098 int GetFontSize(){return m_Label.GetFontSize();}
00099
00100 virtual void OnReset();
00101
00105 bool IsPushed(){return m_yPushed;}
00107 void PushIt(bool b=true){m_yPushed=b;}
00109 Tlabel& GetLabel(){return m_Label;}
00110 };
00111
00112 template<class Tlabel,class Tbase>
00113 inline void CButtonCtrlTmpl<Tlabel,Tbase>::OnReset()
00114 {
00115 m_yPushed=false;
00116 Tbase::OnReset();
00117 }
00118
00119 template<class Tlabel,class Tbase>
00120 inline CButtonCtrlTmpl<Tlabel,Tbase>::CButtonCtrlTmpl():Tbase()
00121 {
00122 RegisterChild(&m_Label);
00123 m_yPushed=false;
00124 m_iState=0;
00125 m_iNumStates=2;
00126 m_yChecked=false;
00127 SetAllowedForFocus(true);
00128 SetSize(SJGUI_USE_STYLE::def_button_size);
00129 }
00130
00131 template<class Tlabel,class Tbase>
00132 inline void CButtonCtrlTmpl<Tlabel,Tbase>::OnKeyUp(int &iKey)
00133 {
00134 Tbase::OnKeyUp(iKey);
00135 switch(iKey)
00136 {
00137
00138 case SJ_KEY_MOUSE_LEFT:
00139 case SJ_KEY_SPACE:
00140 case SJ_KEY_ENTER:
00141 if(IsPressed())
00142 {
00143
00144
00145 if(iKey!=SJ_KEY_MOUSE_LEFT || IsOnWindow(GetMouseX(),GetMouseY()))
00146 {
00147 PushIt();
00148 SetChecked(!IsChecked());
00149 GoToNextState();
00150 }
00151
00152 iKey=SJ_KEY_IGNORE;
00153 SetReleased();
00154 }
00155 break;
00156 }
00157 }
00158
00159 template<class Tlabel,class Tbase>
00160 inline void CButtonCtrlTmpl<Tlabel,Tbase>::OnKeyDown(int &iKey)
00161 {
00162 Tbase::OnKeyDown(iKey);
00163 switch(iKey)
00164 {
00165
00166 case SJ_KEY_MOUSE_LEFT:
00167 case SJ_KEY_SPACE:
00168 case SJ_KEY_ENTER:
00169 if(IsInFocus())
00170 {
00171 SetPressed();
00172
00173 iKey=SJ_KEY_IGNORE;
00174 }
00175 break;
00176 }
00177 }
00178
00179 }
00180
00181 #endif // !defined(SJBUTTON_H_INCLUDED)