Pebble Foundation Classes  0.2.0
C++ for Pebble
Draw Commands

Pebble Draw Commands are a way to encode arbitrary path draw and fill calls in binary format, so that vector-like graphics can be represented on the watch. More...

Collaboration diagram for Draw Commands:

Typedefs

typedef struct GDrawCommand GDrawCommand
 
typedef struct GDrawCommandFrame GDrawCommandFrame
 
typedef struct GDrawCommandImage GDrawCommandImage
 
typedef struct GDrawCommandList GDrawCommandList
 Draw command lists contain a list of commands that can be iterated over and drawn all at once.
 
typedef bool(* GDrawCommandListIteratorCb) (GDrawCommand *command, uint32_t index, void *context)
 
typedef struct GDrawCommandSequence GDrawCommandSequence
 

Enumerations

enum  GDrawCommandType { GDrawCommandTypeInvalid = 0, GDrawCommandTypePath, GDrawCommandTypeCircle, GDrawCommandTypePrecisePath }
 

Functions

void gdraw_command_draw (GContext *ctx, GDrawCommand *command)
 
GDrawCommandType gdraw_command_get_type (GDrawCommand *command)
 
void gdraw_command_set_fill_color (GDrawCommand *command, GColor fill_color)
 
GColor gdraw_command_get_fill_color (GDrawCommand *command)
 
void gdraw_command_set_stroke_color (GDrawCommand *command, GColor stroke_color)
 
GColor gdraw_command_get_stroke_color (GDrawCommand *command)
 
void gdraw_command_set_stroke_width (GDrawCommand *command, uint8_t stroke_width)
 
uint8_t gdraw_command_get_stroke_width (GDrawCommand *command)
 
uint16_t gdraw_command_get_num_points (GDrawCommand *command)
 Get the number of points in a command.
 
void gdraw_command_set_point (GDrawCommand *command, uint16_t point_idx, GPoint point)
 
GPoint gdraw_command_get_point (GDrawCommand *command, uint16_t point_idx)
 
void gdraw_command_set_radius (GDrawCommand *command, uint16_t radius)
 
uint16_t gdraw_command_get_radius (GDrawCommand *command)
 
void gdraw_command_set_path_open (GDrawCommand *command, bool path_open)
 
bool gdraw_command_get_path_open (GDrawCommand *command)
 
void gdraw_command_set_hidden (GDrawCommand *command, bool hidden)
 
bool gdraw_command_get_hidden (GDrawCommand *command)
 
void gdraw_command_frame_draw (GContext *ctx, GDrawCommandSequence *sequence, GDrawCommandFrame *frame, GPoint offset)
 
void gdraw_command_frame_set_duration (GDrawCommandFrame *frame, uint32_t duration)
 
uint32_t gdraw_command_frame_get_duration (GDrawCommandFrame *frame)
 
GDrawCommandImagegdraw_command_image_create_with_resource (uint32_t resource_id)
 
GDrawCommandImagegdraw_command_image_clone (GDrawCommandImage *image)
 
void gdraw_command_image_destroy (GDrawCommandImage *image)
 
void gdraw_command_image_draw (GContext *ctx, GDrawCommandImage *image, GPoint offset)
 
GSize gdraw_command_image_get_bounds_size (GDrawCommandImage *image)
 
void gdraw_command_image_set_bounds_size (GDrawCommandImage *image, GSize size)
 
GDrawCommandListgdraw_command_image_get_command_list (GDrawCommandImage *image)
 
void gdraw_command_list_iterate (GDrawCommandList *command_list, GDrawCommandListIteratorCb handle_command, void *callback_context)
 
void gdraw_command_list_draw (GContext *ctx, GDrawCommandList *command_list)
 
GDrawCommandgdraw_command_list_get_command (GDrawCommandList *command_list, uint16_t command_idx)
 
uint32_t gdraw_command_list_get_num_commands (GDrawCommandList *command_list)
 
GDrawCommandSequencegdraw_command_sequence_create_with_resource (uint32_t resource_id)
 
GDrawCommandSequencegdraw_command_sequence_clone (GDrawCommandSequence *sequence)
 
void gdraw_command_sequence_destroy (GDrawCommandSequence *sequence)
 
