Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/gui/orxonox_gui_keys.cc @ 3181

Last change on this file since 3181 was 3166, checked in by bensch, 20 years ago

orxonox/trunk/gui: now it does something without GTK and it looks nice

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