This would require it's own little sub-library. As you can see every OS requires a different structure, pointer or handler for the mouse cursor object - different from the Image objects or the ImageID that is used inside the drawing libraries.
It may not be so trivial; it seems that generally you could associate a cursor for each class of (and / or individual) gadgets, at least that's how I know it from the Windows API. As for animated cursors, they may have different features for each OS (play once, loop, on mouse click or something like that - idk) so this may also need some deeper consideration.
This would be my first "proposal" of how a cursor library could look like.
Code: Select all
; Mouse Cursor
; Pseudo PB library
Structure PBMouseCursor
OSHandle.i ; HCursor, *GtkCursor, *Cursor
flags.i ; 1=is animated
hotspot_x.i ;
hotspot_y.i ;
Image.i ;
List AssociatedGadgets.i() ; points to a structure or element that contains #Gadget and the default/old cursor value to be reset on FreeCursor()
List AssociatedWindows.i()
EndStructure
; following procedures would have to be implemented for each platform independently, currently that would be 3x at least
; "Minimum" functionality
Declare LoadCursor(#Cursor, File$ [, flags])
Declare CatchCursor(#Cursor, *Memory [, Length [, flags]])
Declare FreeCursor(#Cursor)
Declare CreateCursor(#Cursor, #Image, HotspotX, HotspotY [, flags])
Declare SetWindowCursor(#Window, #Cursor)
Declare SetGadgetCursor(#Gadget, #Cursor)
; More functionality:
Declare GetWindowCursor(#Window)
Declare GetGadgetCursor(#Gadget)
Declare GetCursorHotspotX(#Cursor)
Declare GetCursorHotspotY(#Cursor)
Declare GetCursorHeight(#Cursor)
Declare GetCursorWidth(#Cursor)
Declare GetCursorImage(#Cursor)
;Declare SetCursorImage(#Cursor, #Image)
; (...)
Declare SaveCursor(#Cursor, File$ [, format])
Declare ExportCursor(#Cursor [, format])
I count at least 6 procedure for basic functionality. When a cursor is released all windows and gadgets using it must have their associated cursor reset. This must also be considered by the window & gadget libraries when they free their windows and gadget to update the cursor association lists. So there would be work to be done on 3 libraries at least, including the new one.
The Image may have to be released, it may also only be present when creating the cursor with CreateCursor(); because the loadcursor() and catchcursor() would have to extract the image from the platform dependent cursor objects, most probably. So this is relatively labor intensive, especially when you want to have the image accessible for PB drawing. For example windows cursors, icons etc. are based on the bitmap format and bit-masks for transparency, but there are also possibly newer formats like png; and other platforms most probably use completely different image and mask formats. It may be easier to use the API to draw the cursor into a new image, instead of extracting it manually, when the cursor file is loaded or caught...
Not so trivial if you want to make it "perfect".
