Author: yuri
Date: 2009-06-22 11:01:01 -0700 (Mon, 22 Jun 2009)
New Revision: 6793
Log:
Add Win32 and X11 (need libXcursor ) cursor(Image*,int,int) implimentation
tested on Linux (x86, amd64) and mingw32
Modified:
trunk/configh.in
trunk/configure.in
trunk/src/Cursor.cxx
trunk/test/Makefile
trunk/test/cursor.cxx
Modified: trunk/configh.in
===================================================================
--- trunk/configh.in 2009-06-05 08:47:44 UTC (rev 6792)
+++ trunk/configh.in 2009-06-22 18:01:01 UTC (rev 6793)
@@ -63,6 +63,10 @@
anti-aliasing. (ignored if !USE_X11) */
#define USE_XFT 0
+/* Use Xcursor library for fltk::cursor(Image*,int,int) function.
+ (ignored if !USE_X11) */
+#define USE_XCURSOR 0
+
/* Use the Cairo library to draw everything. Ignored if !USE_X11
Currently only partly implemented, though line drawing looks
nice. For more info on Cairo see http://www.cairographics.org */
Modified: trunk/configure.in
===================================================================
--- trunk/configure.in 2009-06-05 08:47:44 UTC (rev 6792)
+++ trunk/configure.in 2009-06-22 18:01:01 UTC (rev 6793)
@@ -686,6 +686,14 @@
fi
fi
+ dnl Check for the XCursor library
+ AC_CHECK_HEADER(
+ X11/Xcursor/Xcursor.h,
+ AC_CHECK_LIB(Xcursor, XcursorImageLoadCursor,
+ AC_DEFINE(USE_XCURSOR)
+ LIBS="-lXcursor $LIBS",
+ AC_MSG_WARN("XCursor library not found"))
+ )
dnl Check for the Xshm extension unless disabled...
AC_ARG_ENABLE(xshm, [ --enable-xshm turn on MIT-SHM support
(default=no)])
if test x$enable_xshm == xyes; then
Modified: trunk/src/Cursor.cxx
===================================================================
--- trunk/src/Cursor.cxx 2009-06-05 08:47:44 UTC (rev 6792)
+++ trunk/src/Cursor.cxx 2009-06-22 18:01:01 UTC (rev 6793)
@@ -36,8 +36,12 @@
#include <fltk/Cursor.h>
#include <fltk/Window.h>
#include <fltk/x.h>
+#if defined(USE_X11) && defined(USE_XCURSOR)
+#include <X11/Xcursor/Xcursor.h>
+#endif
#include <fltk/draw.h>
#include <fltk/Color.h>
+#include <fltk/Image.h>
using namespace fltk;
@@ -104,6 +108,44 @@
return c;
}
+#ifdef USE_XCURSOR
+#warning we assume PixelType = 6 ARGB32 in test it is true for color images
+static XcursorImage* create_cursor_image(Image *cimg, int x, int y) {
+ XcursorImage *xcimage = XcursorImageCreate(cimg->w(),cimg->h());
+ XcursorPixel *dest;
+
+ xcimage->xhot = x;
+ xcimage->yhot = y;
+
+ dest = xcimage->pixels;
+ unsigned char *src = cimg->buffer();
+ //cimg->buffer_pixeltype()
+ for (int j = 0; j < cimg->h() ; ++j){
+ for (int i = 0; i < cimg->w() ; ++i){
+
+ *dest = (src[3] <<24) | (src[2] << 16) | (src[1] << 8) | src[0];
+ src += 4;
+ dest++;
+ }
+ }
+ return xcimage;
+}
+
+FL_API fltk::Cursor *fltk::cursor(Image *img, int x, int y) {
+ fltk::Cursor *c = new fltk::Cursor;
+ if(!xdisplay)fltk::open_display();
+ img->fetch();
+ XcursorImage *xcimage = create_cursor_image(img, x, y);
+ c->cursor = XcursorImageLoadCursor(xdisplay, xcimage);
+ XcursorImageDestroy (xcimage);
+
+ c->fontid = 0;
+ c->tableid = 0;
+ return c;
+}
+
+#endif //USE_XCURSOR
+
static fltk::Cursor arrow = {0,35};
static fltk::Cursor cross = {0,66};
static fltk::Cursor wait_c = {0,76};
@@ -234,6 +276,83 @@
return c;
}
+//thanx to gtk team for reference
+//http://www.dotnet247.com/247reference/msgs/13/66301.aspx
+#warning we assume PixelType = 6 ARGB32 in test it is true for color images
+
+#include <stdio.h>
+
+static HCURSOR create_cursor_from_image(Image *img, int x, int y)
+{
+ BITMAPV5HEADER bi;
+ HBITMAP hBitmap;
+ const int cw = 32, ch = 32; // Hm it seams only one size of cursors for
Windows
+
+ ZeroMemory(&bi,sizeof(BITMAPV5HEADER));
+ bi.bV5Size = sizeof(BITMAPV5HEADER);
+ bi.bV5Width = cw;
+ bi.bV5Height = ch;
+ bi.bV5Planes = 1;
+ bi.bV5BitCount = 32;
+ bi.bV5Compression = BI_BITFIELDS;
+ // The following mask specification specifies a supported 32 BPP
+ // alpha format for Windows XP.
+ bi.bV5RedMask = 0x00FF0000;
+ bi.bV5GreenMask = 0x0000FF00;
+ bi.bV5BlueMask = 0x000000FF;
+ bi.bV5AlphaMask = 0xFF000000;
+
+ HDC hdc;
+ hdc = GetDC(NULL);
+
+ // Create the DIB section with an alpha channel.
+ void *lpBits;
+ hBitmap = CreateDIBSection(hdc, (BITMAPINFO *)&bi, DIB_RGB_COLORS,(void
**)&lpBits, NULL, (DWORD)0);
+
+ ReleaseDC(NULL,hdc);
+
+ printf("Img format:%d\n",img->buffer_pixeltype());
+ int w = img->w() , h = img->h();
+ unsigned char* isrc = img->buffer();
+ DWORD *lpdwPixel = (DWORD *)lpBits;
+ for (int i=0;i<cw;i++)
+ for (int j=0;j<ch;j++)
+ {
+ fprintf(stderr,"%d %d\n",i,j);
+ unsigned char* src = isrc + 4*(j + w*(cw - i -1));
+ //*lpdwPixel = (src[0] << 24) | (src[1] << 16) | (src[2] << 8) | src[3];
+ *lpdwPixel = (src[3] << 24) | (src[2] << 16) | (src[1] << 8) | src[0];
+ lpdwPixel++;
+ }
+
+ // Create an empty mask bitmap
+ HBITMAP hMonoBitmap = CreateBitmap(cw,cw,1,1,NULL);
+
+ ICONINFO ii;
+ ii.fIcon = FALSE; // Change fIcon to TRUE to create an alpha icon
+ ii.xHotspot = x;
+ ii.yHotspot = y;
+ ii.hbmMask = hMonoBitmap;
+ ii.hbmColor = hBitmap;
+
+ // Create the alpha cursor with the alpha DIB section
+ HCURSOR hAlphaCursor = CreateIconIndirect(&ii);
+
+ DeleteObject(hBitmap);
+ DeleteObject(hMonoBitmap);
+
+ return hAlphaCursor;
+}
+
+FL_API fltk::Cursor *fltk::cursor(Image *img, int x, int y) {
+ img->fetch();
+ fltk::Cursor *c = new fltk::Cursor;
+ c->cursor = create_cursor_from_image(img, x, y);
+ c->resource = 0;
+ return c;
+}
+
+
static fltk::Cursor arrow = {TEXT(IDC_ARROW)};
static fltk::Cursor cross = {TEXT(IDC_CROSS)};
static fltk::Cursor wait_c = {TEXT(IDC_WAIT)};
Modified: trunk/test/Makefile
===================================================================
--- trunk/test/Makefile 2009-06-05 08:47:44 UTC (rev 6792)
+++ trunk/test/Makefile 2009-06-22 18:01:01 UTC (rev 6793)
@@ -248,6 +248,11 @@
$(CXX) -I.. $(CXXFLAGS) $< $(LINKFLTKGL) $(GLDLIBS) -o $@
$(POSTBUILD) $@ ../fltk/mac.r
+cursor$(EXEEXT): cursor.o
+ echo Linking $...@...
+ $(CXX) -I.. $(CXXFLAGS) $< $(LINKFLTKIMG) $(LDLIBS) -o $@
+ $(POSTBUILD) $@ ../fltk/mac.r
+
fullscreen$(EXEEXT): fullscreen.o ../lib/$(LIBPREFIX)fltk2_gl$(LIBSUFFIX)
echo Linking $...@...
$(CXX) -I.. $(CXXFLAGS) $< $(LINKFLTKGL) $(GLDLIBS) -o $@
Modified: trunk/test/cursor.cxx
===================================================================
--- trunk/test/cursor.cxx 2009-06-05 08:47:44 UTC (rev 6792)
+++ trunk/test/cursor.cxx 2009-06-22 18:01:01 UTC (rev 6793)
@@ -26,17 +26,22 @@
// This is a complete rewrite that replaces the old test program.
// Cursors are no longer identified by an integer.
+#include <config.h>
#include <fltk/run.h>
#include <fltk/events.h>
#include <fltk/Window.h>
#include <fltk/Cursor.h>
+#ifdef USE_XCURSOR
+#include <fltk/SharedImage.h>
+#include <stdio.h>
+#endif
using namespace fltk;
class CursorBox : public Widget {
- Cursor* cursor;
int handle(int);
public:
+ Cursor* cursor;
CursorBox(int x, int y, int w, int h, const char* name, Cursor* c)
: Widget(x,y,w,h,name), cursor(c) {}
};
@@ -62,13 +67,37 @@
{"CURSOR_NESW", CURSOR_NESW},
{"CURSOR_NO", CURSOR_NO},
{"CURSOR_NONE", CURSOR_NONE},
+#ifdef USE_XCURSOR
+ {"CUSTOM_CURSOR", 0},
+#endif
};
#define COUNT (sizeof(table)/sizeof(table[0]))
#define W 200
#define H 25
#define GAP 5
+#ifdef USE_XCURSOR
+int load_file(int argc, char** argv, int&i){
+ Image *img = SharedImage::get(argv[i]);
+ if( img ){
+ table[COUNT-1].cursor = fltk::cursor(img, 0, 0);
+ ++i;
+ return 1;
+ }
+ return 0;
+}
+
int main(int argc, char **argv) {
+ register_images();
+ int i;
+ if ( fltk::args(argc, argv, i, load_file) < argc -1) {
+ fprintf(stderr,"args return %d (%d)\n",i,argc);
+ return 1;
+ }
+ if(!table[COUNT-1].cursor)table[COUNT-1].cursor =
fltk::cursor(SharedImage::get("porsche.xpm"),32,32);
+#else
+int main(int argc, char **argv) {
+#endif
Window window(W+2*GAP, (H+GAP)*COUNT+GAP);
window.begin();
for (unsigned i = 0; i < COUNT; i++)
_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit