In this section:
You can access some features of GDI+ using a %gr (Graphics Region) format code. In particular you can utilise anti-aliasing and use opacity. Simply turning on anti-aliasing will give your graphics a much smoother look. In some cases you may need to do some work to get the most out of these features. The %gr options [smooth4] and [smooth8] provide a simple and direct way to add anti-aliased smoothing to existing code. smooth4 uses an 8x4 box filter whilst smooth8 uses an 8x8 box. It is possible that simply adding a smooth4 or smooth8 option to %gr will provide the functionality required. ClearWin+, however, allows more control if it is required. The additional functionality that GDI+ bring falls into broadly two main areas: Anti-aliasing and opacity.
Anti-aliasing is a process whereby pixels next to drawn lines are modified to produce a smoother effect. For example, if a circle was drawn in red the standard algorithm will produce a set of red pixels that approximate a circle. The actual pixels coloured red will appear jagged when view closely. When the same pixel is drawn using an anti-aliased algorithm then extra coloured pixels are used to give the illusion of a smoother line. On a screen display the effects can be dramatic with the anti-aliased graphics looking much cleaner and less jagged.
The following simple program illustrates how turning on anti-aliasing can improve a program's output. More precise control can be achieved using the SET_SMOOTHING_MODE@ library routine.
PROGRAM main use clrwin INTEGER iw integer ctrl integer last_x, last_y, mid_y integer new_x, new_y integer :: parameter, width = 500, height = 250, gutter = 20 real sinx iw=winio@('%ca[sin(x)]&') ! set up the surface to draw onto. Remove [smooth4] to see what anti-aliasing has given you iw=winio@('%gr[smooth4]&', width, height) iw=winio@('%lw', ctrl) ! draw axes mid_y = height / 2 call draw_line_between@(gutter, gutter, gutter, width-gutter, 0 ) call draw_line_between@(gutter, mid_y, width-gutter, mid_y, 0 ) do i = 0,width-(2*gutter) ! make the width of the x-axis span 0..2pi. REAL(width-(2*gutter) is the width of that axis sin_x = sin((i/REAL(width-(2*gutter)))*2*3.1415926) new_y = mid_y + sin_x*(mid_y-gutter) if (i > 0) then call draw_line_between@(gutter+i-1, last_y, gutter+i, new_y, RGB@(255,0,0) ) end if last_y = new_y end do END PROGRAM main
By varying opacity you can allow some of the background to show through when you draw onto a surface. you can either set the overall opacity through a call to SET_OPACITY@ or you can set it on a call by call basis using the nARGB@ function to create the colour. In the example below two sets of three circles are overlapped. The right hand set has the opacity set. The left hand set has just one circle drawn with opacity.
PROGRAM main use clrwin INTEGER iw integer ctrl real sinx iw=winio@('%ca[ATV]&') iw=winio@('%gr[smooth4]&', 220, 110) iw=winio@('%lw', ctrl) call draw_filled_ellipse@(40, 40, 30, 30, RGB@(255,0,0) ) call draw_filled_ellipse@(70, 40, 30, 30, RGB@(0,255,0) ) ! draw this circle with opacity call draw_filled_ellipse@(55, 70, 30, 30, nARGB@(192,0,0,255) ) ! set general opacity to 50% call set_opacity@(128) call draw_filled_ellipse@(150, 40, 30, 30, RGB@(255,0,0) ) call draw_filled_ellipse@(180, 40, 30, 30, RGB@(0,255,0) ) call draw_filled_ellipse@(165, 70, 30, 30, RGB@(0,0,255) ) END PROGRAM main
The following existing routines have been extended to use the opacity and smoothing parameters:
DRAW_CHARACTERS@ (with SELECT_FONT@ etc.)
The following routines have been added and take DOUBLE PRECISION values for co-ordinate points and sizes:DRAW_LINE_BETWEEND@