00001
00028 #ifndef _CGUILISTOPTION_
00029 #define _CGUILISTOPTION_
00030
00031 #include "GUIElement.h"
00032 #include "GUIList.h"
00033
00034 template<class Class, typename T>
00035 class CGUIListOption: public CGUIElement {
00036
00037 public:
00038
00039 CGUIListOption();
00040
00041 void render();
00042
00043 void setValue(int value) {
00044 m_value = value;
00045 }
00046
00047 int getValue() const {
00048 return m_value;
00049 }
00050
00051 void update() {
00052 }
00053
00054 void active() {
00055 m_active = true;
00056 }
00057
00058 void nonactive() {
00059 m_active = false;
00060 }
00061
00062 bool isActive() {
00063 return m_active;
00064 }
00065
00066 void setID(int id) {
00067 m_ID = id;
00068 }
00069
00070 void mouseButtons(int button, int state, int x, int y);
00071
00072 void setParent(Class* parent) {
00073 m_parent = parent;
00074 }
00075
00076 void setParentOnActivated(void(Class::*func)(int)) {
00077 m_func = func;
00078 }
00079
00080 protected:
00081
00082 T m_value;
00083 bool m_active;
00084 int m_ID;
00085
00086 Color4f m_colorActive;
00087 Color4f m_colorTextActive;
00088
00089 Class* m_parent;
00090 void (Class::*m_func)(int);
00091
00092 };
00093
00094 template<class C, typename T>
00095 CGUIListOption<C, T>::CGUIListOption() {
00096 this->setDimension(96, 20);
00097 this->setBackgroundColor(50, 50, 50, 128);
00098 this->setBackgroundHoverColor(0, 0, 0, 128);
00099 this->setTextHoverColor(255, 255, 255, 255);
00100
00101 m_colorActive.r = 1;
00102 m_colorActive.b = 1;
00103 m_colorActive.g = 1;
00104 m_colorActive.alpha = 0.5;
00105
00106 this->m_active = false;
00107
00108 }
00109
00110 template<class C, typename T>
00111 void CGUIListOption<C, T>::render() {
00112
00113 CFontPrinter* fontPrinter = CFontPrinter::getInstance();
00114 fontPrinter->activeFont(this->getFontId());
00115
00116 Color4f color;
00117
00118 glPushMatrix();
00119
00120 glTranslatef(getPositionX(), getPositionY(), 0);
00121
00122 Color4f backgroundColor = this->getCurrentBackgroundColor();
00123
00124 if (this->isActive()) {
00125 backgroundColor = m_colorActive;
00126 }
00127
00128 glColor4f(backgroundColor.r, backgroundColor.g, backgroundColor.b,
00129 backgroundColor.alpha);
00130
00131 glBegin(GL_QUADS);
00132 glVertex2f(0, 0);
00133 glVertex2f(getWidth(), 0);
00134 glVertex2f(getWidth(), getHeight());
00135 glVertex2f(0, getHeight());
00136 glEnd();
00137
00138 glPopMatrix();
00139
00140 fontPrinter->print(getFontId(), getPositionX(), getPositionY(),
00141 this->getCurrentTextColor(), this->getString());
00142 }
00143
00144 template<class C, typename T>
00145 void CGUIListOption<C, T>::mouseButtons(int button, int state, int x, int y) {
00146 if (this->isHover()) {
00147 if (button == GLUT_LEFT && state == GLUT_DOWN) {
00148 if (m_parent != NULL && m_func != NULL) {
00149
00150 (this->m_parent->*m_func)(m_ID);
00151 }
00152 }
00153 }
00154 }
00155
00156 #endif