Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 5969 was 5945, checked in by bensch, 19 years ago

orxonox/trunk: small rearangements

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