Help > Software > The <graphics.h> Library for C.impl
The <graphics.h> Library for C.impl

void drawLine(int x1, int y1, int x2, int y2, int c)

Draw line from point (x1,y2) to point (x2,y2) and colour (c).

void drawFrame(int x1, int y1, int x2, int y2, int c)

Draw a rectangular frame built from four lines between points (x1,y1) and (x2,y2), and colour (c).

void drawRect(int x1, int y1, int x2, int y2, int c)

Draw a solid rectangle between points (x1,y1) and (x2,y2), and colour (c).

void drawTriangle(int x1, int y1, int x2, int y2, int x3, int y3, int c)

Draw a solid triangle between points (x1,y1), (x2,y2), and (x3,y3), and colour (c).

void drawCircle(int x, int y, int r, int c)

Draw a circle with centre point (x,y) and radius (r) and colour (c).

If the radius is specified as a positive number, the circle is drawn solid. If (r) is negative, only a circle frame is drawn.

void drawEllipse(int x, int y, int rx, int ry, double tiltAngle, int c)

Draw an ellipse with centre point (x,y), two radiuses (rx) and (ry), and colour (c). The parameter ‘tiltAngle’ specifies the tilt (rotation) angle of the ellipse in measure of radians.

If both radiuses are given as positive numbers, the ellipse is drawn solid.

If both radiuses are given as negative numbers, the ellipse is drawn as a frame.

If one of the radiuses is positive while the other is negative, nothing is drawn.

void drawSector(int x, int y, int rx, int ry, double tiltAngle, double startAngle, double endAngle, int c)

Draw a sector of ellipse, whose centre is at (x,y), radiuses (rx) and (ry), tilt angle (tiltAngle) in radians, and colour (c).

Two additional angular parameters (startAngle) and (endAngle), both in measure of radians, specify the actual draw sector as part of a full ellipse.

In case the radiuses (rx) and (ry) are equal, the ellipse is transformed into a circle.

If both radiuses are given as positive numbers, the ellipse is drawn solid. If both radiuses are given as negative numbers, the ellipse is drawn as a frame. If one of the radiuses is positive while the other is negative, nothing is drawn.

void floodFill(int x, int y, int c)

Flood fill with colour (c) an enclosed area. The start point (x,y) must be inside the area to be filled.

void getRect(void *buffer, int x1, int y1, int x2, int y2)

Get a rectangular area from the screen into a memory buffer. The buffer must be pre-allocated and with sufficient size. The minimum needed buffer size can be calculated with the formula:

Buffer(bytes) = 8 + (H * V) / 8

Where H and V are the horizontal and vertical dimensions of the rectangle in pixels.

void putRect(void *buffer, int x, int y, int opr)

Restore a rectangular area from a buffer on the screen starting from specified coordinates of the top left corner of the area.

The last parameter defines the logic type of restoring the pixels:

 OPR_COPY 0 All pixels from the buffer overwrite the pixels on the screen. OPR_OR 1 Logical operation “OR” is performed between every pixel from the buffer and its destination on the screen. OPR_XOR 2 Logical operation “Exclusive OR” is performed between every pixel from the buffer and its destination on the screen. OPR_AND 3 Logical operation “AND” is performed between every pixel from the buffer and its destination on the screen. OPR_NOT 4 All pixels are restored on the screen in their inverted form.

Unknown operation types are assumed as type 0. Constants “OPR_xxx” as per the table above are predefined in the library.

void drawShape(int x, int y, double tiltAngle, char *def)

Draw a vector-defined shape, starting from point (x,y) and with tilt angle (rotation) given in measure of radians.

The shape definition is a text string consisting of commands and vectors:

 M [relX],[relY] Move to a new point with relative coordinates (relX,relY) C [col] Set new drawing colour and enable draw when moving D Enable draw when moving N Disable draw when moving F Flood fill taking the current position as start point

Whitespaces are ignored in the definition string. Vectors and colours also allow use of hexadecimal numbers, preceded by ‘X’ or ‘x’ character. Missing numbers are assumed 0. Thus, a command “M,10” is a functional equivalent to “M0,10”. Command “M-10,” is a functional equivalent to “M-10,0”.

Predefined colour constants are not supported in the shape definition string. Colours must be specified in a numeric form.

An example for vectored shape:

drawShape( 160, 130, 0.0, "C-3 M10,20 M20,10 M-20,10 M-10,20 C1 M-10,-20 M-20,-10 M20,-10 M10,-20 N M,15 C-12 M,30 N M-15,-15 D M30," );

This definition will draw a four-rayed star with green left part and red right part (on a system that supports colours), and a blue cross inside, starting from the top point at screen coordinates (160,130) and not rotated.

void drawChar(int ch)

Draw a character from the currently active font.

In scale factors greater than 2, the drawing function applies an algorithm to smooth down the blocky appearance of the large characters.

void lockScroll(void)

Prevent the screen from automatically scroll up when printing characters normally would require it to.

void unlockScroll(void)

Restore the automatically scroll up when printing characters requires.

void posX(int x)

int posX(void)

Set or return horizontal position for the next text character.

void posY(int x)

int posY(void)

Set or return vertical position for the next text character.

void fontScale(int factor)

int fontScale(void)

Set or return the scale factor for drawing font characters.

void fontFcol(int col)

int fontFcol(void)

Set or return the drawing colour for font characters.

void fontBcol(int col)

int fontBcol(void)

Set or return the background colour for font characters.

void fontSet(font_t *font)

Activate custom font. The parameter (*font) is a pointer to a font structure. Once activated, the font will be used by all following functions which output characters on the screen.