/* orxonox - the future of 3D-vertical-scrollers Copyright (C) 2004 orx This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ### File Specific: main-programmer: Benjamin Grauer */ #include "orxonox_gui_keys.h" /** \brief Creates an Keyboard-Frame */ OrxonoxGuiKeys::OrxonoxGuiKeys () { keysFrame = new Frame ("Keyboard-Options:"); // keysFrame->setGroupName("Keyboard"); keysBox = new Box ('h'); player1 = new Player("player1"); player2 = new Player("player2"); keysBox->fill(player1->getOpenButton()); keysBox->fill(player2->getOpenButton()); keysFrame->fill (keysBox); } /** \brief Return the Frame \return Returns the Audio-frame */ Widget* OrxonoxGuiKeys::getWidget () { return keysFrame; } /* PLAYER */ /** \brief Creates new inputs for a player \param player the name of the Player */ Player::Player(char* player) { char windowName[100] = "Keyboard settings of "; strcat (windowName, player); pKeyWindow = new Window(windowName); pKeyFrame = new Frame (windowName); pKeysBox = new Box('v'); pKeysBox->setGroupName (player); pKeysBox->fill(addKey(UP, "up")); pKeysBox->fill(addKey(DOWN, "down")); pKeysBox->fill(addKey(LEFT, "left")); pKeysBox->fill(addKey(RIGHT, "right")); pKeysBox->fill(addKey(SHOOT, "shoot")); closeButton = new Button("close"); #ifdef HAVE_GTK2 closeButton->connectSignal("button_press_event", pKeyWindow, Window::windowClose); #endif /* HAVE_GTK2 */ pKeysBox->fill(closeButton); pKeyFrame->fill(pKeysBox); pKeyWindow->fill(pKeyFrame); Window::addWindow(pKeyWindow); #ifdef HAVE_GTK2 pKeyWindow->connectSignal("destroy", pKeyWindow, Window::windowClose); pKeyWindow->connectSignal("delete_event", pKeyWindow, Window::windowClose); #endif /* HAVE_GTK2 */ openButton = new Button (player); #ifdef HAVE_GTK2 openButton->connectSignal("button_press_event", pKeyWindow, Window::windowOpen); #endif /* HAVE_GTK2 */ inputWindow = new Window("inputWindow"); inputButton = new Button ("test"); inputWindow->fill (inputButton); #ifdef HAVE_GTK2 inputWindow->connectSignal("destroy", Widget::doNothingSignal); inputWindow->connectSignal("delete_event", Widget::doNothingSignal); #endif /* HAVE_GTK2 */ } /** \brief adds a new Key. \param key the number of the Key \param name The name of the new Key. \returns A widget that has the Key-Box */ Widget* Player::addKey (KEYS key, char* name) { inputKey[key] = new InputKey; inputKey[key]->pKeyBox = new Box(); inputKey[key]->pKeyButton = new Button(name); inputKey[key]->pKeyOLabel = new OptionLabel (name, name); inputKey[key]->pKeyOLabel->saveable = true; #ifdef HAVE_GTK2 //inputKey[key]->pKeyButton->connectSignal("key_press_event", inputKey[key]->pKeyButton, key_cb); inputKey[key]->pKeyButton->connectSignal("button_press_event", inputKey[key], inputWindowEvent); #endif /* HAVE_GTK2 */ inputKey[key]->pKeyBox->fill(inputKey[key]->pKeyButton); inputKey[key]->pKeyBox->fill(inputKey[key]->pKeyOLabel); return inputKey[key]->pKeyBox; } /** \returns the OpenButton of a Player */ Button* Player::getOpenButton() { return openButton; } /** \brief sets a new Key (only output) \param key the new Key. */ void Player::setkey(KEYS key) { cout << "setting up Key: "<< key <setTitle("press a Key"); keySignal = inputButton->connectSignal("key_press_event", inputKey, key_cb); inputWindow->open(); } /** \brief Function which gets keystrokes \param w the widget that released the Function. \param event The event that happened. \param Widget the Widget which will be applied. \returns Nothing */ gint Player::key_cb(GtkWidget* w, GdkEventKey* event, void* inputKey) { InputKey* inputkey = (InputKey*) inputKey; char title [20]; switch(event->keyval) { case GDK_Up: strcpy(title, "up"); break; case GDK_Down: strcpy(title, "down"); break; case GDK_Left: strcpy(title, "left"); break; case GDK_Right: strcpy(title, "right"); break; case GDK_space: strcpy(title, "space"); break; case 65293: strcpy(title, "enter"); break; // Special Keys // case GDK_Escape: strcpy(title, "esc"); break; case GDK_Tab: strcpy(title, "tab"); break; case GDK_Shift_L: strcpy(title, "l_shift"); break; case GDK_Shift_R: strcpy(title, "r_shift"); break; case GDK_Control_L: strcpy(title, "l_ctrl"); break; case GDK_Control_R: strcpy(title, "r_ctrl"); break; case GDK_Alt_L: strcpy(title, "l_alt"); break; case GDK_Alt_R: strcpy(title, "r_alt"); break; // FXX KEYS // case GDK_F1: strcpy(title, "f1"); break; case GDK_F2: strcpy(title, "f2"); break; case GDK_F3: strcpy(title, "f3"); break; case GDK_F4: strcpy(title, "f4"); break; case GDK_F5: strcpy(title, "f5"); break; case GDK_F6: strcpy(title, "f6"); break; case GDK_F7: strcpy(title, "f7"); break; case GDK_F8: strcpy(title, "f8"); break; case GDK_F9: strcpy(title, "f9"); break; case GDK_F10: strcpy(title, "f10"); break; case GDK_F11: strcpy(title, "f11"); break; case GDK_F12: strcpy(title, "f12"); break; default: char* tmp; sprintf(tmp, "%c", event->keyval); printf ("other key %s \n", tmp); strcpy(title, tmp); break; } inputkey->pKeyOLabel->setValue (title); inputButton->disconnectSignal(keySignal); inputWindow->close(); } #endif /* HAVE_GTK2 */