1 /*
2 * XPilotNG/SDL, an SDL/OpenGL XPilot client. Copyright (C) 2003-2004 by
3 *
4 * Juha Lindstr�m <juhal@users.sourceforge.net>
5 * Erik Andersson <deity_at_home.se>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22
23 #include "xpclient_sdl.h"
24
25 #include "sdlinit.h"
26 #include "sdlkeys.h"
27 #include "console.h"
28 #include "sdlpaint.h"
29 #include "glwidgets.h"
30 #include "../xhacks.h"
31
32 /* TODO: remove these from client.h and put them in *event.h */
33 bool initialPointerControl = false;
34
35 static int mouseMovement; /* horizontal mouse movement. */
36
37 GLWidget *clicktarget[NUM_MOUSE_BUTTONS];
38 GLWidget *hovertarget = NULL;
39
40 int Process_event(SDL_Event *evt);
41
Platform_specific_pointer_control_set_state(bool on)42 void Platform_specific_pointer_control_set_state(bool on)
43 {
44 assert(clData.pointerControl != on);
45
46 if (on) {
47 MainWidget_ShowMenu(MainWidget, false);
48 SDL_WM_GrabInput(SDL_GRAB_ON);
49 SDL_ShowCursor(SDL_DISABLE);
50 } else {
51 MainWidget_ShowMenu(MainWidget, true);
52 SDL_WM_GrabInput(SDL_GRAB_OFF);
53 SDL_ShowCursor(SDL_ENABLE);
54 }
55
56 #ifdef HAVE_XF86MISC
57 {
58 SDL_SysWMinfo info;
59 SDL_VERSION(&info.version);
60 if (SDL_GetWMInfo(&info) > 0)
61 Disable_emulate3buttons(on, info.info.x11.display);
62 }
63 #endif
64 }
65
Platform_specific_talk_set_state(bool on)66 void Platform_specific_talk_set_state(bool on)
67 {
68 assert(clData.talking != on);
69 if (on)
70 Console_show();
71 else
72 Console_hide();
73 }
74
Record_toggle(void)75 void Record_toggle(void)
76 {
77 /* TODO: implement if you think it is worth it */
78 Add_message("Can't record with this client. [*Client reply*]");
79 }
80
Toggle_radar_and_scorelist(void)81 void Toggle_radar_and_scorelist(void)
82 {
83 /* TODO */
84 return;
85 }
86
87 #ifndef _WINDOWS
88 extern int videoFlags;
Toggle_fullscreen(void)89 void Toggle_fullscreen(void)
90 {
91 static int initial_w = -1, initial_h = -1;
92 int w, h;
93
94 if (initial_w == -1) {
95 initial_w = draw_width;
96 initial_h = draw_height;
97 }
98
99 if (videoFlags & SDL_FULLSCREEN) {
100 videoFlags ^= SDL_FULLSCREEN;
101 Resize_Window(initial_w, initial_h);
102 return;
103 }
104
105 w = initial_w = draw_width;
106 h = initial_h = draw_height;
107
108 videoFlags ^= SDL_FULLSCREEN;
109 if (Resize_Window(w, h) == 0)
110 return;
111
112 videoFlags ^= SDL_FULLSCREEN;
113 Resize_Window(initial_w, initial_h);
114 Add_message("Failed to change video mode. [*Client reply*]");
115 }
116 #else
Toggle_fullscreen(void)117 void Toggle_fullscreen(void)
118 {
119 Add_message("Changing mode does not work in Windows. [*Client reply*]");
120 }
121 #endif
122
Process_event(SDL_Event * evt)123 int Process_event(SDL_Event *evt)
124 {
125 int button;
126
127 mouseMovement = 0;
128
129 if (Console_process(evt)) return 1;
130
131 switch (evt->type) {
132
133 case SDL_QUIT:
134 Client_exit(0);
135 break;
136
137 case SDL_KEYDOWN:
138 if (Console_isVisible()) break;
139 Keyboard_button_pressed((xp_keysym_t)evt->key.keysym.sym);
140 break;
141
142 case SDL_KEYUP:
143 /* letting release events through to prevent some keys from locking */
144 /*if (Console_isVisible()) break;*/
145 Keyboard_button_released((xp_keysym_t)evt->key.keysym.sym);
146 break;
147
148 case SDL_MOUSEBUTTONDOWN:
149 button = evt->button.button;
150 if (!clData.pointerControl) {
151 if ( (clicktarget[button-1] = FindGLWidget(MainWidget,evt->button.x,evt->button.y)) ) {
152 if (clicktarget[button-1]->button) {
153 clicktarget[button-1]->button(button,evt->button.state,
154 evt->button.x,evt->button.y,
155 clicktarget[button-1]->buttondata);
156 }
157 }
158
159 } else {
160 Pointer_button_pressed(button);
161 }
162 break;
163
164 case SDL_MOUSEMOTION:
165 if (clData.pointerControl) {
166 mouseMovement += evt->motion.xrel;
167 } else {
168 /*xpprintf("mouse motion xrel=%i yrel=%i\n",evt->motion.xrel,evt->motion.yrel);*/
169 /*for (i = 0;i<NUM_MOUSE_BUTTONS;++i)*/ /* dragdrop for all mouse buttons*/
170 if (clicktarget[0]) { /*is button one pressed?*/
171 /*xpprintf("SDL_MOUSEBUTTONDOWN drag: area found!\n");*/
172 if (clicktarget[0]->motion) {
173 clicktarget[0]->motion(evt->motion.xrel,evt->motion.yrel,
174 evt->button.x,evt->button.y,
175 clicktarget[0]->motiondata);
176 }
177 } else {
178 GLWidget *tmp = FindGLWidget(MainWidget,evt->button.x,evt->button.y);
179 if (tmp != hovertarget) {
180 if (hovertarget && hovertarget->hover) {
181 hovertarget->hover(false,evt->button.x,evt->button.y,hovertarget->hoverdata);
182 }
183 tmp = FindGLWidget(MainWidget,evt->button.x,evt->button.y);
184 if (tmp && tmp->hover)
185 tmp->hover(true,evt->button.x,evt->button.y,tmp->hoverdata);
186 hovertarget = tmp;
187 }
188 }
189 }
190 break;
191
192 case SDL_MOUSEBUTTONUP:
193 button = evt->button.button;
194 if (clData.pointerControl) {
195 Pointer_button_released(button);
196 } else {
197 if ( clicktarget[button-1] ) {
198 if (clicktarget[button-1]->button) {
199 clicktarget[button-1]->button(button,evt->button.state,
200 evt->button.x,evt->button.y,
201 clicktarget[button-1]->buttondata);
202 }
203 clicktarget[button-1] = NULL;
204 }
205 }
206 break;
207
208 case SDL_VIDEORESIZE:
209 Resize_Window(evt->resize.w, evt->resize.h);
210 break;
211
212 default:
213 break;
214 }
215
216 if (mouseMovement) {
217 Client_pointer_move(mouseMovement);
218 Net_flush();
219 }
220 return 1;
221 }
222
223 /* kps - just here so that this can link to generic client files */
Config_redraw(void)224 void Config_redraw(void)
225 {
226
227 }
228