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:
MOUSE_LEFT_CLICK |
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. |
|
MOUSE_LEFT_RELEASE |
These reasons only occur if the option FULL_MOUSE_INPUT is used with %gr. They occur when the corresponding mouse button is released. |
|
MOUSE_DOUBLE_CLICK |
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. |
|
RESIZE |
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. |
|
DRAG_AND_DROP |
Given when an icon has been dragged and dropped on to the graphics area. |
Tip |
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:
1 |
Left button pressed |
|
2 |
Right button pressed |
|
4 |
Shift key pressed |
|
8 |
Control key pressed |
|
16 |
Middle button pressed |
Tip |
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. |