In this section:
It is possible to supply the user with more interesting ways to interact with your graphics area than merely clicking with the mouse. A %gr (Graphics Region) drawing surface can have an icon resource 'attached' to it. The icon can be moved freely around the graphics window with the mouse. Control of the icon is maintained by the call-back function attached to %gr.
ADD_GRAPHICS_ICON@ is used to attach an icon resource (defined in a resource script) to the current screen drawing surface. A NAME argument is used to stipulate the resource. X and Y variables are used as arguments that hold the initial location of the image. These variables also hold the new position when the image is moved. The call-back function for %gr can modify the X and Y values if required. In this way it is possible to 'lock' the image on to a horizontal or vertical plane by repeatedly setting either X or Y to a constant value.
The width and height arguments of ADD_GRAPHICS_ICON@ should be set to zero except when the icon image is less than 32x32 pixels. A smaller icon is constructed by starting at the top-left corner and by filling the remaining unused area with the 'transparent' colour. In this case, if you do not specify the correct size of the icon then the unused area will be detected by the mouse.
CLEARWIN_INFO@('DRAGGED_ICON') returns the handle of the icon that has moved. This handle is initially obtained as the value returned by ADD_GRAPHICS_ICON@.
When the icon is dropped, CLEARWIN_INFO@('DROPPED_ICON') returns the handle of the associated icon. A graphics icon can be removed with a call to REMOVE_GRAPHICS_ICON@.
The following program draws a horizontal scale with an icon that can be dragged across it. The resource script attaches an icon file to the 'arrow_r' resource in the program. The Windows API function ClipCursor is used to provide a clipping rectangle for the mouse cursor when the left mouse button is held down over the icon. The Silverfrost intrinsic CORE4 is used to pass a NULL pointer to ClipCursor.
INTEGER FUNCTION start_cb()
INTEGER FUNCTION gr_cb()