home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
No Fragments Archive 10: Diskmags
/
nf_archive_10.iso
/
MAGS
/
ST_USER
/
1990
/
USEROC90.MSA
/
TEXT_GEM.DOC
< prev
next >
Wrap
Text File
|
1990-08-19
|
8KB
|
161 lines
GEM PROGRAMMING
Roland Waddilove continues his exploration of the ST's
almost impenetrable virtual device interface, this month,
shedding some light on rectangles and fill patterns
Those of you who have been following this series from the start (on the July
'90 cover disk), will be familiar with the TV/monitor test card. This was
written to demonstrate some of the VDI's most common functions. The source code
is repeated yet again on this month's disk - it still contains functions that
we have yet to explore.
This month I'll be looking at the various VDI functions for drawing
rectangles and filling them with patterns. There are four that you need to
remember:
-----------------------------------------------------------------------
FUNCTION RESULT
-----------------------------------------------------------------------
vr_recfl(handle,xyarray) Draw a filled rectangle
v_bar(handle,xyarray) Draw a filled rectangle
v_rbox(handle,xyarray) Draw a rounded rectangle
v_rfbox(handle,xyarray) Draw a filled rounded rectangle
-----------------------------------------------------------------------
Notice that the parameters are always the same - the VDI handle, followed
by 'xyarray'. The 'xyarray' parameter is a short (16 bit) pointer to an array
which holds the coordinates of the top left corner and bottom right corner. As
with previous VDI functions we have looked at, there are dozens of parameters
which have to be set before you can call one of these rectangle functions.
Let's take a look at them.
The first thing you must decide is how you want the rectangle to be drawn,
and by this I mean using replace, transparent, XOR or reverse transparent mode.
Replace mode obscures anything behind the rectangle. Transparent lets the
background show through, for instance, if it's a hollow rectangle. XOR mode
exclusively ORs the rectangle and contents with the background. Reverse
transparent lets the background show through only where parts of the rectangle
or contents are filled in.
The best way to find out what these VDI functions really mean in practice
is to try them out and see. The function vswr_mode(handle,mode) sets the
drawing mode (in fact, all VDI output, including text). The (short) 'mode'
parameter takes the value 1 (replace), 2 (transparent), 3 (XOR) or 4 (reverse
transparent):
----------------------------------------------------------------------------
FUNCTION EFFECT
----------------------------------------------------------------------------
vswr_mode(handle,1) Replace background
vswr_mode(handle,2) Background shows through where pixels not set
vswr_mode(handle,3) Exclusively ORed with background
vswr_mode(handle,4) Background shows through where pixels set
----------------------------------------------------------------------------
The next three functions are related because they tell the VDI how you want
the interior of the rectangle drawn. Should it be hollow, filled with a solid
colour, a pre-set pattern or one you have designed yourself? The first
function, vsf_interior(handle,type), tells the VDI whether the rectangle should
be drawn hollow (type=0), filled with a solid colour (type=1), filled with a
pre-set pattern (type=2), filled with a pre-set hatch pattern (type=3) or
filled with some pattern you have designed yourself (type=4).
----------------------------------------------------------------------------
FUNCTION EFFECT
----------------------------------------------------------------------------
vsf_interior(handle,0) Hollow rectangle - no fill
vsf_interior(handle,1) Rectangle to be filled with colour
vsf_interior(handle,2) Rectangle to be filled with a pre-set pattern
vsf_interior(handle,3) Rectangle to be filled with a pre-set hatch
vsf_interior(handle,4) Rectangle to be filled with user defined pattern
----------------------------------------------------------------------------
(The function, vsf_color(handle,colour), is very simple - it just sets the
colour if you are using a solid fill colour with vsf_interior(handle,1). The
'colour' parameter ranges from 0 to 15, but don't forget that you can only
display four colours in medium res and two in monocrome.)
The second of the related functions mentioned above is
vsf_style(handle,style). The (short) 'style' parameter is used to select the
type of pattern or hatch when using vsf_interior(handle,2) or
vsf_interior(handle,3). There are 24 patterns and 12 hatches to choose from. If
you wanted to draw a rectangle that was filled with hatch type three you would
use the following code:
vsf_interior(handle,3) /* we want a hatch fill, ok? */
vsf_style(handle,3) /* we'll choose hatch number 3 */
.
.
.
The third related function is only used when you want to design your own
fill patterns, for which you would use vsf_interior(handle,4). The VDI function
that defines a fill pattern is vsf_udpat(handle,word,planes) - all short (16
bit) parameters. The 'planes' parameter relates to the number of planes the
screen display is made up of, and is four in low res, two in medium res and one
in mono. The 'word' parameter is a pointer to an array that contains 16, word,
entries for each plane.
It's quite easy to design your own fill patterns for a monochrome display,
because only one plane is required and each bit set corresponds to a pixel on
the screen. Here's a short piece of code to define a fill pattern and set the
fill option so that all filled shapes use this new design:
pat[0] = 0x0F0F;
pat[1] = 0x0F0F;
pat[2] = 0x0000;
pat[3] = 0x0000;
pat[4] = 0xAAAA;
pat[5] = 0xAAAA;
pat[6] = 0xBBBB;
pat[7] = 0xBBBB;
pat[8] = 0xCCCC;
pat[9] = 0xCCCC;
pat[10] = 0xBBBB;
pat[11] = 0xBBBB;
pat[12] = 0x0000;
pat[13] = 0x0000;
pat[14] = 0x1234;
pat[15] = 0x4321;
vsf_udpat(handle,pat,1); /* define my own pattern - 1 plane mono */
vsf_interior(handle,4); /* set user defined fill */
Now that we can set all the parameters like colour, writing mode, hatch or
fill pattern, pre-set or user defined, how about actually drawing a rectangle?
It's now quite easy, so here is a section of code taken from the PATTERNS.C
program on this month's cover disk. It draws 24 rounded rectangles and then
fills them with the 24 different patterns:
/* draw the fill patterns */
vsf_color(handle,1); /* colour=black */
for ( x=0; x<24; ++x ) { /* pattern styles 1-24 */
vsf_interior(handle,2); /* set patterned fill */
vsf_style(handle,x+1); /* choose pattern to fill with*/
xyarray[0] = x*26; /* top left x */
xyarray[1] = 0; /* top left y */
xyarray[2] = xyarray[0]+23; /* bottom right x */
xyarray[3] = xyarray[1]+40; /* bottom right y */
v_rfbox(handle,xyarray); /* draw rounded filled box */
}
When a rectangle is drawn using the vr_recfl(handle,xyarray) function, the
perimeter of the shape is never drawn. If you specifically wanted to draw a
perimeter around it you would use v_bar(handle,xyarray) instead, however, you
would also need to tell the VDI to draw the perimeter with a call to
vsf_perimeter(handle,flag) where flag=1. The perimeter is drawn using the line
attributes that we looked at last month.
The functions v_rbox(handle,xyarray) and v_rfbox(handle,xyarray) are
identical except that the former simply draws a rounded box outline, while the
latter also fills it with the current fill/hatch/user defined pattern.
That's all for now. See you next month when I'll be documenting more VDI
functions. In the meantime, try running PATTERNS.PRG and look at the different
patterns and hatches. There's also a user defined one, too. The source code is
in PATTERNS.C and was written with Digital Wisdom C.