1 | /* |
---|
2 | orxonox - the future of 3D-vertical-scrollers |
---|
3 | |
---|
4 | Copyright (C) 2004 orx |
---|
5 | |
---|
6 | This program is free software; you can redistribute it and/or modify |
---|
7 | it under the terms of the GNU General Public License as published by |
---|
8 | the Free Software Foundation; either version 2, or (at your option) |
---|
9 | any later version. |
---|
10 | |
---|
11 | ### File Specific: |
---|
12 | main-programmer: Benjamin Grauer |
---|
13 | co-programmer: ... |
---|
14 | */ |
---|
15 | |
---|
16 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GUI |
---|
17 | |
---|
18 | #include "glgui_checkbutton.h" |
---|
19 | |
---|
20 | #include "text.h" |
---|
21 | |
---|
22 | namespace OrxGui |
---|
23 | { |
---|
24 | |
---|
25 | |
---|
26 | /** |
---|
27 | * standard constructor |
---|
28 | */ |
---|
29 | GLGuiCheckButton::GLGuiCheckButton (const std::string& label, bool active) |
---|
30 | : GLGuiButton(label) |
---|
31 | { |
---|
32 | this->init(); |
---|
33 | this->bActive = active; |
---|
34 | |
---|
35 | this->resize(); |
---|
36 | } |
---|
37 | |
---|
38 | |
---|
39 | /** |
---|
40 | * standard deconstructor |
---|
41 | */ |
---|
42 | GLGuiCheckButton::~GLGuiCheckButton() |
---|
43 | { |
---|
44 | } |
---|
45 | |
---|
46 | /** |
---|
47 | * initializes the GUI-element |
---|
48 | */ |
---|
49 | void GLGuiCheckButton::init() |
---|
50 | { |
---|
51 | this->setClassID(CL_GLGUI_CHECKBUTTON, "GLGuiCheckButton"); |
---|
52 | } |
---|
53 | |
---|
54 | |
---|
55 | void GLGuiCheckButton::toggleActiveState() |
---|
56 | { |
---|
57 | this->bActive = !this->bActive; |
---|
58 | } |
---|
59 | |
---|
60 | void GLGuiCheckButton::resize() |
---|
61 | { |
---|
62 | this->label.setRelCoor2D(25, 5); |
---|
63 | this->setSize2D(this->label.getSizeX2D() + 30, this->label.getSizeY2D() + 10); |
---|
64 | } |
---|
65 | |
---|
66 | |
---|
67 | void GLGuiCheckButton::released() |
---|
68 | { |
---|
69 | printf("%s released\n", this->getLabel().c_str()); |
---|
70 | GLGuiWidget::released(); |
---|
71 | this->toggleActiveState(); |
---|
72 | } |
---|
73 | |
---|
74 | /** |
---|
75 | * @brief draws the GLGuiPushButton |
---|
76 | */ |
---|
77 | void GLGuiCheckButton::draw() const |
---|
78 | { |
---|
79 | this->startDraw(); |
---|
80 | GLGuiButton::draw(); |
---|
81 | |
---|
82 | this->frontMaterial().select(); |
---|
83 | glBegin(GL_QUADS); |
---|
84 | |
---|
85 | glTexCoord2i(0,0); glVertex2d(1, 1); |
---|
86 | glTexCoord2i(0,1); glVertex2d(1, this->getSizeY2D() - 1); |
---|
87 | glTexCoord2i(1,1); glVertex2d(this->getSizeX2D() - 1, this->getSizeY2D() -1); |
---|
88 | glTexCoord2i(1,0); glVertex2d(this->getSizeX2D() - 1, 1); |
---|
89 | |
---|
90 | if (this->bActive) |
---|
91 | { |
---|
92 | glColor3f( 1, 1 ,1); |
---|
93 | glTexCoord2i(0,0); glVertex2d(8, 8); |
---|
94 | glTexCoord2i(0,1); glVertex2d(8, this->getSizeY2D()-8); |
---|
95 | glTexCoord2i(1,1); glVertex2d(this->getSizeY2D()-8, this->getSizeY2D()-8); |
---|
96 | glTexCoord2i(1,0); glVertex2d(this->getSizeY2D()-8, 8); |
---|
97 | glEnd(); |
---|
98 | |
---|
99 | |
---|
100 | // DRAW a cross :) |
---|
101 | glColor3f(0,0,0); |
---|
102 | glLineWidth(3.0); |
---|
103 | glBegin(GL_LINE_LOOP); |
---|
104 | glVertex2d(8,8); |
---|
105 | glVertex2d(this->getSizeY2D()/2, this->getSizeY2D()/2 - 1); |
---|
106 | |
---|
107 | glVertex2d(this->getSizeY2D() -8, 8); |
---|
108 | glVertex2d(this->getSizeY2D()/2 +1, this->getSizeY2D()/2); |
---|
109 | |
---|
110 | glVertex2d(this->getSizeY2D() -8, this->getSizeY2D() - 8); |
---|
111 | glVertex2d(this->getSizeY2D()/2, this->getSizeY2D()/2+1); |
---|
112 | |
---|
113 | glVertex2d(8, this->getSizeY2D() - 8); |
---|
114 | glVertex2d(this->getSizeY2D()/2 -1, this->getSizeY2D()/2); |
---|
115 | glEnd(); |
---|
116 | } |
---|
117 | else |
---|
118 | { |
---|
119 | glColor3f(0, 0, 0); |
---|
120 | glTexCoord2i(0,0); glVertex2d(8, 8); |
---|
121 | glTexCoord2i(0,1); glVertex2d(8, this->getSizeY2D()-8); |
---|
122 | glTexCoord2i(1,1); glVertex2d(this->getSizeY2D()-8, this->getSizeY2D()-8); |
---|
123 | glTexCoord2i(1,0); glVertex2d(this->getSizeY2D()-8, 8); |
---|
124 | glEnd(); |
---|
125 | } |
---|
126 | |
---|
127 | |
---|
128 | this->endDraw(); |
---|
129 | // this->label->draw(); |
---|
130 | // printf("test"); |
---|
131 | } |
---|
132 | } |
---|