GDrawCommandFramegdraw_command_sequence_get_frame_by_elapsed (GDrawCommandSequence *sequence, uint32_t elapsed_ms)
 
GDrawCommandFramegdraw_command_sequence_get_frame_by_index (GDrawCommandSequence *sequence, uint32_t index)
 
GSize gdraw_command_sequence_get_bounds_size (GDrawCommandSequence *sequence)
 
void gdraw_command_sequence_set_bounds_size (GDrawCommandSequence *sequence, GSize size)
 
uint32_t gdraw_command_sequence_get_play_count (GDrawCommandSequence *sequence)
 
void gdraw_command_sequence_set_play_count (GDrawCommandSequence *sequence, uint32_t play_count)
 
uint32_t gdraw_command_sequence_get_total_duration (GDrawCommandSequence *sequence)
 
uint32_t gdraw_command_sequence_get_num_frames (GDrawCommandSequence *sequence)
 
GDrawCommandListgdraw_command_frame_get_command_list (GDrawCommandFrame *frame)
 

Detailed Description

Pebble Draw Commands are a way to encode arbitrary path draw and fill calls in binary format, so that vector-like graphics can be represented on the watch.

These draw commands can be loaded from resources, manipulated in place and drawn to the current graphics context. Each GDrawCommand can be an arbitrary path or a circle with optional fill or stroke. The stroke width and color of the stroke and fill are also encoded within the GDrawCommand. Paths can can be drawn open or closed.

All aspects of a draw command can be modified, except for the number of points in a path (a circle only has one point, the center).

Draw commands are grouped into a GDrawCommandList, which can be drawn all at once. Each individual GDrawCommand can be accessed from a GDrawCommandList for modification.

A GDrawCommandList forms the basis for GDrawCommandImage and GDrawCommandFrame objects. A GDrawCommandImage represents a static image and can be represented by the PDC file format and can be loaded as a resource.

Once you have a GDrawCommandImage loaded in memory you can draw it on the screen in a LayerUpdateProc with the gdraw_command_image_draw().

A GDrawCommandFrame represents a single frame of an animated sequence, with multiple frames making up a single GDrawCommandSequence, which can also be stored as a PDC and loaded as a resource.

To draw a GDrawCommandSequence, use the gdraw_command_sequence_get_frame_by_elapsed() to obtain the current GDrawCommandFrame and gdraw_command_frame_draw() to draw it.

Draw commands also allow access to drawing with sub-pixel precision. The points are treated as Fixed point types in the format 13.3, so that 1/8th of a pixel precision is possible. Only the points in draw commands of the type GDrawCommandTypePrecisePath will be treated as higher precision.

Typedef Documentation

◆ GDrawCommand

typedef struct GDrawCommand GDrawCommand

