Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » hardware enabled custom cursors

This thread is locked; no one can reply to it. rss feed Print
hardware enabled custom cursors
curriguy
Member #6,162
August 2005

hi.

I was wondering how one would go about using enable_hardware_cursor() AND having the OS draw my custom sprite as a cursor?

is this even possible?

I tried fiddling with

enable_hardware_cursor();
set_mouse_cursor_bitmap(MOUSE_CURSOR_ALLEGRO, CustomCursorBmp);
select_mouse_cursor(MOUSE_CURSOR_ALLEGRO);
show_mouse(screen);

but that didn't have the results I wanted.

besides it was kindova random stab at solving the problem.

It'd be helpful if anyone knew how to do this.

Tobias Dammers
Member #2,604
August 2002
avatar

TFM said:

Allegro offers three ways to display the mouse cursor:

* Standard Allegro cursor
Allegro is responsible for drawing the mouse cursor from a timer. Use set_mouse_sprite() and show_mouse() to define your own cursor and display it on the screen. You need to call scare_mouse()/unscare_mouse() to hide the mouse cursor whenever you draw to the screen.
* Custom operating system cursor (hardware cursor)
Allegro will let the operating system draw the mouse cursor. Use set_mouse_sprite() and show_mouse() (or show_os_cursor) to define your own cursor and display it on the screen. Not all graphics drivers are capable of this and some may only be able to display cursors upto a certain size. Allegro will fall back on its own cursor drawing if it cannot let the OS handle this. On some platforms, the hardware cursor is incompatible with get_mouse_mickeys() and it is therefor disabled by default. In such cases you need to call enable_hardware_cursor() to enable it explicitly.
* Default operating system cursor
Allegro will not draw its own cursor, but use the operating system default cursor. You can use the select_mouse_cursor() function to select the cursor shape to display. As with custom operating system cursors, you need to call enable_hardware_cursor() before you can use this. Or you can use the low level show_os_cursor() function.

(emphasis mine)

---
Me make music: Triofobie
---
"We need Tobias and his awesome trombone, too." - Johan Halmén

miran
Member #2,407
June 2002

I think you also need to call set_mouse_sprite() somewhere, but I'm not 100% sure. Anyway, if you want some special kind of custom cursor, you can kiss hardware enabled cursros goodbye. Like for example if you want a cursor that's translucent, has a shadow, a glow, or something like that...

--
sig used to be here

curriguy
Member #6,162
August 2005

hmm okay yeah I should have read that more carefully, I guess my system just can't handle it. And even if it could, I think what you've bolded is more than enough reason to not use this system in general.

I guess I'll hack out a sluggish reduce mouse-flicker hack like everyone else.

miran
Member #2,407
June 2002

Quote:

I guess I'll hack out a sluggish reduce mouse-flicker hack like everyone else.

Hack? Sluggish? ???

--
sig used to be here

Tobias Dammers
Member #2,604
August 2002
avatar

Have you implemented a screen buffering system yet? If so, then all you need to do is draw any sprite you like onto the back buffer, at the current mouse position, after rendering a frame, but before flipping / blitting. You might want to add a "hotspot" offset, though.

---
Me make music: Triofobie
---
"We need Tobias and his awesome trombone, too." - Johan Halmén

curriguy
Member #6,162
August 2005

Tobias,

actually that's exactly what I'm doing. And That's what I meant by "sluggish" because the mouse is less responsive when using this method. It seems to be working fine. What exactly do you mean by the "hot spot" effect?

thanks for the info everyone

Tobias Dammers
Member #2,604
August 2002
avatar

Offset, not effect. Quite simple. With a standard "arrow" type mouse pointer, the click position is at the tip of the arrow, which is the top-left corner of the sprite. For other cursors, though (e.g. a cross), it's not. To compensate for that, you define a "hotspot", that is, an x- and y-offset to add to (or rather subtract from) the mouse position before blitting. For example, if your "hotspot" is at position )(4, 8) on the mouse sprite, then you'd draw your sprite at mouse_x-4 and mouse_y-8.

And it's always as responsive as your game. If your frame rate drops, so does the mouse responsiveness.

---
Me make music: Triofobie
---
"We need Tobias and his awesome trombone, too." - Johan Halmén

Evert
Member #794
November 2000
avatar

Quote:

I guess my system just can't handle it.

As far as I know, all graphics drivers except for fullscreen Windows DirectX can do hardware cursors (you can complain to Microsoft).

Quote:

And even if it could, I think what you've bolded is more than enough reason to not use this system in general.

If you don't need mouse mickeys when the cursor is outside of your window (and the hardware cursor is available), then it is the best way to show the cursor.
To use it, just call enable_hardware_cursor(), then check gfx_capabilities after calling show_mouse(). It will tell you if you actually got a hardware cursor or not. Example:

enable_hardware_cursor();
set_mouse_sprite(some_sprite);
show_mouse(screen);
if (gfx_capabilities & GFX_HW_CURSOR) {
   celebrate();
} else {
   cry();
}

Go to: