Generated by Doxygen 1.8.14
Neographics
draw_command.h
1 #pragma once
2 #include <pebble.h>
3 #include "../macros.h"
4 #include "../path/path.h"
5 #include "../primitives/circle.h"
6 
7 /*-----------------------------------------------------------------------------.
8 | |
9 | Draw Commands |
10 | |
11 | Draw Commands were some of the most overlooked features of PebbleOS. |
12 | Neographics will continue to support them and even expand on them: |
13 | For example, you may have noticed that Draw Commands originally didn't |
14 | circles centered on subpixels, and that having multiple points in a |
15 | circle would lead to weird behavior in lieu of drawing multiple circles |
16 | with different centers. |
17 | |
18 | To facilitate these changes, neographics defines the Draw Command file |
19 | format version 2. Note that previously invalid files may now count as |
20 | valid. Neographics should be backwards-compatible with all valid files |
21 | from Draw Command version 1. |
22 | |
23 | The `flags` byte (offset 1 in commands) now also lets users specify |
24 | specific fallback colors for b/w screens. |
25 | |
26 `-----------------------------------------------------------------------------*/
27 
33 #define __N_DRAW_COMMAND_MAXIMUM_SUPPORTED_VERSION 2
34 
39 typedef enum n_GDrawCommandType {
40  n_GDrawCommandTypeInvalid = 0,
41  n_GDrawCommandTypePath = 1,
42  n_GDrawCommandTypeCircle = 2,
43  n_GDrawCommandTypePrecisePath = 3,
44  n_GDrawCommandTypePreciseCircle = 4,
46 
55 typedef enum n_GDrawCommandBWColor {
56  n_GDrawCommandBWColorClear = 0,
57  n_GDrawCommandBWColorBlack = 1,
58  n_GDrawCommandBWColorGray = 2,
59  n_GDrawCommandBWColorWhite = 3,
61 
67 typedef struct n_GDrawCommandFlags {
68  bool hidden:1;
69  bool use_bw_color:1;
70  uint8_t bw_stroke:2;
71  uint8_t bw_fill:2;
73 
77 typedef struct n_GDrawCommand {
78  n_GDrawCommandType type;
79  n_GDrawCommandFlags flags;
80  n_GColor stroke_color;
81  uint8_t stroke_width;
82  n_GColor fill_color;
83  union {
84  struct {
85  bool path_open:1;
86  } path_flags;
87  uint16_t circle_radius;
88  };
89  uint16_t num_points;
90  n_GPoint points[];
91 } __attribute((__packed__)) n_GDrawCommand;
92 
96 typedef struct n_GDrawCommandList {
97  uint16_t num_commands;
98  n_GDrawCommand commands[];
99 } __attribute((__packed__)) n_GDrawCommandList;
100 
105 typedef struct n_GDrawCommandImage {
106  uint64_t reserved_0;
107  uint8_t version;
108  uint8_t reserved_1;
109  n_GSize view_box;
110  n_GDrawCommandList command_list[];
111 } __attribute((__packed__)) n_GDrawCommandImage;
112 
117 typedef struct n_GDrawCommandFrame {
118  uint16_t duration;
119  n_GDrawCommandList command_list[];
120 } __attribute((__packed__)) n_GDrawCommandFrame;
121 
127 typedef struct n_GDrawCommandSequence {
128  uint64_t reserved_0;
129  uint8_t version;
130  uint8_t reserved_1;
131  n_GSize view_box;
132  uint16_t play_count;
133  uint16_t num_frames;
134  n_GDrawCommandFrame frames[];
135 } __attribute((__packed__)) n_GDrawCommandSequence;
136 
137 typedef bool (n_GDrawCommandListIteratorCb)(n_GDrawCommand * command, uint32_t index, void * context);
138 
143 
148 
156 void n_gdraw_command_set_stroke_color(n_GDrawCommand * command, n_GColor stroke_color);
157 
165 void n_gdraw_command_set_stroke_width(n_GDrawCommand * command, uint8_t stroke_width);
166 
174 void n_gdraw_command_set_fill_color(n_GDrawCommand * command, n_GColor fill_color);
175 
179 n_GPoint n_gdraw_command_get_point(n_GDrawCommand * command, uint16_t index);
183 void n_gdraw_command_set_point(n_GDrawCommand * command, uint16_t index, n_GPoint point);
184 
188 uint16_t n_gdraw_command_get_radius(n_GDrawCommand * command);
192 void n_gdraw_command_set_radius(n_GDrawCommand * command, uint16_t radius);
193 
201 void n_gdraw_command_set_path_open(n_GDrawCommand * command, bool path_open);
202 
210 void n_gdraw_command_set_hidden(n_GDrawCommand * command, bool hidden);
211 
212 /* draw: defined for image / frame / sequence */
213 
214 // NB these all take offsets. in the builtins, only image and frame drawing do.
218 void n_gdraw_command_draw(n_GContext * ctx, n_GDrawCommand * command, n_GPoint offset);
231 
240 
249 
250 /* miscellaneous list-only */
251 
255 void n_gdraw_command_list_iterate(n_GDrawCommandList * list, n_GDrawCommandListIteratorCb cb, void * cb_context);
256 
257 /* miscellaneous frame-only */
258 
266 void n_gdraw_command_frame_set_duration(n_GDrawCommandFrame * frame, uint16_t duration);
267 
268 /* miscellaneous sequence-only */
269 
285 void n_gdraw_command_sequence_set_play_count(n_GDrawCommandSequence * sequence, uint16_t play_count);
286 
291 
296 
297 /* get / set bounds: defined for image and sequence */
298 
311 
324 
325 /* create with resource / clone / destroy */
326 
339 
352 
void n_gdraw_command_set_point(n_GDrawCommand *command, uint16_t index, n_GPoint point)
Definition: draw_command.c:43
void n_gdraw_command_frame_draw(n_GContext *ctx, n_GDrawCommandSequence *sequence, n_GDrawCommandFrame *frame, n_GPoint offset)
Definition: draw_command.c:143
void n_gdraw_command_sequence_destroy(n_GDrawCommandSequence *sequence)
Definition: draw_command.c:282
n_GPoint n_gdraw_command_get_point(n_GDrawCommand *command, uint16_t index)
Definition: draw_command.c:40
bool n_gdraw_command_get_hidden(n_GDrawCommand *command)
Definition: draw_command.c:61
void n_gdraw_command_frame_set_duration(n_GDrawCommandFrame *frame, uint16_t duration)
Definition: draw_command.c:202
void n_gdraw_command_set_stroke_color(n_GDrawCommand *command, n_GColor stroke_color)
Definition: draw_command.c:22
n_GSize n_gdraw_command_image_get_bounds_size(n_GDrawCommandImage *image)
Definition: draw_command.c:242
bool n_gdraw_command_get_path_open(n_GDrawCommand *command)
Definition: draw_command.c:54
uint16_t n_gdraw_command_sequence_get_num_frames(n_GDrawCommandSequence *sequence)
Definition: draw_command.c:237
n_GDrawCommandSequence * n_gdraw_command_sequence_clone(n_GDrawCommandSequence *image)
Definition: draw_command.c:280
uint16_t n_gdraw_command_frame_get_duration(n_GDrawCommandFrame *frame)
Definition: draw_command.c:200
Definition: color.h:26
void n_gdraw_command_set_radius(n_GDrawCommand *command, uint16_t radius)
Definition: draw_command.c:50
Definition: draw_command.h:77
n_GColor n_gdraw_command_get_fill_color(n_GDrawCommand *command)
Definition: draw_command.c:33
Definition: draw_command.h:127
n_GDrawCommandBWColor
Definition: draw_command.h:55
void n_gdraw_command_set_hidden(n_GDrawCommand *command, bool hidden)
Definition: draw_command.c:64
void n_gdraw_command_set_path_open(n_GDrawCommand *command, bool path_open)
Definition: draw_command.c:57
void n_gdraw_command_set_fill_color(n_GDrawCommand *command, n_GColor fill_color)
Definition: draw_command.c:36
n_GDrawCommandImage * n_gdraw_command_image_clone(n_GDrawCommandImage *image)
Definition: draw_command.c:264
n_GDrawCommandFrame * n_gdraw_command_sequence_get_frame_by_index(n_GDrawCommandSequence *sequence, uint32_t index)
Definition: draw_command.c:221
uint8_t n_gdraw_command_get_stroke_width(n_GDrawCommand *command)
Definition: draw_command.c:26
void n_gdraw_command_sequence_set_bounds_size(n_GDrawCommandSequence *sequence, n_GSize size)
Definition: draw_command.c:249
Definition: draw_command.h:96
n_GDrawCommand * n_gdraw_command_list_get_command(n_GDrawCommandList *list, uint32_t index)
Definition: draw_command.c:178
void n_gdraw_command_image_destroy(n_GDrawCommandImage *image)
Definition: draw_command.c:266
void n_gdraw_command_image_draw(n_GContext *ctx, n_GDrawCommandImage *image, n_GPoint offset)
Definition: draw_command.c:139
Definition: context.h:28
uint16_t n_gdraw_command_get_radius(n_GDrawCommand *command)
Definition: draw_command.c:47
uint16_t n_gdraw_command_get_num_points(n_GDrawCommand *command)
Definition: draw_command.c:15
n_GDrawCommandSequence * n_gdraw_command_sequence_create_with_resource(uint32_t resource_id)
Definition: draw_command.c:270
n_GDrawCommandType
Definition: draw_command.h:39
Definition: draw_command.h:117
uint32_t n_gdraw_command_list_get_num_commands(n_GDrawCommandList *list)
Definition: draw_command.c:175
n_GSize n_gdraw_command_sequence_get_bounds_size(n_GDrawCommandSequence *sequence)
Definition: draw_command.c:247
n_GDrawCommandList * n_gdraw_command_frame_get_command_list(n_GDrawCommandFrame *frame)
Definition: draw_command.c:171
uint32_t n_gdraw_command_sequence_get_total_duration(n_GDrawCommandSequence *sequence)
Definition: draw_command.c:228
struct n_GDrawCommand __attribute((__packed__)) n_GDrawCommand
void n_gdraw_command_list_iterate(n_GDrawCommandList *list, n_GDrawCommandListIteratorCb cb, void *cb_context)
Definition: draw_command.c:188
void n_gdraw_command_image_set_bounds_size(n_GDrawCommandImage *image, n_GSize size)
Definition: draw_command.c:244
n_GColor n_gdraw_command_get_stroke_color(n_GDrawCommand *command)
Definition: draw_command.c:19
n_GDrawCommandImage * n_gdraw_command_image_create_with_resource(uint32_t resource_id)
Definition: draw_command.c:254
Definition: draw_command.h:105
Definition: point.h:24
void n_gdraw_command_list_draw(n_GContext *ctx, n_GDrawCommandList *list, n_GPoint offset)
Definition: draw_command.c:158
void n_gdraw_command_draw(n_GContext *ctx, n_GDrawCommand *command, n_GPoint offset)
Definition: draw_command.c:70
Definition: size.h:22
void n_gdraw_command_set_stroke_width(n_GDrawCommand *command, uint8_t stroke_width)
Definition: draw_command.c:29
void n_gdraw_command_sequence_set_play_count(n_GDrawCommandSequence *sequence, uint16_t play_count)
Definition: draw_command.c:225
uint32_t n_gdraw_command_sequence_get_play_count(n_GDrawCommandSequence *sequence)
Definition: draw_command.c:223
Definition: draw_command.h:67
n_GDrawCommandType n_gdraw_command_get_type(n_GDrawCommand *command)
Definition: draw_command.c:11
n_GDrawCommandList * n_gdraw_command_image_get_command_list(n_GDrawCommandImage *image)
Definition: draw_command.c:168
struct n_GDrawCommandFlags n_GDrawCommandFlags
n_GDrawCommandFrame * n_gdraw_command_sequence_get_frame_by_elapsed(n_GDrawCommandSequence *sequence, uint32_t ms)
Definition: draw_command.c:207