Re: [AD] Using system mouse cursor

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


Evert Glebbeek wrote:
Don't the Allegro docs state that Allegro will use a hardware cursor when possible? I think this could be extended to mean a hardware or system cursor on modern platforms. If it's possible to use the system's native pointer, then we don't even need to draw the sprite ourselves in those cases, and we probably don't need to scare the mouse either.

I completely agree, and that's the main reason for doing this (so we don't have to draw to the screen in a timer (which is dangerous), and so the program doesn't waste time hiding and showing the mouse, potentially causing droppings). The problem seems to be that you need a somewhat recent version of X to be able to use non-monochrome mouse pointers.

All you need to do is make a pixmap of the right size, copy the mouse bitmap data into it, and set it as the mouse/cursor image. Allegro currently does this to hide the mouse image in X:

/* Create invisible X cursor.  */
pixmap = XCreatePixmap(_xwin.display, _xwin.window, 1, 1, 1);
if (pixmap != None) {
   GC temp_gc;
   XColor color;

   gcmask = GCFunction | GCForeground | GCBackground;
   gcvalues.function = GXcopy;
   gcvalues.foreground = 0;
   gcvalues.background = 0;
   temp_gc = XCreateGC(_xwin.display, pixmap, gcmask, &gcvalues);
   XDrawPoint(_xwin.display, pixmap, temp_gc, 0, 0);
   XFreeGC(_xwin.display, temp_gc);
   color.pixel = 0;
   color.red = color.green = color.blue = 0;
   color.flags = DoRed | DoGreen | DoBlue;
_xwin.cursor = XCreatePixmapCursor(_xwin.display, pixmap, pixmap, &color, &color, 0, 0);
   XDefineCursor(_xwin.display, _xwin.window, _xwin.cursor);
   XFreePixmap(_xwin.display, pixmap);
}
else {
   _xwin.cursor = XCreateFontCursor(_xwin.display, _xwin.cursor_shape);
   XDefineCursor(_xwin.display, _xwin.window, _xwin.cursor);
}

I don't think that should be too hard to extend to use data from a bitmap if multi-colored cursors are available.

- Kitty Cat




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/