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