Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk/gui: gtk-fix if window gets closed by windowManager

File size: 5.2 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 ('v');
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
55
56/* PLAYER */
57Player::Player(char* player)
58{
59
60  pKeyWindow = new Window("keys of player");
61  pKeyFrame = new Frame ("keys");
62   pKeysBox = new Box('v');
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    closeButton->connectSignal("button_press_event", pKeyWindow, Window::windowClose);
71
72    pKeysBox->fill(closeButton);
73    pKeyFrame->fill(pKeysBox);
74   pKeyWindow->fill(pKeyFrame);
75   //  Window::addWindow(pKeyWindow);
76   pKeyWindow->connectSignal("destroy", pKeyWindow, Window::windowClose);
77   pKeyWindow->connectSignal("delete_event", pKeyWindow, Window::windowClose);
78
79  openButton = new Button (player);
80  openButton->connectSignal("button_press_event", pKeyWindow, Window::windowOpen);
81
82}
83
84Widget* Player::addKey (KEYS key, char* name)
85{
86  pKeyBox[key] = new Box();
87  pKeyLabel[key] = new Label (name);
88  pKeyButton[key] = new Button(name);
89  pKeyButton[key]->saveable = true;
90 
91  pKeyButton[key]->connectSignal("key_press_event", pKeyButton[key], key_cb);
92 
93  pKeyBox[key]->fill(pKeyLabel[key]);
94  pKeyBox[key]->fill(pKeyButton[key]);
95  return pKeyBox[key];
96}
97
98Button* Player::getOpenButton()
99{
100  return openButton;
101}
102
103
104void Player::setkey(KEYS key)
105{
106  cout << "setting up Key: "<< key <<endl;
107}
108
109/**
110   \brief Function which gets keystrokes
111   \param w the widget that released the Function.
112   \param event The event that happened.
113   \param Widget the Widget which will be applied.
114   \returns Nothing
115*/
116gint Player::key_cb(GtkWidget* w, GdkEventKey* event, void* widget)
117{
118  Button* button = static_cast<Button*>(widget);
119
120  switch(event->keyval) {
121  case GDK_Up:
122    printf("Up arrow key!\n");
123    button->setTitle("up");
124    break;
125  case GDK_Down:
126    printf("Down arrow key!\n");
127    button->setTitle("down");
128    break;
129  case GDK_Left:
130    printf("Left arrow key!\n");
131    button->setTitle("left");
132    break;
133  case GDK_Right:
134    printf("Right arrow key!\n");
135    button->setTitle("right");
136    break;
137
138  case GDK_space:
139    printf("Space Pressed.\n");
140    button->setTitle("space");
141    break;
142
143  case 65293:
144    printf("Enter Pressed\n");
145    button->setTitle("enter");
146    break;
147
148    // Special Keys //
149  case GDK_Shift_L:
150    printf("Left Shift!\n");
151    button->setTitle("l_shift");
152    break;
153  case GDK_Shift_R:
154    printf("Right Shift!\n");
155    button->setTitle("r_shift");
156    break;
157  case GDK_Control_L:
158    printf("Left Control!\n");
159    button->setTitle("l_ctrl");
160    break;
161  case GDK_Control_R:
162    printf("Right Control!\n");
163    button->setTitle("r_ctrl");
164    break;
165  case GDK_Alt_L:
166    printf("Left Alt!\n");
167    button->setTitle("l_alt");
168    break;
169  case GDK_Alt_R:
170    printf("Rigth Alt!\n");
171    button->setTitle("r_alt");
172    break;
173    // FXX KEYS //
174  case GDK_F1:
175    printf("F1!\n");
176    button->setTitle("f1");
177    break;
178  case GDK_F2:
179    printf("F2!\n");
180    button->setTitle("f2");
181    break;
182  case GDK_F3:
183    printf("F3!\n");
184    button->setTitle("f3");
185    break;
186  case GDK_F4:
187    printf("F4!\n");
188    button->setTitle("f4");
189    break;
190  case GDK_F5:
191    printf("F5!\n");
192    button->setTitle("f5");
193    break;
194  case GDK_F6:
195    printf("F6!\n");
196    button->setTitle("f6");
197    break;
198  case GDK_F7:
199    printf("F7!\n");
200    button->setTitle("f7");
201    break;
202  case GDK_F8:
203    printf("F8!\n");
204    button->setTitle("f8");
205    break;
206  case GDK_F9:
207    printf("F9\n");
208    button->setTitle("f9");
209    break;
210  case GDK_F10:
211    printf("F10!\n");
212    button->setTitle("f10");
213    break;
214  case GDK_F11:
215    printf("F11!\n");
216    button->setTitle("f11");
217    break;
218  case GDK_F12:
219    printf("F12!\n");
220    button->setTitle("f12");
221    break;
222
223
224  default:
225    char* tmp;
226    sprintf(tmp, "%c", event->keyval);
227    printf ("other key %s \n", tmp);
228    button->setTitle(tmp);
229    break;
230  }
231}
Note: See TracBrowser for help on using the repository browser.