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