In this section:
There are two colour modes for ClearWin+ drawing routines: (a) VGA colour mode, designed to emulate the EGA and VGA palette registers and used to port legacy code to Windows and (b) RGB colour mode, the native Windows colour mode.
Initially, to assist in the porting of legacy code, the default colour mode was set as VGA colour mode. However, it is recommended that all new programs should use RGB colour mode and (from FTN95 version 7.00) this is the default. There are three ways to change the colour mode.
1. The default is changed to VGA colour mode by calling SET_RGB_COLOURS_DEFAULT@(0) at the beginning of the program.
2. Alternatively, when creating a drawing surface using %gr (Graphics Region), you can include the option VGA_COLOURS (see below).
3. In either case you can change the colour mode for a particular drawing surface by calling USE_RGB_COLOURS@.
%gr (Graphics Region) can be followed by a list of options that is any valid combination of the following:
BLACK, WHITE, RED, BLUE, YELLOW, GREY (or GRAY) |
Specifies the initial background colour of the drawing surface. Otherwise this defaults to the background colour of the surrounding window. |
COLOUR=#rrggbb COLOR=#rrggbb |
Specifies the intial background colour of the drawing surface where rr represents hexadecimal digits for the red component etc.. |
METAFILE_RESIZE USER_RESIZE KEEP_ASPECT_RATIO |
Options specifying the behaviour of the graphics area as it is re-sized. |
RGB_COLOURS |
Selects RGB colour mode. This is the default for ClearWin+ releases from FTN95 version 7.00. |
VGA_COLOURS |
Selects VGA colour mode. This is the default for ClearWin+ releases before FTN95 version 7.00. |
FULL_MOUSE_INPUT |
Specifies that mouse movements and mouse button releases should be notified to the call-back function, not just clicks and double clicks. |
POPUP |
Used with FULL_MOUSE_INPUT in order to enable a %pm (Popup Menu) popup menu that is otherwise disabled. |
BOX_SELECTION LINE_SELECTION FREE_SELECTION |
Specifies the initial selection mode, that controls the behaviour when the user presses the left mouse button and drags the mouse over the graphics area. These options are useful for interactive programs. |
USER_SURFACE |
A Win32-only option to enable software to access the in-memory copy of the graphics area so as to modify it at the highest possible speed. This option is particularly useful for image processing software. |
FLUSH |
Used with %sy (Dialog Style) 3d styles to re-align the %gr border. |
SMOOTH8 | Use 8x8 box filter box filter anti-aliasing |
HSCROLL, VSCROLL |
Adds scrolling options. Previously %vx and %hx could be used with %gr but provided scroll bars as separate controls. The new options create scroll bars that are built into the control and as a result have all of the expected "hot track" characteristics of a scroll bar. %gr[hscroll] uses the same data as %hx whilst %gr[vscroll] uses the same data as %vx. This is accommodated by presenting %hx with its data before %gr[hscroll] and %vx with its data before %gr[vscroll]. The only restriction is that the %hx and %vx information must not include callback functions. For example:
integer iw,page,range,pos The values used for 'page' and 'range' determine the y offset of the origin when drawing to the graphics region. Typically the adjustment could be y = y-pos*range. In this way, %gr can be used to display a snapshot of a larger graph by redrawing the area required. Alternatively a full sized graphics region could be created off-screen, with areas copied to the %gr region as required. |
%gr (Graphics Region) creates a 'control' that is a rectangular graphics area (a drawing surface) that will be filled by subsequent calls to ClearWin+ drawing routines. In the absence of %gr, using drawing surface routines causes ClearWin+ to create a separate window containing a drawing surface together with a button to close the window. This is analogous to the automatic creation of a ClearWin window for standard Fortran I/O. The various options to the %gr format are explained in this and subsequent sections of the chapter.
%gr takes two arguments that provide the pixel width and height of a rectangular area. You may want to vary these values depending on the resolution of the user's screen. The pixel width and depth of the screen is obtained by calling CLEARWIN_INFO@ using SCREEN_WIDTH and SCREEN_DEPTH.
The %gr options consisting of simple colour names (such as black) supply an initial background colour that would otherwise default to the background colour of the surrounding window.
For example:
INTEGER ctrl,i
i=winio@('%ww%gr[black]&',400L,300L)
i=winio@('bt[OK]%lw',ctrl)
CALL draw_line_between@(100,100,300,200,RGB@(255,0,0))
This will draw a red line on a black background. In this example, %lw (Leave Window Open) has been used to leave the window open so that code to draw to the drawing surface can follow. A alternative approach is to provide a startup call-back function using %sc (OnShow Callback) and to place the graphics code in the call-back. This approach is usually preferred unless you need to use %lw (Leave Window Open) for other reasons.
If more than one drawing surface is to be drawn (either within one window, or on different windows) then a grave accent modifier is supplied to %gr (Graphics Region) and a third argument is required to input an integer identifier that you provide. This identifier is used in the subroutine SELECT_GRAPHICS_OBJECT@ in order to select the current drawing surface.
The following example creates two drawing surfaces and draws to each in turn.
INTEGER ctrl,hnd1,hnd2
DATA hnd1,hnd2/1,2/
c ----Graphics handles are input values to %gr ---
c
i=winio@('%`gr&',400L,300L,hnd1)
i=winio@('%`gr&',400L,300L,hnd2)
i=winio@('%ww%lw',ctrl)
i=select_graphics_object@(hnd1)
CALL draw_line_between@(100,100,300,200,RGB@(0,0,255))
i=select_graphics_object@(hnd2)
CALL draw_filled_ellipse@(200,150,75,50,RGB@(255,0,0))
As an alternative to using %`gr, you can can call GET_CURRENT_GRAPHICS_REGION@ immediately after the %gr has been used to return a HANDLE to the surface. You can then use SELECT_GRAPHICS_REGION@ to select that surface.
Other drawing surfaces can be set up to write an image to memory or to write output to the printer. The graphics calls in the above program can also be used on such surfaces. Details appear later in this chapter and in Using the printer.