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