Graphics Primitives

Graphics Primitives — Basic drawing functions

Functions

Types and Values

Includes

#include <grx-3.0.h>

Description

These functions operate on the current context.

Functions

grx_clear_screen ()

void
grx_clear_screen (GrxColor bg);

Clears the screen using the specified background color.

Thanks to the special GrxColor definition, you can do more than simple clear with this functions, by example with:

grx_clear_screen (grx_color_to_xor_mode (grx_color_get_white ()));

the screen is negativized, do it again and the screen is restored.

Parameters

bg

the background color

 

grx_clear_context ()

void
grx_clear_context (GrxColor bg);

Clears the current context using the specified background color.

Thanks to the special GrxColor definition, you can do more than simple clear with this functions, by example with:

grx_clear_context (grx_color_to_xor_mode (grx_color_get_white ()));

the context is negativized, do it again and the context is restored.

Parameters

bg

the background color

 

grx_clear_clip_box ()

void
grx_clear_clip_box (GrxColor bg);

Clears the current clip box using the specified background color.

Thanks to the special GrxColor definition, you can do more than simple clear with this functions, by example with:

grx_clear_clip_box (grx_color_to_xor_mode (grx_color_get_white ()));

the clip box is negativized, do it again and the clip box is restored.

Parameters

bg

the background color

 

grx_draw_pixel ()

void
grx_draw_pixel (gint x,
                gint y,
                GrxColor c);

Draw a single pixel on the current context at the specified coordinates.

Parameters

x

the X coordinate

 

y

the Y coordinate

 

c

the color (can include GrxColorMode)

 

grx_draw_line ()

void
grx_draw_line (gint x1,
               gint y1,
               gint x2,
               gint y2,
               GrxColor c);

Draws a line on the current context from the starting coordinates to the ending coordinates using the specified color.

For horizontal and vertical lines, see grx_draw_hline() and grx_draw_vline().

Parameters

x1

starting X coordinate

 

y1

starting Y coordinate

 

x2

ending X coordinate

 

y2

ending Y coordinate

 

c

the color

 

grx_draw_hline ()

void
grx_draw_hline (gint x1,
                gint x2,
                gint y,
                GrxColor c);

Draws a horizontal line on the current context from the starting coordinates to the ending coordinates using the specified color.

This is more efficient that using grx_draw_line().

Parameters

x1

starting X coordinate

 

x2

ending X coordinate

 

y

Y coordinate

 

c

the color

 

grx_draw_vline ()

void
grx_draw_vline (gint x,
                gint y1,
                gint y2,
                GrxColor c);

Draws a vertical line on the current context from the starting coordinates to the ending coordinates using the specified color.

This is more efficient that using grx_draw_line().

Parameters

x

X coordinate

 

y1

starting Y coordinate

 

y2

ending Y coordinate

 

c

the color

 

grx_draw_box ()

void
grx_draw_box (gint x1,
              gint y1,
              gint x2,
              gint y2,
              GrxColor c);

Draws a rectangle on the current context using the specified coordinates and color.

Parameters

x1

the left X coordinate

 

y1

the top Y coordinate

 

x2

the right X coordinate

 

y2

the bottom Y coordinate

 

c

the color

 

grx_draw_rounded_box ()

void
grx_draw_rounded_box (gint x1,
                      gint y1,
                      gint x2,
                      gint y2,
                      gint r,
                      GrxColor c);

Draws a rectangle with rounded corners on the current context using the specified coordinates and color.

Parameters

x1

the left X coordinate

 

y1

the top Y coordinate

 

x2

the right X coordinate

 

y2

the bottom Y coordinate

 

r

the radius of the corners

 

c

the color

 

grx_draw_circle ()

void
grx_draw_circle (gint xc,
                 gint yc,
                 gint r,
                 GrxColor c);

Draws a circle on the current context centered at the specified coordinates with the specified radius and color.

Parameters

xc

the X coordinate of the center of the circle

 

yc

the Y coordinate of the center of the circle

 

r

