Path Primitives

Path Primitives — Functions for constructing and drawing 2D paths.

Synopsis

gboolean            cogl_is_path                        (CoglHandle handle);
void                cogl_path_new                       (void);
CoglPath *          cogl_get_path                       (void);
void                cogl_set_path                       (CoglPath *path);
CoglPath *          cogl_path_copy                      (CoglPath *path);
void                cogl_path_move_to                   (float x,
                                                         float y);
void                cogl_path_close                     (void);
void                cogl_path_line_to                   (float x,
                                                         float y);
void                cogl_path_curve_to                  (float x_1,
                                                         float y_1,
                                                         float x_2,
                                                         float y_2,
                                                         float x_3,
                                                         float y_3);
void                cogl_path_arc                       (float center_x,
                                                         float center_y,
                                                         float radius_x,
                                                         float radius_y,
                                                         float angle_1,
                                                         float angle_2);
void                cogl_path_rel_move_to               (float x,
                                                         float y);
void                cogl_path_rel_line_to               (float x,
                                                         float y);
void                cogl_path_rel_curve_to              (float x_1,
                                                         float y_1,
                                                         float x_2,
                                                         float y_2,
                                                         float x_3,
                                                         float y_3);
void                cogl_path_line                      (float x_1,
                                                         float y_1,
                                                         float x_2,
                                                         float y_2);
void                cogl_path_polyline                  (const float *coords,
                                                         int num_points);
void                cogl_path_polygon                   (const float *coords,
                                                         int num_points);
void                cogl_path_rectangle                 (float x_1,
                                                         float y_1,
                                                         float x_2,
                                                         float y_2);
void                cogl_path_round_rectangle           (float x_1,
                                                         float y_1,
                                                         float x_2,
                                                         float y_2,
                                                         float radius,
                                                         float arc_step);
void                cogl_path_ellipse                   (float center_x,
                                                         float center_y,
                                                         float radius_x,
                                                         float radius_y);

enum                CoglPathFillRule;
void                cogl_path_set_fill_rule             (CoglPathFillRule fill_rule);
CoglPathFillRule    cogl_path_get_fill_rule             (void);
void                cogl_path_fill                      (void);
void                cogl_path_fill_preserve             (void);
void                cogl_path_stroke                    (void);
void                cogl_path_stroke_preserve           (void);

Description

There are two levels on which drawing with cogl-paths can be used. The highest level functions construct various simple primitive shapes to be either filled or stroked. Using a lower-level set of functions more complex and arbitrary paths can be constructed by concatenating straight line, bezier curve and arc segments.

When constructing arbitrary paths, the current pen location is initialized using the move_to command. The subsequent path segments implicitly use the last pen location as their first vertex and move the pen location to the last vertex they produce at the end. Also there are special versions of functions that allow specifying the vertices of the path segments relative to the last pen location rather then in the absolute coordinates.

Details

cogl_is_path ()

gboolean            cogl_is_path                        (CoglHandle handle);

Gets whether the given handle references an existing path object.

handle :

A CoglHandle

Returns :

TRUE if the handle references a CoglPath, FALSE otherwise

cogl_path_new ()

void                cogl_path_new                       (void);

Clears the current path and starts a new one. Creating a new path also resets the fill rule to the default which is COGL_PATH_FILL_RULE_EVEN_ODD.

Since 1.0


cogl_get_path ()

CoglPath *          cogl_get_path                       (void);

Gets a pointer to the current path. The path can later be used again by calling cogl_path_set(). Note that the path isn't copied so if you later call any functions to add to the path it will affect the returned object too. No reference is taken on the path so if you want to retain it you should take your own reference with cogl_object_ref().

Returns :

a pointer to the current path.

Since 1.4


cogl_set_path ()

void                cogl_set_path                       (CoglPath *path);

Replaces the current path with path. A reference is taken on the object so if you no longer need the path you should unref with cogl_object_unref().

path :

A CoglPath object

Since 1.4


cogl_path_copy ()

CoglPath *          cogl_path_copy                      (CoglPath *path);

Returns a new copy of the path in path. The new path has a reference count of 1 so you should unref it with cogl_object_unref() if you no longer need it.

Internally the path will share the data until one of the paths is modified so copying paths should be relatively cheap.

path :

A CoglPath object

Returns :

a copy of the path in path.

cogl_path_move_to ()

void                cogl_path_move_to                   (float x,
                                                         float y);

Moves the pen to the given location. If there is an existing path this will start a new disjoint subpath.

x :

X coordinate of the pen location to move to.

y :

Y coordinate of the pen location to move to.

cogl_path_close ()

void                cogl_path_close                     (void);

Closes the path being constructed by adding a straight line segment to it that ends at the first vertex of the path.


cogl_path_line_to ()

