Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

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

File size: 6.1 KB
RevLine 
[2613]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:");
[3163]34  //  keysFrame->setGroupName("Keyboard");
35  keysBox = new Box ('h');
[2613]36  player1 = new Player("player1");
[3163]37  player2 = new Player("player2");
[2735]38
[2613]39  keysBox->fill(player1->getOpenButton());
[3163]40  keysBox->fill(player2->getOpenButton());
[2613]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{
[3163]57  char windowName[100] = "Keyboard settings of ";
58  strcat (windowName, player);
59  pKeyWindow = new Window(windowName);
60  pKeyFrame = new Frame (windowName);
[3152]61   pKeysBox = new Box('v');
[3163]62   pKeysBox->setGroupName (player);
[3152]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");
[3165]70#ifdef HAVE_GTK2
[3153]71    closeButton->connectSignal("button_press_event", pKeyWindow, Window::windowClose);
[3165]72#endif /* HAVE_GTK2 */
[3154]73
[3152]74    pKeysBox->fill(closeButton);
[3154]75    pKeyFrame->fill(pKeysBox);
76   pKeyWindow->fill(pKeyFrame);
[3161]77   Window::addWindow(pKeyWindow);
[3165]78#ifdef HAVE_GTK2
[3154]79   pKeyWindow->connectSignal("destroy", pKeyWindow, Window::windowClose);
80   pKeyWindow->connectSignal("delete_event", pKeyWindow, Window::windowClose);
[3165]81#endif /* HAVE_GTK2 */
[3153]82
83  openButton = new Button (player);
[3165]84#ifdef HAVE_GTK2
[3153]85  openButton->connectSignal("button_press_event", pKeyWindow, Window::windowOpen);
[3165]86#endif /* HAVE_GTK2 */
[3153]87
[3156]88  inputWindow = new Window("inputWindow");
89
90  inputButton = new Button ("test");
91  inputWindow->fill (inputButton);
[3165]92#ifdef HAVE_GTK2
[3158]93  inputWindow->connectSignal("destroy",  Widget::doNothingSignal);
94  inputWindow->connectSignal("delete_event", Widget::doNothingSignal);
[3165]95#endif /* HAVE_GTK2 */
[3156]96
[2613]97}
98
[2736]99Widget* Player::addKey (KEYS key, char* name)
100{
[3156]101  inputKey[key] = new InputKey;
102  inputKey[key]->pKeyBox = new Box();
103  inputKey[key]->pKeyButton = new Button(name);
[3161]104  inputKey[key]->pKeyOLabel = new OptionLabel (name, name);
[3156]105  inputKey[key]->pKeyOLabel->saveable = true;
[3165]106
107#ifdef HAVE_GTK2
[3156]108  //inputKey[key]->pKeyButton->connectSignal("key_press_event", inputKey[key]->pKeyButton, key_cb);
109  inputKey[key]->pKeyButton->connectSignal("button_press_event", inputKey[key], inputWindowEvent);
[3165]110#endif /* HAVE_GTK2 */
[3156]111  inputKey[key]->pKeyBox->fill(inputKey[key]->pKeyButton);
112  inputKey[key]->pKeyBox->fill(inputKey[key]->pKeyOLabel);
113  return inputKey[key]->pKeyBox;
[2736]114}
115
[2613]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
[3156]127Window* Player::inputWindow = NULL;
128Button* Player::inputButton = NULL;
129long Player::keySignal = 0;
130
[3165]131#ifdef HAVE_GTK2
[3156]132gint Player::inputWindowEvent(GtkWidget* w, GdkEventKey* event, void* inputKey)
133{
[3157]134  inputButton->setTitle("press a Key");
[3156]135  keySignal = inputButton->connectSignal("key_press_event", inputKey, key_cb);
136  inputWindow->open();
137}
[3157]138 
[2735]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*/
[3156]146gint Player::key_cb(GtkWidget* w, GdkEventKey* event, void* inputKey)
[2733]147{
[3156]148  InputKey* inputkey = (InputKey*) inputKey;
149  char title [20];
[2737]150
[3156]151  switch(event->keyval) 
152    {
153    case GDK_Up:
[3163]154      strcpy(title, "up");
[3156]155      break;
156    case GDK_Down:
[3163]157      strcpy(title, "down");
[3156]158      break;
159    case GDK_Left:
[3163]160      strcpy(title, "left");
[3156]161      break;
162    case GDK_Right:
[3163]163      strcpy(title, "right");
[3156]164      break;
165     
166    case GDK_space:
[3163]167      strcpy(title, "space");
[3156]168      break;
169     
170    case 65293:
[3163]171      strcpy(title, "enter");
[3156]172      break;
173     
174      // Special Keys //
[3163]175    case GDK_Escape:
176      strcpy(title, "esc");
177      break;
178    case GDK_Tab:
179      strcpy(title, "tab");
180      break;
[3156]181    case GDK_Shift_L:
[3163]182      strcpy(title, "l_shift");
[3156]183      break;
184    case GDK_Shift_R:
[3163]185      strcpy(title, "r_shift");
[3156]186      break;
187    case GDK_Control_L:
[3163]188      strcpy(title, "l_ctrl");
[3156]189      break;
190    case GDK_Control_R:
[3163]191      strcpy(title, "r_ctrl");
[3156]192      break;
193    case GDK_Alt_L:
[3163]194      strcpy(title, "l_alt");
[3156]195      break;
196    case GDK_Alt_R:
[3163]197      strcpy(title, "r_alt");
[3156]198      break;
199      // FXX KEYS //
200    case GDK_F1:
[3163]201      strcpy(title, "f1");
[3156]202      break;
203    case GDK_F2:
[3163]204      strcpy(title, "f2");
[3156]205      break;
206    case GDK_F3:
[3163]207      strcpy(title, "f3");
[3156]208      break;
209    case GDK_F4:
[3163]210      strcpy(title, "f4");
[3156]211      break;
212    case GDK_F5:
[3163]213      strcpy(title, "f5");
[3156]214      break;
215    case GDK_F6:
[3163]216      strcpy(title, "f6");
[3156]217      break;
218    case GDK_F7:
[3163]219      strcpy(title, "f7");
[3156]220      break;
221    case GDK_F8:
[3163]222      strcpy(title, "f8");
[3156]223      break;
224    case GDK_F9:
[3163]225      strcpy(title, "f9");
[3156]226      break;
227    case GDK_F10:
[3163]228      strcpy(title, "f10");
[3156]229      break;
230    case GDK_F11:
[3163]231      strcpy(title, "f11");
[3156]232      break;
233    case GDK_F12:
[3163]234      strcpy(title, "f12");
[3156]235      break;
236     
237     
238    default:
239      char* tmp;
240      sprintf(tmp, "%c", event->keyval);
241      printf ("other key %s \n", tmp);
[3163]242      strcpy(title, tmp);
[3156]243      break;
244    }
[3158]245
[3161]246  inputkey->pKeyOLabel->setValue (title);
[3156]247  inputButton->disconnectSignal(keySignal);
248  inputWindow->close();
[2733]249}
[3165]250#endif /* HAVE_GTK2 */
Note: See TracBrowser for help on using the repository browser.