The %gr call-back function

In this section:

Simple graphics operations can be performed without the use of a call-back function. However, you will need a call-back function if you want to respond to mouse changes, or to icon movements, or if you want to redraw in response to a re-size event.

If a call-back function is supplied with %gr (Graphics Region), it will be called for a variety of reasons, conveniently distinguished using CLEARWIN_STRING@('CALLBACK_REASON'). Here is the full set of reasons for calling the call-back function:



These reasons are given after the corresponding mouse button has been pressed and released. In FULL_MOUSE_INPUT mode, these call-back reasons occur when the key is pressed.



These reasons only occur if the option FULL_MOUSE_INPUT is used with %gr. They occur when the corresponding mouse button is released.



This reason is given when two successive left mouse clicks have occurred within the interval defined as a double click. Individual mouse LEFT_MOUSE_CLICK events will also be generated.



Given when the USER_RESIZE option is used and the window has just been created or re-sized. Usually the call-back function will draw or re-draw the image.



Given when an icon has been dragged and dropped on to the graphics area.



Many systems are configured so that the middle mouse button is inactive, even though it is physically present on the mouse. For this reason it is better to avoid relying on this button.

Once the reason for the call-back has been established, additional information can be obtained by calling CLEARWIN_INFO@. You can use GRAPHICS_MOUSE_X and GRAPHICS_MOUSE_Y to obtain the pixel co-ordinates of the mouse event that caused the call-back. Also GRAPHICS_MOUSE_FLAGS gives full information about the state of the mouse keys (this is most useful when the FULL_MOUSE_INPUT %gr option is used). The mouse flags are bitwise significant as follows:


Left button pressed


Right button pressed


Shift key pressed


Control key pressed


Middle button pressed



Using the FULL_MOUSE_INPUT option it is possible to respond to a mouse press by altering parts of your image, reversing these changes when the key is released again. This can give a very dynamic feel to your program. Remember, however, that any operations you perform at this point should not take too long, otherwise the mouse response will become sluggish.



Copyright © 1999-2024 Silverfrost Limited