Navigation C API Pages Python bindings Applications

Drawing primitives

Drawing primitives implements algorithms to draw basic geometric shapes such as lines, circles, etc.

You may want to see the coordinate system first.

See also RGB tripplet to pixel conversions.

Rotation Flags

Drawing orientation is affected by the context rotation flags. The parameters passed to the functions are transformed accordingly to the flags before the drawing, which allows for fast and transparent rotated or mirrored rendering.

GetPixel and PutPixel

GetPixel and PutPixel are implemented in the library Core.

Fill

void GP_Fill(GP_Context *context, GP_Pixel pixel);

Fills the whole context bitmap with the specified pixel value.

Note GP_Fill is implemented in the library Core rather than in GFX so that it’s available to all library parts.

Lines

void GP_HLineXXY(GP_Context *context, GP_Coord x0, GP_Coord x1, GP_Coord y,
                 GP_Pixel pixel);

void GP_HLine(GP_Context *context, GP_Coord x0, GP_Coord x1, GP_Coord y,
              GP_Pixel pixel);

Draws a horizontal line from (x0, y) to (x1, y), inclusive. The coordinates x0, x1 can be specified in any order.

GP_HLine() is an alias for GP_HLineXXY().

void GP_HLineXYW(GP_Context *context, GP_Coord x, GP_Coord y, GP_Size w,
                 GP_Pixel pixel);

Draws a horizontal line from (x, y) to (x+w-1, y), inclusive.

void GP_VLineXYY(GP_Context *context, GP_Coord x, GP_Coord y0, GP_Coord y1,
                 GP_Pixel pixel);

void GP_VLine(GP_Context *context, GP_Coord x, GP_Coord y0, GP_Coord y1,
              GP_Pixel pixel);

Draws a vertical line from (x, y0) to (x, y1), inclusive. The coordinates y0, y1 can be specified in any order.

GP_VLine() is an alias for GP_VLineXYY().

void GP_VLineXYH(GP_Context *context, GP_Coord x, GP_Coord y, GP_Size h,
                 GP_Pixel pixel);

Draws a vertical line from (x, y) to (x, y+h-1), inclusive.

void GP_Line(GP_Context *context, GP_Coord x0, GP_Coord y0,
             GP_Coord x1, GP_Coord y1, GP_Pixel pixel);

Draws a line from (x0, y0) to (x1, y1), inclusive. The starting and ending point can be specified in any order (the implementation guarantees that exactly the same set of pixels will be drawn in both cases).

Circles

void GP_Circle(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter,
               GP_Size r, GP_Pixel pixel);

Draws a circle centered at (xcenter, ycenter) with radius r (in pixels).

The circle is drawn so that all affected pixels will fit into a square specified by points (xcenter-r, ycenter-r, xcenter+r, ycenter+r), inclusive.

void GP_FillCircle(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter,
                   GP_Size r, GP_Pixel pixel);

Draws a filled circle.

The set of pixels affected by GP_FillCircle() is exactly the same as if drawing the circle boundary using GP_Circle() and then filling all pixels within the boundary with the same color.

Rings

void GP_Ring(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter,
             GP_Size r1, GP_Size r2, GP_Pixel pixel);

Draws a ring (two circles centered at (xcenter, ycenter) with radii r1 and r2).

The result is exactly the same as calling GP_Circle() with the same center and appropriate radii.

void GP_FillRing(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter,
                 GP_Size r1, GP_Size r2, GP_Pixel pixel);

Draws a filled ring.

The smaller of r1 and r2 is used for inner radius and bigger one for outer radius.

Ellipses

void GP_Ellipse(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter,
                GP_Size a, GP_Size b, GP_Pixel pixel);

Draws an axis-aligned ellipse.

The ellipse is drawn so that all affected pixels will fit into a rectangle specified by points (xcenter-a, ycenter-b, xcenter+a, ycenter+b), inclusive.

void GP_FillEllipse(GP_Context *context, GP_Coord xcenter, GP_Coord ycenter,
                    GP_Size a, GP_Size b, GP_Pixel pixel);

Draws a filled axis-aligned ellipse.

Triangles

void GP_Triangle(GP_Context *context, GP_Coord x0, GP_Coord y0,
                 GP_Coord x1, GP_Coord y1, GP_Coord x2, GP_Coord y2,
                 GP_Pixel pixel);

Draws a triangle.

void GP_FillTriangle(GP_Context *context, GP_Coord x0, GP_Coord y0,
                     GP_Coord x1, GP_Coord y1, GP_Coord x2, GP_Coord y2,
                     GP_Pixel pixel);

Draws a filled triangle.

Rects

void GP_RectXYXY(GP_Context *context, GP_Coord x0, GP_Coord y0,
                 GP_Coord x1, GP_Coord y1, GP_Pixel pixel);

void GP_RectXYWH(GP_Context *context, GP_Coord x, GP_Coord y,
                 GP_Size w, GP_Size h, GP_Pixel pixel);

void GP_Rect(GP_Context *context, GP_Coord x0, GP_Coord y0,
             GP_Coord x1, GP_Coord y1, GP_Pixel pixel);

Draws a rectangle.

The GP_RectXYXY() expects two corner points (x0, y0), and (x1, y1). The GP_RectXYWH() expects a corner point (x0, y0), width and height. The GP_Rect() function is an alias for GP_RectXYXY().

void GP_FillRectXYXY(GP_Context *context, GP_Coord x0, GP_Coord y0,
                     GP_Coord x1, GP_Coord y1, GP_Pixel pixel);

void GP_FillRectXYWH(GP_Context *context, GP_Coord x, GP_Coord y,
                     GP_Size w, GP_Size h, GP_Pixel pixel);

void GP_FillRect(GP_Context *context, GP_Coord x0, GP_Coord y0,
                 GP_Coord x1, GP_Coord y1, GP_Pixel pixel);

Draws a filled rectangle.

The GP_RectXYXY fills an area between corner points (x0, y0) and (x1, y1), inclusive. The GP_RectXYWH fills an area starting from (x0, y0) with specified width and height, i.e. from (x0, y0) to (x0 + w, x1 + y), NOT inclusive. The GP_FillRect() functions is an alias for GP_FillRectXYXY().

Tetragons

void GP_Tetragon(GP_Context *context, GP_Coord x0, GP_Coord y0,
                 GP_Coord x1, GP_Coord y1, GP_Coord x2, GP_Coord y2,
                 GP_Coord x3, GP_Coord y3, GP_Pixel pixel);

Draws a tetragon.

void GP_FillTetragon(GP_Context *context, GP_Coord x0, GP_Coord y0,
                     GP_Coord x1, GP_Coord y1, GP_Coord x2, GP_Coord y2,
                     GP_Coord x3, GP_Coord y3, GP_Pixel pixel);

Draws a filled tetragon.

Polygons

void GP_Polygon(GP_Context *context, unsigned int vertex_count,
                const GP_Coord *xy, GP_Pixel pixel);

Draws a polygon.

void GP_FillPolygon(GP_Context *context, unsigned int vertex_count,
                    const GP_Coord *xy, GP_Pixel pixel);

Draws a filled polygon.

The coordinages are passed in [x0, y0, x1, y1, …] order, the vertex count describes a number of nodes, i.e. half of the size of the array.