/* 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 ('v'); 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 */ Player::Player(char* player) { pKeyWindow = new Window("keys of player"); pKeyFrame = new Frame ("keys"); pKeysBox = new Box('v'); pKeysBox->setGroupName ("player1"); 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"); closeButton->connectSignal("button_press_event", pKeyWindow, Window::windowClose); pKeysBox->fill(closeButton); pKeyFrame->fill(pKeysBox); pKeyWindow->fill(pKeyFrame); Window::addWindow(pKeyWindow); pKeyWindow->connectSignal("destroy", pKeyWindow, Window::windowClose); pKeyWindow->connectSignal("delete_event", pKeyWindow, Window::windowClose); openButton = new Button (player); openButton->connectSignal("button_press_event", pKeyWindow, Window::windowOpen); inputWindow = new Window("inputWindow"); inputButton = new Button ("test"); inputWindow->fill (inputButton); inputWindow->connectSignal("destroy", Widget::doNothingSignal); inputWindow->connectSignal("delete_event", Widget::doNothingSignal); } 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; //inputKey[key]->pKeyButton->connectSignal("key_press_event", inputKey[key]->pKeyButton, key_cb); inputKey[key]->pKeyButton->connectSignal("button_press_event", inputKey[key], inputWindowEvent); inputKey[key]->pKeyBox->fill(inputKey[key]->pKeyButton); inputKey[key]->pKeyBox->fill(inputKey[key]->pKeyOLabel); return inputKey[key]->pKeyBox; } Button* Player::getOpenButton() { return openButton; } 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: printf("Up arrow key!\n"); sprintf(title, "%s", "up"); break; case GDK_Down: printf("Down arrow key!\n"); sprintf(title, "%s", "down"); break; case GDK_Left: printf("Left arrow key!\n"); sprintf(title, "%s", "left"); break; case GDK_Right: printf("Right arrow key!\n"); sprintf(title, "%s", "right"); break; case GDK_space: printf("Space Pressed.\n"); sprintf(title, "%s", "space"); break; /* case GDK_escape: printf("Esc Pressed.\n"); sprintf(title, "%s", "esc"); */ case 65293: printf("Enter Pressed\n"); sprintf(title, "%s", "enter"); break; // Special Keys // case GDK_Shift_L: printf("Left Shift!\n"); sprintf(title, "%s", "l_shift"); break; case GDK_Shift_R: printf("Right Shift!\n"); sprintf(title, "%s", "r_shift"); break; case GDK_Control_L: printf("Left Control!\n"); sprintf(title, "%s", "l_ctrl"); break; case GDK_Control_R: printf("Right Control!\n"); sprintf(title, "%s", "r_ctrl"); break; case GDK_Alt_L: printf("Left Alt!\n"); sprintf(title, "%s", "l_alt"); break; case GDK_Alt_R: printf("Rigth Alt!\n"); sprintf(title, "%s", "r_alt"); break; // FXX KEYS // case GDK_F1: printf("F1!\n"); sprintf(title, "%s", "f1"); break; case GDK_F2: printf("F2!\n"); sprintf(title, "%s", "f2"); break; case GDK_F3: printf("F3!\n"); sprintf(title, "%s", "f3"); break; case GDK_F4: printf("F4!\n"); sprintf(title, "%s", "f4"); break; case GDK_F5: printf("F5!\n"); sprintf(title, "%s", "f5"); break; case GDK_F6: printf("F6!\n"); sprintf(title, "%s", "f6"); break; case GDK_F7: printf("F7!\n"); sprintf(title, "%s", "f7"); break; case GDK_F8: printf("F8!\n"); sprintf(title, "%s", "f8"); break; case GDK_F9: printf("F9\n"); sprintf(title, "%s", "f9"); break; case GDK_F10: printf("F10!\n"); sprintf(title, "%s", "f10"); break; case GDK_F11: printf("F11!\n"); sprintf(title, "%s", "f11"); break; case GDK_F12: printf("F12!\n"); sprintf(title, "%s", "f12"); break; default: char* tmp; sprintf(tmp, "%c", event->keyval); printf ("other key %s \n", tmp); sprintf(title, "%s", tmp); break; } inputkey->pKeyOLabel->setValue (title); inputButton->disconnectSignal(keySignal); inputWindow->close(); }