28 #if defined( __unix__ )
29 #include <X11/Xcursor/Xcursor.h>
38 #include "util/structures/rect.h"
39 #include "util/time/timemanager.h"
40 #include "util/log/logger.h"
41 #include "video/imagemanager.h"
43 #include "animation.h"
45 #include "renderbackend.h"
61 #if defined( __unix__ )
64 typedef Cursor XCursor;
74 static Logger _log(LM_GUI);
77 m_cursor_id(NC_ARROW),
79 m_cursor_type(CURSOR_NATIVE),
80 m_drag_type(CURSOR_NONE),
81 m_native_cursor(NULL),
82 m_renderbackend(renderbackend),
90 m_invalidated(false) {
91 assert(m_timemanager);
96 m_cursor_type = CURSOR_NATIVE;
98 if (!SDL_ShowCursor(1)) {
103 m_cursor_image.
reset();
104 m_cursor_animation.
reset();
110 m_cursor_image = image;
111 m_cursor_type = CURSOR_IMAGE;
113 if (SDL_ShowCursor(0)) {
117 m_cursor_id = NC_ARROW;
118 m_cursor_animation.
reset();
124 m_cursor_animation = anim;
125 m_cursor_type = CURSOR_ANIMATION;
127 if (SDL_ShowCursor(0)) {
130 m_animtime = m_timemanager->
getTime();
132 m_cursor_id = NC_ARROW;
133 m_cursor_image.
reset();
139 m_cursor_drag_image = image;
140 m_drag_type = CURSOR_IMAGE;
141 m_drag_offset_x = drag_offset_x;
142 m_drag_offset_y = drag_offset_y;
144 m_cursor_drag_animation.
reset();
150 m_cursor_drag_animation = anim;
151 m_drag_type = CURSOR_ANIMATION;
152 m_drag_offset_x = drag_offset_x;
153 m_drag_offset_y = drag_offset_y;
155 m_drag_animtime = m_timemanager->
getTime();
157 m_cursor_drag_image.
reset();
161 m_drag_type = CURSOR_NONE;
167 m_cursor_drag_animation.
reset();
168 m_cursor_drag_image.
reset();
174 SDL_WarpMouse(m_mx, m_my);
182 void Cursor::invalidate() {
183 if (m_native_cursor != NULL) {
184 SDL_free(m_native_cursor->wm_cursor);
185 m_native_cursor->wm_cursor = NULL;
186 SDL_FreeCursor(m_native_cursor);
187 m_native_cursor = NULL;
189 m_invalidated =
true;
195 if (m_cursor_type != CURSOR_ANIMATION || m_cursor_type == CURSOR_IMAGE ) {
199 m_invalidated =
false;
202 SDL_GetMouseState(&m_mx, &m_my);
203 if ((m_cursor_type == CURSOR_NATIVE) && (m_drag_type == CURSOR_NONE)) {
209 if (m_drag_type == CURSOR_IMAGE) {
210 img = m_cursor_drag_image;
212 else if (m_drag_type == CURSOR_ANIMATION) {
213 int32_t animtime = (m_timemanager->
getTime() - m_drag_animtime) % m_cursor_drag_animation->
getDuration();
218 Rect area(m_mx + m_drag_offset_x + img->getXShift(), m_my + m_drag_offset_y + img->getYShift(), img->getWidth(), img->getHeight());
227 if (m_cursor_type == CURSOR_IMAGE) {
228 img2 = m_cursor_image;
230 else if (m_cursor_type == CURSOR_ANIMATION) {
231 int32_t animtime = (m_timemanager->
getTime() - m_animtime) % m_cursor_animation->
getDuration();
236 Rect area(m_mx + img2->getXShift(), m_my + img2->getYShift(), img2->getWidth(), img2->getHeight());
287 #elif defined( __unix__ )
333 #if defined( WIN32 ) || defined(__unix__)
338 #if defined( __unix__ )
339 static Display* dsp = XOpenDisplay(NULL);
340 XCursor xCursor = XcursorShapeLoadCursor(dsp, cursor_id);
342 if (m_native_cursor != NULL) {
343 SDL_FreeCursor(m_native_cursor);
344 m_native_cursor = NULL;
346 FL_WARN(_log,
"Cursor: No cursor matching cursor_id was found.");
349 #elif defined( WIN32 )
351 HCURSOR hIcon = LoadCursor(NULL, MAKEINTRESOURCE(cursor_id));
352 if (hIcon == static_cast<HCURSOR>(0)) {
353 if (m_native_cursor != NULL) {
354 SDL_FreeCursor(m_native_cursor);
355 m_native_cursor = NULL;
357 FL_WARN(_log,
"Cursor: No cursor matching cursor_id was found.");
366 cursor = (WMcursor *)SDL_malloc(
sizeof(*cursor));
367 curs2 = (SDL_Cursor *)SDL_malloc(
sizeof *curs2);
370 curs2->wm_cursor = cursor;
373 curs2->save[0] = NULL;
374 curs2->save[1] = NULL;
383 cursor->curs = hIcon;
391 if (GetIconInfo(hIcon, &iconinfo)) {
392 curs2->hot_x =
static_cast<Sint16
>(iconinfo.xHotspot);
393 curs2->hot_y =
static_cast<Sint16
>(iconinfo.yHotspot);
396 #elif defined(__unix__)
397 cursor->x_cursor = xCursor;
401 m_native_cursor = curs2;
402 SDL_SetCursor(curs2);
404 #endif // WIN32 || __unix__