Path Primitives

Path Primitives

Synopsis

                    CoglPath;
CoglPath *          cogl_path_new                       (CoglContext *context);
CoglPath *          cogl_path_copy                      (CoglPath *path);

void                cogl_path_polygon                   (CoglPath *path,
                                                         const float *coords,
                                                         int num_points);
void                cogl_path_rectangle                 (CoglPath *path,
                                                         float x_1,
                                                         float y_1,
                                                         float x_2,
                                                         float y_2);
void                cogl_path_ellipse                   (CoglPath *path,
                                                         float center_x,
                                                         float center_y,
                                                         float radius_x,
                                                         float radius_y);
void                cogl_path_round_rectangle           (CoglPath *path,
                                                         float x_1,
                                                         float y_1,
                                                         float x_2,
                                                         float y_2,
                                                         float radius,
                                                         float arc_step);

void                cogl_path_move_to                   (CoglPath *path,
                                                         float x,
                                                         float y);
void                cogl_path_rel_move_to               (CoglPath *path,
                                                         float x,
                                                         float y);
void                cogl_path_line_to                   (CoglPath *path,
                                                         float x,
                                                         float y);
void                cogl_path_rel_line_to               (CoglPath *path,
                                                         float x,
                                                         float y);
void                cogl_path_arc                       (CoglPath *path,
                                                         float center_x,
                                                         float center_y,
                                                         float radius_x,
                                                         float radius_y,
                                                         float angle_1,
                                                         float angle_2);
void                cogl_path_curve_to                  (CoglPath *path,
                                                         float x_1,
                                                         float y_1,
                                                         float x_2,
                                                         float y_2,
                                                         float x_3,
                                                         float y_3);
void                cogl_path_rel_curve_to              (CoglPath *path,
                                                         float x_1,
                                                         float y_1,
                                                         float x_2,
                                                         float y_2,
                                                         float x_3,
                                                         float y_3);
void                cogl_path_line                      (CoglPath *path,
                                                         float x_1,
                                                         float y_1,
                                                         float x_2,
                                                         float y_2);
void                cogl_path_polyline                  (CoglPath *path,
                                                         const float *coords,
                                                         int num_points);
void                cogl_path_close                     (CoglPath *path);

void                cogl_path_fill                      (CoglPath *path,
                                                         CoglFramebuffer *framebuffer,
                                                         CoglPipeline *pipeline);
void                cogl_path_stroke                    (CoglPath *path,
                                                         CoglFramebuffer *framebuffer,
                                                         CoglPipeline *pipeline);

enum                CoglPathFillRule;
void                cogl_path_set_fill_rule             (CoglPath *path,
                                                         CoglPathFillRule fill_rule);
CoglPathFillRule    cogl_path_get_fill_rule             (CoglPath *path);

Description

Details

CoglPath

typedef struct {
  CoglObject _parent;

  CoglPathData *data;
} CoglPath;

cogl_path_new ()

CoglPath *          cogl_path_new                       (CoglContext *context);

Creates a new, empty path object. The default fill rule is COGL_PATH_FILL_RULE_EVEN_ODD.

context :

A CoglContext pointer

Returns :

A pointer to a newly allocated CoglPath, which can be freed using cogl_object_unref().

Since 2.0


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.

Since 2.0


cogl_path_polygon ()

void                cogl_path_polygon                   (CoglPath *path,
                                                         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.

path :

A CoglPath

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.

Since 2.0


cogl_path_rectangle ()

void                cogl_path_rectangle                 (CoglPath *path,
                                                         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.

path :

A CoglPath

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.

Since 2.0


cogl_path_ellipse ()

void                cogl_path_ellipse                   (CoglPath *path,
                                                         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.

path :

A CoglPath

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

Since 2.0


cogl_path_round_rectangle ()

void                cogl_path_round_rectangle           (CoglPath *path,
                                                         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.

path :

A CoglPath

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.

Since 2.0


cogl_path_move_to ()

void                cogl_path_move_to                   (CoglPath *path,
                                                         float x,
                                                         float y);

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

path :

A CoglPath

x :

X coordinate of the pen location to move to.

y :

Y coordinate of the pen location to move to.

Since 2.0


cogl_path_rel_move_to ()

void                cogl_path_rel_move_to               (CoglPath *path,
                                                         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.

path :

A CoglPath

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.

Since 2.0


cogl_path_line_to ()

void                cogl_path_line_to                   (CoglPath *path,
                                                         float x,
                                                         float y);

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

path :

A CoglPath

x :

X coordinate of the end line vertex

y :

Y coordinate of the end line vertex

Since 2.0


cogl_path_rel_line_to ()

void                cogl_path_rel_line_to               (CoglPath *path,
                                                         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.

path :

A CoglPath

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

Since 2.0


cogl_path_arc ()

void                cogl_path_arc                       (CoglPath *path,
                                                         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).

path :

A CoglPath

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

Since 2.0


cogl_path_curve_to ()

void                cogl_path_curve_to                  (CoglPath *path,
                                                         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.

path :

A CoglPath

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

Since 2.0


cogl_path_rel_curve_to ()

void                cogl_path_rel_curve_to              (CoglPath *path,
                                                         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.

path :

A CoglPath

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

Since 2.0


cogl_path_line ()

void                cogl_path_line                      (CoglPath *path,
                                                         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.

path :

A CoglPath

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

Since 2.0


cogl_path_polyline ()

void                cogl_path_polyline                  (CoglPath *path,
                                                         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.

path :

A CoglPath

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.

Since 2.0


cogl_path_close ()

void                cogl_path_close                     (CoglPath *path);

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

path :

A CoglPath

Since 2.0


cogl_path_fill ()

void                cogl_path_fill                      (CoglPath *path,
                                                         CoglFramebuffer *framebuffer,
                                                         CoglPipeline *pipeline);

cogl_path_stroke ()

void                cogl_path_stroke                    (CoglPath *path,
                                                         CoglFramebuffer *framebuffer,
                                                         CoglPipeline *pipeline);

Draws a list of line primitives corresponding to the edge of the given path using the specified GPU pipeline to the given framebuffer.

Note

Cogl does not provide any sophisticated path stroking features for things like stroke width, dashes or caps. The stroke line will have a width of 1 pixel regardless of the current transformation matrix.

path :

The CoglPath to stroke

framebuffer :

A CoglFramebuffer

pipeline :

A CoglPipeline to render with

Since 2.0


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 when creating a path is COGL_PATH_FILL_RULE_EVEN_ODD.

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

Example of filling various paths using the non-zero rule


Figure 2. 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 1, “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 2, “Example of filling various paths using the even-odd rule”.

Since 1.4


cogl_path_set_fill_rule ()

void                cogl_path_set_fill_rule             (CoglPath *path,
                                                         CoglPathFillRule fill_rule);

Sets the fill rule of the current path to fill_rule. This will affect how the path is filled when cogl_framebuffer_fill_path() is later called.

path :

A CoglPath

fill_rule :

The new fill rule.

Since 2.0


cogl_path_get_fill_rule ()

CoglPathFillRule    cogl_path_get_fill_rule             (CoglPath *path);

Retrieves the fill rule set using cogl_path_set_fill_rule().

path :

A CoglPath

Returns :

the fill rule that is used for the current path.

Since 2.0