void                cogl_path_line_to                   (float x,
                                                         float y);

Adds a straight line segment to the current path that ends at the given coordinates.

x :

X coordinate of the end line vertex

y :

Y coordinate of the end line vertex

cogl_path_curve_to ()

void                cogl_path_curve_to                  (float x_1,
                                                         float y_1,
                                                         float x_2,
                                                         float y_2,
                                                         float x_3,
                                                         float y_3);

Adds a cubic bezier curve segment to the current path with the given second, third and fourth control points and using current pen location as the first control point.

x_1 :

X coordinate of the second bezier control point

y_1 :

Y coordinate of the second bezier control point

x_2 :

X coordinate of the third bezier control point

y_2 :

Y coordinate of the third bezier control point

x_3 :

X coordinate of the fourth bezier control point

y_3 :

Y coordinate of the fourth bezier control point

cogl_path_arc ()

void                cogl_path_arc                       (float center_x,
                                                         float center_y,
                                                         float radius_x,
                                                         float radius_y,
                                                         float angle_1,
                                                         float angle_2);

Adds an elliptical arc segment to the current path. A straight line segment will link the current pen location with the first vertex of the arc. If you perform a move_to to the arcs start just before drawing it you create a free standing arc.

The angles are measured in degrees where 0° is in the direction of the positive X axis and 90° is in the direction of the positive Y axis. The angle of the arc begins at angle_1 and heads towards angle_2 (so if angle_2 is less than angle_1 it will decrease, otherwise it will increase).

center_x :

X coordinate of the elliptical arc center

center_y :

Y coordinate of the elliptical arc center

radius_x :

X radius of the elliptical arc

radius_y :

Y radius of the elliptical arc

angle_1 :

Angle in degrees at which the arc begin

angle_2 :

Angle in degrees at which the arc ends

cogl_path_rel_move_to ()

void                cogl_path_rel_move_to               (float x,
                                                         float y);

Moves the pen to the given offset relative to the current pen location. If there is an existing path this will start a new disjoint subpath.

x :

X offset from the current pen location to move the pen to.

y :

Y offset from the current pen location to move the pen to.

cogl_path_rel_line_to ()

void                cogl_path_rel_line_to               (float x,
                                                         float y);

Adds a straight line segment to the current path that ends at the given coordinates relative to the current pen location.

x :

X offset from the current pen location of the end line vertex

y :

Y offset from the current pen location of the end line vertex

cogl_path_rel_curve_to ()

void                cogl_path_rel_curve_to              (float x_1,
                                                         float y_1,
                                                         float x_2,
                                                         float y_2,
                                                         float x_3,
                                                         float y_3);

Adds a cubic bezier curve segment to the current path with the given second, third and fourth control points and using current pen location as the first control point. The given coordinates are relative to the current pen location.

x_1 :

X coordinate of the second bezier control point

y_1 :

Y coordinate of the second bezier control point

x_2 :

X coordinate of the third bezier control point

y_2 :

Y coordinate of the third bezier control point

x_3 :

X coordinate of the fourth bezier control point

y_3 :

Y coordinate of the fourth bezier control point

cogl_path_line ()

void                cogl_path_line                      (float x_1,
                                                         float y_1,
                                                         float x_2,
                                                         float y_2);

Constructs a straight line shape starting and ending at the given coordinates. If there is an existing path this will start a new disjoint sub-path.

x_1 :

X coordinate of the start line vertex

y_1 :

Y coordinate of the start line vertex

x_2 :

X coordinate of the end line vertex

y_2 :

Y coordinate of the end line vertex

cogl_path_polyline ()

void                cogl_path_polyline                  (const float *coords,
                                                         int num_points);

Constructs a series of straight line segments, starting from the first given vertex coordinate. If there is an existing path this will start a new disjoint sub-path. Each subsequent segment starts where the previous one ended and ends at the next given vertex coordinate.

The coords array must contain 2 * num_points values. The first value represents the X coordinate of the first vertex, the second value represents the Y coordinate of the first vertex, continuing in the same fashion for the rest of the vertices. (num_points - 1) segments will be constructed.

coords :

A pointer to the first element of an array of fixed-point values that specify the vertex coordinates. [in][array][transfer none]

num_points :

The total number of vertices.

cogl_path_polygon ()

void                cogl_path_polygon                   (const float *coords,
                                                         int num_points);

Constructs a polygonal shape of the given number of vertices. If there is an existing path this will start a new disjoint sub-path.

The coords array must contain 2 * num_points values. The first value represents the X coordinate of the first vertex, the second value represents the Y coordinate of the first vertex, continuing in the same fashion for the rest of the vertices.

coords :

A pointer to the first element of an array of fixed-point values that specify the vertex coordinates. [in][array][transfer none]

