Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk/gui: better order of key-options

File size: 5.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#include <iostream.h>
28
29/**
30   \brief Creates an Keyboard-Frame
31*/
32OrxonoxGuiKeys::OrxonoxGuiKeys ()
33{
34  keysFrame = new Frame ("Keyboard-Options:");
35  keysFrame->setGroupName("Keyboard");
36  keysBox = new Box ('v');
37  player1 = new Player("player1");
38  //  player2 = new Player("player2");
39
40  keysBox->fill(player1->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
55
56/* PLAYER */
57Player::Player(char* player)
58{
59  openButton = new Button (player);
60  openButton->connectSignal("button_press_event", this, openWindowEvent);
61
62  keyWindow = new Window("keys of player");
63
64  keysBox = new Box('v');
65  keysBox->fill(addKey(UP, "up"));
66  keysBox->fill(addKey(DOWN, "down"));
67  keysBox->fill(addKey(LEFT, "left"));
68  keysBox->fill(addKey(RIGHT, "right"));
69  keysBox->fill(addKey(SHOOT, "shoot"));
70  keyWindow->fill(keysBox);
71  windowIsOpen = false;
72
73}
74
75Widget* Player::addKey (KEYS key, char* name)
76{
77  keyBox[key] = new Box();
78  keyLabel[key] = new Label (name);
79  keyButton[key] = new Button(name);
80 
81  keyButton[key]->connectSignal("key_press_event", keyButton[key], key_cb);
82 
83  keyBox[key]->fill(keyLabel[key]);
84  keyBox[key]->fill(keyButton[key]);
85  return keyBox[key];
86}
87
88Button* Player::getOpenButton()
89{
90  return openButton;
91}
92
93
94void Player::setkey(KEYS key)
95{
96  cout << "setting up Key: "<< key <<endl;
97
98}
99
100/**
101   \brief function to display, hide the palyer window
102   Buggy, segmentation fault on WindowMaker
103*/
104void Player::openWindow ()
105{
106  if (!windowIsOpen)
107    keyWindow->showall();
108  else
109    keyWindow->hide();
110  windowIsOpen = !windowIsOpen;
111}
112
113gint Player::openWindowEvent (GtkWidget* widget, GdkEvent* event, void* player)
114{
115
116  static_cast<Player*>(player)->openWindow();
117}
118
119
120/**
121   \brief Function which gets keystrokes
122   \param w the widget that released the Function.
123   \param event The event that happened.
124   \param Widget the Widget which will be applied.
125   \returns Nothing
126*/
127gint Player::key_cb(GtkWidget* w, GdkEventKey* event, void* widget)
128{
129  Button* button = static_cast<Button*>(widget);
130
131  switch(event->keyval) {
132  case GDK_Up:
133    printf("Up arrow key!\n");
134    button->setTitle("up");
135    break;
136  case GDK_Down:
137    printf("Down arrow key!\n");
138    button->setTitle("down");
139    break;
140  case GDK_Left:
141    printf("Left arrow key!\n");
142    button->setTitle("left");
143    break;
144  case GDK_Right:
145    printf("Right arrow key!\n");
146    button->setTitle("right");
147    break;
148
149  case GDK_space:
150    printf("Space Pressed.\n");
151    button->setTitle("space");
152    break;
153
154  case 65293:
155    printf("Enter Pressed\n");
156    button->setTitle("enter");
157    break;
158
159    // Special Keys //
160  case GDK_Shift_L:
161    printf("Left Shift!\n");
162    button->setTitle("l_shift");
163    break;
164  case GDK_Shift_R:
165    printf("Right Shift!\n");
166    button->setTitle("r_shift");
167    break;
168  case GDK_Control_L:
169    printf("Left Control!\n");
170    button->setTitle("l_ctrl");
171    break;
172  case GDK_Control_R:
173    printf("Right Control!\n");
174    button->setTitle("r_ctrl");
175    break;
176  case GDK_Alt_L:
177    printf("Left Alt!\n");
178    button->setTitle("l_alt");
179    break;
180  case GDK_Alt_R:
181    printf("Rigth Alt!\n");
182    button->setTitle("r_alt");
183    break;
184    // FXX KEYS //
185  case GDK_F1:
186    printf("F1!\n");
187    button->setTitle("f1");
188    break;
189  case GDK_F2:
190    printf("F2!\n");
191    button->setTitle("f2");
192    break;
193  case GDK_F3:
194    printf("F3!\n");
195    button->setTitle("f3");
196    break;
197  case GDK_F4:
198    printf("F4!\n");
199    button->setTitle("f4");
200    break;
201  case GDK_F5:
202    printf("F5!\n");
203    button->setTitle("f5");
204    break;
205  case GDK_F6:
206    printf("F6!\n");
207    button->setTitle("f6");
208    break;
209  case GDK_F7:
210    printf("F7!\n");
211    button->setTitle("f7");
212    break;
213  case GDK_F8:
214    printf("F8!\n");
215    button->setTitle("f8");
216    break;
217  case GDK_F9:
218    printf("F9\n");
219    button->setTitle("f9");
220    break;
221  case GDK_F10:
222    printf("F10!\n");
223    button->setTitle("f10");
224    break;
225  case GDK_F11:
226    printf("F11!\n");
227    button->setTitle("f11");
228    break;
229  case GDK_F12:
230    printf("F12!\n");
231    button->setTitle("f12");
232    break;
233
234
235  default:
236    char* tmp;
237    sprintf(tmp, "%c", event->keyval);
238    printf ("other key %s \n", tmp);
239    button->setTitle(tmp);
240    break;
241  }
242}
Note: See TracBrowser for help on using the repository browser.