Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/md2_loader/src/lib/gui/gui/gui_keys.cc @ 4063

Last change on this file since 4063 was 4063, checked in by patrick, 19 years ago

orxonox/branche/md2_loader: merged trunk into my branche

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 "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, "shoot"));
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 65293:
191      strcpy(title, "enter");
192      break;
193     
194      // Special Keys //
195    case GDK_Escape:
196      strcpy(title, "esc");
197      break;
198    case GDK_Tab:
199      strcpy(title, "tab");
200      break;
201    case GDK_Shift_L:
202      strcpy(title, "l_shift");
203      break;
204    case GDK_Shift_R:
205      strcpy(title, "r_shift");
206      break;
207    case GDK_Control_L:
208      strcpy(title, "l_ctrl");
209      break;
210    case GDK_Control_R:
211      strcpy(title, "r_ctrl");
212      break;
213    case GDK_Alt_L:
214      strcpy(title, "l_alt");
215      break;
216    case GDK_Alt_R:
217      strcpy(title, "r_alt");
218      break;
219      // FXX KEYS //
220    case GDK_F1:
221      strcpy(title, "f1");
222      break;
223    case GDK_F2:
224      strcpy(title, "f2");
225      break;
226    case GDK_F3:
227      strcpy(title, "f3");
228      break;
229    case GDK_F4:
230      strcpy(title, "f4");
231      break;
232    case GDK_F5:
233      strcpy(title, "f5");
234      break;
235    case GDK_F6:
236      strcpy(title, "f6");
237      break;
238    case GDK_F7:
239      strcpy(title, "f7");
240      break;
241    case GDK_F8:
242      strcpy(title, "f8");
243      break;
244    case GDK_F9:
245      strcpy(title, "f9");
246      break;
247    case GDK_F10:
248      strcpy(title, "f10");
249      break;
250    case GDK_F11:
251      strcpy(title, "f11");
252      break;
253    case GDK_F12:
254      strcpy(title, "f12");
255      break;
256     
257     
258    default:
259      char* tmp;
260      sprintf(tmp, "%c", event->keyval);
261      printf("other key %s \n", tmp);
262      strcpy(title, tmp);
263      break;
264    }
265
266  inputkey->pKeyOLabel->setValue(title);
267  inputButton->disconnectSignal(keySignal);
268  inputWindow->close();
269}
270#endif /* HAVE_GTK2 */
Note: See TracBrowser for help on using the repository browser.