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
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   \brief Creates an Keyboard-Frame
32*/
33GuiKeys::GuiKeys(void)
34{
35  this->keysFrame = new Frame("Keyboard-Options:");
36  //  keysFrame->setGroupName("Keyboard");
37  this->keysBox = new Box('h');
38  this->player1 = new Player("player1");
39  this->player2 = new Player("player2");
40
41  this->keysBox->fill(this->player1->getOpenButton());
42  this->keysBox->fill(this->player2->getOpenButton());
43
44  this->keysFrame->fill(this->keysBox);
45  this->setMainWidget(keysFrame);
46}
47
48/**
49   \brief Destructs the Keys-stuff
50*/
51GuiKeys::~GuiKeys(void)
52{
53  // nothing to do here.
54}
55
56/* PLAYER */
57
58/**
59   \brief Creates new inputs for a player
60   \param player the name of the Player
61*/
62Player::Player(char* player)
63{
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);
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"));
76    delete windowName;
77    closeButton = new Button("close");
78#ifdef HAVE_GTK2
79    this->closeButton->connectSignal("button_press_event", this->pKeyWindow, Window::windowClose);
80#endif /* HAVE_GTK2 */
81
82    this->pKeysBox->fill(this->closeButton);
83    this->pKeyFrame->fill(this->pKeysBox);
84   this->pKeyWindow->fill(this->pKeyFrame);
85   Window::addWindow(this->pKeyWindow);
86#ifdef HAVE_GTK2
87   this->pKeyWindow->connectSignal("destroy", this->pKeyWindow, Window::windowClose);
88   this->pKeyWindow->connectSignal("delete_event", this->pKeyWindow, Window::windowClose);
89#endif /* HAVE_GTK2 */
90
91  this->openButton = new Button(player);
92#ifdef HAVE_GTK2
93  this->openButton->connectSignal("button_press_event", this->pKeyWindow, Window::windowOpen);
94#endif /* HAVE_GTK2 */
95
96  this->inputWindow = new Window("inputWindow");
97
98  this->inputButton = new Button("test");
99  this->inputWindow->fill(inputButton);
100#ifdef HAVE_GTK2
101  this->inputWindow->connectSignal("destroy",  Widget::doNothingSignal);
102  this->inputWindow->connectSignal("delete_event", Widget::doNothingSignal);
103#endif /* HAVE_GTK2 */
104
105}
106
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*/
113Widget* Player::addKey(KEYS key, char* name)
114{
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();
120
121#ifdef HAVE_GTK2
122  //inputKey[key]->pKeyButton->connectSignal("key_press_event", inputKey[key]->pKeyButton, key_cb);
123  this->inputKey[key]->pKeyButton->connectSignal("button_press_event", this->inputKey[key], inputWindowEvent);
124#endif /* HAVE_GTK2 */
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;
128}
129
130/**
131   \returns the OpenButton of a Player
132*/
133Button* Player::getOpenButton(void)
134{
135  return this->openButton;
136}
137
138/**
139   \brief sets a new Key(only output)
140   \param key the new Key.
141*/
142void Player::setkey(KEYS key)
143{
144  PRINT(4)("setting up Key: %d\n", key);
145}
146
147Window* Player::inputWindow = NULL;
148Button* Player::inputButton = NULL;
149long Player::keySignal = 0;
150
151#ifdef HAVE_GTK2
152gint Player::inputWindowEvent(GtkWidget* w, GdkEventKey* event, void* inputKey)
153{
154  inputButton->setTitle("press a Key");
155  keySignal = inputButton->connectSignal("key_press_event", inputKey, key_cb);
156  inputWindow->open();
157}
158 
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*/
166gint Player::key_cb(GtkWidget* w, GdkEventKey* event, void* inputKey)
167{
168  InputKey* inputkey =(InputKey*) inputKey;
169  char title [20];
170
171  switch(event->keyval) 
172    {
173    case GDK_Up:
174      strcpy(title, "UP");
175      break;
176    case GDK_Down:
177      strcpy(title, "DOWN");
178      break;
179    case GDK_Left:
180      strcpy(title, "LEFT");
181      break;
182    case GDK_Right:
183      strcpy(title, "RIGHT");
184      break;
185     
186    case GDK_space:
187      strcpy(title, "SPACE");
188      break;
189     
190    case GDK_Return:
191      strcpy(title, "RETURN");
192      break;
193     
194      // Special Keys //
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     
266    case GDK_Escape:
267      strcpy(title, "ESCAPE");
268      break;
269    case GDK_Tab:
270      strcpy(title, "TAB");
271      break;
272    case GDK_Shift_L:
273      strcpy(title, "LSHIFT");
274      break;
275    case GDK_Shift_R:
276      strcpy(title, "R_SHIFT");
277      break;
278    case GDK_Control_L:
279      strcpy(title, "LCTRL");
280      break;
281    case GDK_Control_R:
282      strcpy(title, "RCTRL");
283      break;
284    case GDK_Alt_L:
285      strcpy(title, "LALT");
286      break;
287    case GDK_Alt_R:
288      strcpy(title, "RALT");
289      break;
290      // FXX KEYS //
291    case GDK_F1:
292      strcpy(title, "F1");
293      break;
294    case GDK_F2:
295      strcpy(title, "F2");
296      break;
297    case GDK_F3:
298      strcpy(title, "F3");
299      break;
300    case GDK_F4:
301      strcpy(title, "F4");
302      break;
303    case GDK_F5:
304      strcpy(title, "F5");
305      break;
306    case GDK_F6:
307      strcpy(title, "F6");
308      break;
309    case GDK_F7:
310      strcpy(title, "F7");
311      break;
312    case GDK_F8:
313      strcpy(title, "F8");
314      break;
315    case GDK_F9:
316      strcpy(title, "F9");
317      break;
318    case GDK_F10:
319      strcpy(title, "F10");
320      break;
321    case GDK_F11:
322      strcpy(title, "F11");
323      break;
324    case GDK_F12:
325      strcpy(title, "F12");
326      break;
327     
328     
329    default:
330      char* tmp;
331      sprintf(tmp, "%c", event->keyval);
332      printf("other key %s \n", tmp);
333      strcpy(title, tmp);
334      break;
335    }
336
337  inputkey->pKeyOLabel->setValue(title);
338  inputButton->disconnectSignal(keySignal);
339  inputWindow->close();
340}
341#endif /* HAVE_GTK2 */
Note: See TracBrowser for help on using the repository browser.