Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 5766 was 5766, checked in by bensch, 18 years ago

orxonox/trunk: merged the GuidedMissiles to the trunk, without the changed aiming_turret

File size: 11.1 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);
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"));
[5766]121        pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_FIRE, "MOUSE_LEFT"));
[5020]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");
[3165]125#ifdef HAVE_GTK2
[5020]126        closeButton->connectSignal("button_press_event", pKeyWindow, Window::windowClose);
[3165]127#endif /* HAVE_GTK2 */
[3154]128
[5020]129        pKeysBox->fill(closeButton);
[4088]130      }
131      pKeyFrame->fill(pKeysBox);
132    }
133    pKeyWindow->fill(pKeyFrame);
134  }
[5241]135  delete[] windowName;
[4088]136  Window::addWindow(pKeyWindow);
[3165]137#ifdef HAVE_GTK2
[4088]138  pKeyWindow->connectSignal("destroy", pKeyWindow, Window::windowClose);
139  pKeyWindow->connectSignal("delete_event", pKeyWindow, Window::windowClose);
[3165]140#endif /* HAVE_GTK2 */
[5020]141
[3423]142  this->openButton = new Button(player);
[3165]143#ifdef HAVE_GTK2
[4088]144  this->openButton->connectSignal("button_press_event", pKeyWindow, Window::windowOpen);
[3165]145#endif /* HAVE_GTK2 */
[2613]146}
147
[3187]148/**
[4836]149 * @returns the OpenButton of a Player
[3187]150*/
[4746]151Button* PlayerKeys::getOpenButton()
[2613]152{
[3423]153  return this->openButton;
[2613]154}
155
[4089]156//////////////////
157/* MISC_OPTIONS */
158//////////////////
[3187]159/**
[4836]160 *  Creates new inputs for a misc
161 * @param player the name of the Misc
[3187]162*/
[4089]163MiscKeys::MiscKeys()
[2613]164{
[4089]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      {
[5020]176        Button* closeButton;    //!< The CloseButton for this key-settings.
[4089]177
[5020]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"));
[4089]189
[5020]190        closeButton = new Button("close");
[4089]191#ifdef HAVE_GTK2
[5020]192        closeButton->connectSignal("button_press_event", keyWindow, Window::windowClose);
[4089]193#endif /* HAVE_GTK2 */
194
[5020]195        keysBox->fill(closeButton);
[4089]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 */
[5020]206
[4089]207  this->openButton = new Button("misc");
208#ifdef HAVE_GTK2
209  this->openButton->connectSignal("button_press_event", keyWindow, Window::windowOpen);
210#endif /* HAVE_GTK2 */
[2613]211}
212
[4086]213/**
[4836]214 * @returns the OpenButton of a Misc
[4089]215*/
[4746]216Button* MiscKeys::getOpenButton()
[4089]217{
218  return this->openButton;
219}
220
221
222/**
[4836]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
[4086]227*/
[4089]228Widget* addKey(const char* name, const char* defaultVal)
[4086]229{
230  InputKey* inputKey = new InputKey;
[4089]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();
[3156]238
[3165]239#ifdef HAVE_GTK2
[4089]240  //inputKey->keyButton->connectSignal("key_press_event", inputKey->keyButton, key_cb);
241  inputKey->keyButton->connectSignal("button_press_event", inputKey, inputWindowEvent);
[4086]242#endif /* HAVE_GTK2 */
[4089]243  inputKey->keyBox->fill(inputKey->keyButton);
244  inputKey->keyBox->fill(inputKey->keyOLabel);
245  return inputKey->keyBox;
[4086]246}
247
248
249#ifdef HAVE_GTK2
250gint inputWindowEvent(GtkWidget* w, GdkEventKey* event, void* inputKey)
[3156]251{
[4086]252  GuiKeys::inputButton->setTitle("press a Key");
253  GuiKeys::keySignal = GuiKeys::inputButton->connectSignal("key_press_event", inputKey, key_cb);
254  GuiKeys::inputWindow->open();
[3156]255}
[5020]256
[2735]257/**
[4836]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
[2735]263*/
[4086]264gint key_cb(GtkWidget* w, GdkEventKey* event, void* inputKey)
[2733]265{
[3423]266  InputKey* inputkey =(InputKey*) inputKey;
[4089]267  char title [50];
[2737]268
[4089]269  switch(event->keyval)
[3156]270    {
271    case GDK_Up:
[4085]272      strcpy(title, "UP");
[3156]273      break;
274    case GDK_Down:
[4085]275      strcpy(title, "DOWN");
[3156]276      break;
277    case GDK_Left:
[4085]278      strcpy(title, "LEFT");
[3156]279      break;
280    case GDK_Right:
[4085]281      strcpy(title, "RIGHT");
[3156]282      break;
[5020]283
[3156]284    case GDK_space:
[4085]285      strcpy(title, "SPACE");
[3156]286      break;
[5020]287
[4085]288    case GDK_Return:
289      strcpy(title, "RETURN");
[3156]290      break;
[5020]291
[3156]292      // Special Keys //
[4085]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;
[5020]363
[3163]364    case GDK_Escape:
[4085]365      strcpy(title, "ESCAPE");
[3163]366      break;
367    case GDK_Tab:
[4085]368      strcpy(title, "TAB");
[3163]369      break;
[3156]370    case GDK_Shift_L:
[4085]371      strcpy(title, "LSHIFT");
[3156]372      break;
373    case GDK_Shift_R:
[4085]374      strcpy(title, "R_SHIFT");
[3156]375      break;
376    case GDK_Control_L:
[4085]377      strcpy(title, "LCTRL");
[3156]378      break;
379    case GDK_Control_R:
[4085]380      strcpy(title, "RCTRL");
[3156]381      break;
382    case GDK_Alt_L:
[4085]383      strcpy(title, "LALT");
[3156]384      break;
385    case GDK_Alt_R:
[4085]386      strcpy(title, "RALT");
[3156]387      break;
388      // FXX KEYS //
389    case GDK_F1:
[4085]390      strcpy(title, "F1");
[3156]391      break;
392    case GDK_F2:
[4085]393      strcpy(title, "F2");
[3156]394      break;
395    case GDK_F3:
[4085]396      strcpy(title, "F3");
[3156]397      break;
398    case GDK_F4:
[4085]399      strcpy(title, "F4");
[3156]400      break;
401    case GDK_F5:
[4085]402      strcpy(title, "F5");
[3156]403      break;
404    case GDK_F6:
[4085]405      strcpy(title, "F6");
[3156]406      break;
407    case GDK_F7:
[4085]408      strcpy(title, "F7");
[3156]409      break;
410    case GDK_F8:
[4085]411      strcpy(title, "F8");
[3156]412      break;
413    case GDK_F9:
[4085]414      strcpy(title, "F9");
[3156]415      break;
416    case GDK_F10:
[4085]417      strcpy(title, "F10");
[3156]418      break;
419    case GDK_F11:
[4085]420      strcpy(title, "F11");
[3156]421      break;
422    case GDK_F12:
[4085]423      strcpy(title, "F12");
[3156]424      break;
[5020]425
426
[3156]427    default:
428      char* tmp;
429      sprintf(tmp, "%c", event->keyval);
[3423]430      printf("other key %s \n", tmp);
[3163]431      strcpy(title, tmp);
[3156]432      break;
433    }
[3158]434
[4089]435  inputkey->keyOLabel->setValue(title);
[4086]436  GuiKeys::inputButton->disconnectSignal(GuiKeys::keySignal);
437  GuiKeys::inputWindow->close();
[2733]438}
[3165]439#endif /* HAVE_GTK2 */
Note: See TracBrowser for help on using the repository browser.