Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: key-definition, and the keys get read as they should, eg. name == Usage, value == KeyName

File size: 8.4 KB
RevLine 
[2613]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
[4047]26#include "gui_keys.h"
[2613]27
[4034]28#include <string.h>
29
[2613]30/**
31   \brief Creates an Keyboard-Frame
32*/
[4056]33GuiKeys::GuiKeys(void)
[2613]34{
[3423]35  this->keysFrame = new Frame("Keyboard-Options:");
[3163]36  //  keysFrame->setGroupName("Keyboard");
[3423]37  this->keysBox = new Box('h');
38  this->player1 = new Player("player1");
39  this->player2 = new Player("player2");
[2735]40
[3423]41  this->keysBox->fill(this->player1->getOpenButton());
42  this->keysBox->fill(this->player2->getOpenButton());
[2613]43
[3423]44  this->keysFrame->fill(this->keysBox);
[4024]45  this->setMainWidget(keysFrame);
[2613]46}
47
48/**
[3423]49   \brief Destructs the Keys-stuff
50*/
[4056]51GuiKeys::~GuiKeys(void)
[3423]52{
53  // nothing to do here.
54}
55
[2613]56/* PLAYER */
[3187]57
58/**
59   \brief Creates new inputs for a player
60   \param player the name of the Player
61*/
[2613]62Player::Player(char* player)
63{
[3423]64  char* windowName = new char[strlen(player)+25];
65  strcpy(windowName, "Keyboard settings of ");
66  strcat(windowName, player);
67  this->pKeyWindow = new Window(windowName);
68  this->pKeyFrame = new Frame(windowName);
69   this->pKeysBox = new Box('v');
70   this->pKeysBox->setGroupName(player);
[4085]71    this->pKeysBox->fill(addKey(UP, "up"));
72    this->pKeysBox->fill(addKey(DOWN, "down"));
73    this->pKeysBox->fill(addKey(LEFT, "left"));
74    this->pKeysBox->fill(addKey(RIGHT, "right"));
75    this->pKeysBox->fill(addKey(SHOOT, "fire"));
[3423]76    delete windowName;
[3152]77    closeButton = new Button("close");
[3165]78#ifdef HAVE_GTK2
[3423]79    this->closeButton->connectSignal("button_press_event", this->pKeyWindow, Window::windowClose);
[3165]80#endif /* HAVE_GTK2 */
[3154]81
[3423]82    this->pKeysBox->fill(this->closeButton);
83    this->pKeyFrame->fill(this->pKeysBox);
84   this->pKeyWindow->fill(this->pKeyFrame);
85   Window::addWindow(this->pKeyWindow);
[3165]86#ifdef HAVE_GTK2
[3423]87   this->pKeyWindow->connectSignal("destroy", this->pKeyWindow, Window::windowClose);
88   this->pKeyWindow->connectSignal("delete_event", this->pKeyWindow, Window::windowClose);
[3165]89#endif /* HAVE_GTK2 */
[3153]90
[3423]91  this->openButton = new Button(player);
[3165]92#ifdef HAVE_GTK2
[3423]93  this->openButton->connectSignal("button_press_event", this->pKeyWindow, Window::windowOpen);
[3165]94#endif /* HAVE_GTK2 */
[3153]95
[3423]96  this->inputWindow = new Window("inputWindow");
[3156]97
[3423]98  this->inputButton = new Button("test");
99  this->inputWindow->fill(inputButton);
[3165]100#ifdef HAVE_GTK2
[3423]101  this->inputWindow->connectSignal("destroy",  Widget::doNothingSignal);
102  this->inputWindow->connectSignal("delete_event", Widget::doNothingSignal);
[3165]103#endif /* HAVE_GTK2 */
[3156]104
[2613]105}
106
[3187]107/**
108   \brief adds a new Key.
109   \param key the number of the Key
110   \param name The name of the new Key.
111   \returns A widget that has the Key-Box
112*/
[3423]113Widget* Player::addKey(KEYS key, char* name)
[2736]114{
[3423]115  this->inputKey[key] = new InputKey;
116  this->inputKey[key]->pKeyBox = new Box();
117  this->inputKey[key]->pKeyButton = new Button(name);
118  this->inputKey[key]->pKeyOLabel = new OptionLabel(name, name);
119  this->inputKey[key]->pKeyOLabel->saveability();
[3165]120
121#ifdef HAVE_GTK2
[3156]122  //inputKey[key]->pKeyButton->connectSignal("key_press_event", inputKey[key]->pKeyButton, key_cb);
[3423]123  this->inputKey[key]->pKeyButton->connectSignal("button_press_event", this->inputKey[key], inputWindowEvent);
[3165]124#endif /* HAVE_GTK2 */
[3423]125  this->inputKey[key]->pKeyBox->fill(this->inputKey[key]->pKeyButton);
126  this->inputKey[key]->pKeyBox->fill(this->inputKey[key]->pKeyOLabel);
127  return this->inputKey[key]->pKeyBox;
[2736]128}
129
[3187]130/**
131   \returns the OpenButton of a Player
132*/
[3423]133Button* Player::getOpenButton(void)
[2613]134{
[3423]135  return this->openButton;
[2613]136}
137
[3187]138/**
[3423]139   \brief sets a new Key(only output)
[3187]140   \param key the new Key.
141*/
[2613]142void Player::setkey(KEYS key)
143{
[4034]144  PRINT(4)("setting up Key: %d\n", key);
[2613]145}
146
[3156]147Window* Player::inputWindow = NULL;
148Button* Player::inputButton = NULL;
149long Player::keySignal = 0;
150
[3165]151#ifdef HAVE_GTK2
[3156]152gint Player::inputWindowEvent(GtkWidget* w, GdkEventKey* event, void* inputKey)
153{
[3157]154  inputButton->setTitle("press a Key");
[3156]155  keySignal = inputButton->connectSignal("key_press_event", inputKey, key_cb);
156  inputWindow->open();
157}
[3157]158 
[2735]159/**
160   \brief Function which gets keystrokes
161   \param w the widget that released the Function.
162   \param event The event that happened.
163   \param Widget the Widget which will be applied.
164   \returns Nothing
165*/
[3156]166gint Player::key_cb(GtkWidget* w, GdkEventKey* event, void* inputKey)
[2733]167{
[3423]168  InputKey* inputkey =(InputKey*) inputKey;
[3156]169  char title [20];
[2737]170
[3156]171  switch(event->keyval) 
172    {
173    case GDK_Up:
[4085]174      strcpy(title, "UP");
[3156]175      break;
176    case GDK_Down:
[4085]177      strcpy(title, "DOWN");
[3156]178      break;
179    case GDK_Left:
[4085]180      strcpy(title, "LEFT");
[3156]181      break;
182    case GDK_Right:
[4085]183      strcpy(title, "RIGHT");
[3156]184      break;
185     
186    case GDK_space:
[4085]187      strcpy(title, "SPACE");
[3156]188      break;
189     
[4085]190    case GDK_Return:
191      strcpy(title, "RETURN");
[3156]192      break;
193     
194      // Special Keys //
[4085]195    case GDK_BackSpace:
196      strcpy(title, "BACKSPACE");
197      break;
198    case GDK_Scroll_Lock:
199      strcpy(title, "SCROLLOCK");
200      break;
201    case GDK_minus:
202      strcpy(title, "MINUS");
203      break;
204    case GDK_plus:
205      strcpy(title, "PLUS");
206      break;
207    case GDK_slash:
208      strcpy(title, "SLASH");
209      break;
210    case GDK_period:
211      strcpy(title, "PERIOD");
212      break;
213    case GDK_comma:
214      strcpy(title, "COMMA");
215      break;
216    case GDK_colon:
217      strcpy(title, "COLON");
218      break;
219    case GDK_semicolon:
220      strcpy(title, "SEMICOLON");
221      break;
222    case GDK_less:
223      strcpy(title, "LESS");
224      break;
225    case GDK_equal:
226      strcpy(title, "EQUALS");
227      break;
228    case GDK_greater:
229      strcpy(title, "GREATER");
230      break;
231    case GDK_question:
232      strcpy(title, "QUESTION");
233      break;
234    case GDK_at:
235      strcpy(title, "AT");
236      break;
237    case GDK_bracketleft:
238      strcpy(title, "LEFTBRACKET");
239      break;
240    case GDK_bracketright:
241      strcpy(title, "RIGHTBRACKET");
242      break;
243    case GDK_backslash:
244      strcpy(title, "BACKSLASH");
245      break;
246    case GDK_underscore:
247      strcpy(title, "UNDERSCORE");
248      break;
249    case GDK_quoteleft:
250      strcpy(title, "BACKQUOTE");
251      break;
252
253    case GDK_Page_Up:
254      strcpy(title, "PAGEUP");
255      break;
256    case GDK_Page_Down:
257      strcpy(title, "PAGEDOWN");
258      break;
259    case GDK_Home:
260      strcpy(title, "HOME");
261      break;
262    case GDK_Insert:
263      strcpy(title, "INSERT");
264      break;
265     
[3163]266    case GDK_Escape:
[4085]267      strcpy(title, "ESCAPE");
[3163]268      break;
269    case GDK_Tab:
[4085]270      strcpy(title, "TAB");
[3163]271      break;
[3156]272    case GDK_Shift_L:
[4085]273      strcpy(title, "LSHIFT");
[3156]274      break;
275    case GDK_Shift_R:
[4085]276      strcpy(title, "R_SHIFT");
[3156]277      break;
278    case GDK_Control_L:
[4085]279      strcpy(title, "LCTRL");
[3156]280      break;
281    case GDK_Control_R:
[4085]282      strcpy(title, "RCTRL");
[3156]283      break;
284    case GDK_Alt_L:
[4085]285      strcpy(title, "LALT");
[3156]286      break;
287    case GDK_Alt_R:
[4085]288      strcpy(title, "RALT");
[3156]289      break;
290      // FXX KEYS //
291    case GDK_F1:
[4085]292      strcpy(title, "F1");
[3156]293      break;
294    case GDK_F2:
[4085]295      strcpy(title, "F2");
[3156]296      break;
297    case GDK_F3:
[4085]298      strcpy(title, "F3");
[3156]299      break;
300    case GDK_F4:
[4085]301      strcpy(title, "F4");
[3156]302      break;
303    case GDK_F5:
[4085]304      strcpy(title, "F5");
[3156]305      break;
306    case GDK_F6:
[4085]307      strcpy(title, "F6");
[3156]308      break;
309    case GDK_F7:
[4085]310      strcpy(title, "F7");
[3156]311      break;
312    case GDK_F8:
[4085]313      strcpy(title, "F8");
[3156]314      break;
315    case GDK_F9:
[4085]316      strcpy(title, "F9");
[3156]317      break;
318    case GDK_F10:
[4085]319      strcpy(title, "F10");
[3156]320      break;
321    case GDK_F11:
[4085]322      strcpy(title, "F11");
[3156]323      break;
324    case GDK_F12:
[4085]325      strcpy(title, "F12");
[3156]326      break;
327     
328     
329    default:
330      char* tmp;
331      sprintf(tmp, "%c", event->keyval);
[3423]332      printf("other key %s \n", tmp);
[3163]333      strcpy(title, tmp);
[3156]334      break;
335    }
[3158]336
[3423]337  inputkey->pKeyOLabel->setValue(title);
[3156]338  inputButton->disconnectSignal(keySignal);
339  inputWindow->close();
[2733]340}
[3165]341#endif /* HAVE_GTK2 */
Note: See TracBrowser for help on using the repository browser.