Mercurial > fife-parpg
comparison engine/core/video/cursor.cpp @ 255:51cc05d862f2
Merged editor_rewrite branch to trunk.
This contains changes that may break compatibility against existing clients.
For a list of changes that may affect your client, see: http://wiki.fifengine.de/Changes_to_pychan_and_FIFE_in_editor_rewrite_branch
author | cheesesucker@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Mon, 08 Jun 2009 16:00:02 +0000 |
parents | 90005975cdbb |
children | f2195628947b |
comparison
equal
deleted
inserted
replaced
254:10b5f7f36dd4 | 255:51cc05d862f2 |
---|---|
18 * Free Software Foundation, Inc., * | 18 * Free Software Foundation, Inc., * |
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * | 19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * |
20 ***************************************************************************/ | 20 ***************************************************************************/ |
21 | 21 |
22 // Standard C++ library includes | 22 // Standard C++ library includes |
23 #if defined( WIN32 ) | |
24 #include <windows.h> | |
25 #include <sdl.h> | |
26 #endif | |
27 | |
28 #if defined( __linux__ ) | |
29 #include <X11/Xcursor/Xcursor.h> | |
30 #endif | |
23 | 31 |
24 // 3rd party library includes | 32 // 3rd party library includes |
25 | 33 |
26 // FIFE includes | 34 // FIFE includes |
27 // These includes are split up in two parts, separated by one empty line | 35 // These includes are split up in two parts, separated by one empty line |
28 // First block: files included from the FIFE root src directory | 36 // First block: files included from the FIFE root src directory |
29 // Second block: files included from the same folder | 37 // Second block: files included from the same folder |
30 #include "util/structures/rect.h" | 38 #include "util/structures/rect.h" |
31 #include "util/time/timemanager.h" | 39 #include "util/time/timemanager.h" |
40 #include "util/log/logger.h" | |
32 | 41 |
33 #include "imagepool.h" | 42 #include "imagepool.h" |
34 #include "animationpool.h" | 43 #include "animationpool.h" |
35 #include "animation.h" | 44 #include "animation.h" |
36 #include "image.h" | 45 #include "image.h" |
37 #include "renderbackend.h" | 46 #include "renderbackend.h" |
38 #include "cursor.h" | 47 #include "cursor.h" |
39 | 48 |
49 #if defined( WIN32 ) | |
50 | |
51 // From SDL_sysmouse.c | |
52 struct WMcursor { | |
53 HCURSOR curs; | |
54 #ifndef _WIN32_WCE | |
55 Uint8 *ands; | |
56 Uint8 *xors; | |
57 #endif | |
58 }; | |
59 | |
60 #endif | |
61 | |
62 #if defined( __linux__ ) | |
63 | |
64 // Stops the compiler from confusing it with FIFE:Cursor | |
65 typedef Cursor XCursor; | |
66 | |
67 // From SDL_x11mouse.c | |
68 struct WMcursor { | |
69 Cursor x_cursor; | |
70 }; | |
71 | |
72 #endif | |
73 | |
40 namespace FIFE { | 74 namespace FIFE { |
41 | 75 static Logger _log(LM_GUI); // We should have a log module for cursor |
76 | |
42 Cursor::Cursor(ImagePool* imgpool, AnimationPool* animpool, RenderBackend* renderbackend): | 77 Cursor::Cursor(ImagePool* imgpool, AnimationPool* animpool, RenderBackend* renderbackend): |
43 m_cursor_id(0), | 78 m_cursor_id(NC_ARROW), |
44 m_drag_id(0), | 79 m_drag_id(0), |
45 m_cursor_type(CURSOR_NATIVE), | 80 m_cursor_type(CURSOR_NATIVE), |
46 m_drag_type(CURSOR_NONE), | 81 m_drag_type(CURSOR_NONE), |
47 m_renderbackend(renderbackend), | 82 m_renderbackend(renderbackend), |
48 m_imgpool(imgpool), | 83 m_imgpool(imgpool), |
49 m_animpool(animpool), | 84 m_animpool(animpool), |
50 m_animtime(0), | 85 m_animtime(0), |
51 m_drag_animtime(0), | 86 m_drag_animtime(0), |
52 m_drag_offset_x(0), | 87 m_drag_offset_x(0), |
53 m_drag_offset_y(0), | 88 m_drag_offset_y(0), |
89 m_native_cursor(NULL), | |
54 m_timemanager(TimeManager::instance()) { | 90 m_timemanager(TimeManager::instance()) { |
55 assert(m_timemanager); | 91 assert(m_timemanager); |
92 set(m_cursor_type, m_cursor_id); | |
56 } | 93 } |
57 | 94 |
58 void Cursor::set(MouseCursorType ctype, unsigned int cursor_id) { | 95 void Cursor::set(MouseCursorType ctype, unsigned int cursor_id) { |
59 m_cursor_id = cursor_id; | 96 m_cursor_id = cursor_id; |
60 m_cursor_type = ctype; | 97 m_cursor_type = ctype; |
61 if (ctype == CURSOR_NATIVE) { | 98 if (ctype == CURSOR_NATIVE) { |
62 SDL_ShowCursor(1); | 99 SDL_ShowCursor(1); |
100 setNativeCursor(cursor_id); | |
63 } else { | 101 } else { |
64 SDL_ShowCursor(0); | 102 SDL_ShowCursor(0); |
65 if (ctype == CURSOR_ANIMATION) { | 103 if (ctype == CURSOR_ANIMATION) { |
66 m_animtime = m_timemanager->getTime(); | 104 m_animtime = m_timemanager->getTime(); |
67 } | 105 } |
118 m_renderbackend->pushClipArea(area, false); | 156 m_renderbackend->pushClipArea(area, false); |
119 img->render(area); | 157 img->render(area); |
120 m_renderbackend->popClipArea(); | 158 m_renderbackend->popClipArea(); |
121 } | 159 } |
122 } | 160 } |
161 | |
162 unsigned int Cursor::getNativeId(unsigned int cursor_id) { | |
163 #if defined( WIN32 ) | |
164 switch (cursor_id) { | |
165 case NC_ARROW: | |
166 return 32512; // IDC_ARROW; | |
167 case NC_IBEAM: | |
168 return 32513; // IDC_IBEAM; | |
169 case NC_WAIT: | |
170 return 32514; // IDC_WAIT; | |
171 case NC_CROSS: | |
172 return 32515; // IDC_CROSS; | |
173 case NC_UPARROW: | |
174 return 32516; // IDC_UPARROW; | |
175 case NC_RESIZESE: | |
176 return 32642; // IDC_SIZENWSE; | |
177 case NC_RESIZESW: | |
178 return 32643; // IDC_SIZENESW; | |
179 case NC_RESIZEE: | |
180 return 32644; // IDC_SIZEWE; | |
181 case NC_RESIZES: | |
182 return 32645; // IDC_SIZENS; | |
183 case NC_RESIZENW: | |
184 return 32642; // IDC_SIZENWSE; | |
185 case NC_RESIZENE: | |
186 return 32643; // IDC_SIZENESW; | |
187 case NC_RESIZEW: | |
188 return 32644; // IDC_SIZEWE; | |
189 case NC_RESIZEN: | |
190 return 32645; // IDC_SIZENS; | |
191 case NC_RESIZEALL: | |
192 return 32646; // IDC_SIZEALL; | |
193 case NC_NO: | |
194 return 32648; // IDC_NO; | |
195 case NC_HAND: | |
196 return 32649; // IDC_HAND; | |
197 case NC_APPSTARTING: | |
198 return 32650; // IDC_APPSTARTING; | |
199 case NC_HELP: | |
200 return 32651; // IDC_HELP; | |
201 default: | |
202 break; | |
203 } | |
204 | |
205 #elif defined( __linux__ ) | |
206 switch (cursor_id) { | |
207 case NC_ARROW: | |
208 return 68; | |
209 case NC_IBEAM: | |
210 return 152; | |
211 case NC_WAIT: | |
212 return 150; | |
213 case NC_CROSS: | |
214 return 130; | |
215 case NC_UPARROW: | |
216 return 22; | |
217 case NC_RESIZESE: | |
218 return 14; | |
219 case NC_RESIZESW: | |
220 return 12; | |
221 case NC_RESIZEE: | |
222 return 96; | |
223 case NC_RESIZES: | |
224 return 16; | |
225 case NC_RESIZENW: | |
226 return 134; | |
227 case NC_RESIZENE: | |
228 return 136; | |
229 case NC_RESIZEW: | |
230 return 70; | |
231 case NC_RESIZEN: | |
232 return 138; | |
233 case NC_RESIZEALL: | |
234 return 52; | |
235 case NC_NO: | |
236 return 0; | |
237 case NC_HAND: | |
238 return 60; | |
239 case NC_APPSTARTING: | |
240 return 150; | |
241 case NC_HELP: | |
242 return 92; | |
243 default: | |
244 break; | |
245 } | |
246 #endif | |
247 return cursor_id; | |
248 } | |
249 | |
250 void Cursor::setNativeCursor(unsigned int cursor_id) { | |
251 #if !defined( WIN32 ) && !defined(__linux__) | |
252 return; | |
253 #endif | |
254 | |
255 // Check if a value in NativeCursors is requested | |
256 cursor_id = getNativeId(cursor_id); | |
257 | |
258 // Load cursor | |
259 #if defined( __linux__ ) | |
260 static Display* dsp = XOpenDisplay(NULL); | |
261 XCursor xCursor = XcursorShapeLoadCursor(dsp, cursor_id); | |
262 if (xCursor == 0) { | |
263 if (m_native_cursor != NULL) { | |
264 SDL_FreeCursor(m_native_cursor); | |
265 m_native_cursor = NULL; | |
266 } | |
267 FL_WARN(_log, "Cursor: No cursor matching cursor_id was found."); | |
268 return; | |
269 } | |
270 #elif defined( WIN32 ) | |
271 // Load native cursor | |
272 HCURSOR hIcon = LoadCursor(NULL, MAKEINTRESOURCE(cursor_id)); | |
273 if (hIcon == static_cast<HCURSOR>(0)) { | |
274 if (m_native_cursor != NULL) { | |
275 SDL_FreeCursor(m_native_cursor); | |
276 m_native_cursor = NULL; | |
277 } | |
278 FL_WARN(_log, "Cursor: No cursor matching cursor_id was found."); | |
279 return; | |
280 } | |
281 #endif | |
282 | |
283 WMcursor *cursor; | |
284 SDL_Cursor *curs2; | |
285 | |
286 // Allocate memory. Use SDL_FreeCursor to free cursor memory | |
287 cursor = (WMcursor *)SDL_malloc(sizeof(*cursor)); | |
288 curs2 = (SDL_Cursor *)SDL_malloc(sizeof *curs2); | |
289 | |
290 //-- Set up some default values -- | |
291 curs2->wm_cursor = cursor; | |
292 curs2->data = NULL; | |
293 curs2->mask = NULL; | |
294 curs2->save[0] = NULL; | |
295 curs2->save[1] = NULL; | |
296 curs2->area.x = 0; | |
297 curs2->area.y = 0; | |
298 curs2->area.w = 32; | |
299 curs2->area.h = 32; | |
300 curs2->hot_x = 0; | |
301 curs2->hot_y = 0; | |
302 | |
303 #if defined(WIN32) | |
304 cursor->curs = hIcon; | |
305 #ifndef _WIN32_WCE | |
306 cursor->ands = NULL; | |
307 cursor->xors = NULL; | |
308 #endif | |
309 | |
310 // Get hot spot | |
311 ICONINFO iconinfo; | |
312 if (GetIconInfo(hIcon, &iconinfo)) { | |
313 curs2->hot_x = static_cast<Sint16>(iconinfo.xHotspot); | |
314 curs2->hot_y = static_cast<Sint16>(iconinfo.yHotspot); | |
315 } | |
316 | |
317 #elif defined(__linux__) | |
318 cursor->x_cursor = xCursor; | |
319 XSync(dsp, false); | |
320 #endif | |
321 | |
322 m_native_cursor = curs2; | |
323 SDL_SetCursor(curs2); | |
324 | |
325 } | |
123 } | 326 } |