Solid Lines

Fastgraph includes eight functions for drawing solid lines. All of them draw lines in the current color and observe the clipping limits. The fg_draw() function draws a line from the current graphics cursor position to an absolute screen space position, while fg_draww() draws a line to an absolute world space position. The fg_drawrel() function draws a line from the current graphics cursor position to a screen space position relative to it. The fg_drawrw() function does the same in world space. You can draw absolute lines in XOR mode with fg_drawx() and relative XOR lines with fg_drawrelx(), or with their world space counterparts fg_drawxw() and fg_drawrxw(). XOR lines are often used when drawing cursors (such as cross hairs) or rubberband boxes to insure they are visible against colored backgrounds. Another useful property of XOR lines is that drawing the same line twice restores what was originally beneath the line.

Each of these functions has two parameters that specify the (x,y) coordinates of the destination position. For the screen space functions, the parameters are integer quantities. For the world space functions, the parameters are floating point quantities. In either case the destination position becomes the new graphics cursor position. This makes it possible to draw connected lines without calling a graphics cursor movement function between successive calls to a line drawing function.

Suppose we wanted to draw a pair of crossed lines that divide the active virtual buffer into quadrants. We could do this with fg_move() and fg_draw() like this:

C/C++:

max_x = fg_getmaxx();
max_y = fg_getmaxy();
mid_x = max_x / 2;
mid_y = max_y / 2;
fg_move(mid_x,0);
fg_draw(mid_x,max_y);
fg_move(0,mid_y);
fg_draw(max_x,mid_y);

Delphi:

max_x := fg_getmaxx;
max_y := fg_getmaxy;
mid_x := max_x div 2;
mid_y := max_y div 2;
fg_move(mid_x,0);
fg_draw(mid_x,max_y);
fg_move(0,mid_y);
fg_draw(max_x,mid_y);

Visual Basic:

max_x = fg_getmaxx()
max_y = fg_getmaxy()
mid_x = max_x / 2
mid_y = max_y / 2
Call fg_move(mid_x, 0)
Call fg_draw(mid_x, max_y)
Call fg_move(0, mid_y)
Call fg_draw(max_x, mid_y)

We could instead use relative coordinates and achieve the same result with fg_moverel() and fg_drawrel():

C/C++ and Delphi:

fg_move(mid_x,0);
fg_drawrel(0,max_y);
fg_moverel(-mid_x,-mid_y);
fg_drawrel(max_x,0);

Visual Basic:

Call fg_move(mid_x, 0)
Call fg_drawrel(0, max_y)
Call fg_moverel(-mid_x, -mid_y)
Call fg_drawrel(max_x, 0)

If we wanted to use world coordinates, we would use fg_movew() and fg_draww():

C/C++ and Delphi:

fg_setworld(-10.0,10.0,-10.0,10.0);
fg_movew(0.0,10.0);
fg_draww(0.0,-10.0);
fg_movew(-10.0,0.0);
fg_draww(10.0,0.0);

Visual Basic:

Call fg_setworld(-10.0, 10.0, -10.0, 10.0)
Call fg_movew(0.0, 10.0)
Call fg_draww(0.0, -10.0)
Call fg_movew(-10.0, 0.0)
Call fg_draww(10.0, 0.0)

Finally, we could define a clipping area to restrict drawing to the upper left quadrant:

C/C++ and Delphi:

fg_setclip(0,mid_x,0,mid_y);
fg_move(mid_x,0);
fg_draw(mid_x,max_y);
fg_move(0,mid_y);
fg_draw(max_x,mid_y);

Visual Basic:

Call fg_setclip(0, mid_x, 0, mid_y)
Call fg_move(mid_x, 0)
Call fg_draw(mid_x, max_y)
Call fg_move(0, mid_y)
Call fg_draw(max_x, mid_y)

The clipping suppresses the right half of the horizontal line and the lower half of the vertical line.

<< Prev

Next >>

Contents
Fastgraph Home Page

 

copyright 2001 Ted Gruber Software, Inc.