 |
» |
|
|
 |
Now that you have seen some of the workings of Display List,
the operations done in the program OneLiner.c
will make more sense. Here again is a listing of the program, along
with some pertinent comments:  |
#include <starbase.c.h> /* don't forget Starbase definitions */ #include <dl.c.h> /* get Display List definitions */ #include <stdio.h> /* get standard I/O definitions */ #define AppendOff FALSE /* sent to "open_segment" */ #define AppendOn TRUE /* sent to "open_segment" */ #define DisplayOff FALSE /* sent to "open_segment" */ #define DisplayOn TRUE /* sent to "open_segment" */ main() /* file "OneLiner.c" */ { int fildes; /* file descriptor */ if ((fildes = gopen(getenv("SB_OUTDEV"), OUTDEV, NULL, INIT)) == -1) { fprintf(stderr, "%s %s\n", "Error: gopen failed using environment, "variable SB_OUTDEV"); exit(-1); } open_segment(fildes, 1, AppendOff, DisplayOff); /* open segment 1 */ move2d(fildes, 0.0, 0.0); /* move to 0,0... */ draw2d(fildes, 1.0, 1.0); /* ...and draw to 1,1. */ close_segment(fildes); /* stop defining segment */ refresh_segment(fildes, 1); /* display segment 1 */ gclose(fildes); |
 |
- Line 1:
Include the Starbase header file (this must be included
before the Display List header file). - Line 2:
Include the Display List header file (this must
be included after the Starbase header file). - Line 3:
Include the Standard I/O header file. This file
need not be in any particular place, relative to the other header
files; it could just as easily have been the first #include statement. It is
included merely for the logistics of the gopen
error-message printing, and is not inherently required by Display
List, as starbase.c.h
is. - Lines 5-8:
These are macro definitions whose names have been
chosen specifically to make the calls to open_segment easier to comprehend. - Lines 14-19:
Open the device and its display list. The environment
variables are accessed for the value of 〈path〉,
and this makes the program more device-independent.
However, the display list still must be device-dependent
(in this example) because of the method of drawing the image: refresh_segment. If the display
list were to have been device-independent, display_segment would have
been used instead of refresh_segment
(more about this later). - Line 20:
Open a segment. This segment has been arbitrarily
given an identifying number of 1. This segment didn't exist before,
so the open_segment
routine creates an empty segment and then opens it. AppendOff instructs the routine
to start entering the subsequent Starbase commands at the current
element pointer position instead of the end. (In this case, however,
with an initially empty segment, AppendOff
and AppendOn
would accomplish the same result.) DisplayOff
tells the routine to put subsequent commands into the display list,
but do not display them at this time. - Lines 21-22:
These are the Starbase commands that are put into
the display list segment currently open. - Line 23:
This line closes the currently open segment, which
happens to be named #1. Because at most one segment can be open
at any one time, this call is not ambiguous. - Line 24:
The refresh_segment
routine hasn't been covered yet. At this point, suffice it to say
that this draws everything in the specified segment, #1, which,
in this case, consists of a single line. - Line 25:
Close the display list and the device associated
with 〈fildes〉.
|