the radius of the circle

 

c

the color

 

grx_draw_ellipse ()

void
grx_draw_ellipse (gint xc,
                  gint yc,
                  gint rx,
                  gint ry,
                  GrxColor c);

Draws an ellipse on the current context using the specified color.

The ellipse can only draw ellipses with its major axis parallel with either the X or Y coordinate axis

Parameters

xc

the X coordinate of the center of the ellipse

 

yc

the Y coordinate of the center of the ellipse

 

rx

the radius in the X direction

 

ry

the radius in the Y direction

 

c

the color

 

grx_draw_circle_arc ()

void
grx_draw_circle_arc (gint xc,
                     gint yc,
                     gint r,
                     gint start,
                     gint end,
                     GrxArcStyle style,
                     GrxColor c);

Draws an arc on the current context centered at the specified coordinates from the starting angle to the ending angle with the specified radius, arc style and color.

Parameters

xc

the X coordinate of the center of the arc

 

yc

the Y coordinate of the center of the arc

 

r

the radius of the arc

 

start

the starting angle in 1/10ths of degrees

 

end

the ending angle in 1/10ths of degrees

 

style

the arc style

 

c

the color

 

grx_draw_ellipse_arc ()

void
grx_draw_ellipse_arc (gint xc,
                      gint yc,
                      gint rx,
                      gint ry,
                      gint start,
                      gint end,
                      GrxArcStyle style,
                      GrxColor c);

Draws an arc on the current context centered at the specified coordinates from the starting angle to the ending angle with the specified radii, arc style and color.

Parameters

xc

the X coordinate of the center of the arc

 

yc

the Y coordinate of the center of the arc

 

rx

the radius in the X direction

 

ry

the radius in the Y direction

 

start

the starting angle in 1/10ths of degrees

 

end

the ending angle in 1/10ths of degrees

 

style

the arc style

 

c

the color

 

grx_draw_polyline ()

void
grx_draw_polyline (gint n_points,
                   GrxPoint *points,
                   GrxColor c);

Draw a multi-segment line on the current context that connects each point in the points array using the specified color.

Parameters

n_points

the number of points in points

 

points

an array of GrxPoint.

[array length=n_points]

c

the color

 

grx_draw_polygon ()

void
grx_draw_polygon (gint n_points,
                  GrxPoint *points,
                  GrxColor c);

Draw a closed polygon on the current context that connects each point in the points array using the specified color.

Coordinate arrays can either contain or omit the closing edge of the polygon. It will be automatically appended to the list if it is missing.

Parameters

n_points

the number of points in points

 

points

an array of GrxPoint.

[array length=n_points]

c

the color

 

grx_get_last_arc_coordinates ()

void
grx_get_last_arc_coordinates (gint *xs,
                              gint *ys,
                              gint *xe,
                              gint *ye,
                              gint *xc,
                              gint *yc);

Gets the starting, ending and center coordinates of the arc from the most recent call to an arc function.

Parameters

xs

the starting X coordinate.

[out]

ys

the starting Y coordinate.

[out]

xe

the ending X coordinate.

[out]

ye

the ending Y coordinate.

[out]

xc

the center X coordinate.

[out]

yc

the center Y coordinate.

[out]

grx_generate_ellipse ()

GArray *
grx_generate_ellipse (gint xc,
                      gint yc,
                      gint rx,
                      gint ry);

Creates an array of points that describe the ellipse with the specified coordinates and radii.

These coordinates can be drawn using polygon functions. This is more efficient when drawing the same or similar circles and ellipses multiple times.

Parameters

xc

the center X coordinate

 

yc

the center Y coordinate

 

rx

the radius along the X axis

 

ry

the radius along the Y axis

 

Returns

array containing the calculated points.

[element-type GrxPoint][transfer full]


grx_generate_ellipse_arc ()

GArray *
grx_generate_ellipse_arc (gint xc,
                          gint yc,
                          gint rx,
                          gint ry,
                          gint start,
                          gint end);

