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 | #include <iostream.h> |
---|
28 | |
---|
29 | /** |
---|
30 | \brief Creates an Keyboard-Frame |
---|
31 | */ |
---|
32 | OrxonoxGuiKeys::OrxonoxGuiKeys () |
---|
33 | { |
---|
34 | keysFrame = new Frame ("Keyboard-Options:"); |
---|
35 | keysFrame->setGroupName("Keyboard"); |
---|
36 | keysBox = new Box ('v'); |
---|
37 | player1 = new Player("player1"); |
---|
38 | // player2 = new Player("player2"); |
---|
39 | |
---|
40 | keysBox->fill(player1->getOpenButton()); |
---|
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 | |
---|
55 | |
---|
56 | /* PLAYER */ |
---|
57 | Player::Player(char* player) |
---|
58 | { |
---|
59 | openButton = new Button (player); |
---|
60 | openButton->connectSignal("button_press_event", this, openWindowEvent); |
---|
61 | |
---|
62 | keyWindow = new Window("keys of player"); |
---|
63 | |
---|
64 | keyBox = new Box('v'); |
---|
65 | Keys[UP] = new Button("up"); |
---|
66 | Keys[DOWN] = new Button("down"); |
---|
67 | Keys[LEFT] = new Button("left"); |
---|
68 | Keys[RIGHT] = new Button("right"); |
---|
69 | Keys[SHOOT] = new Button("shoot"); |
---|
70 | |
---|
71 | Keys[UP]->connectSignal("key_press_event", Keys[UP], key_cb); |
---|
72 | Keys[DOWN]->connectSignal("key_press_event", Keys[DOWN], key_cb); |
---|
73 | Keys[LEFT]->connectSignal("key_press_event", Keys[LEFT], key_cb); |
---|
74 | Keys[RIGHT]->connectSignal("key_press_event", Keys[RIGHT], key_cb); |
---|
75 | Keys[SHOOT]->connectSignal("key_press_event", Keys[SHOOT], key_cb); |
---|
76 | |
---|
77 | keyBox->fill(Keys[UP]); |
---|
78 | keyBox->fill(Keys[DOWN]); |
---|
79 | keyBox->fill(Keys[LEFT]); |
---|
80 | keyBox->fill(Keys[RIGHT]); |
---|
81 | keyBox->fill(Keys[SHOOT]); |
---|
82 | |
---|
83 | keyWindow->fill(keyBox); |
---|
84 | windowIsOpen = false; |
---|
85 | |
---|
86 | } |
---|
87 | |
---|
88 | Button* Player::getOpenButton() |
---|
89 | { |
---|
90 | return openButton; |
---|
91 | } |
---|
92 | |
---|
93 | |
---|
94 | void Player::setkey(KEYS key) |
---|
95 | { |
---|
96 | cout << "setting up Key: "<< key <<endl; |
---|
97 | |
---|
98 | } |
---|
99 | |
---|
100 | /** |
---|
101 | \brief function to display, hide the palyer window |
---|
102 | Buggy, segmentation fault on WindowMaker |
---|
103 | */ |
---|
104 | void Player::openWindow () |
---|
105 | { |
---|
106 | if (!windowIsOpen) |
---|
107 | keyWindow->showall(); |
---|
108 | else |
---|
109 | keyWindow->hide(); |
---|
110 | windowIsOpen = !windowIsOpen; |
---|
111 | } |
---|
112 | |
---|
113 | gint Player::openWindowEvent (GtkWidget* widget, GdkEvent* event, void* player) |
---|
114 | { |
---|
115 | |
---|
116 | static_cast<Player*>(player)->openWindow(); |
---|
117 | } |
---|
118 | |
---|
119 | |
---|
120 | /** |
---|
121 | \brief Function which gets keystrokes |
---|
122 | \param w the widget that released the Function. |
---|
123 | \param event The event that happened. |
---|
124 | \param Widget the Widget which will be applied. |
---|
125 | \returns Nothing |
---|
126 | */ |
---|
127 | gint key_cb(GtkWidget* w, GdkEventKey* event, void* Widget) |
---|
128 | { |
---|
129 | switch(event->keyval) { |
---|
130 | |
---|
131 | case GDK_Up: |
---|
132 | printf("Up arrow key!\n"); |
---|
133 | break; |
---|
134 | case GDK_Down: |
---|
135 | printf("Down arrow key!\n"); |
---|
136 | break; |
---|
137 | case GDK_Right: |
---|
138 | printf("Right arrow key!\n"); |
---|
139 | break; |
---|
140 | case GDK_Left: |
---|
141 | printf("Left arrow key!\n"); |
---|
142 | break; |
---|
143 | |
---|
144 | case GDK_space: |
---|
145 | printf("Space Pressed.\n"); |
---|
146 | break; |
---|
147 | |
---|
148 | case 65293: |
---|
149 | printf("Enter Pressed\n"); |
---|
150 | break; |
---|
151 | |
---|
152 | // Special Keys // |
---|
153 | case GDK_Shift_L: |
---|
154 | printf("Left Shift!\n"); |
---|
155 | break; |
---|
156 | case GDK_Shift_R: |
---|
157 | printf("Right Shift!\n"); |
---|
158 | break; |
---|
159 | case GDK_Control_L: |
---|
160 | printf("Left Control!\n"); |
---|
161 | break; |
---|
162 | case GDK_Control_R: |
---|
163 | printf("Right Control!\n"); |
---|
164 | break; |
---|
165 | case GDK_Alt_L: |
---|
166 | printf("Left Alt!\n"); |
---|
167 | break; |
---|
168 | case GDK_Alt_R: |
---|
169 | printf("Rigth Alt!\n"); |
---|
170 | break; |
---|
171 | // FXX KEYS // |
---|
172 | case GDK_F1: |
---|
173 | printf("F1!\n"); |
---|
174 | break; |
---|
175 | case GDK_F2: |
---|
176 | printf("F2!\n"); |
---|
177 | break; |
---|
178 | case GDK_F3: |
---|
179 | printf("F3!\n"); |
---|
180 | break; |
---|
181 | case GDK_F4: |
---|
182 | printf("F4!\n"); |
---|
183 | break; |
---|
184 | case GDK_F5: |
---|
185 | printf("F5!\n"); |
---|
186 | break; |
---|
187 | case GDK_F6: |
---|
188 | printf("F6!\n"); |
---|
189 | break; |
---|
190 | case GDK_F7: |
---|
191 | printf("F7!\n"); |
---|
192 | break; |
---|
193 | case GDK_F8: |
---|
194 | printf("F8!\n"); |
---|
195 | break; |
---|
196 | case GDK_F9: |
---|
197 | printf("F9\n"); |
---|
198 | break; |
---|
199 | case GDK_F10: |
---|
200 | printf("F10!\n"); |
---|
201 | break; |
---|
202 | case GDK_F11: |
---|
203 | printf("F11!\n"); |
---|
204 | break; |
---|
205 | case GDK_F12: |
---|
206 | printf("F12!\n"); |
---|
207 | break; |
---|
208 | |
---|
209 | |
---|
210 | default: |
---|
211 | printf ("other key %c \n", event->keyval,event->keyval); |
---|
212 | break; |
---|
213 | } |
---|
214 | } |
---|