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"
42 #include "imagepool.h"
43 #include "animationpool.h"
44 #include "animation.h"
46 #include "renderbackend.h"
62 #if defined( __unix__ )
65 typedef Cursor XCursor;
75 static Logger _log(LM_GUI);
78 m_cursor_id(NC_ARROW),
80 m_cursor_type(CURSOR_NATIVE),
81 m_drag_type(CURSOR_NONE),
82 m_native_cursor(NULL),
83 m_renderbackend(renderbackend),
93 m_invalidated(false) {
94 assert(m_timemanager);
95 set(m_cursor_type, m_cursor_id);
99 m_cursor_id = cursor_id;
100 m_cursor_type = ctype;
102 SDL_GetMouseState(&mx, &my);
104 if (ctype == CURSOR_NATIVE) {
105 if (!SDL_ShowCursor(1)) {
107 SDL_WarpMouse(mx, my);
111 if (SDL_ShowCursor(0)) {
113 SDL_WarpMouse(mx, my);
115 if (ctype == CURSOR_ANIMATION) {
116 m_animtime = m_timemanager->
getTime();
119 m_invalidated =
false;
125 m_drag_offset_x = drag_offset_x;
126 m_drag_offset_y = drag_offset_y;
127 if (ctype != CURSOR_NONE) {
128 if (ctype == CURSOR_ANIMATION) {
129 m_drag_animtime = m_timemanager->
getTime();
134 void Cursor::invalidate() {
135 if (m_native_cursor != NULL) {
136 SDL_free(m_native_cursor->wm_cursor);
137 m_native_cursor->wm_cursor = NULL;
138 SDL_FreeCursor(m_native_cursor);
139 m_native_cursor = NULL;
141 m_invalidated =
true;
147 set(m_cursor_type, m_cursor_id);
150 SDL_GetMouseState(&m_mx, &m_my);
151 if ((m_cursor_type == CURSOR_NATIVE) && (m_drag_type == CURSOR_NONE)) {
157 if (m_drag_type == CURSOR_IMAGE) {
158 img = &m_imgpool->getImage(m_drag_id);
159 }
else if (m_drag_type == CURSOR_ANIMATION) {
160 Animation& anim = m_animpool->getAnimation(m_drag_id);
165 Rect area(m_mx + m_drag_offset_x + img->getXShift(), m_my + m_drag_offset_y + img->getYShift(), img->getWidth(), img->getHeight());
166 m_renderbackend->pushClipArea(area,
false);
168 m_renderbackend->popClipArea();
173 if (m_cursor_type == CURSOR_IMAGE) {
174 img = &m_imgpool->getImage(m_cursor_id);
175 }
else if (m_cursor_type == CURSOR_ANIMATION) {
176 Animation& anim = m_animpool->getAnimation(m_cursor_id);
181 Rect area(m_mx + img->getXShift(), m_my + img->getYShift(), img->getWidth(), img->getHeight());
182 m_renderbackend->pushClipArea(area,
false);
184 m_renderbackend->popClipArea();
231 #elif defined( __unix__ )
277 #if defined( WIN32 ) || defined(__unix__)
282 #if defined( __unix__ )
283 static Display* dsp = XOpenDisplay(NULL);
284 XCursor xCursor = XcursorShapeLoadCursor(dsp, cursor_id);
286 if (m_native_cursor != NULL) {
287 SDL_FreeCursor(m_native_cursor);
288 m_native_cursor = NULL;
290 FL_WARN(_log,
"Cursor: No cursor matching cursor_id was found.");
293 #elif defined( WIN32 )
295 HCURSOR hIcon = LoadCursor(NULL, MAKEINTRESOURCE(cursor_id));
296 if (hIcon == static_cast<HCURSOR>(0)) {
297 if (m_native_cursor != NULL) {
298 SDL_FreeCursor(m_native_cursor);
299 m_native_cursor = NULL;
301 FL_WARN(_log,
"Cursor: No cursor matching cursor_id was found.");
310 cursor = (WMcursor *)SDL_malloc(
sizeof(*cursor));
311 curs2 = (SDL_Cursor *)SDL_malloc(
sizeof *curs2);
314 curs2->wm_cursor = cursor;
317 curs2->save[0] = NULL;
318 curs2->save[1] = NULL;
327 cursor->curs = hIcon;
335 if (GetIconInfo(hIcon, &iconinfo)) {
336 curs2->hot_x =
static_cast<Sint16
>(iconinfo.xHotspot);
337 curs2->hot_y =
static_cast<Sint16
>(iconinfo.yHotspot);
340 #elif defined(__unix__)
341 cursor->x_cursor = xCursor;
345 m_native_cursor = curs2;
346 SDL_SetCursor(curs2);
348 #endif // WIN32 || __unix__