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