Creates an array with points that describe the arc with the specified coordinates, radii, and starting and ending angles.

These coordinates can be drawn using polyline functions. This is more efficient when drawing the same or similar arcs multiple times.

Parameters

xc

the center X coordinate

 

yc

the center Y coordinate

 

rx

the radius along the X axis

 

ry

the radius along the Y axis

 

start

the starting angle in 1/10ths of degrees

 

end

the ending angle in 1/10ths of degrees

 

Returns

array containing the calculated points.

[element-type GrxPoint][transfer full]


grx_generate_points ()

GArray *
grx_generate_points (GArray *coords);

Creates an array of points.

This function is intended for use with language bindings that don't have an elegant way to create an array of points. Each pair of coordinates is converted into a point, so the returned array will be 1/2 the length of coords .

Parameters

coords

the coordinate pairs.

[element-type gint]

Returns

a new GArray.

[element-type GrxPoint][transfer full]


grx_draw_filled_box ()

void
grx_draw_filled_box (gint x1,
                     gint y1,
                     gint x2,
                     gint y2,
                     GrxColor c);

Draws a filled rectangle on the current context using the specified coordinates and color.

Parameters

x1

the left X coordinate

 

y1

the top Y coordinate

 

x2

the right X coordinate

 

y2

the bottom Y coordinate

 

c

the color

 

grx_draw_filled_rounded_box ()

void
grx_draw_filled_rounded_box (gint x1,
                             gint y1,
                             gint x2,
                             gint y2,
                             gint r,
                             GrxColor c);

Draws a filled rectangle with rounded corners on the current context using the specified coordinates and color.

Parameters

x1

the left X coordinate

 

y1

the top Y coordinate

 

x2

the right X coordinate

 

y2

the bottom Y coordinate

 

r

the radius of the corners

 

c

the color

 

grx_draw_framed_box ()

void
grx_draw_framed_box (gint x1,
                     gint y1,
                     gint x2,
                     gint y2,
                     gint width,
                     const GrxFramedBoxColors *c);

Draws a framed rectangle on the current context using the specified coordinates and colors. The coordinates specify the interior box. The border extends outside of the box using the given width .

Parameters

x1

the left X coordinate

 

y1

the top Y coordinate

 

x2

the right X coordinate

 

y2

the bottom Y coordinate

 

width

the width of the frame

 

c

the colors

 

grx_draw_filled_circle ()

void
grx_draw_filled_circle (gint xc,
                        gint yc,
                        gint r,
                        GrxColor c);

Draws a filled circle on the current context centered at the specified coordinates with the specified radius and color.

Parameters

xc

the X coordinate of the center of the circle

 

yc

the Y coordinate of the center of the circle

 

r

the radius of the circle

 

c

the color

 

grx_draw_filled_ellipse ()

void
grx_draw_filled_ellipse (gint xc,
                         gint yc,
                         gint rx,
                         gint ry,
                         GrxColor c);

Draws a filled ellipse on the current context using the specified color.

The ellipse can only draw ellipses with its major axis parallel with either the X or Y coordinate axis

Parameters

xc

the X coordinate of the center of the ellipse

 

yc

the Y coordinate of the center of the ellipse

 

rx

the radius in the X direction

 

ry

the radius in the Y direction

 

c

the color

 

grx_draw_filled_circle_arc ()

void
grx_draw_filled_circle_arc (gint xc,
                            gint yc,
                            gint r,
                            gint start,
                            gint end,
                            GrxArcStyle style,
                            GrxColor c);

Draws a filled arc on the current context centered at the specified coordinates from the starting angle to the ending angle with the specified radius, arc style and color.

Parameters

xc

the X coordinate of the center of the arc

 

yc

the Y coordinate of the center of the arc

 

r

the radius of the arc

 

start

the starting angle in 1/10ths of degrees

 

end

the ending angle in 1/10ths of degrees

 

style

the arc style

 

c

the color

 

grx_draw_filled_ellipse_arc ()

