diff options
| author | Pierre Ossman <ossman@cendio.se> | 2014-06-16 11:17:57 +0000 |
|---|---|---|
| committer | Pierre Ossman <ossman@cendio.se> | 2014-06-16 11:17:57 +0000 |
| commit | 332dc1b7acfedbf80b71cc6f538a14f24d435df3 (patch) | |
| tree | f690751dd9b592b2b00b4d54c803f98073d74b97 /src/Fl_x.cxx | |
| parent | b4013ef60225b91af17d664b0938a074b7115202 (diff) | |
Add method to set any custom cursor, based on a Fl_RGB_Image object.
Also change our fallback cursors to use this method, so that fallback
cursors are handled in a platform independent manner. STR #2660.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@10196 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/Fl_x.cxx')
| -rw-r--r-- | src/Fl_x.cxx | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/src/Fl_x.cxx b/src/Fl_x.cxx index 3896777cd..b2b0f705a 100644 --- a/src/Fl_x.cxx +++ b/src/Fl_x.cxx @@ -62,6 +62,11 @@ static int xfixes_event_base = 0; static bool have_xfixes = false; # endif +# include <X11/cursorfont.h> + +# if HAVE_XCURSOR +# include <X11/Xcursor/Xcursor.h> +# endif static Fl_Xlib_Graphics_Driver fl_xlib_driver; static Fl_Display_Device fl_xlib_display(&fl_xlib_driver); Fl_Display_Device *Fl_Display_Device::_display = &fl_xlib_display;// the platform display @@ -2600,6 +2605,94 @@ void Fl_Window::size_range_() { //////////////////////////////////////////////////////////////// +int Fl_X::set_cursor(Fl_Cursor c) { + unsigned int shape; + Cursor xc; + + switch (c) { + case FL_CURSOR_ARROW: shape = XC_left_ptr; break; + case FL_CURSOR_CROSS: shape = XC_tcross; break; + case FL_CURSOR_WAIT: shape = XC_watch; break; + case FL_CURSOR_INSERT: shape = XC_xterm; break; + case FL_CURSOR_HAND: shape = XC_hand2; break; + case FL_CURSOR_HELP: shape = XC_question_arrow; break; + case FL_CURSOR_MOVE: shape = XC_fleur; break; + case FL_CURSOR_NS: shape = XC_sb_v_double_arrow; break; + case FL_CURSOR_WE: shape = XC_sb_h_double_arrow; break; + case FL_CURSOR_NE: shape = XC_top_right_corner; break; + case FL_CURSOR_N: shape = XC_top_side; break; + case FL_CURSOR_NW: shape = XC_top_left_corner; break; + case FL_CURSOR_E: shape = XC_right_side; break; + case FL_CURSOR_W: shape = XC_left_side; break; + case FL_CURSOR_SE: shape = XC_bottom_right_corner; break; + case FL_CURSOR_S: shape = XC_bottom_side; break; + case FL_CURSOR_SW: shape = XC_bottom_left_corner; break; + default: + return 0; + } + + xc = XCreateFontCursor(fl_display, shape); + XDefineCursor(fl_display, xid, xc); + XFreeCursor(fl_display, xc); + + return 1; +} + +int Fl_X::set_cursor(const Fl_RGB_Image *image, int hotx, int hoty) { +#if ! HAVE_XCURSOR + return 0; +#else + XcursorImage *cursor; + Cursor xc; + + if ((hotx < 0) || (hotx >= image->w())) + return 0; + if ((hoty < 0) || (hoty >= image->h())) + return 0; + + cursor = XcursorImageCreate(image->w(), image->h()); + if (!cursor) + return 0; + + const uchar *i = (const uchar*)*image->data(); + XcursorPixel *o = cursor->pixels; + for (int y = 0;y < image->h();y++) { + for (int x = 0;x < image->w();x++) { + switch (image->d()) { + case 1: + *o = (0xff<<24) | (i[0]<<16) | (i[0]<<8) | i[0]; + break; + case 2: + *o = (i[1]<<24) | (i[0]<<16) | (i[0]<<8) | i[0]; + break; + case 3: + *o = (0xff<<24) | (i[0]<<16) | (i[1]<<8) | i[2]; + break; + case 4: + *o = (i[3]<<24) | (i[0]<<16) | (i[1]<<8) | i[2]; + break; + } + i += image->d(); + o++; + } + i += image->ld(); + } + + cursor->xhot = hotx; + cursor->yhot = hoty; + + xc = XcursorImageLoadCursor(fl_display, cursor); + XDefineCursor(fl_display, xid, xc); + XFreeCursor(fl_display, xc); + + XcursorImageDestroy(cursor); + + return 1; +#endif +} + +//////////////////////////////////////////////////////////////// + // returns pointer to the filename, or null if name ends with '/' const char *fl_filename_name(const char *name) { const char *p,*q; |
