Silverfrost Logo About Us | Contact Us

Re-sizing a graphics surface

It is often desirable to allow a graphics area to be re-sized by the user by altering the size of the window in which it is contained. Like all ClearWin+ controls, by default the drawing surface created by %gr will have a fixed size. However, %gr - Graphics Region can take a pivot, enabling it to be re-sized. Unlike other simple controls, the desired effect of re-sizing a graphics area is not obvious. ClearWin+ offers the choice of either re-drawing the image from scratch (with different contents if you wish) or of letting the system re-scale the existing graphics.

A %gr region will change size when the enclosing window is re-sized if it is preceded by a pivot format (%pv - Pivot) and provision has been made to re-draw the graphics by one of the following two methods:

1) If the user_resize option is given to %gr and a call-back function is supplied (i.e. %^gr[user_resize]) then, when the window is re-sized, the whole area will be blanked out and the call-back function will be called. It is assumed that this function will re-draw the contents of the box. The function can determine that a re-draw is required by calling clearwin_string@ using callback_reason. This will return the string resize if a re-size is occurring. The clearwin_info@ parameter GRAPHICS_RESIZING will also return 1 if a re-size is occurring, but this has been superseded by the general purpose callback_reason mechanism. The clearwin_info@ parameters GRAPHICS_WIDTH and GRAPHICS_DEPTH are used to return the new size of the area. For convenience the box is assumed to be re-sized immediately it is created, so it is only necessary to draw your graphics in one place in your code. Here is some sample code:

 INTEGER i,winio@

 INCLUDE <windows.ins>
 INTEGER x,y,resize
  CALL draw_line_between@(0,0,x,y,RGB@(255,0,0))

2) An alternative method for re-sizing a %gr region is to supply the option metafile_resize to the %gr format code. In this case, a record (stored in a Windows object known as a meta-file) of all graphics operations is made and the result is re-played at the new box size. This approach is clearly the easiest to program, however there are two factors to consider before using this technique.

a) The number of graphics operations being sent to the region must not be unreasonably large since each graphics call will be recorded for re-play. For example, a fractal drawing program (that continued to draw more detail for as long as it ran) could not use this technique because it would ultimately run out of memory.

b) Also some images may not respond well to such automatic re-scaling. This is because floating point co-ordinates are truncated to integers when the original image is drawn. When scaled, they are truncated a second time. In general, line drawing will still look good, but images drawn pixel by pixel are probably best re-sized by method 1.



Copyright © 1999-2018 Silverfrost Limited