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_widget.h" |
---|
19 | |
---|
20 | #include "glgui_cursor.h" |
---|
21 | |
---|
22 | #include "material.h" |
---|
23 | |
---|
24 | #include "debug.h" |
---|
25 | |
---|
26 | namespace OrxGui |
---|
27 | { |
---|
28 | |
---|
29 | /** |
---|
30 | * @brief standard constructor |
---|
31 | */ |
---|
32 | GLGuiWidget::GLGuiWidget (GLGuiWidget* parent) |
---|
33 | { |
---|
34 | this->init(); |
---|
35 | |
---|
36 | if (parent != NULL) |
---|
37 | parent->addChild2D(this); |
---|
38 | } |
---|
39 | |
---|
40 | |
---|
41 | /** |
---|
42 | * @brief standard deconstructor |
---|
43 | */ |
---|
44 | GLGuiWidget::~GLGuiWidget() |
---|
45 | { |
---|
46 | if (this == GLGuiWidget::_focused) |
---|
47 | GLGuiWidget::_focused = NULL; |
---|
48 | } |
---|
49 | |
---|
50 | GLGuiWidget* GLGuiWidget::_focused = NULL; |
---|
51 | GLGuiWidget* GLGuiWidget::_inputGrabber = NULL; |
---|
52 | |
---|
53 | |
---|
54 | |
---|
55 | /** |
---|
56 | * initializes the GUI-element |
---|
57 | */ |
---|
58 | void GLGuiWidget::init() |
---|
59 | { |
---|
60 | this->setClassID(CL_GLGUI_WIDGET, "GLGuiWidget"); |
---|
61 | |
---|
62 | this->_focusable = false; |
---|
63 | this->_clickable = false; |
---|
64 | this->_pushed = false; |
---|
65 | |
---|
66 | this->setVisibility(GLGUI_WIDGET_DEFAULT_VISIBLE); |
---|
67 | |
---|
68 | this->_backMat.setDiffuse(1.0, 1.0, 1.0); |
---|
69 | this->_frontMat.setDiffuse(1.0, 0.0, 0.0); |
---|
70 | |
---|
71 | this->widgetSignals.resize(SignalCount, SignalConnector()); |
---|
72 | } |
---|
73 | |
---|
74 | |
---|
75 | /** @brief gives focus to this widget */ |
---|
76 | void GLGuiWidget::giveFocus() |
---|
77 | { |
---|
78 | if (GLGuiWidget::focused() != NULL) |
---|
79 | GLGuiWidget::focused()->breakFocus(); |
---|
80 | GLGuiWidget::_focused = this; |
---|
81 | this->receivedFocus(); |
---|
82 | }; |
---|
83 | |
---|
84 | void GLGuiWidget::breakFocus() |
---|
85 | { |
---|
86 | if (GLGuiWidget::_focused == this) |
---|
87 | { |
---|
88 | GLGuiWidget::_focused = NULL; |
---|
89 | this->_pushed = false; |
---|
90 | this->removedFocus(); |
---|
91 | } |
---|
92 | }; |
---|
93 | |
---|
94 | |
---|
95 | bool GLGuiWidget::focusOverWidget(const Vector2D& position) const |
---|
96 | { |
---|
97 | return (this->getAbsCoor2D().x < position.x && this->getAbsCoor2D().x + this->getSizeX2D() > position.x && |
---|
98 | this->getAbsCoor2D().y < position.y && this->getAbsCoor2D().y + this->getSizeY2D() > position.y); |
---|
99 | } |
---|
100 | |
---|
101 | bool GLGuiWidget::focusOverWidget(const GLGuiCursor* const cursor) const |
---|
102 | { |
---|
103 | return this->focusOverWidget(cursor->getAbsCoor2D()); |
---|
104 | } |
---|
105 | |
---|
106 | |
---|
107 | void GLGuiWidget::resize() |
---|
108 | { |
---|
109 | this->backRect().setSize(this->getSize2D()); |
---|
110 | } |
---|
111 | |
---|
112 | |
---|
113 | void GLGuiWidget::click() |
---|
114 | { |
---|
115 | assert (!this->_pushed); |
---|
116 | this->widgetSignals[Signal_click]("none"); |
---|
117 | this->_pushed = true; |
---|
118 | |
---|
119 | this->clicked(); |
---|
120 | } |
---|
121 | |
---|
122 | void GLGuiWidget::release() |
---|
123 | { |
---|
124 | if (this->_pushed) |
---|
125 | { |
---|
126 | this->widgetSignals[Signal_release]("none"); |
---|
127 | |
---|
128 | this->released(); |
---|
129 | this->_pushed = false; |
---|
130 | } |
---|
131 | } |
---|
132 | |
---|
133 | |
---|
134 | void GLGuiWidget::clicked() |
---|
135 | { |
---|
136 | this->frontMaterial().setDiffuse(0, 0, 1); |
---|
137 | |
---|
138 | } |
---|
139 | |
---|
140 | void GLGuiWidget::released() |
---|
141 | { |
---|
142 | this->frontMaterial().setDiffuse(0,1,0); |
---|
143 | |
---|
144 | } |
---|
145 | |
---|
146 | void GLGuiWidget::receivedFocus() |
---|
147 | { |
---|
148 | this->frontMaterial().setDiffuse(0, 1, 0); |
---|
149 | } |
---|
150 | |
---|
151 | void GLGuiWidget::removedFocus() |
---|
152 | { |
---|
153 | this->frontMaterial().setDiffuse(1, 0, 0); |
---|
154 | |
---|
155 | } |
---|
156 | |
---|
157 | void GLGuiWidget::destroyed() |
---|
158 | { |
---|
159 | }; |
---|
160 | |
---|
161 | |
---|
162 | |
---|
163 | |
---|
164 | /** |
---|
165 | * @brief connects a Signal to the Gui-Elements' Event. |
---|
166 | * @param sinalType the Type of Signal to set. @see GLGuiSignalType |
---|
167 | * @param signal the name of the Signal |
---|
168 | */ |
---|
169 | void GLGuiWidget::connectSignal(SignalType signalType, BaseObject* object, const Executor* signal) |
---|
170 | { |
---|
171 | if (signalType >= this->widgetSignals.size()) |
---|
172 | return; |
---|
173 | |
---|
174 | // if (this->widgetSignals[signalType] != NULL) |
---|
175 | // PRINTF(2)("Already connected a Signal to '%s::%s' type %s... overwriting\n", this->getClassName(), this->getName(), "TEST"); |
---|
176 | |
---|
177 | this->widgetSignals[signalType] = SignalConnector(object, signal); |
---|
178 | } |
---|
179 | |
---|
180 | /** |
---|
181 | * @brief removes a Signal from a Gui-ELements' Event |
---|
182 | * @param signalType the type of Signal to remove. |
---|
183 | */ |
---|
184 | void GLGuiWidget::disconnectSignal(SignalType signalType) |
---|
185 | { |
---|
186 | if (signalType >= this->widgetSignals.size()) |
---|
187 | return; |
---|
188 | |
---|
189 | this->widgetSignals[signalType] = SignalConnector(); |
---|
190 | } |
---|
191 | |
---|
192 | |
---|
193 | void GLGuiWidget::show() |
---|
194 | { |
---|
195 | this->setVisibility(true); |
---|
196 | } |
---|
197 | |
---|
198 | |
---|
199 | void GLGuiWidget::hide() |
---|
200 | { |
---|
201 | this->setVisibility(false); |
---|
202 | } |
---|
203 | |
---|
204 | |
---|
205 | /** |
---|
206 | * USE THIS FUNCTION ONLY FROM DERIVED CLASS |
---|
207 | */ |
---|
208 | void GLGuiWidget::draw() const |
---|
209 | { |
---|
210 | this->backMaterial().select(); |
---|
211 | this->drawRect(this->backRect()); |
---|
212 | } |
---|
213 | |
---|
214 | } |
---|