00001
00027 #ifndef GUICONFIRM_H_
00028 #define GUICONFIRM_H_
00029
00030 #include "GUIInput.h"
00031 #include "GUIButton.h"
00032 #include "GUIFrame.h"
00033
00034 template<class T>
00035 class CGUIConfirm: public CGUIFrame {
00036 public:
00037 CGUIConfirm();
00038 virtual ~CGUIConfirm();
00039
00040 void setConfirmMessage(string message);
00041 void setCallbackInstance(T* _instance) {
00042 m_instance = _instance;
00043 }
00044 ;
00045 void setResultCallback(void(T::*_func)(bool)) {
00046 m_funcResult = _func;
00047 }
00048 ;
00049
00050 void setCallback(T* _instance, void(T::*_func)(bool)) {
00051 setCallbackInstance(_instance);
00052 setResultCallback(_func);
00053 }
00054
00055 virtual void initChilds();
00056 virtual void centered();
00057
00058 protected:
00059
00060 void onConfirm();
00061 void onCancel();
00062
00063 T* m_instance;
00064 void (T::*m_funcResult)(bool);
00065
00066 };
00067
00068 template<class T>
00069 CGUIConfirm<T>::CGUIConfirm() {
00070
00071 m_instance = NULL;
00072 m_funcResult = NULL;
00073 }
00074
00075 template<class T>
00076 CGUIConfirm<T>::~CGUIConfirm() {
00077
00078 }
00079
00080 template<class T>
00081 void CGUIConfirm<T>::initChilds() {
00082 CGUILabel* text = new CGUILabel();
00083 text->setColor(200, 200, 200, 255);
00084
00085 CGUIButton<CGUIConfirm> *buttonOK = new CGUIButton<CGUIConfirm> (this);
00086 buttonOK->setMouseDownCallback(&CGUIConfirm::onConfirm);
00087 buttonOK->setString("OK");
00088 buttonOK->setDimension(25, 14);
00089
00090 CGUIButton<CGUIConfirm> *buttonCancel = new CGUIButton<CGUIConfirm> (this);
00091 buttonCancel->setMouseDownCallback(&CGUIConfirm::onCancel);
00092 buttonCancel->setString("CANCEL");
00093 buttonCancel->setDimension(50, 14);
00094
00095 this->addChild(text);
00096 this->addChild(buttonOK);
00097 this->addChild(buttonCancel);
00098 }
00099
00100 template<class T>
00101 void CGUIConfirm<T>::onCancel() {
00102
00103 bool m_result = false;
00104
00105 if (m_instance != NULL && m_funcResult != NULL) {
00106 (m_instance->*m_funcResult)(m_result);
00107 }
00108
00109 }
00110
00111 template<class T>
00112 void CGUIConfirm<T>::onConfirm() {
00113
00114 bool m_result = true;
00115
00116 if (m_instance != NULL && m_funcResult != NULL) {
00117 (m_instance->*m_funcResult)(m_result);
00118 }
00119
00120 }
00121
00122 template<class T>
00123 void CGUIConfirm<T>::setConfirmMessage(string message) {
00124 CGUIElement* element = NULL;
00125 if ((element = getChild(0)) != NULL) {
00126 element->setString(message);
00127 }
00128 }
00129
00130 template<class T>
00131 void CGUIConfirm<T>::centered() {
00132
00133 GLint viewport[4];
00134 glGetIntegerv(GL_VIEWPORT, viewport);
00135
00136 GLfloat positionX = (viewport[2] / 2) - (this->getWidth() / 2);
00137 GLfloat positionY = (viewport[3] / 2) - (this->getHeight() / 2);
00138
00139 setPosition(positionX, positionY);
00140
00141 CGUIElement* curr = NULL;
00142
00143 for( int i = 1; i < size(); i++ ){
00144 if( ( curr = getChild(i) ) != NULL ){
00145 GLfloat px = positionX + (getWidth()/2) - curr->getWidth() / 2 ;
00146 curr->setPositionX( px );
00147 }
00148 }
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163 }
00164
00165 #endif