home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
No Fragments Archive 10: Diskmags
/
nf_archive_10.iso
/
MAGS
/
ST_USER
/
1990
/
USERSP90.MSA
/
TEXT_GEM.DOC
< prev
next >
Wrap
Text File
|
1990-07-25
|
5KB
|
110 lines
ON THE RIGHT LINES
Exploring GEM's VDI line functions with Roland Waddilove
GEM's virtual device interface, or VDI for short, is a powerful, yet very
complex part of the operating system that all programmers must eventually get
to grips with if they want to harness the power of the ST. The VDI handles all
text and graphic output to the screen and last month we examined a host of
related text functions that enable you to display characters in a variety of
styles, sizes and colours.
This month I'll move on to look at drawing lines, which might seem like a
simple subject, but there's more to it than meets the eye. Last month's colour
and mono test cards have been repeated on this month's disk because they
contain some simple examples of drawing lines using the VDI.
If you have a C compiler you can compile the two test cards and run them.
(Any programming language that enables you to call GEM will use the same
function calls so you can still follow this series even if you're a Pascal or
BASIC user.) Here is the section of C code that produces the lines:
short y,i,j,line[4];
vsl_color(handle,0); /* colour=white */
vsl_width(handle,1); /* line width=1 pixel */
for ( y=-1; y<2; y+=2 ) {
line[0] = 91; /* start x */
line[1] = 90 + y*32; /* start y */
line[2] = line[0]; /* end x */
line[3] = line[1] + 20; /* end y */
for ( i=1; i<5; ++i )
for ( j=0; j<14; ++j ) {
v_pline(handle,2,line); /* draw line */
line[0] += i;
line[2] += i;
}
}
The function that draws the line is called v_pline(). It doesn't simply
draw a line between two coordinates, you pass an array or list of coordinates
and it joins up the points with straight lines. If there are two points in the
array a single straight line is drawn, but if there are three points then lines
will be drawn from the first to the second and from the second to the third.
There's no limit to the number of points you can pass in the array and you
could easily arrange the points to make a triangle, rectangle or octagon. Any
open or closed shape is possible.
The VDI v_pline() function takes three parameters: the VDI handle, the
number of points and the address of the array (or list) of coordinates. To draw
a single line between two points in C you would set up a word array, store the
coordinates in it and then call the VDI like:
short handle, line[4];
...
line[0] = 0;
line[1] = 10;
line[2] = 50;
line[3] = 100;
v_pline(handle, 2, line);
This short piece of code draws a line from 0,10 to 50,100. The number 2 in
the function call tells the VDI that there are two pairs of coordinates.
You can simply call the v_pline(handle,count,array) function straight away
to draw a line, but there are several other parameters that can be set to
produce a variety of effects and styles. Using vswr_mode(handle,mode) the
writing mode can be set to replace (mode=1), transparent (mode=2), XOR (mode=3)
or reverse transparent (mode=4).
Lines can be drawn either solid or dashed, and there are several varieties
of dashed lines. The type is chosen using vsl_type(handle, style where the
value of style is in the range 1 to 7:
1 solid ---------------------------------------------
2 long dashed ---------- ---------- ---------- ----------
3 dotted -- -- -- -- -- -- -- -- -- -- -- --
4 dash-dot ---------- -- ---------- -- ---------- --
5 dashed ----- ----- ----- ----- ----- -----
6 dash-dot-dot ----- -- -- ----- -- -- ----- -- -- -----
7 user defined using vsl_udsty(handle,pattern)
Line type 7, as you can see, enables you to define your own pattern using
the vsl_udsty(handle,pattern) VDI function. The pattern parameter is a 16-bit
number whose bit pattern defines the style, so 0101010101010101 (21,845 in
decimal) would be a fine dot pattern and 0011001100110011 (13,107 in decimal)
would be a coarser dot pattern.
Once you have set the drawing mode and line type, possibly user defined,
you should set the line width by calling vsl_width(handle,width). For some
strange reason the VDI will only draw lines with odd widths (measured in
pixels) - 1, 3, 5, 7 and so on.
Next you should set the colour using vsl_color(handle,colour) where the
colour number ranges from 0 to 15. You must remember however, that you can only
display two colours in monochrome (black and white), four in medium res and 16
in low res.
Every line has a start and a finish, and you can instruct the VDI to square
off, round or draw arrows at either of the line ends. The VDI function used is
vsl_ends(handle,beginning,end). The two parameters, beginning and end, can be
zero (squared end), one (arrow end) or two (round end). All the parameters are
16-bit words.
And that rounds up this month's look at the VDI's functions. See you next
time with some more programming GEMs!