Pebble Foundation Classes  0.2.0
C++ for Pebble
Drawing Paths

Functions to draw polygons into a graphics context. More...

Collaboration diagram for Drawing Paths:

Classes

struct  GPathInfo
 
struct  GPath
 

Typedefs

typedef struct GPathInfo GPathInfo
 
typedef struct GPath GPath
 

Functions

GPathgpath_create (const GPathInfo *init)
 
void gpath_destroy (GPath *gpath)
 Free a dynamically allocated gpath created with gpath_create()
 
void gpath_draw_filled (GContext *ctx, GPath *path)
 
void gpath_draw_outline (GContext *ctx, GPath *path)
 
void gpath_rotate_to (GPath *path, int32_t angle)
 
void gpath_move_to (GPath *path, GPoint point)
 
void gpath_draw_outline_open (GContext *ctx, GPath *path)
 

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...

Typedef Documentation

◆ GPath

typedef struct GPath GPath

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

Note
See the remark with GPathInfo

◆ GPathInfo

typedef struct GPathInfo 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.

Function Documentation

◆ gpath_create()

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

◆ gpath_draw_filled()

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()

◆ gpath_draw_outline()

void gpath_draw_outline ( GContext *  ctx,
GPath path 
)

Draws the outline of a path into a graphics context, using the current stroke color and width, relative to the drawing area as set up by the layering system. The first and last points in the path do have a line between them.

Parameters
ctxThe graphics context to draw into
pathThe path to draw
See also
graphics_context_set_stroke_color()
gpath_draw_outline_open()

◆ gpath_draw_outline_open()

void gpath_draw_outline_open ( GContext *  ctx,
GPath path 
)

Draws an open outline of a path into a graphics context, using the current stroke color and width, relative to the drawing area as set up by the layering system. The first and last points in the path do not have a line between them.

Parameters
ctxThe graphics context to draw into
pathThe path to draw
See also
graphics_context_set_stroke_color()
gpath_draw_outline()

◆ gpath_move_to()

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().

◆ gpath_rotate_to()

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().
GColorWhite
#define GColorWhite
GColorWhite
Definition: gcolor_definitions.h:302
GPathInfo
Definition: pebble.h:4520
GPoint
Definition: pebble.h:3316
GPathInfo::num_points
uint32_t num_points
The number of points in the points array.
Definition: pebble.h:4522
graphics_context_set_stroke_color
void graphics_context_set_stroke_color(GContext *ctx, GColor color)
gpath_draw_filled
void gpath_draw_filled(GContext *ctx, GPath *path)
GPoint
struct GPoint GPoint
gpath_draw_outline
void gpath_draw_outline(GContext *ctx, GPath *path)
gpath_create
GPath * gpath_create(const GPathInfo *init)
graphics_context_set_fill_color
void graphics_context_set_fill_color(GContext *ctx, GColor color)
GPath
Definition: pebble.h:4529
TRIG_MAX_ANGLE
#define TRIG_MAX_ANGLE
Definition: pebble.h:298
gpath_move_to
void gpath_move_to(GPath *path, GPoint point)
GColorBlack
#define GColorBlack
GColorBlack
Definition: gcolor_definitions.h:113
gpath_rotate_to
void gpath_rotate_to(GPath *path, int32_t angle)