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 | * Creates an Keyboard-Frame |
---|
32 | */ |
---|
33 | GuiKeys::GuiKeys() |
---|
34 | { |
---|
35 | Frame* keysFrame; //!< The Frame that holds the keyOptions. |
---|
36 | |
---|
37 | keysFrame = new Frame("Keyboard-Options:"); |
---|
38 | { |
---|
39 | Box* keysBox0; //!< The Frame that holds the keyOptions. |
---|
40 | |
---|
41 | // keysFrame->setGroupName("Keyboard"); |
---|
42 | keysBox0 = new Box('v'); |
---|
43 | { |
---|
44 | Box* keysBox1; |
---|
45 | MiscKeys* misc; //!< The Misc Keys |
---|
46 | |
---|
47 | keysBox1 = new Box('h'); |
---|
48 | { |
---|
49 | PlayerKeys* player1; //!< The first Player's keys. |
---|
50 | PlayerKeys* player2; //!< The seconds Player's keys. |
---|
51 | |
---|
52 | player1 = new PlayerKeys(CONFIG_SECTION_PLAYER "1"); |
---|
53 | player2 = new PlayerKeys(CONFIG_SECTION_PLAYER "2"); |
---|
54 | |
---|
55 | keysBox1->fill(player1->getOpenButton()); |
---|
56 | keysBox1->fill(player2->getOpenButton()); |
---|
57 | } |
---|
58 | keysBox0->fill(keysBox1); |
---|
59 | |
---|
60 | misc = new MiscKeys(); |
---|
61 | keysBox0->fill(misc->getOpenButton()); |
---|
62 | } |
---|
63 | keysFrame->fill(keysBox0); |
---|
64 | } |
---|
65 | |
---|
66 | // setting up the Input Windows that receives keystrokes. |
---|
67 | this->inputWindow = new Window("inputWindow"); |
---|
68 | this->inputButton = new Button("test"); |
---|
69 | #ifdef HAVE_GTK2 |
---|
70 | this->inputWindow->connectSignal("destroy", Widget::doNothingSignal); |
---|
71 | this->inputWindow->connectSignal("delete_event", Widget::doNothingSignal); |
---|
72 | #endif /* HAVE_GTK2 */ |
---|
73 | this->inputWindow->fill(inputButton); |
---|
74 | |
---|
75 | this->setMainWidget(keysFrame); |
---|
76 | } |
---|
77 | |
---|
78 | /** |
---|
79 | * Destructs the Keys-stuff |
---|
80 | */ |
---|
81 | GuiKeys::~GuiKeys() |
---|
82 | { |
---|
83 | // nothing to do here. |
---|
84 | } |
---|
85 | |
---|
86 | |
---|
87 | Window* GuiKeys::inputWindow = NULL; |
---|
88 | Button* GuiKeys::inputButton = NULL; |
---|
89 | long GuiKeys::keySignal = 0; |
---|
90 | |
---|
91 | //////////// |
---|
92 | /* PLAYER */ |
---|
93 | //////////// |
---|
94 | /** |
---|
95 | * Creates new inputs for a player |
---|
96 | * @param player the name of the Player |
---|
97 | */ |
---|
98 | PlayerKeys::PlayerKeys(char* player) |
---|
99 | { |
---|
100 | Window* pKeyWindow; //!< The Window for a new Key-setting. |
---|
101 | |
---|
102 | char* windowName = new char[strlen(player)+12]; |
---|
103 | strcpy(windowName, "KeySets: "); |
---|
104 | strcat(windowName, player); |
---|
105 | pKeyWindow = new Window(windowName); |
---|
106 | { |
---|
107 | Frame* pKeyFrame; //!< The Frame for a new Key-setting. |
---|
108 | |
---|
109 | pKeyFrame = new Frame(windowName); |
---|
110 | { |
---|
111 | Box* pKeysBox; //!< The Box that holds the Key-settings. |
---|
112 | pKeysBox = new Box('v'); |
---|
113 | { |
---|
114 | Button* closeButton; //!< The CloseButton for this key-settings. |
---|
115 | |
---|
116 | pKeysBox->setGroupName(player); |
---|
117 | pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_FORWARD, "w")); |
---|
118 | pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_BACKWARD, "s")); |
---|
119 | pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_LEFT, "a")); |
---|
120 | pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_RIGHT, "d")); |
---|
121 | |
---|
122 | pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_UP, "r")); |
---|
123 | pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_DOWN, "f")); |
---|
124 | pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_ROLL_LEFT, "q")); |
---|
125 | pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_ROLL_RIGHT, "e")); |
---|
126 | |
---|
127 | pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_FIRE, "BUTTON_LEFT")); |
---|
128 | pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_NEXT_WEAPON, "m")); |
---|
129 | pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_PREV_WEAPON, "n")); |
---|
130 | pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_CHANGE_SHIP, "g")); |
---|
131 | closeButton = new Button("close"); |
---|
132 | #ifdef HAVE_GTK2 |
---|
133 | closeButton->connectSignal("button_press_event", pKeyWindow, Window::windowClose); |
---|
134 | #endif /* HAVE_GTK2 */ |
---|
135 | |
---|
136 | pKeysBox->fill(closeButton); |
---|
137 | } |
---|
138 | pKeyFrame->fill(pKeysBox); |
---|
139 | } |
---|
140 | pKeyWindow->fill(pKeyFrame); |
---|
141 | } |
---|
142 | delete[] windowName; |
---|
143 | Window::addWindow(pKeyWindow); |
---|
144 | #ifdef HAVE_GTK2 |
---|
145 | pKeyWindow->connectSignal("destroy", pKeyWindow, Window::windowClose); |
---|
146 | pKeyWindow->connectSignal("delete_event", pKeyWindow, Window::windowClose); |
---|
147 | #endif /* HAVE_GTK2 */ |
---|
148 | |
---|
149 | this->openButton = new Button(player); |
---|
150 | #ifdef HAVE_GTK2 |
---|
151 | this->openButton->connectSignal("button_press_event", pKeyWindow, Window::windowOpen); |
---|
152 | #endif /* HAVE_GTK2 */ |
---|
153 | } |
---|
154 | |
---|
155 | /** |
---|
156 | * @returns the OpenButton of a Player |
---|
157 | */ |
---|
158 | Button* PlayerKeys::getOpenButton() |
---|
159 | { |
---|
160 | return this->openButton; |
---|
161 | } |
---|
162 | |
---|
163 | ////////////////// |
---|
164 | /* MISC_OPTIONS */ |
---|
165 | ////////////////// |
---|
166 | /** |
---|
167 | * Creates new inputs for a misc |
---|
168 | * @param player the name of the Misc |
---|
169 | */ |
---|
170 | MiscKeys::MiscKeys() |
---|
171 | { |
---|
172 | Window* keyWindow; //!< The Window for a new Key-setting. |
---|
173 | |
---|
174 | keyWindow = new Window("misc Keys"); |
---|
175 | { |
---|
176 | Frame* keyFrame; //!< The Frame for a new Key-setting. |
---|
177 | |
---|
178 | keyFrame = new Frame("misc Keys:"); |
---|
179 | { |
---|
180 | Box* keysBox; //!< The Box that holds the Key-settings. |
---|
181 | keysBox = new Box('v'); |
---|
182 | { |
---|
183 | Button* closeButton; //!< The CloseButton for this key-settings. |
---|
184 | |
---|
185 | keysBox->setGroupName(CONFIG_SECTION_MISC_KEYS); |
---|
186 | keysBox->fill(addKey(CONFIG_NAME_QUIT , "ESCAPE")); |
---|
187 | keysBox->fill(addKey(CONFIG_NAME_PAUSE, "PAUSE")); |
---|
188 | keysBox->fill(addKey(CONFIG_NAME_NEXT_WORLD, "x")); |
---|
189 | keysBox->fill(addKey(CONFIG_NAME_PREV_WORLD, "z")); |
---|
190 | keysBox->fill(addKey(CONFIG_NAME_VIEW0, "1")); |
---|
191 | keysBox->fill(addKey(CONFIG_NAME_VIEW1, "2")); |
---|
192 | keysBox->fill(addKey(CONFIG_NAME_VIEW2, "3")); |
---|
193 | keysBox->fill(addKey(CONFIG_NAME_VIEW3, "4")); |
---|
194 | keysBox->fill(addKey(CONFIG_NAME_VIEW4, "5")); |
---|
195 | keysBox->fill(addKey(CONFIG_NAME_VIEW5, "6")); |
---|
196 | |
---|
197 | closeButton = new Button("close"); |
---|
198 | #ifdef HAVE_GTK2 |
---|
199 | closeButton->connectSignal("button_press_event", keyWindow, Window::windowClose); |
---|
200 | #endif /* HAVE_GTK2 */ |
---|
201 | |
---|
202 | keysBox->fill(closeButton); |
---|
203 | } |
---|
204 | keyFrame->fill(keysBox); |
---|
205 | } |
---|
206 | keyWindow->fill(keyFrame); |
---|
207 | } |
---|
208 | Window::addWindow(keyWindow); |
---|
209 | #ifdef HAVE_GTK2 |
---|
210 | keyWindow->connectSignal("destroy", keyWindow, Window::windowClose); |
---|
211 | keyWindow->connectSignal("delete_event", keyWindow, Window::windowClose); |
---|
212 | #endif /* HAVE_GTK2 */ |
---|
213 | |
---|
214 | this->openButton = new Button("misc"); |
---|
215 | #ifdef HAVE_GTK2 |
---|
216 | this->openButton->connectSignal("button_press_event", keyWindow, Window::windowOpen); |
---|
217 | #endif /* HAVE_GTK2 */ |
---|
218 | } |
---|
219 | |
---|
220 | /** |
---|
221 | * @returns the OpenButton of a Misc |
---|
222 | */ |
---|
223 | Button* MiscKeys::getOpenButton() |
---|
224 | { |
---|
225 | return this->openButton; |
---|
226 | } |
---|
227 | |
---|
228 | |
---|
229 | /** |
---|
230 | * adds a new Key. |
---|
231 | * @param key the number of the Key |
---|
232 | * @param name The name of the new Key. |
---|
233 | * @returns A widget that has the Key-Box |
---|
234 | */ |
---|
235 | Widget* addKey(const char* name, const char* defaultVal) |
---|
236 | { |
---|
237 | InputKey* inputKey = new InputKey; |
---|
238 | inputKey->keyBox = new Box(); |
---|
239 | inputKey->keyButton = new Button(name); |
---|
240 | if (defaultVal) |
---|
241 | inputKey->keyOLabel = new OptionLabel(name, defaultVal); |
---|
242 | else |
---|
243 | inputKey->keyOLabel = new OptionLabel(name, name); |
---|
244 | inputKey->keyOLabel->saveability(); |
---|
245 | |
---|
246 | #ifdef HAVE_GTK2 |
---|
247 | //inputKey->keyButton->connectSignal("key_press_event", inputKey->keyButton, key_cb); |
---|
248 | inputKey->keyButton->connectSignal("button_press_event", inputKey, inputWindowEvent); |
---|
249 | #endif /* HAVE_GTK2 */ |
---|
250 | inputKey->keyBox->fill(inputKey->keyButton); |
---|
251 | inputKey->keyBox->fill(inputKey->keyOLabel); |
---|
252 | return inputKey->keyBox; |
---|
253 | } |
---|
254 | |
---|
255 | |
---|
256 | #ifdef HAVE_GTK2 |
---|
257 | gint inputWindowEvent(GtkWidget* w, GdkEventKey* event, void* inputKey) |
---|
258 | { |
---|
259 | GuiKeys::inputButton->setTitle("press a Key"); |
---|
260 | GuiKeys::keySignal = GuiKeys::inputButton->connectSignal("key_press_event", inputKey, key_cb); |
---|
261 | GuiKeys::inputWindow->open(); |
---|
262 | } |
---|
263 | |
---|
264 | /** |
---|
265 | * Function which gets keystrokes |
---|
266 | * @param w the widget that released the Function. |
---|
267 | * @param event The event that happened. |
---|
268 | * @param Widget the Widget which will be applied. |
---|
269 | * @returns Nothing |
---|
270 | */ |
---|
271 | gint key_cb(GtkWidget* w, GdkEventKey* event, void* inputKey) |
---|
272 | { |
---|
273 | InputKey* inputkey =(InputKey*) inputKey; |
---|
274 | char title [50]; |
---|
275 | |
---|
276 | switch(event->keyval) |
---|
277 | { |
---|
278 | case GDK_Up: |
---|
279 | strcpy(title, "UP"); |
---|
280 | break; |
---|
281 | case GDK_Down: |
---|
282 | strcpy(title, "DOWN"); |
---|
283 | break; |
---|
284 | case GDK_Left: |
---|
285 | strcpy(title, "LEFT"); |
---|
286 | break; |
---|
287 | case GDK_Right: |
---|
288 | strcpy(title, "RIGHT"); |
---|
289 | break; |
---|
290 | |
---|
291 | case GDK_space: |
---|
292 | strcpy(title, "SPACE"); |
---|
293 | break; |
---|
294 | |
---|
295 | case GDK_Return: |
---|
296 | strcpy(title, "RETURN"); |
---|
297 | break; |
---|
298 | |
---|
299 | // Special Keys // |
---|
300 | case GDK_BackSpace: |
---|
301 | strcpy(title, "BACKSPACE"); |
---|
302 | break; |
---|
303 | case GDK_Scroll_Lock: |
---|
304 | strcpy(title, "SCROLLOCK"); |
---|
305 | break; |
---|
306 | case GDK_minus: |
---|
307 | strcpy(title, "MINUS"); |
---|
308 | break; |
---|
309 | case GDK_plus: |
---|
310 | strcpy(title, "PLUS"); |
---|
311 | break; |
---|
312 | case GDK_slash: |
---|
313 | strcpy(title, "SLASH"); |
---|
314 | break; |
---|
315 | case GDK_period: |
---|
316 | strcpy(title, "PERIOD"); |
---|
317 | break; |
---|
318 | case GDK_comma: |
---|
319 | strcpy(title, "COMMA"); |
---|
320 | break; |
---|
321 | case GDK_colon: |
---|
322 | strcpy(title, "COLON"); |
---|
323 | break; |
---|
324 | case GDK_semicolon: |
---|
325 | strcpy(title, "SEMICOLON"); |
---|
326 | break; |
---|
327 | case GDK_less: |
---|
328 | strcpy(title, "LESS"); |
---|
329 | break; |
---|
330 | case GDK_equal: |
---|
331 | strcpy(title, "EQUALS"); |
---|
332 | break; |
---|
333 | case GDK_greater: |
---|
334 | strcpy(title, "GREATER"); |
---|
335 | break; |
---|
336 | case GDK_question: |
---|
337 | strcpy(title, "QUESTION"); |
---|
338 | break; |
---|
339 | case GDK_at: |
---|
340 | strcpy(title, "AT"); |
---|
341 | break; |
---|
342 | case GDK_bracketleft: |
---|
343 | strcpy(title, "LEFTBRACKET"); |
---|
344 | break; |
---|
345 | case GDK_bracketright: |
---|
346 | strcpy(title, "RIGHTBRACKET"); |
---|
347 | break; |
---|
348 | case GDK_backslash: |
---|
349 | strcpy(title, "BACKSLASH"); |
---|
350 | break; |
---|
351 | case GDK_underscore: |
---|
352 | strcpy(title, "UNDERSCORE"); |
---|
353 | break; |
---|
354 | case GDK_quoteleft: |
---|
355 | strcpy(title, "BACKQUOTE"); |
---|
356 | break; |
---|
357 | |
---|
358 | case GDK_Page_Up: |
---|
359 | strcpy(title, "PAGEUP"); |
---|
360 | break; |
---|
361 | case GDK_Page_Down: |
---|
362 | strcpy(title, "PAGEDOWN"); |
---|
363 | break; |
---|
364 | case GDK_Home: |
---|
365 | strcpy(title, "HOME"); |
---|
366 | break; |
---|
367 | case GDK_Insert: |
---|
368 | strcpy(title, "INSERT"); |
---|
369 | break; |
---|
370 | |
---|
371 | case GDK_Escape: |
---|
372 | strcpy(title, "ESCAPE"); |
---|
373 | break; |
---|
374 | case GDK_Tab: |
---|
375 | strcpy(title, "TAB"); |
---|
376 | break; |
---|
377 | case GDK_Shift_L: |
---|
378 | strcpy(title, "LSHIFT"); |
---|
379 | break; |
---|
380 | case GDK_Shift_R: |
---|
381 | strcpy(title, "R_SHIFT"); |
---|
382 | break; |
---|
383 | case GDK_Control_L: |
---|
384 | strcpy(title, "LCTRL"); |
---|
385 | break; |
---|
386 | case GDK_Control_R: |
---|
387 | strcpy(title, "RCTRL"); |
---|
388 | break; |
---|
389 | case GDK_Alt_L: |
---|
390 | strcpy(title, "LALT"); |
---|
391 | break; |
---|
392 | case GDK_Alt_R: |
---|
393 | strcpy(title, "RALT"); |
---|
394 | break; |
---|
395 | // FXX KEYS // |
---|
396 | case GDK_F1: |
---|
397 | strcpy(title, "F1"); |
---|
398 | break; |
---|
399 | case GDK_F2: |
---|
400 | strcpy(title, "F2"); |
---|
401 | break; |
---|
402 | case GDK_F3: |
---|
403 | strcpy(title, "F3"); |
---|
404 | break; |
---|
405 | case GDK_F4: |
---|
406 | strcpy(title, "F4"); |
---|
407 | break; |
---|
408 | case GDK_F5: |
---|
409 | strcpy(title, "F5"); |
---|
410 | break; |
---|
411 | case GDK_F6: |
---|
412 | strcpy(title, "F6"); |
---|
413 | break; |
---|
414 | case GDK_F7: |
---|
415 | strcpy(title, "F7"); |
---|
416 | break; |
---|
417 | case GDK_F8: |
---|
418 | strcpy(title, "F8"); |
---|
419 | break; |
---|
420 | case GDK_F9: |
---|
421 | strcpy(title, "F9"); |
---|
422 | break; |
---|
423 | case GDK_F10: |
---|
424 | strcpy(title, "F10"); |
---|
425 | break; |
---|
426 | case GDK_F11: |
---|
427 | strcpy(title, "F11"); |
---|
428 | break; |
---|
429 | case GDK_F12: |
---|
430 | strcpy(title, "F12"); |
---|
431 | break; |
---|
432 | |
---|
433 | |
---|
434 | default: |
---|
435 | char* tmp; |
---|
436 | sprintf(tmp, "%c", event->keyval); |
---|
437 | printf("other key %s \n", tmp); |
---|
438 | strcpy(title, tmp); |
---|
439 | break; |
---|
440 | } |
---|
441 | |
---|
442 | inputkey->keyOLabel->setValue(title); |
---|
443 | GuiKeys::inputButton->disconnectSignal(GuiKeys::keySignal); |
---|
444 | GuiKeys::inputWindow->close(); |
---|
445 | } |
---|
446 | #endif /* HAVE_GTK2 */ |
---|