void
grx_draw_filled_ellipse_arc (gint xc,
                             gint yc,
                             gint rx,
                             gint ry,
                             gint start,
                             gint end,
                             GrxArcStyle style,
                             GrxColor c);

Draws a filled arc on the current context centered at the specified coordinates from the starting angle to the ending angle with the specified radii, arc style and color.

Parameters

xc

the X coordinate of the center of the arc

 

yc

the Y coordinate of the center of the arc

 

rx

the radius in the X direction

 

ry

the radius in the Y direction

 

start

the starting angle in 1/10ths of degrees

 

end

the ending angle in 1/10ths of degrees

 

style

the arc style

 

c

the color

 

grx_draw_filled_polygon ()

void
grx_draw_filled_polygon (gint n_points,
                         GrxPoint *points,
                         GrxColor c);

Draw a filled polygon on the current context that connects each point in the points array using the specified color.

Coordinate arrays can either contain or omit the closing edge of the polygon. It will be automatically appended to the list if it is missing.

Parameters

n_points

the number of points in points

 

points

an array of GrxPoint.

[array length=n_points]

c

the color

 

grx_draw_filled_convex_polygon ()

void
grx_draw_filled_convex_polygon (gint n_points,
                                GrxPoint *points,
                                GrxColor c);

Draw a filled polygon on the current context that connects each point in the points array using the specified color.

Coordinate arrays can either contain or omit the closing edge of the polygon. It will be automatically appended to the list if it is missing.

This version is slightly more efficient that grx_draw_filled_polygon() but requires that the polygon is convex. It can also be used to fill some concave polygons whose boundaries do not intersect any horizontal scan line more than twice. It can also be used to fill several disjoint nonoverlapping polygons in a single operation.

Parameters

n_points

the number of points in points

 

points

an array of GrxPoint.

[array length=n_points]

c

the color

 

grx_flood_fill ()

void
grx_flood_fill (gint x,
                gint y,
                GrxColor border,
                GrxColor c);

Flood-fills the area of the current context bounded by the color border using x , y as the starting point.

Parameters

x

the starting X coordinate

 

y

the starting Y coordinate

 

border

the color of the border that contains the fill

 

c

the color of the fill

 

grx_flood_spill ()

void
grx_flood_spill (gint x1,
                 gint y1,
                 gint x2,
                 gint y2,
                 GrxColor old_c,
                 GrxColor new_c);

Replaces old color with new color in the current context in the area bounded by the rectangle x1, y1, x2, y2.

This is quite useful for highlighting a selected item in a list, or changing a selected color(s) in a multi colored area.

Parameters

x1

the left edge of the bounding rectangle

 

y1

the top edge of the bounding rectangle

 

x2

the right edge of the bounding rectangle

 

y2

the bottom edge of the bounding rectangle

 

old_c

the color to be replaced

 

new_c

the new color

 

grx_flood_spill2 ()

void
grx_flood_spill2 (gint x1,
                  gint y1,
                  gint x2,
                  gint y2,
                  GrxColor old_c1,
                  GrxColor new_c1,
                  GrxColor old_c2,
                  GrxColor new_c2);

Replaces two old colors with two new colors in the current context in the area bounded by the rectangle x1, y1, x2, y2. old_c1 is replaced with new_c1 and old_c2 is replaced with new_c2 .

This is quite useful for highlighting a selected item in a list, or changing a selected color(s) in a multi colored area.

Parameters

x1

the left edge of the bounding rectangle

 

y1

the top edge of the bounding rectangle

 

x2

the right edge of the bounding rectangle

 

y2

the bottom edge of the bounding rectangle

 

old_c1

the first color to be replaced

 

new_c1

the first new color

 

old_c2

the second color to be replaced

 

new_c2

the second new color

 

grx_get_pixel_at ()

GrxColor
grx_get_pixel_at (gint x,
                  gint y);

Gets the color value of the pixel in the current context at the specified coordinates.

Parameters

x

the X coordinate

 

y

the Y coordinate

 

grx_bit_blt ()

