00001
00024 #ifndef _CGUIMESSAGE_H_
00025 #define _CGUIMESSAGE_H_
00026
00027 #include "GUIFrame.h"
00028
00029 template<class T>
00030 class CGUIMessage: public CGUIFrame {
00031 public:
00032
00033 CGUIMessage();
00034 CGUIMessage(const char* message);
00035 CGUIMessage(string message);
00036
00037 virtual ~CGUIMessage();
00038 void init(string message);
00039
00040 void setMessage(string message) {
00041 this->get(0)->setString(message);
00042 }
00043 ;
00044
00045 void callOnConfirm();
00046
00047 void setCallback(T* _instance, void(T::*_func)(void)) {
00048 m_instance = _instance;
00049 m_funcOnConfirm = _func;
00050 }
00051
00052 virtual void centered();
00053
00054 protected:
00055 T* m_instance;
00056 void (T::*m_funcOnConfirm)(void);
00057
00058 };
00059
00060 template<class T>
00061 CGUIMessage<T>::CGUIMessage() {
00062 init("No message set.");
00063 }
00064
00065 template<class T>
00066 CGUIMessage<T>::CGUIMessage(string message) {
00067 init(message);
00068 }
00069
00070 template<class T>
00071 CGUIMessage<T>::CGUIMessage(const char * message) {
00072 string tmp(message);
00073 init(tmp);
00074 }
00075
00076 template<class T>
00077 CGUIMessage<T>::~CGUIMessage() {
00078
00079 }
00080
00081 template<class T>
00082 void CGUIMessage<T>::init(string message) {
00083
00084 this->setColor(0, 0, 0, 128);
00085 this->setDimension(300, 150);
00086 this->setPosition(100, 100);
00087
00088 CGUIButton<CGUIMessage>* button = new CGUIButton<CGUIMessage> ;
00089 button->setString("OK");
00090 button->setDimension(30, 20);
00091
00092 button->setCallbackClass(this);
00093 button->setMouseDownCallback(&CGUIMessage::callOnConfirm);
00094
00095 CGUILabel* label = new CGUILabel();
00096 label->setString(message);
00097
00098 this->addChild(label);
00099 this->addChild(button);
00100 }
00101
00102 template<class T>
00103 void CGUIMessage<T>::callOnConfirm() {
00104
00105 if (this->m_instance != NULL && this->m_funcOnConfirm != NULL) {
00106 (this->m_instance->*this->m_funcOnConfirm)();
00107 }
00108
00109 }
00110
00111 template<class T>
00112 void CGUIMessage<T>::centered() {
00113 GLint viewport[4];
00114 glGetIntegerv(GL_VIEWPORT, viewport);
00115
00116 GLfloat positionX = (viewport[2] / 2) - (this->getWidth() / 2);
00117 GLfloat positionY = (viewport[3] / 2) - (this->getHeight() / 2);
00118
00119 setPosition(positionX, positionY);
00120
00121 CGUIElement* curr = NULL;
00122
00123 for (int i = 1; i < size(); i++) {
00124 if ((curr = getChild(i)) != NULL) {
00125 GLfloat px = positionX + (getWidth() / 2) - curr->getWidth() / 2;
00126 curr->setPositionX(px);
00127 }
00128 }
00129 }
00130
00131 #endif