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 | This program is distributed in the hope that it will be useful, |
---|
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
14 | GNU General Public License for more details. |
---|
15 | |
---|
16 | You should have received a copy of the GNU General Public License |
---|
17 | along with this program; if not, write to the Free Software Foundation, |
---|
18 | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
19 | |
---|
20 | |
---|
21 | ### File Specific: |
---|
22 | main-programmer: Benjamin Grauer |
---|
23 | |
---|
24 | */ |
---|
25 | |
---|
26 | #include "gui_keys.h" |
---|
27 | |
---|
28 | #include <string.h> |
---|
29 | |
---|
30 | /** |
---|
31 | \brief Creates an Keyboard-Frame |
---|
32 | */ |
---|
33 | GuiKeys::GuiKeys(void) |
---|
34 | { |
---|
35 | this->keysFrame = new Frame("Keyboard-Options:"); |
---|
36 | // keysFrame->setGroupName("Keyboard"); |
---|
37 | this->keysBox = new Box('h'); |
---|
38 | this->player1 = new Player("player1"); |
---|
39 | this->player2 = new Player("player2"); |
---|
40 | |
---|
41 | this->keysBox->fill(this->player1->getOpenButton()); |
---|
42 | this->keysBox->fill(this->player2->getOpenButton()); |
---|
43 | |
---|
44 | this->keysFrame->fill(this->keysBox); |
---|
45 | |
---|
46 | |
---|
47 | this->inputWindow = new Window("inputWindow"); |
---|
48 | this->inputButton = new Button("test"); |
---|
49 | #ifdef HAVE_GTK2 |
---|
50 | this->inputWindow->connectSignal("destroy", Widget::doNothingSignal); |
---|
51 | this->inputWindow->connectSignal("delete_event", Widget::doNothingSignal); |
---|
52 | #endif /* HAVE_GTK2 */ |
---|
53 | this->inputWindow->fill(inputButton); |
---|
54 | |
---|
55 | this->setMainWidget(keysFrame); |
---|
56 | } |
---|
57 | |
---|
58 | /** |
---|
59 | \brief Destructs the Keys-stuff |
---|
60 | */ |
---|
61 | GuiKeys::~GuiKeys(void) |
---|
62 | { |
---|
63 | // nothing to do here. |
---|
64 | } |
---|
65 | |
---|
66 | |
---|
67 | Window* GuiKeys::inputWindow = NULL; |
---|
68 | Button* GuiKeys::inputButton = NULL; |
---|
69 | long GuiKeys::keySignal = 0; |
---|
70 | |
---|
71 | |
---|
72 | /* PLAYER */ |
---|
73 | |
---|
74 | /** |
---|
75 | \brief Creates new inputs for a player |
---|
76 | \param player the name of the Player |
---|
77 | */ |
---|
78 | Player::Player(char* player) |
---|
79 | { |
---|
80 | char* windowName = new char[strlen(player)+25]; |
---|
81 | strcpy(windowName, "Keyboard settings of "); |
---|
82 | strcat(windowName, player); |
---|
83 | this->pKeyWindow = new Window(windowName); |
---|
84 | this->pKeyFrame = new Frame(windowName); |
---|
85 | this->pKeysBox = new Box('v'); |
---|
86 | this->pKeysBox->setGroupName(player); |
---|
87 | this->pKeysBox->fill(addKey(UP, "up")); |
---|
88 | this->pKeysBox->fill(addKey(DOWN, "down")); |
---|
89 | this->pKeysBox->fill(addKey(LEFT, "left")); |
---|
90 | this->pKeysBox->fill(addKey(RIGHT, "right")); |
---|
91 | this->pKeysBox->fill(addKey(SHOOT, "fire")); |
---|
92 | delete windowName; |
---|
93 | closeButton = new Button("close"); |
---|
94 | #ifdef HAVE_GTK2 |
---|
95 | this->closeButton->connectSignal("button_press_event", this->pKeyWindow, Window::windowClose); |
---|
96 | #endif /* HAVE_GTK2 */ |
---|
97 | |
---|
98 | this->pKeysBox->fill(this->closeButton); |
---|
99 | this->pKeyFrame->fill(this->pKeysBox); |
---|
100 | this->pKeyWindow->fill(this->pKeyFrame); |
---|
101 | Window::addWindow(this->pKeyWindow); |
---|
102 | #ifdef HAVE_GTK2 |
---|
103 | this->pKeyWindow->connectSignal("destroy", this->pKeyWindow, Window::windowClose); |
---|
104 | this->pKeyWindow->connectSignal("delete_event", this->pKeyWindow, Window::windowClose); |
---|
105 | #endif /* HAVE_GTK2 */ |
---|
106 | |
---|
107 | this->openButton = new Button(player); |
---|
108 | #ifdef HAVE_GTK2 |
---|
109 | this->openButton->connectSignal("button_press_event", this->pKeyWindow, Window::windowOpen); |
---|
110 | #endif /* HAVE_GTK2 */ |
---|
111 | } |
---|
112 | |
---|
113 | /** |
---|
114 | \returns the OpenButton of a Player |
---|
115 | */ |
---|
116 | Button* Player::getOpenButton(void) |
---|
117 | { |
---|
118 | return this->openButton; |
---|
119 | } |
---|
120 | |
---|
121 | /** |
---|
122 | \brief sets a new Key(only output) |
---|
123 | \param key the new Key. |
---|
124 | */ |
---|
125 | void Player::setkey(KEYS key) |
---|
126 | { |
---|
127 | PRINT(4)("setting up Key: %d\n", key); |
---|
128 | } |
---|
129 | |
---|
130 | /** |
---|
131 | \brief adds a new Key. |
---|
132 | \param key the number of the Key |
---|
133 | \param name The name of the new Key. |
---|
134 | \returns A widget that has the Key-Box |
---|
135 | */ |
---|
136 | Widget* addKey(KEYS key, char* name) |
---|
137 | { |
---|
138 | InputKey* inputKey = new InputKey; |
---|
139 | inputKey->pKeyBox = new Box(); |
---|
140 | inputKey->pKeyButton = new Button(name); |
---|
141 | inputKey->pKeyOLabel = new OptionLabel(name, name); |
---|
142 | inputKey->pKeyOLabel->saveability(); |
---|
143 | |
---|
144 | #ifdef HAVE_GTK2 |
---|
145 | //inputKey->pKeyButton->connectSignal("key_press_event", inputKey->pKeyButton, key_cb); |
---|
146 | inputKey->pKeyButton->connectSignal("button_press_event", inputKey, inputWindowEvent); |
---|
147 | #endif /* HAVE_GTK2 */ |
---|
148 | inputKey->pKeyBox->fill(inputKey->pKeyButton); |
---|
149 | inputKey->pKeyBox->fill(inputKey->pKeyOLabel); |
---|
150 | return inputKey->pKeyBox; |
---|
151 | } |
---|
152 | |
---|
153 | |
---|
154 | #ifdef HAVE_GTK2 |
---|
155 | gint inputWindowEvent(GtkWidget* w, GdkEventKey* event, void* inputKey) |
---|
156 | { |
---|
157 | GuiKeys::inputButton->setTitle("press a Key"); |
---|
158 | GuiKeys::keySignal = GuiKeys::inputButton->connectSignal("key_press_event", inputKey, key_cb); |
---|
159 | GuiKeys::inputWindow->open(); |
---|
160 | } |
---|
161 | |
---|
162 | /** |
---|
163 | \brief Function which gets keystrokes |
---|
164 | \param w the widget that released the Function. |
---|
165 | \param event The event that happened. |
---|
166 | \param Widget the Widget which will be applied. |
---|
167 | \returns Nothing |
---|
168 | */ |
---|
169 | gint key_cb(GtkWidget* w, GdkEventKey* event, void* inputKey) |
---|
170 | { |
---|
171 | InputKey* inputkey =(InputKey*) inputKey; |
---|
172 | char title [20]; |
---|
173 | |
---|
174 | switch(event->keyval) |
---|
175 | { |
---|
176 | case GDK_Up: |
---|
177 | strcpy(title, "UP"); |
---|
178 | break; |
---|
179 | case GDK_Down: |
---|
180 | strcpy(title, "DOWN"); |
---|
181 | break; |
---|
182 | case GDK_Left: |
---|
183 | strcpy(title, "LEFT"); |
---|
184 | break; |
---|
185 | case GDK_Right: |
---|
186 | strcpy(title, "RIGHT"); |
---|
187 | break; |
---|
188 | |
---|
189 | case GDK_space: |
---|
190 | strcpy(title, "SPACE"); |
---|
191 | break; |
---|
192 | |
---|
193 | case GDK_Return: |
---|
194 | strcpy(title, "RETURN"); |
---|
195 | break; |
---|
196 | |
---|
197 | // Special Keys // |
---|
198 | case GDK_BackSpace: |
---|
199 | strcpy(title, "BACKSPACE"); |
---|
200 | break; |
---|
201 | case GDK_Scroll_Lock: |
---|
202 | strcpy(title, "SCROLLOCK"); |
---|
203 | break; |
---|
204 | case GDK_minus: |
---|
205 | strcpy(title, "MINUS"); |
---|
206 | break; |
---|
207 | case GDK_plus: |
---|
208 | strcpy(title, "PLUS"); |
---|
209 | break; |
---|
210 | case GDK_slash: |
---|
211 | strcpy(title, "SLASH"); |
---|
212 | break; |
---|
213 | case GDK_period: |
---|
214 | strcpy(title, "PERIOD"); |
---|
215 | break; |
---|
216 | case GDK_comma: |
---|
217 | strcpy(title, "COMMA"); |
---|
218 | break; |
---|
219 | case GDK_colon: |
---|
220 | strcpy(title, "COLON"); |
---|
221 | break; |
---|
222 | case GDK_semicolon: |
---|
223 | strcpy(title, "SEMICOLON"); |
---|
224 | break; |
---|
225 | case GDK_less: |
---|
226 | strcpy(title, "LESS"); |
---|
227 | break; |
---|
228 | case GDK_equal: |
---|
229 | strcpy(title, "EQUALS"); |
---|
230 | break; |
---|
231 | case GDK_greater: |
---|
232 | strcpy(title, "GREATER"); |
---|
233 | break; |
---|
234 | case GDK_question: |
---|
235 | strcpy(title, "QUESTION"); |
---|
236 | break; |
---|
237 | case GDK_at: |
---|
238 | strcpy(title, "AT"); |
---|
239 | break; |
---|
240 | case GDK_bracketleft: |
---|
241 | strcpy(title, "LEFTBRACKET"); |
---|
242 | break; |
---|
243 | case GDK_bracketright: |
---|
244 | strcpy(title, "RIGHTBRACKET"); |
---|
245 | break; |
---|
246 | case GDK_backslash: |
---|
247 | strcpy(title, "BACKSLASH"); |
---|
248 | break; |
---|
249 | case GDK_underscore: |
---|
250 | strcpy(title, "UNDERSCORE"); |
---|
251 | break; |
---|
252 | case GDK_quoteleft: |
---|
253 | strcpy(title, "BACKQUOTE"); |
---|
254 | break; |
---|
255 | |
---|
256 | case GDK_Page_Up: |
---|
257 | strcpy(title, "PAGEUP"); |
---|
258 | break; |
---|
259 | case GDK_Page_Down: |
---|
260 | strcpy(title, "PAGEDOWN"); |
---|
261 | break; |
---|
262 | case GDK_Home: |
---|
263 | strcpy(title, "HOME"); |
---|
264 | break; |
---|
265 | case GDK_Insert: |
---|
266 | strcpy(title, "INSERT"); |
---|
267 | break; |
---|
268 | |
---|
269 | case GDK_Escape: |
---|
270 | strcpy(title, "ESCAPE"); |
---|
271 | break; |
---|
272 | case GDK_Tab: |
---|
273 | strcpy(title, "TAB"); |
---|
274 | break; |
---|
275 | case GDK_Shift_L: |
---|
276 | strcpy(title, "LSHIFT"); |
---|
277 | break; |
---|
278 | case GDK_Shift_R: |
---|
279 | strcpy(title, "R_SHIFT"); |
---|
280 | break; |
---|
281 | case GDK_Control_L: |
---|
282 | strcpy(title, "LCTRL"); |
---|
283 | break; |
---|
284 | case GDK_Control_R: |
---|
285 | strcpy(title, "RCTRL"); |
---|
286 | break; |
---|
287 | case GDK_Alt_L: |
---|
288 | strcpy(title, "LALT"); |
---|
289 | break; |
---|
290 | case GDK_Alt_R: |
---|
291 | strcpy(title, "RALT"); |
---|
292 | break; |
---|
293 | // FXX KEYS // |
---|
294 | case GDK_F1: |
---|
295 | strcpy(title, "F1"); |
---|
296 | break; |
---|
297 | case GDK_F2: |
---|
298 | strcpy(title, "F2"); |
---|
299 | break; |
---|
300 | case GDK_F3: |
---|
301 | strcpy(title, "F3"); |
---|
302 | break; |
---|
303 | case GDK_F4: |
---|
304 | strcpy(title, "F4"); |
---|
305 | break; |
---|
306 | case GDK_F5: |
---|
307 | strcpy(title, "F5"); |
---|
308 | break; |
---|
309 | case GDK_F6: |
---|
310 | strcpy(title, "F6"); |
---|
311 | break; |
---|
312 | case GDK_F7: |
---|
313 | strcpy(title, "F7"); |
---|
314 | break; |
---|
315 | case GDK_F8: |
---|
316 | strcpy(title, "F8"); |
---|
317 | break; |
---|
318 | case GDK_F9: |
---|
319 | strcpy(title, "F9"); |
---|
320 | break; |
---|
321 | case GDK_F10: |
---|
322 | strcpy(title, "F10"); |
---|
323 | break; |
---|
324 | case GDK_F11: |
---|
325 | strcpy(title, "F11"); |
---|
326 | break; |
---|
327 | case GDK_F12: |
---|
328 | strcpy(title, "F12"); |
---|
329 | break; |
---|
330 | |
---|
331 | |
---|
332 | default: |
---|
333 | char* tmp; |
---|
334 | sprintf(tmp, "%c", event->keyval); |
---|
335 | printf("other key %s \n", tmp); |
---|
336 | strcpy(title, tmp); |
---|
337 | break; |
---|
338 | } |
---|
339 | |
---|
340 | inputkey->pKeyOLabel->setValue(title); |
---|
341 | GuiKeys::inputButton->disconnectSignal(GuiKeys::keySignal); |
---|
342 | GuiKeys::inputWindow->close(); |
---|
343 | } |
---|
344 | #endif /* HAVE_GTK2 */ |
---|