Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/gui/gtk_gui/gui_keys.cc @ 6849

Last change on this file since 6849 was 5978, checked in by bensch, 19 years ago

orxonox/trunk:
merged spaceshipcontrol back to the trunk
merged with command:
svn merge -r5915:HEAD spaceshipcontrol/ ../trunk/
no conflicts (nice work guys :)

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