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