Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/gui/gtk/gui_keys.cc @ 9389

Last change on this file since 9389 was 8145, checked in by bensch, 19 years ago

trunk: merged the gui back
merged with command:
svn merge -r8114:HEAD https://svn.orxonox.net/orxonox/branches/gui .
→ no conflicts

File size: 11.5 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);
[6997]117        pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_FORWARD, "w"));
118        pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_BACKWARD, "s"));
[5978]119        pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_LEFT, "a"));
120        pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_RIGHT, "d"));
[6998]121
122        pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_UP, "r"));
123        pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_DOWN, "f"));
[5978]124        pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_ROLL_LEFT, "q"));
125        pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_ROLL_RIGHT, "e"));
[6998]126
[5945]127        pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_FIRE, "BUTTON_LEFT"));
[5020]128        pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_NEXT_WEAPON, "m"));
129        pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_PREV_WEAPON, "n"));
[6998]130        pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_CHANGE_SHIP, "g"));
[5020]131        closeButton = new Button("close");
[3165]132#ifdef HAVE_GTK2
[5020]133        closeButton->connectSignal("button_press_event", pKeyWindow, Window::windowClose);
[3165]134#endif /* HAVE_GTK2 */
[3154]135
[5020]136        pKeysBox->fill(closeButton);
[4088]137      }
138      pKeyFrame->fill(pKeysBox);
139    }
140    pKeyWindow->fill(pKeyFrame);
141  }
[5241]142  delete[] windowName;
[4088]143  Window::addWindow(pKeyWindow);
[3165]144#ifdef HAVE_GTK2
[4088]145  pKeyWindow->connectSignal("destroy", pKeyWindow, Window::windowClose);
146  pKeyWindow->connectSignal("delete_event", pKeyWindow, Window::windowClose);
[3165]147#endif /* HAVE_GTK2 */
[5020]148
[3423]149  this->openButton = new Button(player);
[3165]150#ifdef HAVE_GTK2
[4088]151  this->openButton->connectSignal("button_press_event", pKeyWindow, Window::windowOpen);
[3165]152#endif /* HAVE_GTK2 */
[2613]153}
154
[3187]155/**
[4836]156 * @returns the OpenButton of a Player
[3187]157*/
[4746]158Button* PlayerKeys::getOpenButton()
[2613]159{
[3423]160  return this->openButton;
[2613]161}
162
[4089]163//////////////////
164/* MISC_OPTIONS */
165//////////////////
[3187]166/**
[4836]167 *  Creates new inputs for a misc
168 * @param player the name of the Misc
[3187]169*/
[4089]170MiscKeys::MiscKeys()
[2613]171{
[4089]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      {
[5020]183        Button* closeButton;    //!< The CloseButton for this key-settings.
[4089]184
[5020]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"));
[4089]196
[5020]197        closeButton = new Button("close");
[4089]198#ifdef HAVE_GTK2
[5020]199        closeButton->connectSignal("button_press_event", keyWindow, Window::windowClose);
[4089]200#endif /* HAVE_GTK2 */
201
[5020]202        keysBox->fill(closeButton);
[4089]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 */
[5020]213
[4089]214  this->openButton = new Button("misc");
215#ifdef HAVE_GTK2
216  this->openButton->connectSignal("button_press_event", keyWindow, Window::windowOpen);
217#endif /* HAVE_GTK2 */
[2613]218}
219
[4086]220/**
[4836]221 * @returns the OpenButton of a Misc
[4089]222*/
[4746]223Button* MiscKeys::getOpenButton()
[4089]224{
225  return this->openButton;
226}
227
228
229/**
[4836]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
[4086]234*/
[4089]235Widget* addKey(const char* name, const char* defaultVal)
[4086]236{
237  InputKey* inputKey = new InputKey;
[4089]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();
[3156]245
[3165]246#ifdef HAVE_GTK2
[4089]247  //inputKey->keyButton->connectSignal("key_press_event", inputKey->keyButton, key_cb);
248  inputKey->keyButton->connectSignal("button_press_event", inputKey, inputWindowEvent);
[4086]249#endif /* HAVE_GTK2 */
[4089]250  inputKey->keyBox->fill(inputKey->keyButton);
251  inputKey->keyBox->fill(inputKey->keyOLabel);
252  return inputKey->keyBox;
[4086]253}
254
255
256#ifdef HAVE_GTK2
257gint inputWindowEvent(GtkWidget* w, GdkEventKey* event, void* inputKey)
[3156]258{
[4086]259  GuiKeys::inputButton->setTitle("press a Key");
260  GuiKeys::keySignal = GuiKeys::inputButton->connectSignal("key_press_event", inputKey, key_cb);
261  GuiKeys::inputWindow->open();
[3156]262}
[5020]263
[2735]264/**
[4836]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
[2735]270*/
[4086]271gint key_cb(GtkWidget* w, GdkEventKey* event, void* inputKey)
[2733]272{
[3423]273  InputKey* inputkey =(InputKey*) inputKey;
[4089]274  char title [50];
[2737]275
[4089]276  switch(event->keyval)
[3156]277    {
278    case GDK_Up:
[4085]279      strcpy(title, "UP");
[3156]280      break;
281    case GDK_Down:
[4085]282      strcpy(title, "DOWN");
[3156]283      break;
284    case GDK_Left:
[4085]285      strcpy(title, "LEFT");
[3156]286      break;
287    case GDK_Right:
[4085]288      strcpy(title, "RIGHT");
[3156]289      break;
[5020]290
[3156]291    case GDK_space:
[4085]292      strcpy(title, "SPACE");
[3156]293      break;
[5020]294
[4085]295    case GDK_Return:
296      strcpy(title, "RETURN");
[3156]297      break;
[5020]298
[3156]299      // Special Keys //
[4085]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;
[5020]370
[3163]371    case GDK_Escape:
[4085]372      strcpy(title, "ESCAPE");
[3163]373      break;
374    case GDK_Tab:
[4085]375      strcpy(title, "TAB");
[3163]376      break;
[3156]377    case GDK_Shift_L:
[4085]378      strcpy(title, "LSHIFT");
[3156]379      break;
380    case GDK_Shift_R:
[4085]381      strcpy(title, "R_SHIFT");
[3156]382      break;
383    case GDK_Control_L:
[4085]384      strcpy(title, "LCTRL");
[3156]385      break;
386    case GDK_Control_R:
[4085]387      strcpy(title, "RCTRL");
[3156]388      break;
389    case GDK_Alt_L:
[4085]390      strcpy(title, "LALT");
[3156]391      break;
392    case GDK_Alt_R:
[4085]393      strcpy(title, "RALT");
[3156]394      break;
395      // FXX KEYS //
396    case GDK_F1:
[4085]397      strcpy(title, "F1");
[3156]398      break;
399    case GDK_F2:
[4085]400      strcpy(title, "F2");
[3156]401      break;
402    case GDK_F3:
[4085]403      strcpy(title, "F3");
[3156]404      break;
405    case GDK_F4:
[4085]406      strcpy(title, "F4");
[3156]407      break;
408    case GDK_F5:
[4085]409      strcpy(title, "F5");
[3156]410      break;
411    case GDK_F6:
[4085]412      strcpy(title, "F6");
[3156]413      break;
414    case GDK_F7:
[4085]415      strcpy(title, "F7");
[3156]416      break;
417    case GDK_F8:
[4085]418      strcpy(title, "F8");
[3156]419      break;
420    case GDK_F9:
[4085]421      strcpy(title, "F9");
[3156]422      break;
423    case GDK_F10:
[4085]424      strcpy(title, "F10");
[3156]425      break;
426    case GDK_F11:
[4085]427      strcpy(title, "F11");
[3156]428      break;
429    case GDK_F12:
[4085]430      strcpy(title, "F12");
[3156]431      break;
[5020]432
433
[3156]434    default:
435      char* tmp;
436      sprintf(tmp, "%c", event->keyval);
[3423]437      printf("other key %s \n", tmp);
[3163]438      strcpy(title, tmp);
[3156]439      break;
440    }
[3158]441
[4089]442  inputkey->keyOLabel->setValue(title);
[4086]443  GuiKeys::inputButton->disconnectSignal(GuiKeys::keySignal);
444  GuiKeys::inputWindow->close();
[2733]445}
[3165]446#endif /* HAVE_GTK2 */
Note: See TracBrowser for help on using the repository browser.