home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD2.bin
/
bbs
/
dev
/
cmanual-3.0.lha
/
CManual
/
Intuition
/
Graphics
/
Graphics.doc
< prev
next >
Wrap
Text File
|
1993-10-12
|
26KB
|
864 lines
3 GRAPHICS
3.1 INTRODUCTION
We have now looked at how to open different types of screens,
and how to open different types of windows connected to the
screens etc. It is all very good, but what would Intuition be
without any graphics to display in the screens/windows?
Intuition's main idea is to make the communication between
the program and the user as easy as possible. Graphics enables
you to display the results that the computer has calculated in
an understandable way (a picture says more than...). Graphics
makes it also much easier to use the program, and can warn the
user if something dangerous is going to happen: It is very easy
to press the wrong button if you have got a question like "OK
to erase disk?", but if there also had been a picture
showing a cross with the text "RIP" on, you would probably
have been a bit more careful.
There exist both a low- and a high-level way of making
graphics. The low-level approach (Graphics Primitives) is
not described in this chapter since it is not related to
Intuition. The low-level graphics routines are very fast, but
if you are not careful they can trash menus etc. We will here
concentrate our self on the high-level approach which is
supported by Intuition, and is a safe way of drawing.
3.2 LINES TEXT PICTURES
Intuition gives you three different methods of making graphics:
- You can draw lines (Borders).
- Print text (IntuiText).
- Or you can directly print graphics images (Images).
3.3 BORDERS
Border has a bit misleading name since you are not limited to
only draw borders, you may draw any kind of shapes which is
made out of connecting lines. A Border structure may also be
connected to other Border structures, so everything which can
be drawn with lines, can be drawn with Intuition's Border
structure.
3.3.1 THE BORDER STRUCTURE
When you want to draw lines you need to declare and initialize
a Border structure which look like this:
struct Border
{
SHORT LeftEdge, TopEdge;
SHORT FrontPen, BackPen, DrawMode;
SHORT Count;
SHORT *XY;
struct Border *NextBorder;
};
LeftEdge, TopEdge: Start position of the lines.
FrontPen: Colour register used to draw the lines.
BackPen: This variable is for the moment unused.
DrawMode: Must be either JAM1 or XOR. If the JAM1 flag
is set, the colour specified (FrontPen) will
be used to draw the lines regardless what
the background colour is. The XOR flag makes
the lines to be drawn with the binary
complement of the background colours.
Count: The number of coordinates there is in the XY
array. (See below for more information.)
XY: A pointer to an array of coordinates used to
draw the lines. (See below for more
information.)
NextBorder: A pointer to the next Border structure if
there exist one, else NULL.
3.3.2 COORDINATES
If you want to draw this:
(10,10) (25,10)
*--------------*
| (35,12)
| *
| |
*---------*
(25,14) (35,14)
The array of coordinates would look like this:
SHORT my_points[]=
{
10,10, /* Start at position (10,10) */
25,10, /* Draw a line to the right to position (25,10) */
25,14, /* Draw a line down to position (25,14) */
35,14, /* Draw a line to the right to position (35,14) */
35,12 /* Finish of by drawing a line up to position (35,12) */
};
The array contains 5 pair of coordinates, so the variable Count
should be set accordingly. The entire Border structure would
therefore look something like this:
struct Border my_border=
{
0, 0, /* LeftEdge, TopEdge. */
3, /* FrontPen, colour register 3. */
0, /* BackPen, for the moment unused. */
JAM1, /* DrawMode, draw the lines with colour 3. */
5, /* Count, 5 pair of coordinates in the array. */
my_points, /* XY, pointer to the array with the */
/* coordinates. */
/* (Remember my_points == &my_points[0]) */
NULL /* NextBorder, no other Border structures */
/* comes after this one. */
};
3.4 HOW TO USE THE BORDER STRUCTURE
The Border structure is either used to draw lines in a screen
or window, but can also be used to draw lines connected to a
Gadget, Requester or Menu. (See chapter 4, 5 and 7 for more
information about Gadgets, Requesters and Menus.)
If you want to connect a Border structure with a Gadget etc,
you simply initialize the Gadget structure with a pointer to
the Border structure, and Intuition will draw the lines for
you. This will be explained later.
If you want to draw the lines in a screen or window you need to
tell Intuition that you want it to use the structure to make
some lines. You do it by calling the function DrawBorder():
Synopsis: DrawBorder( rast_port, border, x, y );
rast_port: (struct RastPort *) Pointer to a RastPort.
If the lines should be drawn in a window, and
my_window is a pointer to that window, you write:
my_window->RPort.
If the lines should be drawn in a Screen, and
my_screen is a pointer to that screen, you write:
my_screen->RastPort.
border: (struct Border *) Pointer to a Border structure
which has been initialized with your requirements.
x: (long) Number of pixels added to the x coordinates.
y: (long) Number of lines added to the y coordinates.
A call to draw some lines using my_border structure would look
something like this:
DrawBorder( my_window->RPort, &my_border, 0, 0 );
If you have created a Border structure which, for example,
draws a box, you can draw several boxes at different places
just by changing the LeftEdge, RightEdge fields of the Border
structure, or by changing the x, y fields in the function call.
This shows how versatile Intuition's high-level way of drawing
is.
3.4 TEXT
Printing text in the Display is supported by the IntuiText
structure. It is quite similar to the Border structure, and is
executed in the same way. The only difference is that you need
to tell Intuition what Font you want to use, and what text to
print.
3.4.1 THE INTUITEXT STRUCTURE
When you want to print text you need to declare and initialize
a IntuiText structure which look like this:
struct IntuiText
{
UBYTE FrontPen, BackPen;
UBYTE DrawMode;
SHORT LeftEdge;
SHORT TopEdge;
struct TextAttr *ITextFont;
UBYTE *IText;
struct IntuiText *NextText;
};
FrontPen: Colour register used to draw the text with.
BackPen: Colour register used to draw the background
of the text.
DrawMode: There exist three different way of printing
the text:
JAM1 The colour specified (FrontPen) will
be used to draw the text with, the
background is unchanged.
JAM2 The FrontPen colour will be used to
draw the text with, the background is
drawn with the BackPen colour.
XOR The text is drawn with the the binary
complement of the background.
LeftEdge, TopEdge: Start position of the text.
ITextFont: A pointer to a TextAttr structure which
tells Intuition what font, size and style
etc to print the text with. Set to NULL if
you want to use the default font. (See below
for more information.)
IText: A pointer to a NULL-terminated string that
should be printed.
NextText: A pointer to the next IntuiText structure if
there exist one, else write NULL.
3.4.2 FONTS
You can tell Intuition to print the text with a specific font/
style. You only need to declare and initialize a TextAttr
structure, and give your IntuiText structure a pointer to the
TextAttr stru