Silverfrost Logo About Us | Contact Us
 

Graphics format %gr[options]

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 July 2013) 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, 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 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

Options specifying the behaviour of the graphics area as it is re-sized. See later in this chapter.

RGB_COLOURS

Selects RGB colour mode. This is the default for ClearWin+ releases after July 2013.

VGA_COLOURS

Selects VGA colour mode. This is the default for ClearWin+ releases before July 2013.

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 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 3d styles to re-align the %gr border.


%gr 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 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 and to place the graphics code in the call-back. This approach is usually preferred unless you need to use %lw 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 and a third argument is required to input an integer (called a handle) that you provide. This handle 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))

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.

 

 

Copyright © 1999-2017 Silverfrost Limited