Silverfrost Logo About Us | Contact Us
 

Printer graphics

Here is a simple program that uses the standard call-back GPRINTER_OPEN to repond to a button press and draws a diagonal line across the entire page. GPRINTER_OPEN creates a drawing surface and an additional call-back argument is used to contain code to draw to this surface.

      WINAPP
      INTEGER i,winio@
      EXTERNAL test
      i=winio@('%^bt[Open]','GPRINTER_OPEN',test)
      END
c---
      INTEGER FUNCTION test()
      INCLUDE <windows.ins>
      INTEGER xmax,ymax
      CALL get_graphical_resolution@(xmax,ymax)
      CALL draw_line_between@(0,0,xmax-1,ymax-1,15)
      test=2
      END

Notice that the call to get_graphical_resolution@ will work for all types of drawing surfaces. This means that the same code can be used to generate graphics output to the screen and to the printer.

Notice also that by default the drawing surface for the printer uses VGA rather than RGB mode. So in this example, the colour for draw_line_between@ is provided as a colour index (15 represents intense white in this program) rather than an RGB value. Normally RGB mode is preferred and this requires a prior call of use_rgb_colours@(0,.true.) (see the example in Using a metafile to print multiple copies).

By using open_printer@ etc., it is possible to have two drawing surfaces, one attached to the screen and the other to a graphics printer or plotter. In the following example one handle is attached to a %gr region (a screen drawing surface) whilst a second handle is attached to a graphics printer drawing surface.

  INTEGER ctrl,hnd1,hnd2
  DATA hnd1,hnd2/1,2/
  i=winio@('%`gr&',400L,300L,hnd1)
  i=winio@('%ww%lw',ctrl)
  j=select_graphics_object@(hnd1)
  CALL draw_line_between@(100,100,300,200,15)
  k=open_printer@(hnd2)
  j=select_graphics_object@(hnd2)
  CALL draw_filled_ellipse@(200,150,75,50,2)
  k=close_printer@(hnd2) 

As usual, open_printer@ generates a standard "Open Printer" dialog box from which the user selects a graphics printer or plotter. Subsequent calls to ClearWin+ drawing routines are written to this drawing surface and the output is generated when the ClearWin+ routine close_printer@ or the routine new_page@ is called.

Notes:

open_printer@ etc. may be used independently of winio@.

In the above example, j and k can be used to test for the success of the associated function calls.

 

 

Copyright © 1999-2017 Silverfrost Limited