Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/powerups/src/lib/gui/gtk_gui/gui_keys.cc @ 5985

Last change on this file since 5985 was 5985, checked in by manuel, 18 years ago

merge: factory has now create from class name string function (svn merge -r 5955:HEAD ../trunk/ powerups/)

File size: 11.3 KB
RevLine 
[5020]1/*
[2613]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,
[5020]18   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
[2613]19
20
21   ### File Specific:
22   main-programmer: Benjamin Grauer
23
24*/
25
[4047]26#include "gui_keys.h"
[2613]27
[4034]28#include <string.h>
29
[2613]30/**
[4836]31 *  Creates an Keyboard-Frame
[2613]32*/
[4746]33GuiKeys::GuiKeys()
[2613]34{
[4088]35  Frame* keysFrame;      //!< The Frame that holds the keyOptions.
[2735]36
[4088]37  keysFrame = new Frame("Keyboard-Options:");
38  {
[4089]39    Box* keysBox0;          //!< The Frame that holds the keyOptions.
[5020]40
[4088]41    //  keysFrame->setGroupName("Keyboard");
[4089]42    keysBox0 = new Box('v');
[4088]43    {
[4089]44      Box* keysBox1;
45      MiscKeys* misc;            //!< The Misc Keys
46
47      keysBox1 = new Box('h');
48      {
[5020]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());
[4089]57      }
58      keysBox0->fill(keysBox1);
59
60      misc = new MiscKeys();
61      keysBox0->fill(misc->getOpenButton());
[4088]62    }
[4089]63    keysFrame->fill(keysBox0);
[4088]64  }
[5020]65
[4088]66  // setting up the Input Windows that receives keystrokes.
[4086]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);
[5020]74
[4024]75  this->setMainWidget(keysFrame);
[2613]76}
77
78/**
[4836]79 *  Destructs the Keys-stuff
[3423]80*/
[4746]81GuiKeys::~GuiKeys()
[3423]82{
83  // nothing to do here.
84}
85
[4086]86
87Window* GuiKeys::inputWindow = NULL;
88Button* GuiKeys::inputButton = NULL;
89long GuiKeys::keySignal = 0;
90
[4089]91////////////
[2613]92/* PLAYER */
[4089]93////////////
[3187]94/**
[4836]95 *  Creates new inputs for a player
96 * @param player the name of the Player
[3187]97*/
[4089]98PlayerKeys::PlayerKeys(char* player)
[2613]99{
[4088]100  Window* pKeyWindow;     //!< The Window for a new Key-setting.
101
102  char* windowName = new char[strlen(player)+12];
103  strcpy(windowName, "KeySets: ");
[3423]104  strcat(windowName, player);
[4088]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      {
[5020]114        Button* closeButton;    //!< The CloseButton for this key-settings.
[4088]115
[5020]116        pKeysBox->setGroupName(player);
[5985]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"));
[5955]123        pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_FIRE, "BUTTON_LEFT"));
[5020]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");
[3165]127#ifdef HAVE_GTK2
[5020]128        closeButton->connectSignal("button_press_event", pKeyWindow, Window::windowClose);
[3165]129#endif /* HAVE_GTK2 */
[3154]130
[5020]131        pKeysBox->fill(closeButton);
[4088]132      }
133      pKeyFrame->fill(pKeysBox);
134    }
135    pKeyWindow->fill(pKeyFrame);
136  }
[5241]137  delete[] windowName;
[4088]138  Window::addWindow(pKeyWindow);
[3165]139#ifdef HAVE_GTK2
[4088]140  pKeyWindow->connectSignal("destroy", pKeyWindow, Window::windowClose);
141  pKeyWindow->connectSignal("delete_event", pKeyWindow, Window::windowClose);
[3165]142#endif /* HAVE_GTK2 */
[5020]143
[3423]144  this->openButton = new Button(player);
[3165]145#ifdef HAVE_GTK2
[4088]146  this->openButton->connectSignal("button_press_event", pKeyWindow, Window::windowOpen);
[3165]147#endif /* HAVE_GTK2 */
[2613]148}
149
[3187]150/**
[4836]151 * @returns the OpenButton of a Player
[3187]152*/
[4746]153Button* PlayerKeys::getOpenButton()
[2613]154{
[3423]155  return this->openButton;
[2613]156}
157
[4089]158//////////////////
159/* MISC_OPTIONS */
160//////////////////
[3187]161/**
[4836]162 *  Creates new inputs for a misc
163 * @param player the name of the Misc
[3187]164*/
[4089]165MiscKeys::MiscKeys()
[2613]166{
[4089]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      {
[5020]178        Button* closeButton;    //!< The CloseButton for this key-settings.
[4089]179
[5020]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"));
[4089]191
[5020]192        closeButton = new Button("close");
[4089]193#ifdef HAVE_GTK2
[5020]194        closeButton->connectSignal("button_press_event", keyWindow, Window::windowClose);
[4089]195#endif /* HAVE_GTK2 */
196
[5020]197        keysBox->fill(closeButton);
[4089]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 */
[5020]208
[4089]209  this->openButton = new Button("misc");
210#ifdef HAVE_GTK2
211  this->openButton->connectSignal("button_press_event", keyWindow, Window::windowOpen);
212#endif /* HAVE_GTK2 */
[2613]213}
214
[4086]215/**
[4836]216 * @returns the OpenButton of a Misc
[4089]217*/
[4746]218Button* MiscKeys::getOpenButton()
[4089]219{
220  return this->openButton;
221}
222
223
224/**
[4836]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
[4086]229*/
[4089]230Widget* addKey(const char* name, const char* defaultVal)
[4086]231{
232  InputKey* inputKey = new InputKey;
[4089]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();
[3156]240
[3165]241#ifdef HAVE_GTK2
[4089]242  //inputKey->keyButton->connectSignal("key_press_event", inputKey->keyButton, key_cb);
243  inputKey->keyButton->connectSignal("button_press_event", inputKey, inputWindowEvent);
[4086]244#endif /* HAVE_GTK2 */
[4089]245  inputKey->keyBox->fill(inputKey->keyButton);
246  inputKey->keyBox->fill(inputKey->keyOLabel);
247  return inputKey->keyBox;
[4086]248}
249
250
251#ifdef HAVE_GTK2
252gint inputWindowEvent(GtkWidget* w, GdkEventKey* event, void* inputKey)
[3156]253{
[4086]254  GuiKeys::inputButton->setTitle("press a Key");
255  GuiKeys::keySignal = GuiKeys::inputButton->connectSignal("key_press_event", inputKey, key_cb);
256  GuiKeys::inputWindow->open();
[3156]257}
[5020]258
[2735]259/**
[4836]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
[2735]265*/
[4086]266gint key_cb(GtkWidget* w, GdkEventKey* event, void* inputKey)
[2733]267{
[3423]268  InputKey* inputkey =(InputKey*) inputKey;
[4089]269  char title [50];
[2737]270
[4089]271  switch(event->keyval)
[3156]272    {
273    case GDK_Up:
[4085]274      strcpy(title, "UP");
[3156]275      break;
276    case GDK_Down:
[4085]277      strcpy(title, "DOWN");
[3156]278      break;
279    case GDK_Left:
[4085]280      strcpy(title, "LEFT");
[3156]281      break;
282    case GDK_Right:
[4085]283      strcpy(title, "RIGHT");
[3156]284      break;
[5020]285
[3156]286    case GDK_space:
[4085]287      strcpy(title, "SPACE");
[3156]288      break;
[5020]289
[4085]290    case GDK_Return:
291      strcpy(title, "RETURN");
[3156]292      break;
[5020]293
[3156]294      // Special Keys //
[4085]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;
[5020]365
[3163]366    case GDK_Escape:
[4085]367      strcpy(title, "ESCAPE");
[3163]368      break;
369    case GDK_Tab:
[4085]370      strcpy(title, "TAB");
[3163]371      break;
[3156]372    case GDK_Shift_L:
[4085]373      strcpy(title, "LSHIFT");
[3156]374      break;
375    case GDK_Shift_R:
[4085]376      strcpy(title, "R_SHIFT");
[3156]377      break;
378    case GDK_Control_L:
[4085]379      strcpy(title, "LCTRL");
[3156]380      break;
381    case GDK_Control_R:
[4085]382      strcpy(title, "RCTRL");
[3156]383      break;
384    case GDK_Alt_L:
[4085]385      strcpy(title, "LALT");
[3156]386      break;
387    case GDK_Alt_R:
[4085]388      strcpy(title, "RALT");
[3156]389      break;
390      // FXX KEYS //
391    case GDK_F1:
[4085]392      strcpy(title, "F1");
[3156]393      break;
394    case GDK_F2:
[4085]395      strcpy(title, "F2");
[3156]396      break;
397    case GDK_F3:
[4085]398      strcpy(title, "F3");
[3156]399      break;
400    case GDK_F4:
[4085]401      strcpy(title, "F4");
[3156]402      break;
403    case GDK_F5:
[4085]404      strcpy(title, "F5");
[3156]405      break;
406    case GDK_F6:
[4085]407      strcpy(title, "F6");
[3156]408      break;
409    case GDK_F7:
[4085]410      strcpy(title, "F7");
[3156]411      break;
412    case GDK_F8:
[4085]413      strcpy(title, "F8");
[3156]414      break;
415    case GDK_F9:
[4085]416      strcpy(title, "F9");
[3156]417      break;
418    case GDK_F10:
[4085]419      strcpy(title, "F10");
[3156]420      break;
421    case GDK_F11:
[4085]422      strcpy(title, "F11");
[3156]423      break;
424    case GDK_F12:
[4085]425      strcpy(title, "F12");
[3156]426      break;
[5020]427
428
[3156]429    default:
430      char* tmp;
431      sprintf(tmp, "%c", event->keyval);
[3423]432      printf("other key %s \n", tmp);
[3163]433      strcpy(title, tmp);
[3156]434      break;
435    }
[3158]436
[4089]437  inputkey->keyOLabel->setValue(title);
[4086]438  GuiKeys::inputButton->disconnectSignal(GuiKeys::keySignal);
439  GuiKeys::inputWindow->close();
[2733]440}
[3165]441#endif /* HAVE_GTK2 */
Note: See TracBrowser for help on using the repository browser.