Re: [AD] Using system mouse cursor |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
Evert Glebbeek wrote:
No, although I may change it to system or native.
The reason is that this selects the OS native cursor. This is different
from the hardware cursor, which can also be an Allegro defined one.
I think the only difference between a custom hardware cursor and an OS
cursor should be if the respective mouse bitmap pointer is NULL or not.
Allegro shouldn't handle it any differently (ie. just pass the pointer,
NULL or not, to the mouse driver) and the driver should then decide if
it can accept a NULL pointer (OS cursor) or not.
+static BITMAP *create_mouse_pointer(char data[][DEFAULT_SPRITE_W])
It might be safer to pass (char *data, int w), so you're not restricting
the data to be a specific width.
That may be a good idea, although I don't think we want to keep track of
which predefined cursor has which width. Perhaps we should add an internal
mouse_sprite struct that stores the current data alongside a width/height
count?
You should be able to use:
sizeof(data[0]) / sizeof(data[0][0])
to get the width from a static 2D array (arranged as data[h][w]). Though
a struct would look cleaner.
Effectively, that means to disable the OS cursor? I can see where that
might be convenient.
What I'd propose though is to add a function (ugh, another one!) that
disables the OS cursor, so that Allegro's defaults (or the user specified
defaults) are always used.
I think that's overkill. As I said above, all the Allegro core should do
is store the bitmap pointers. Then when it's selected, the bitmap
pointer and id get passed to the mouse driver. If the mouse driver sees
a NULL bitmap and it can set a system cursor for the specified id, it
does so. Or else, it sets a custom cursor, irrespective of the id.
show_mouse(NULL) should just disable drawing any cursor no matter which
mode we're in.
Now, I suppose the base mouse handling system can take some of this so
the mouse drivers don't have to redo alot of the same code, but it
shouldn't need to be exposed to the API. So, like (psuedo code):
select_mouse_cursor()
{
int ok = FALSE;
// Try a system cursor
if(cursor[id] == NULL)
{
if(mouse_driver->set_system_cursor)
ok = mouse_driver->set_system_cursor(id);
}
// Try for a custom hardware cursor
if(!ok && mouse_driver->set_custom_cursor)
ok = mouse_driver->set_custom_cursor(cursor[id]);
// Fallback to a software cursor
if(!ok)
set_mouse_sprite(cursor[id]);
}
and...
show_mouse(bmp)
{
if(bmp == NULL)
{
mouse_driver->set_custom_cursor(invisible_cursor);
_mouse_screen = NULL;
}
}
... you are correct that this shouldn't really apply to memory bitmaps
(although I think the user who draws a mouse sprite on his memory bitmap
while also displaying an OS cursor on the screen should rethink his
design).
Well, don't forget we should be trying to make as little of a
distinction between an OS cursor and a hardware cursor as possible (the
latter should be enable whenever possible by Allegro, and only disabled
as needed). So if someone enables the hardware cursor, it means they
want to use a hardware cursor when available, though not necesarilly all
the time.
Of course, explicitly requesting an OS cursor (with a NULL bitmap) and
then trying to draw it to a memory bitmap will bring unexpected behavior
(the mouse pointer image changing from the system default to Allegro
default).
- Kitty Cat