In this section:
Consider the task of writing a simple paint program. Such programs often allow the user to hold down the left mouse key in order to open up a box that is used to select an area. Alternatively, the effect of dragging the mouse could be to create a line rather than a box.
%gr drawing surfaces have an associated 'selection mode'. This mode tells ClearWin+ what to do if the mouse is dragged (by the left button) over the area. The mode can be set using the BOX_SELECTION, LINE_SELECTION or FREE_SELECTION options on the %gr (Graphics Region) format code. The mode can also be changed dynamically using the SET_GRAPHICS_SELECTION@ function. This operates on the current drawing surface. The argument to this function takes the following values:
default - no selection
invisible box selection
When a selection is enabled, dragging the mouse with the left button depressed opens an XOR drawn box or line. A program obtains the co-ordinates using GET_GRAPHICS_SELECTED_AREA@. Typically you would call this function on the release of the left mouse (or possibly in response to a button press) so that the program would respond to the final position of the line or box.
The following example uses BOX_SELECTION. When the left mouse button is released, the program draws a diagonal line using the box position and dimensions. If the shift key is held down, a copy of the box is produced instead of a line. Alternatively, if the control key is held down, an ellipse is drawn to fill the box.
INTEGER FUNCTION gr_func()