void
grx_bit_blt (gint x,
             gint y,
             GrxContext *src,
             gint x1,
             gint y1,
             gint x2,
             gint y2,
             GrxColor op);

Copies an area bounded by x1, y2, x2, y2 in the source context to the current context at the location specified by dx, dy using the specified operation.

Parameters

x

the destination X coordinate

 

y

the destination Y coordinate

 

src

the source context or NULL to use the current context.

[nullable]

x1

the source bounding rectangle left coordinate

 

y1

the source bounding rectangle top coordinate

 

x2

the source bounding rectangle right coordinate

 

y2

the source bounding rectangle bottom coordinate

 

op

the GrxColorMode operator and optional transparent color

 

grx_bit_blt_1bpp ()

void
grx_bit_blt_1bpp (gint x,
                  gint y,
                  GrxContext *src,
                  gint x1,
                  gint y1,
                  gint x2,
                  gint y2,
                  GrxColor fg,
                  GrxColor bg);

Copies an area bounded by x1, y2, x2, y2 in the source context to the current context at the location specified by dx, dy using the specified operation.

The source must be a 1 bit per pixel bitmap. The foreground color is used for bits = 1 and the background color is used for bits = 0.

Parameters

x

the destination X coordinate

 

y

the destination Y coordinate

 

src

the source context or NULL to use the current context.

[nullable]

x1

the source bounding rectangle left coordinate

 

y1

the source bounding rectangle top coordinate

 

x2

the source bounding rectangle right coordinate

 

y2

the source bounding rectangle bottom coordinate

 

fg

the foreground color

 

bg

the background color

 

grx_get_scanline ()

const GrxColor *
grx_get_scanline (gint x1,
                  gint x2,
                  gint y,
                  guint *n);

An efficient way to get pixels from the current context. Important: the return value is only valid until the next Grx call!

Parameters

x1

the starting X coordinate

 

x2

the ending X coordinate

 

y

the Y coordinate

 

n

the length of the array.

[out][optional]

Returns

an array of color values from the scanned pixels or NULL if there was an error.

[array length=n][nullable][transfer none]


grx_put_scanline ()

void
grx_put_scanline (gint x1,
                  gint x2,
                  gint y,
                  const GrxColor *scan_line,
                  GrxColor op);

Writes scan_data to the current context using the op operation.

Data values in scan_data must fit GRX_COLOR_VALUE_MASK otherwise the results are implementation dependent. So you can't supply operation code with the pixel data!

Parameters

x1

the starting X coordinate

 

x2

the ending X coordinate

 

y

the Y coordinate

 

scan_line

the data to write.

[array]

op

the color operation

 

Types and Values

GRX_MAX_ANGLE_VALUE

#define GRX_MAX_ANGLE_VALUE      (3600)

The maximum allowable angle (360 degrees).


enum GrxArcStyle

Indicates how an arc should be drawn.

Members

GRX_ARC_STYLE_OPEN

Draws the arc only, leaving the ends open.

 

GRX_ARC_STYLE_CLOSED_CHORD

Draws the arc and closes it with a line that is the chord connecting the two endpoints.

 

GRX_ARC_STYLE_CLOSED_RADIUS

Draws the arc and closes it with two lines along the radii connecting the ends of the arc to the center of the circle/ellipse.

 

GrxFramedBoxColors

typedef struct {
    GrxColor background;
    GrxColor border_top;
    GrxColor border_right;
    GrxColor border_bottom;
    GrxColor border_left;
} GrxFramedBoxColors;

Struct to hold colors for a framed box.

Members

GrxColor background;

the background fill color

 

GrxColor border_top;

the color for the top border

 

GrxColor border_right;

the color for the right border

 

GrxColor border_bottom;

the color for the bottom border

 

GrxColor border_left;

the color for the left border

 

GrxPoint

typedef struct {
    gint x;
    gint y;
} GrxPoint;

Struct that holds coordinates of a point for use in polyline/polygon functions.

Members

gint x;

the X coordinate

 

gint y;

the Y coordinate