[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 | |
---|
[4047] | 26 | #include "gui_keys.h" |
---|
[2613] | 27 | |
---|
[4034] | 28 | #include <string.h> |
---|
| 29 | |
---|
[2613] | 30 | /** |
---|
| 31 | \brief Creates an Keyboard-Frame |
---|
| 32 | */ |
---|
[4056] | 33 | GuiKeys::GuiKeys(void) |
---|
[2613] | 34 | { |
---|
[4088] | 35 | Frame* keysFrame; //!< The Frame that holds the keyOptions. |
---|
[2735] | 36 | |
---|
[4088] | 37 | keysFrame = new Frame("Keyboard-Options:"); |
---|
| 38 | { |
---|
[4089] | 39 | Box* keysBox0; //!< The Frame that holds the keyOptions. |
---|
[4088] | 40 | |
---|
| 41 | // keysFrame->setGroupName("Keyboard"); |
---|
[4089] | 42 | keysBox0 = new Box('v'); |
---|
[4088] | 43 | { |
---|
[4089] | 44 | Box* keysBox1; |
---|
| 45 | MiscKeys* misc; //!< The Misc Keys |
---|
| 46 | |
---|
| 47 | keysBox1 = new Box('h'); |
---|
| 48 | { |
---|
| 49 | PlayerKeys* player1; //!< The first Player's keys. |
---|
| 50 | PlayerKeys* player2; //!< The seconds Player's keys. |
---|
| 51 | |
---|
[4091] | 52 | player1 = new PlayerKeys(CONFIG_SECTION_PLAYER "1"); |
---|
| 53 | player2 = new PlayerKeys(CONFIG_SECTION_PLAYER "2"); |
---|
[4089] | 54 | |
---|
| 55 | keysBox1->fill(player1->getOpenButton()); |
---|
| 56 | keysBox1->fill(player2->getOpenButton()); |
---|
| 57 | } |
---|
| 58 | keysBox0->fill(keysBox1); |
---|
| 59 | |
---|
| 60 | misc = new MiscKeys(); |
---|
| 61 | keysBox0->fill(misc->getOpenButton()); |
---|
[4088] | 62 | } |
---|
[4089] | 63 | keysFrame->fill(keysBox0); |
---|
[4088] | 64 | } |
---|
| 65 | |
---|
| 66 | // setting up the Input Windows that receives keystrokes. |
---|
[4086] | 67 | this->inputWindow = new Window("inputWindow"); |
---|
| 68 | this->inputButton = new Button("test"); |
---|
| 69 | #ifdef HAVE_GTK2 |
---|
| 70 | this->inputWindow->connectSignal("destroy", Widget::doNothingSignal); |
---|
| 71 | this->inputWindow->connectSignal("delete_event", Widget::doNothingSignal); |
---|
| 72 | #endif /* HAVE_GTK2 */ |
---|
| 73 | this->inputWindow->fill(inputButton); |
---|
[4088] | 74 | |
---|
[4024] | 75 | this->setMainWidget(keysFrame); |
---|
[2613] | 76 | } |
---|
| 77 | |
---|
| 78 | /** |
---|
[3423] | 79 | \brief Destructs the Keys-stuff |
---|
| 80 | */ |
---|
[4056] | 81 | GuiKeys::~GuiKeys(void) |
---|
[3423] | 82 | { |
---|
| 83 | // nothing to do here. |
---|
| 84 | } |
---|
| 85 | |
---|
[4086] | 86 | |
---|
| 87 | Window* GuiKeys::inputWindow = NULL; |
---|
| 88 | Button* GuiKeys::inputButton = NULL; |
---|
| 89 | long GuiKeys::keySignal = 0; |
---|
| 90 | |
---|
[4089] | 91 | //////////// |
---|
[2613] | 92 | /* PLAYER */ |
---|
[4089] | 93 | //////////// |
---|
[3187] | 94 | /** |
---|
| 95 | \brief Creates new inputs for a player |
---|
| 96 | \param player the name of the Player |
---|
| 97 | */ |
---|
[4089] | 98 | PlayerKeys::PlayerKeys(char* player) |
---|
[2613] | 99 | { |
---|
[4088] | 100 | Window* pKeyWindow; //!< The Window for a new Key-setting. |
---|
| 101 | |
---|
| 102 | char* windowName = new char[strlen(player)+12]; |
---|
| 103 | strcpy(windowName, "KeySets: "); |
---|
[3423] | 104 | strcat(windowName, player); |
---|
[4088] | 105 | pKeyWindow = new Window(windowName); |
---|
| 106 | { |
---|
| 107 | Frame* pKeyFrame; //!< The Frame for a new Key-setting. |
---|
| 108 | |
---|
| 109 | pKeyFrame = new Frame(windowName); |
---|
| 110 | { |
---|
| 111 | Box* pKeysBox; //!< The Box that holds the Key-settings. |
---|
| 112 | pKeysBox = new Box('v'); |
---|
| 113 | { |
---|
| 114 | Button* closeButton; //!< The CloseButton for this key-settings. |
---|
| 115 | |
---|
| 116 | pKeysBox->setGroupName(player); |
---|
[4091] | 117 | pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_UP, "UP")); |
---|
| 118 | pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_DOWN, "DOWN")); |
---|
| 119 | pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_LEFT, "LEFT")); |
---|
| 120 | pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_RIGHT, "RIGHT")); |
---|
| 121 | pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_FIRE, "SPACE")); |
---|
| 122 | pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_NEXT_WEAPON, "m")); |
---|
| 123 | pKeysBox->fill(addKey(CONFIG_NAME_PLAYER_PREV_WEAPON, "n")); |
---|
[4088] | 124 | closeButton = new Button("close"); |
---|
[3165] | 125 | #ifdef HAVE_GTK2 |
---|
[4088] | 126 | closeButton->connectSignal("button_press_event", pKeyWindow, Window::windowClose); |
---|
[3165] | 127 | #endif /* HAVE_GTK2 */ |
---|
[3154] | 128 | |
---|
[4088] | 129 | pKeysBox->fill(closeButton); |
---|
| 130 | } |
---|
| 131 | pKeyFrame->fill(pKeysBox); |
---|
| 132 | } |
---|
| 133 | pKeyWindow->fill(pKeyFrame); |
---|
| 134 | } |
---|
[4089] | 135 | delete windowName; |
---|
[4088] | 136 | Window::addWindow(pKeyWindow); |
---|
[3165] | 137 | #ifdef HAVE_GTK2 |
---|
[4088] | 138 | pKeyWindow->connectSignal("destroy", pKeyWindow, Window::windowClose); |
---|
| 139 | pKeyWindow->connectSignal("delete_event", pKeyWindow, Window::windowClose); |
---|
[3165] | 140 | #endif /* HAVE_GTK2 */ |
---|
[4088] | 141 | |
---|
[3423] | 142 | this->openButton = new Button(player); |
---|
[3165] | 143 | #ifdef HAVE_GTK2 |
---|
[4088] | 144 | this->openButton->connectSignal("button_press_event", pKeyWindow, Window::windowOpen); |
---|
[3165] | 145 | #endif /* HAVE_GTK2 */ |
---|
[2613] | 146 | } |
---|
| 147 | |
---|
[3187] | 148 | /** |
---|
| 149 | \returns the OpenButton of a Player |
---|
| 150 | */ |
---|
[4089] | 151 | Button* PlayerKeys::getOpenButton(void) |
---|
[2613] | 152 | { |
---|
[3423] | 153 | return this->openButton; |
---|
[2613] | 154 | } |
---|
| 155 | |
---|
[4089] | 156 | ////////////////// |
---|
| 157 | /* MISC_OPTIONS */ |
---|
| 158 | ////////////////// |
---|
[3187] | 159 | /** |
---|
[4089] | 160 | \brief Creates new inputs for a misc |
---|
| 161 | \param player the name of the Misc |
---|
[3187] | 162 | */ |
---|
[4089] | 163 | MiscKeys::MiscKeys() |
---|
[2613] | 164 | { |
---|
[4089] | 165 | Window* keyWindow; //!< The Window for a new Key-setting. |
---|
| 166 | |
---|
| 167 | keyWindow = new Window("misc Keys"); |
---|
| 168 | { |
---|
| 169 | Frame* keyFrame; //!< The Frame for a new Key-setting. |
---|
| 170 | |
---|
| 171 | keyFrame = new Frame("misc Keys:"); |
---|
| 172 | { |
---|
| 173 | Box* keysBox; //!< The Box that holds the Key-settings. |
---|
| 174 | keysBox = new Box('v'); |
---|
| 175 | { |
---|
| 176 | Button* closeButton; //!< The CloseButton for this key-settings. |
---|
| 177 | |
---|
[4091] | 178 | keysBox->setGroupName(CONFIG_SECTION_MISC_KEYS); |
---|
| 179 | keysBox->fill(addKey(CONFIG_NAME_QUIT , "ESCAPE")); |
---|
| 180 | keysBox->fill(addKey(CONFIG_NAME_PAUSE, "PAUSE")); |
---|
| 181 | keysBox->fill(addKey(CONFIG_NAME_NEXT_WORLD, "x")); |
---|
| 182 | keysBox->fill(addKey(CONFIG_NAME_PREV_WORLD, "z")); |
---|
| 183 | keysBox->fill(addKey(CONFIG_NAME_VIEW0, "1")); |
---|
| 184 | keysBox->fill(addKey(CONFIG_NAME_VIEW1, "2")); |
---|
| 185 | keysBox->fill(addKey(CONFIG_NAME_VIEW2, "3")); |
---|
| 186 | keysBox->fill(addKey(CONFIG_NAME_VIEW3, "4")); |
---|
| 187 | keysBox->fill(addKey(CONFIG_NAME_VIEW4, "5")); |
---|
| 188 | keysBox->fill(addKey(CONFIG_NAME_VIEW5, "6")); |
---|
[4089] | 189 | |
---|
| 190 | closeButton = new Button("close"); |
---|
| 191 | #ifdef HAVE_GTK2 |
---|
| 192 | closeButton->connectSignal("button_press_event", keyWindow, Window::windowClose); |
---|
| 193 | #endif /* HAVE_GTK2 */ |
---|
| 194 | |
---|
| 195 | keysBox->fill(closeButton); |
---|
| 196 | } |
---|
| 197 | keyFrame->fill(keysBox); |
---|
| 198 | } |
---|
| 199 | keyWindow->fill(keyFrame); |
---|
| 200 | } |
---|
| 201 | Window::addWindow(keyWindow); |
---|
| 202 | #ifdef HAVE_GTK2 |
---|
| 203 | keyWindow->connectSignal("destroy", keyWindow, Window::windowClose); |
---|
| 204 | keyWindow->connectSignal("delete_event", keyWindow, Window::windowClose); |
---|
| 205 | #endif /* HAVE_GTK2 */ |
---|
| 206 | |
---|
| 207 | this->openButton = new Button("misc"); |
---|
| 208 | #ifdef HAVE_GTK2 |
---|
| 209 | this->openButton->connectSignal("button_press_event", keyWindow, Window::windowOpen); |
---|
| 210 | #endif /* HAVE_GTK2 */ |
---|
[2613] | 211 | } |
---|
| 212 | |
---|
[4086] | 213 | /** |
---|
[4089] | 214 | \returns the OpenButton of a Misc |
---|
| 215 | */ |
---|
| 216 | Button* MiscKeys::getOpenButton(void) |
---|
| 217 | { |
---|
| 218 | return this->openButton; |
---|
| 219 | } |
---|
| 220 | |
---|
| 221 | |
---|
| 222 | /** |
---|
[4086] | 223 | \brief adds a new Key. |
---|
| 224 | \param key the number of the Key |
---|
| 225 | \param name The name of the new Key. |
---|
| 226 | \returns A widget that has the Key-Box |
---|
| 227 | */ |
---|
[4089] | 228 | Widget* addKey(const char* name, const char* defaultVal) |
---|
[4086] | 229 | { |
---|
| 230 | InputKey* inputKey = new InputKey; |
---|
[4089] | 231 | inputKey->keyBox = new Box(); |
---|
| 232 | inputKey->keyButton = new Button(name); |
---|
| 233 | if (defaultVal) |
---|
| 234 | inputKey->keyOLabel = new OptionLabel(name, defaultVal); |
---|
| 235 | else |
---|
| 236 | inputKey->keyOLabel = new OptionLabel(name, name); |
---|
| 237 | inputKey->keyOLabel->saveability(); |
---|
[3156] | 238 | |
---|
[3165] | 239 | #ifdef HAVE_GTK2 |
---|
[4089] | 240 | //inputKey->keyButton->connectSignal("key_press_event", inputKey->keyButton, key_cb); |
---|
| 241 | inputKey->keyButton->connectSignal("button_press_event", inputKey, inputWindowEvent); |
---|
[4086] | 242 | #endif /* HAVE_GTK2 */ |
---|
[4089] | 243 | inputKey->keyBox->fill(inputKey->keyButton); |
---|
| 244 | inputKey->keyBox->fill(inputKey->keyOLabel); |
---|
| 245 | return inputKey->keyBox; |
---|
[4086] | 246 | } |
---|
| 247 | |
---|
| 248 | |
---|
| 249 | #ifdef HAVE_GTK2 |
---|
| 250 | gint inputWindowEvent(GtkWidget* w, GdkEventKey* event, void* inputKey) |
---|
[3156] | 251 | { |
---|
[4086] | 252 | GuiKeys::inputButton->setTitle("press a Key"); |
---|
| 253 | GuiKeys::keySignal = GuiKeys::inputButton->connectSignal("key_press_event", inputKey, key_cb); |
---|
| 254 | GuiKeys::inputWindow->open(); |
---|
[3156] | 255 | } |
---|
[3157] | 256 | |
---|
[2735] | 257 | /** |
---|
| 258 | \brief Function which gets keystrokes |
---|
| 259 | \param w the widget that released the Function. |
---|
| 260 | \param event The event that happened. |
---|
| 261 | \param Widget the Widget which will be applied. |
---|
| 262 | \returns Nothing |
---|
| 263 | */ |
---|
[4086] | 264 | gint key_cb(GtkWidget* w, GdkEventKey* event, void* inputKey) |
---|
[2733] | 265 | { |
---|
[3423] | 266 | InputKey* inputkey =(InputKey*) inputKey; |
---|
[4089] | 267 | char title [50]; |
---|
[2737] | 268 | |
---|
[4089] | 269 | switch(event->keyval) |
---|
[3156] | 270 | { |
---|
| 271 | case GDK_Up: |
---|
[4085] | 272 | strcpy(title, "UP"); |
---|
[3156] | 273 | break; |
---|
| 274 | case GDK_Down: |
---|
[4085] | 275 | strcpy(title, "DOWN"); |
---|
[3156] | 276 | break; |
---|
| 277 | case GDK_Left: |
---|
[4085] | 278 | strcpy(title, "LEFT"); |
---|
[3156] | 279 | break; |
---|
| 280 | case GDK_Right: |
---|
[4085] | 281 | strcpy(title, "RIGHT"); |
---|
[3156] | 282 | break; |
---|
| 283 | |
---|
| 284 | case GDK_space: |
---|
[4085] | 285 | strcpy(title, "SPACE"); |
---|
[3156] | 286 | break; |
---|
| 287 | |
---|
[4085] | 288 | case GDK_Return: |
---|
| 289 | strcpy(title, "RETURN"); |
---|
[3156] | 290 | break; |
---|
| 291 | |
---|
| 292 | // Special Keys // |
---|
[4085] | 293 | case GDK_BackSpace: |
---|
| 294 | strcpy(title, "BACKSPACE"); |
---|
| 295 | break; |
---|
| 296 | case GDK_Scroll_Lock: |
---|
| 297 | strcpy(title, "SCROLLOCK"); |
---|
| 298 | break; |
---|
| 299 | case GDK_minus: |
---|
| 300 | strcpy(title, "MINUS"); |
---|
| 301 | break; |
---|
| 302 | case GDK_plus: |
---|
| 303 | strcpy(title, "PLUS"); |
---|
| 304 | break; |
---|
| 305 | case GDK_slash: |
---|
| 306 | strcpy(title, "SLASH"); |
---|
| 307 | break; |
---|
| 308 | case GDK_period: |
---|
| 309 | strcpy(title, "PERIOD"); |
---|
| 310 | break; |
---|
| 311 | case GDK_comma: |
---|
| 312 | strcpy(title, "COMMA"); |
---|
| 313 | break; |
---|
| 314 | case GDK_colon: |
---|
| 315 | strcpy(title, "COLON"); |
---|
| 316 | break; |
---|
| 317 | case GDK_semicolon: |
---|
| 318 | strcpy(title, "SEMICOLON"); |
---|
| 319 | break; |
---|
| 320 | case GDK_less: |
---|
| 321 | strcpy(title, "LESS"); |
---|
| 322 | break; |
---|
| 323 | case GDK_equal: |
---|
| 324 | strcpy(title, "EQUALS"); |
---|
| 325 | break; |
---|
| 326 | case GDK_greater: |
---|
| 327 | strcpy(title, "GREATER"); |
---|
| 328 | break; |
---|
| 329 | case GDK_question: |
---|
| 330 | strcpy(title, "QUESTION"); |
---|
| 331 | break; |
---|
| 332 | case GDK_at: |
---|
| 333 | strcpy(title, "AT"); |
---|
| 334 | break; |
---|
| 335 | case GDK_bracketleft: |
---|
| 336 | strcpy(title, "LEFTBRACKET"); |
---|
| 337 | break; |
---|
| 338 | case GDK_bracketright: |
---|
| 339 | strcpy(title, "RIGHTBRACKET"); |
---|
| 340 | break; |
---|
| 341 | case GDK_backslash: |
---|
| 342 | strcpy(title, "BACKSLASH"); |
---|
| 343 | break; |
---|
| 344 | case GDK_underscore: |
---|
| 345 | strcpy(title, "UNDERSCORE"); |
---|
| 346 | break; |
---|
| 347 | case GDK_quoteleft: |
---|
| 348 | strcpy(title, "BACKQUOTE"); |
---|
| 349 | break; |
---|
| 350 | |
---|
| 351 | case GDK_Page_Up: |
---|
| 352 | strcpy(title, "PAGEUP"); |
---|
| 353 | break; |
---|
| 354 | case GDK_Page_Down: |
---|
| 355 | strcpy(title, "PAGEDOWN"); |
---|
| 356 | break; |
---|
| 357 | case GDK_Home: |
---|
| 358 | strcpy(title, "HOME"); |
---|
| 359 | break; |
---|
| 360 | case GDK_Insert: |
---|
| 361 | strcpy(title, "INSERT"); |
---|
| 362 | break; |
---|
| 363 | |
---|
[3163] | 364 | case GDK_Escape: |
---|
[4085] | 365 | strcpy(title, "ESCAPE"); |
---|
[3163] | 366 | break; |
---|
| 367 | case GDK_Tab: |
---|
[4085] | 368 | strcpy(title, "TAB"); |
---|
[3163] | 369 | break; |
---|
[3156] | 370 | case GDK_Shift_L: |
---|
[4085] | 371 | strcpy(title, "LSHIFT"); |
---|
[3156] | 372 | break; |
---|
| 373 | case GDK_Shift_R: |
---|
[4085] | 374 | strcpy(title, "R_SHIFT"); |
---|
[3156] | 375 | break; |
---|
| 376 | case GDK_Control_L: |
---|
[4085] | 377 | strcpy(title, "LCTRL"); |
---|
[3156] | 378 | break; |
---|
| 379 | case GDK_Control_R: |
---|
[4085] | 380 | strcpy(title, "RCTRL"); |
---|
[3156] | 381 | break; |
---|
| 382 | case GDK_Alt_L: |
---|
[4085] | 383 | strcpy(title, "LALT"); |
---|
[3156] | 384 | break; |
---|
| 385 | case GDK_Alt_R: |
---|
[4085] | 386 | strcpy(title, "RALT"); |
---|
[3156] | 387 | break; |
---|
| 388 | // FXX KEYS // |
---|
| 389 | case GDK_F1: |
---|
[4085] | 390 | strcpy(title, "F1"); |
---|
[3156] | 391 | break; |
---|
| 392 | case GDK_F2: |
---|
[4085] | 393 | strcpy(title, "F2"); |
---|
[3156] | 394 | break; |
---|
| 395 | case GDK_F3: |
---|
[4085] | 396 | strcpy(title, "F3"); |
---|
[3156] | 397 | break; |
---|
| 398 | case GDK_F4: |
---|
[4085] | 399 | strcpy(title, "F4"); |
---|
[3156] | 400 | break; |
---|
| 401 | case GDK_F5: |
---|
[4085] | 402 | strcpy(title, "F5"); |
---|
[3156] | 403 | break; |
---|
| 404 | case GDK_F6: |
---|
[4085] | 405 | strcpy(title, "F6"); |
---|
[3156] | 406 | break; |
---|
| 407 | case GDK_F7: |
---|
[4085] | 408 | strcpy(title, "F7"); |
---|
[3156] | 409 | break; |
---|
| 410 | case GDK_F8: |
---|
[4085] | 411 | strcpy(title, "F8"); |
---|
[3156] | 412 | break; |
---|
| 413 | case GDK_F9: |
---|
[4085] | 414 | strcpy(title, "F9"); |
---|
[3156] | 415 | break; |
---|
| 416 | case GDK_F10: |
---|
[4085] | 417 | strcpy(title, "F10"); |
---|
[3156] | 418 | break; |
---|
| 419 | case GDK_F11: |
---|
[4085] | 420 | strcpy(title, "F11"); |
---|
[3156] | 421 | break; |
---|
| 422 | case GDK_F12: |
---|
[4085] | 423 | strcpy(title, "F12"); |
---|
[3156] | 424 | break; |
---|
| 425 | |
---|
| 426 | |
---|
| 427 | default: |
---|
| 428 | char* tmp; |
---|
| 429 | sprintf(tmp, "%c", event->keyval); |
---|
[3423] | 430 | printf("other key %s \n", tmp); |
---|
[3163] | 431 | strcpy(title, tmp); |
---|
[3156] | 432 | break; |
---|
| 433 | } |
---|
[3158] | 434 | |
---|
[4089] | 435 | inputkey->keyOLabel->setValue(title); |
---|
[4086] | 436 | GuiKeys::inputButton->disconnectSignal(GuiKeys::keySignal); |
---|
| 437 | GuiKeys::inputWindow->close(); |
---|
[2733] | 438 | } |
---|
[3165] | 439 | #endif /* HAVE_GTK2 */ |
---|