Draw commands are the basic building block of the draw command system, encoding the type of command to draw, the stroke width and color, fill color, and points that define the path (or center of a circle

◆ GDrawCommandFrame

Draw command frames contain a list of commands to draw for that frame and a duration, indicating the length of time for which the frame should be drawn in an animation sequence. Frames form the building blocks of a GDrawCommandSequence, which consists of multiple frames.

◆ GDrawCommandImage

Draw command images contain a list of commands that can be drawn. An image can be loaded from PDC file data.

◆ GDrawCommandListIteratorCb

typedef bool(* GDrawCommandListIteratorCb) (GDrawCommand *command, uint32_t index, void *context)

Callback for iterating over draw command list

Parameters
commandcurrent GDrawCommand in iteration
indexindex of the current command in the list
contextcontext pointer for the iteration operation
Returns
true if the iteration should continue after this command is processed

◆ GDrawCommandSequence

Draw command sequences allow the animation of frames over time. Each sequence has a list of frames that can be accessed by the elapsed duration of the animation (not maintained internally) or by index. Sequences can be loaded from PDC file data.

Enumeration Type Documentation

◆ GDrawCommandType

Enumerator
GDrawCommandTypeInvalid 

Invalid draw command type.

GDrawCommandTypePath 

Arbitrary path draw command type.

GDrawCommandTypeCircle 

Circle draw command type.

GDrawCommandTypePrecisePath 

Arbitrary path drawn with sub-pixel precision (1/8th precision)

Function Documentation

◆ gdraw_command_draw()

void gdraw_command_draw ( GContext *  ctx,
GDrawCommand command 
)

Draw a command

Parameters
ctxThe destination graphics context in which to draw
commandGDrawCommand to draw

◆ gdraw_command_frame_draw()

void gdraw_command_frame_draw ( GContext *  ctx,
GDrawCommandSequence sequence,
GDrawCommandFrame frame,
GPoint  offset 
)

Draw a frame

Parameters
ctxThe destination graphics context in which to draw
sequenceThe sequence from which the frame comes from (this is required)
frameFrame to draw
offsetOffset from draw context origin to draw the frame

◆ gdraw_command_frame_get_command_list()

GDrawCommandList* gdraw_command_frame_get_command_list ( GDrawCommandFrame frame)

Get the command list of the frame

Parameters
frameGDrawCommandFrame from which to get the command list
Returns
command list

◆ gdraw_command_frame_get_duration()

uint32_t gdraw_command_frame_get_duration ( GDrawCommandFrame frame)

Get the duration of the frame

Parameters
frameGDrawCommandFrame from which to get the duration
Returns
duration of the frame in milliseconds

◆ gdraw_command_frame_set_duration()

void gdraw_command_frame_set_duration ( GDrawCommandFrame frame,
uint32_t  duration 
)

Set the duration of the frame

Parameters
frameGDrawCommandFrame for which to set the duration
durationduration of the frame in milliseconds

◆ gdraw_command_get_fill_color()

GColor gdraw_command_get_fill_color ( GDrawCommand command)

Get the fill color of a command

Parameters
commandGDrawCommand from which to get the fill color
Returns
fill color of the given GDrawCommand

◆ gdraw_command_get_hidden()

bool gdraw_command_get_hidden ( GDrawCommand command)

Return whether a command is hidden

Parameters
commandGDrawCommand from which to get the hidden status
Returns
true if command is hidden

◆ gdraw_command_get_path_open()

bool gdraw_command_get_path_open ( GDrawCommand command)

Return whether a stroke command path is open

Note
This only works for commands of type GDrawCommandPath and GDrawCommandPrecisePath
Parameters
commandGDrawCommand from which to get the path open status
Returns
true if the path is open

◆ gdraw_command_get_point()

GPoint gdraw_command_get_point ( GDrawCommand command,
uint16_t  point_idx 
)

Get the value of a point in a command from the specified index

Parameters
commandGDrawCommand from which to get a point
point_idxThe index to get the point for
Returns
The point in the GDrawCommand specified by point_idx
Note
The index must be less than the number of points

◆ gdraw_command_get_radius()

uint16_t gdraw_command_get_radius ( GDrawCommand command)

Get the radius of a circle command.

Note
this only works for commands of typeGDrawCommandCircle.
Parameters
commandGDrawCommand from which to get the circle radius
Returns
The radius in pixels if command is of type GDrawCommandCircle

◆ gdraw_command_get_stroke_color()

GColor gdraw_command_get_stroke_color ( GDrawCommand command)

Get the stroke color of a command

Parameters
commandGDrawCommand from which to get the stroke color
Returns
The stroke color of the given GDrawCommand

◆ gdraw_command_get_stroke_width()

uint8_t gdraw_command_get_stroke_width ( GDrawCommand command)

Get the stroke width of a command

Parameters
commandGDrawCommand from which to get the stroke width
Returns
The stroke width of the given GDrawCommand

◆ gdraw_command_get_type()

GDrawCommandType gdraw_command_get_type ( GDrawCommand command)

Get the command type

Parameters
commandGDrawCommand from which to get the type
Returns
The type of the given GDrawCommand

◆ gdraw_command_image_clone()

GDrawCommandImage* gdraw_command_image_clone ( GDrawCommandImage image)

Creates a GDrawCommandImage as a copy from a given image

Parameters
imageImage to copy.
Returns
cloned image or NULL if the operation failed

◆ gdraw_command_image_create_with_resource()

GDrawCommandImage* gdraw_command_image_create_with_resource ( uint32_t  resource_id)

Creates a GDrawCommandImage from the specified resource (PDC file)

Parameters
resource_idResource containing data to load and create GDrawCommandImage from.
Returns
GDrawCommandImage pointer if the resource was loaded, NULL otherwise

◆ gdraw_command_image_destroy()

void gdraw_command_image_destroy ( GDrawCommandImage image)

Deletes the GDrawCommandImage structure and frees associated data

Parameters
imagePointer to the image to free (delete)

◆ gdraw_command_image_draw()

void gdraw_command_image_draw ( GContext *  ctx,
GDrawCommandImage image,
GPoint  offset 
)

Draw an image

Parameters
ctxThe destination graphics context in which to draw
imageImage to draw
offsetOffset from draw context origin to draw the image

◆ gdraw_command_image_get_bounds_size()

GSize gdraw_command_image_get_bounds_size ( GDrawCommandImage image)

Get size of the bounding box surrounding all draw commands in the image. This bounding box can be used to set the graphics context or layer bounds when drawing the image.

Parameters
imageGDrawCommandImage from which to get the bounding box size
Returns
bounding box size

◆ gdraw_command_image_get_command_list()

GDrawCommandList* gdraw_command_image_get_command_list ( GDrawCommandImage image)

Get the command list of the image

Parameters
imageGDrawCommandImage from which to get the command list
Returns
command list

◆ gdraw_command_image_set_bounds_size()

void gdraw_command_image_set_bounds_size ( GDrawCommandImage image,
GSize  size 
)

Set size of the bounding box surrounding all draw commands in the image. This bounding box can be used to set the graphics context or layer bounds when drawing the image.

Parameters
imageGDrawCommandImage for which to set the bounding box size
sizebounding box size

◆ gdraw_command_list_draw()

void gdraw_command_list_draw ( GContext *  ctx,
GDrawCommandList command_list 
)

Draw all commands in a command list

Parameters
ctxThe destination graphics context in which to draw
command_listlist of commands to draw

◆ gdraw_command_list_get_command()

GDrawCommand* gdraw_command_list_get_command ( GDrawCommandList command_list,
uint16_t  command_idx 
)

Get the command at the specified index

Note
the specified index must be less than the number of commands in the list
Parameters
command_listGDrawCommandList from which to get a command
command_idxindex of the command to get
Returns
pointer to GDrawCommand at the specified index

◆ gdraw_command_list_get_num_commands()

uint32_t gdraw_command_list_get_num_commands ( GDrawCommandList command_list)

Get the number of commands in the list

Parameters
command_listGDrawCommandList from which to get the number of commands
Returns
number of commands in command list

◆ gdraw_command_list_iterate()

void gdraw_command_list_iterate ( GDrawCommandList command_list,
GDrawCommandListIteratorCb  handle_command,
void *  callback_context 
)

Iterate over all commands in a command list

Parameters
command_listGDrawCommandList over which to iterate
handle_commanditerator callback
callback_contextcontext pointer to be passed into the iterator callback

◆ gdraw_command_sequence_clone()

GDrawCommandSequence* gdraw_command_sequence_clone ( GDrawCommandSequence sequence)

Creates a GDrawCommandSequence as a copy from a given sequence

Parameters
sequenceSequence to copy
Returns
cloned sequence or NULL if the operation failed

◆ gdraw_command_sequence_create_with_resource()

GDrawCommandSequence* gdraw_command_sequence_create_with_resource ( uint32_t  resource_id)

Creates a GDrawCommandSequence from the specified resource (PDC file)

Parameters
resource_idResource containing data to load and create GDrawCommandSequence from.
Returns
GDrawCommandSequence pointer if the resource was loaded, NULL otherwise

◆ gdraw_command_sequence_destroy()

void gdraw_command_sequence_destroy ( GDrawCommandSequence sequence)

Deletes the GDrawCommandSequence structure and frees associated data

Parameters
imagePointer to the sequence to destroy

◆ gdraw_command_sequence_get_bounds_size()

GSize gdraw_command_sequence_get_bounds_size ( GDrawCommandSequence sequence)

Get the size of the bounding box surrounding all draw commands in the sequence. This bounding box can be used to set the graphics context or layer bounds when drawing the frames in the sequence.

Parameters
sequenceGDrawCommandSequence from which to get the bounds
Returns
bounding box size

◆ gdraw_command_sequence_get_frame_by_elapsed()

GDrawCommandFrame* gdraw_command_sequence_get_frame_by_elapsed ( GDrawCommandSequence sequence,
uint32_t  elapsed_ms 
)

Get the frame that should be shown after the specified amount of elapsed time The last frame will be returned if the elapsed time exceeds the total time

Parameters
sequenceGDrawCommandSequence from which to get the frame
elapsed_mselapsed time in milliseconds
Returns
pointer to GDrawCommandFrame that should be displayed at the elapsed time

◆ gdraw_command_sequence_get_frame_by_index()

GDrawCommandFrame* gdraw_command_sequence_get_frame_by_index ( GDrawCommandSequence sequence,
uint32_t  index 
)

Get the frame at the specified index

Parameters
sequenceGDrawCommandSequence from which to get the frame
indexIndex of frame to get
Returns
pointer to GDrawCommandFrame at the specified index

◆ gdraw_command_sequence_get_num_frames()

uint32_t gdraw_command_sequence_get_num_frames ( GDrawCommandSequence sequence)

Get the number of frames in the sequence

Parameters
sequenceGDrawCommandSequence from which to get the number of frames
Returns
number of frames in the sequence

◆ gdraw_command_sequence_get_play_count()

uint32_t gdraw_command_sequence_get_play_count ( GDrawCommandSequence sequence)

Get the play count of the sequence

Parameters
sequenceGDrawCommandSequence from which to get the play count
Returns
play count of sequence

◆ gdraw_command_sequence_get_total_duration()

uint32_t gdraw_command_sequence_get_total_duration ( GDrawCommandSequence sequence)

Get the total duration of the sequence.

Parameters
sequenceGDrawCommandSequence from which to get the total duration
Returns
total duration of the sequence in milliseconds

◆ gdraw_command_sequence_set_bounds_size()

void gdraw_command_sequence_set_bounds_size ( GDrawCommandSequence sequence,
GSize  size 
)

Set size of the bounding box surrounding all draw commands in the sequence. This bounding box can be used to set the graphics context or layer bounds when drawing the frames in the sequence.

Parameters
sequenceGDrawCommandSequence for which to set the bounds
sizebounding box size

◆ gdraw_command_sequence_set_play_count()

void gdraw_command_sequence_set_play_count ( GDrawCommandSequence sequence,
uint32_t  play_count 
)

Set the play count of the sequence

Parameters
sequenceGDrawCommandSequence for which to set the play count
play_countplay count

◆ gdraw_command_set_fill_color()

void gdraw_command_set_fill_color ( GDrawCommand command,
GColor  fill_color 
)

Set the fill color of a command

Parameters
commandref DrawCommand for which to set the fill color
fill_colorGColor to set for the fill

◆ gdraw_command_set_hidden()

void gdraw_command_set_hidden ( GDrawCommand command,
bool  hidden 
)

Set a command as hidden. This command will not be drawn when gdraw_command_draw is called with this command

Parameters
commandGDrawCommand for which to set the hidden status
hiddentrue if command should be hidden

◆ gdraw_command_set_path_open()

void gdraw_command_set_path_open ( GDrawCommand command,
bool  path_open 
)

Set the path of a stroke command to be open

Note
This only works for commands of type GDrawCommandPath and GDrawCommandPrecisePath
Parameters
commandGDrawCommand for which to set the path open status
path_opentrue if path should be hidden

◆ gdraw_command_set_point()

void gdraw_command_set_point ( GDrawCommand command,
uint16_t  point_idx,
GPoint  point 
)

Set the value of the point in a command at the specified index

Parameters
commandGDrawCommand for which to set the value of a point
point_idxIndex of the point to set the value for
pointnew point value to set

◆ gdraw_command_set_radius()

void gdraw_command_set_radius ( GDrawCommand command,
uint16_t  radius 
)

Set the radius of a circle command

Note
This only works for commands of type GDrawCommandCircle
Parameters
commandGDrawCommand from which to set the circle radius
radiusThe radius to set for the circle.

◆ gdraw_command_set_stroke_color()

void gdraw_command_set_stroke_color ( GDrawCommand command,
GColor  stroke_color 
)

Set the stroke color of a command

Parameters
commandGDrawCommand for which to set the stroke color
stroke_colorGColor to set for the stroke

◆ gdraw_command_set_stroke_width()

void gdraw_command_set_stroke_width ( GDrawCommand command,
uint8_t  stroke_width 
)

Set the stroke width of a command

Parameters
commandGDrawCommand for which to set the stroke width
stroke_widthstroke width to set for the command