Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/lib/gui/gui/orxonox_gui_keys.cc @ 4024

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

orxonox/trunk: gui: more addaptive structure

File size: 6.9 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 "orxonox_gui_keys.h"
27
28/**
29   \brief Creates an Keyboard-Frame
30*/
31OrxonoxGuiKeys::OrxonoxGuiKeys(void)
32{
33  this->keysFrame = new Frame("Keyboard-Options:");
34  //  keysFrame->setGroupName("Keyboard");
35  this->keysBox = new Box('h');
36  this->player1 = new Player("player1");
37  this->player2 = new Player("player2");
38
39  this->keysBox->fill(this->player1->getOpenButton());
40  this->keysBox->fill(this->player2->getOpenButton());
41
42  this->keysFrame->fill(this->keysBox);
43  this->setMainWidget(keysFrame);
44}
45
46/**
47   \brief Destructs the Keys-stuff
48*/
49OrxonoxGuiKeys::~OrxonoxGuiKeys(void)
50{
51  // nothing to do here.
52}
53
54/* PLAYER */
55
56/**
57   \brief Creates new inputs for a player
58   \param player the name of the Player
59*/
60Player::Player(char* player)
61{
62  char* windowName = new char[strlen(player)+25];
63  strcpy(windowName, "Keyboard settings of ");
64  strcat(windowName, player);
65  this->pKeyWindow = new Window(windowName);
66  this->pKeyFrame = new Frame(windowName);
67   this->pKeysBox = new Box('v');
68   this->pKeysBox->setGroupName(player);
69    this->pKeysBox->fill(addKey(UP, "up"));
70    this->pKeysBox->fill(addKey(DOWN, "down"));
71    this->pKeysBox->fill(addKey(LEFT, "left"));
72    this->pKeysBox->fill(addKey(RIGHT, "right"));
73    this->pKeysBox->fill(addKey(SHOOT, "shoot"));
74    delete windowName;
75    closeButton = new Button("close");
76#ifdef HAVE_GTK2
77    this->closeButton->connectSignal("button_press_event", this->pKeyWindow, Window::windowClose);
78#endif /* HAVE_GTK2 */
79
80    this->pKeysBox->fill(this->closeButton);
81    this->pKeyFrame->fill(this->pKeysBox);
82   this->pKeyWindow->fill(this->pKeyFrame);
83   Window::addWindow(this->pKeyWindow);
84#ifdef HAVE_GTK2
85   this->pKeyWindow->connectSignal("destroy", this->pKeyWindow, Window::windowClose);
86   this->pKeyWindow->connectSignal("delete_event", this->pKeyWindow, Window::windowClose);
87#endif /* HAVE_GTK2 */
88
89  this->openButton = new Button(player);
90#ifdef HAVE_GTK2
91  this->openButton->connectSignal("button_press_event", this->pKeyWindow, Window::windowOpen);
92#endif /* HAVE_GTK2 */
93
94  this->inputWindow = new Window("inputWindow");
95
96  this->inputButton = new Button("test");
97  this->inputWindow->fill(inputButton);
98#ifdef HAVE_GTK2
99  this->inputWindow->connectSignal("destroy",  Widget::doNothingSignal);
100  this->inputWindow->connectSignal("delete_event", Widget::doNothingSignal);
101#endif /* HAVE_GTK2 */
102
103}
104
105/**
106   \brief adds a new Key.
107   \param key the number of the Key
108   \param name The name of the new Key.
109   \returns A widget that has the Key-Box
110*/
111Widget* Player::addKey(KEYS key, char* name)
112{
113  this->inputKey[key] = new InputKey;
114  this->inputKey[key]->pKeyBox = new Box();
115  this->inputKey[key]->pKeyButton = new Button(name);
116  this->inputKey[key]->pKeyOLabel = new OptionLabel(name, name);
117  this->inputKey[key]->pKeyOLabel->saveability();
118
119#ifdef HAVE_GTK2
120  //inputKey[key]->pKeyButton->connectSignal("key_press_event", inputKey[key]->pKeyButton, key_cb);
121  this->inputKey[key]->pKeyButton->connectSignal("button_press_event", this->inputKey[key], inputWindowEvent);
122#endif /* HAVE_GTK2 */
123  this->inputKey[key]->pKeyBox->fill(this->inputKey[key]->pKeyButton);
124  this->inputKey[key]->pKeyBox->fill(this->inputKey[key]->pKeyOLabel);
125  return this->inputKey[key]->pKeyBox;
126}
127
128/**
129   \returns the OpenButton of a Player
130*/
131Button* Player::getOpenButton(void)
132{
133  return this->openButton;
134}
135
136/**
137   \brief sets a new Key(only output)
138   \param key the new Key.
139*/
140void Player::setkey(KEYS key)
141{
142  cout << "setting up Key: "<< key <<endl;
143}
144
145Window* Player::inputWindow = NULL;
146Button* Player::inputButton = NULL;
147long Player::keySignal = 0;
148
149#ifdef HAVE_GTK2
150gint Player::inputWindowEvent(GtkWidget* w, GdkEventKey* event, void* inputKey)
151{
152  inputButton->setTitle("press a Key");
153  keySignal = inputButton->connectSignal("key_press_event", inputKey, key_cb);
154  inputWindow->open();
155}
156 
157/**
158   \brief Function which gets keystrokes
159   \param w the widget that released the Function.
160   \param event The event that happened.
161   \param Widget the Widget which will be applied.
162   \returns Nothing
163*/
164gint Player::key_cb(GtkWidget* w, GdkEventKey* event, void* inputKey)
165{
166  InputKey* inputkey =(InputKey*) inputKey;
167  char title [20];
168
169  switch(event->keyval) 
170    {
171    case GDK_Up:
172      strcpy(title, "up");
173      break;
174    case GDK_Down:
175      strcpy(title, "down");
176      break;
177    case GDK_Left:
178      strcpy(title, "left");
179      break;
180    case GDK_Right:
181      strcpy(title, "right");
182      break;
183     
184    case GDK_space:
185      strcpy(title, "space");
186      break;
187     
188    case 65293:
189      strcpy(title, "enter");
190      break;
191     
192      // Special Keys //
193    case GDK_Escape:
194      strcpy(title, "esc");
195      break;
196    case GDK_Tab:
197      strcpy(title, "tab");
198      break;
199    case GDK_Shift_L:
200      strcpy(title, "l_shift");
201      break;
202    case GDK_Shift_R:
203      strcpy(title, "r_shift");
204      break;
205    case GDK_Control_L:
206      strcpy(title, "l_ctrl");
207      break;
208    case GDK_Control_R:
209      strcpy(title, "r_ctrl");
210      break;
211    case GDK_Alt_L:
212      strcpy(title, "l_alt");
213      break;
214    case GDK_Alt_R:
215      strcpy(title, "r_alt");
216      break;
217      // FXX KEYS //
218    case GDK_F1:
219      strcpy(title, "f1");
220      break;
221    case GDK_F2:
222      strcpy(title, "f2");
223      break;
224    case GDK_F3:
225      strcpy(title, "f3");
226      break;
227    case GDK_F4:
228      strcpy(title, "f4");
229      break;
230    case GDK_F5:
231      strcpy(title, "f5");
232      break;
233    case GDK_F6:
234      strcpy(title, "f6");
235      break;
236    case GDK_F7:
237      strcpy(title, "f7");
238      break;
239    case GDK_F8:
240      strcpy(title, "f8");
241      break;
242    case GDK_F9:
243      strcpy(title, "f9");
244      break;
245    case GDK_F10:
246      strcpy(title, "f10");
247      break;
248    case GDK_F11:
249      strcpy(title, "f11");
250      break;
251    case GDK_F12:
252      strcpy(title, "f12");
253      break;
254     
255     
256    default:
257      char* tmp;
258      sprintf(tmp, "%c", event->keyval);
259      printf("other key %s \n", tmp);
260      strcpy(title, tmp);
261      break;
262    }
263
264  inputkey->pKeyOLabel->setValue(title);
265  inputButton->disconnectSignal(keySignal);
266  inputWindow->close();
267}
268#endif /* HAVE_GTK2 */
Note: See TracBrowser for help on using the repository browser.