num_points :

The total number of vertices.

cogl_path_rectangle ()

void                cogl_path_rectangle                 (float x_1,
                                                         float y_1,
                                                         float x_2,
                                                         float y_2);

Constructs a rectangular shape at the given coordinates. If there is an existing path this will start a new disjoint sub-path.

x_1 :

X coordinate of the top-left corner.

y_1 :

Y coordinate of the top-left corner.

x_2 :

X coordinate of the bottom-right corner.

y_2 :

Y coordinate of the bottom-right corner.

cogl_path_round_rectangle ()

void                cogl_path_round_rectangle           (float x_1,
                                                         float y_1,
                                                         float x_2,
                                                         float y_2,
                                                         float radius,
                                                         float arc_step);

Constructs a rectangular shape with rounded corners. If there is an existing path this will start a new disjoint sub-path.

x_1 :

X coordinate of the top-left corner.

y_1 :

Y coordinate of the top-left corner.

x_2 :

X coordinate of the bottom-right corner.

y_2 :

Y coordinate of the bottom-right corner.

radius :

Radius of the corner arcs.

arc_step :

Angle increment resolution for subdivision of the corner arcs.

cogl_path_ellipse ()

void                cogl_path_ellipse                   (float center_x,
                                                         float center_y,
                                                         float radius_x,
                                                         float radius_y);

Constructs an ellipse shape. If there is an existing path this will start a new disjoint sub-path.

center_x :

X coordinate of the ellipse center

center_y :

Y coordinate of the ellipse center

radius_x :

X radius of the ellipse

radius_y :

Y radius of the ellipse

enum CoglPathFillRule

typedef enum {
  COGL_PATH_FILL_RULE_NON_ZERO,
  COGL_PATH_FILL_RULE_EVEN_ODD
} CoglPathFillRule;

CoglPathFillRule is used to determine how a path is filled. There are two options - 'non-zero' and 'even-odd'. To work out whether any point will be filled imagine drawing an infinetely long line in any direction from that point. The number of times and the direction that the edges of the path crosses this line determines whether the line is filled as described below. Any open sub paths are treated as if there was an extra line joining the first point and the last point.

The default fill rule is COGL_PATH_FILL_RULE_EVEN_ODD. The fill rule is attached to the current path so preserving a path with cogl_get_path() also preserves the fill rule. Calling cogl_path_new() resets the current fill rule to the default.

Figure 2. Example of filling various paths using the non-zero rule

Example of filling various paths using the non-zero rule


Figure 3. Example of filling various paths using the even-odd rule

Example of filling various paths using the even-odd rule


COGL_PATH_FILL_RULE_NON_ZERO

Each time the line crosses an edge of the path from left to right one is added to a counter and each time it crosses from right to left the counter is decremented. If the counter is non-zero then the point will be filled. See Figure 2, “Example of filling various paths using the non-zero rule”.

COGL_PATH_FILL_RULE_EVEN_ODD

If the line crosses an edge of the path an odd number of times then the point will filled, otherwise it won't. See Figure 3, “Example of filling various paths using the even-odd rule”.

Since 1.4


cogl_path_set_fill_rule ()

void                cogl_path_set_fill_rule             (CoglPathFillRule fill_rule);

Sets the fill rule of the current path to fill_rule. This will affect how the path is filled when cogl_path_fill() is later called. Note that the fill rule state is attached to the path so calling cogl_get_path() will preserve the fill rule and calling cogl_path_new() will reset the fill rule back to the default.

fill_rule :

The new fill rule.

Since 1.4


cogl_path_get_fill_rule ()

CoglPathFillRule    cogl_path_get_fill_rule             (void);

Retrieves the fill rule set using cogl_path_set_fill_rule().

Returns :

the fill rule that is used for the current path.

Since 1.4


cogl_path_fill ()

void                cogl_path_fill                      (void);

Fills the interior of the constructed shape using the current drawing color. The current path is then cleared. To use the path again, call cogl_path_fill_preserve() instead.

The interior of the shape is determined using the fill rule of the path. See CoglPathFillRule for details.


cogl_path_fill_preserve ()

void                cogl_path_fill_preserve             (void);

Fills the interior of the constructed shape using the current drawing color and preserves the path to be used again. See cogl_path_fill() for a description what is considered the interior of the shape.

Since 1.0


cogl_path_stroke ()

void                cogl_path_stroke                    (void);

Strokes the constructed shape using the current drawing color and a width of 1 pixel (regardless of the current transformation matrix). To current path is then cleared. To use the path again, call cogl_path_stroke_preserve() instead.


cogl_path_stroke_preserve ()

void                cogl_path_stroke_preserve           (void);

Strokes the constructed shape using the current drawing color and preserves the path to be used again.

Since 1.0