All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
Drawing Paths

Detailed Description

Functions to draw polygons into a graphics context.

Code example:

static GPath *s_my_path_ptr = NULL;
static const GPathInfo BOLT_PATH_INFO = {
.num_points = 6,
.points = (GPoint []) {{21, 0}, {14, 26}, {28, 26}, {7, 60}, {14, 34}, {0, 34}}
};
// .update_proc of my_layer:
void my_layer_update_proc(Layer *my_layer, GContext* ctx) {
// Fill the path:
gpath_draw_filled(ctx, s_my_path_ptr);
// Stroke the path:
gpath_draw_outline(ctx, s_my_path_ptr);
}
void setup_my_path(void) {
s_my_path_ptr = gpath_create(&BOLT_PATH_INFO);
// Rotate 15 degrees:
gpath_rotate_to(s_my_path_ptr, TRIG_MAX_ANGLE / 360 * 15);
// Translate by (5, 5):
gpath_move_to(s_my_path_ptr, GPoint(5, 5));
}
// For brevity, the setup of my_layer is not written out...

Function Documentation

GPath* gpath_create ( const GPathInfo init)

Creates a new GPath on the heap based on a series of points described by a GPathInfo.

Values after initialization:

  • num_points and points pointer: copied from the GPathInfo.
  • rotation: 0
  • offset: (0, 0)
    Returns
    A pointer to the GPath. NULL if the GPath could not be created
void gpath_destroy ( GPath gpath)

Free a dynamically allocated gpath created with gpath_create()

void gpath_draw_filled ( GContext *  ctx,
GPath path 
)

Draws the fill of a path into a graphics context, using the current fill color, relative to the drawing area as set up by the layering system.

Parameters
ctxThe graphics context to draw into
pathThe path to fill
See Also
graphics_context_set_fill_color()
void gpath_draw_outline ( GContext *  ctx,
GPath path 
)

Draws the outline of a path into a graphics context, using the current stroke color, relative to the drawing area as set up by the layering system.

Parameters
ctxThe graphics context to draw into
pathThe path to fill
See Also
graphics_context_set_stroke_color()
void gpath_move_to ( GPath path,
GPoint  point 
)

Sets the absolute offset of the path. The current translation will be replaced by the specified offset.

Parameters
pathThe path onto which to set the translation
pointThe point which is used as the vector for the translation.
Note
Setting a translation does not affect the points in the path directly. The translation is applied on-the-fly during drawing, either using gpath_draw_filled() or gpath_draw_outline().
void gpath_rotate_to ( GPath path,
int32_t  angle 
)

Sets the absolute rotation of the path. The current rotation will be replaced by the specified angle.

Parameters
pathThe path onto which to set the rotation
angleThe absolute angle of the rotation. The angle is represented in the same way that is used with sin_lookup(). See TRIG_MAX_ANGLE for more information.
Note
Setting a rotation does not affect the points in the path directly. The rotation is applied on-the-fly during drawing, either using gpath_draw_filled() or gpath_draw_outline().

Data Structure Documentation

struct GPath

Data structure describing a path, plus its rotation and translation.

Note
See the remark with GPathInfo
Data Fields
uint32_t num_points The number of points in the points array.
GPoint offset The translation that will to be used when drawing the path with gpath_draw_filled() or gpath_draw_outline()
GPoint * points Pointer to an array of points.
int32_t rotation The rotation that will be used when drawing the path with gpath_draw_filled() or gpath_draw_outline()
struct GPathInfo

Data structure describing a naked path.

Note
Note that this data structure only refers to an array of points; the points are not stored inside this data structure itself. In most cases, one cannot use a stack-allocated array of GPoints. Instead one often needs to provide longer-lived (static or "global") storage for the points.
Data Fields
uint32_t num_points The number of points in the points array.
GPoint * points Pointer to an array of points.