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