Created
July 12, 2015 08:22
-
-
Save tanb/b268558731c266158250 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- drowing path | |
GPath * gpath_create(const GPathInfo * init) | |
void gpath_destroy(GPath * gpath) | |
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) | |
struct GPath { | |
uint32_t num_points | |
GPoint points | |
int32_t rotation | |
GPoint offset | |
} | |
struct GPathInfo { | |
uint32_t num_points | |
GPoint points | |
} | |
``` | |
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: | |
graphics_context_set_fill_color(ctx, GColorWhite); | |
gpath_draw_filled(ctx, s_my_path_ptr); | |
// Stroke the path: | |
graphics_context_set_stroke_color(ctx, GColorBlack); | |
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... | |
``` | |
- DRAWING PRIMITIVES | |
void graphics_draw_pixel(GContext * ctx, GPoint point) | |
void graphics_draw_line(GContext * ctx, GPoint p0, GPoint p1) | |
void graphics_draw_rect(GContext * ctx, GRect rect) | |
void graphics_fill_rect(GContext * ctx, GRect rect, uint16_t corner_radius, GCornerMask corner_mask) | |
void graphics_draw_circle(GContext * ctx, GPoint p, uint16_t radius) | |
void graphics_fill_circle(GContext * ctx, GPoint p, uint16_t radius) | |
void graphics_draw_round_rect(GContext * ctx, GRect rect, uint16_t radius) | |
void graphics_draw_bitmap_in_rect(GContext * ctx, const GBitmap * bitmap, GRect rect) | |
GBitmap * graphics_capture_frame_buffer(GContext * ctx) | |
bool graphics_release_frame_buffer(GContext * ctx, GBitmap * buffer) | |
bool graphics_frame_buffer_is_captured(GContext * ctx) | |
enum GCornerMask { | |
GCornerNone | |
GCornerTopLeft | |
GCornerTopRight | |
GCornerBottomLeft | |
GCornerBottomRight | |
GCornersAll | |
GCornersTop | |
GCornersBottom | |
GCornersLeft | |
GCornersRight | |
} | |
#define graphics_capture_frame_buffer_format(ctx, format) | |
- DRAWING TEXT | |
void graphics_draw_text(GContext * ctx, const char * text, GFont const font, const GRect box, const GTextOverflowMode overflow_mode, const GTextAlignment alignment, const GTextLayoutCacheRef layout) | |
GSize graphics_text_layout_get_content_size(const char * text, GFont const font, const GRect box, const GTextOverflowMode overflow_mode, const GTextAlignment alignment) | |
enum GTextOverflowMode { | |
GTextOverflowModeWordWrap | |
GTextOverflowModeTrailingEllipsis | |
GTextOverflowModeFill | |
} | |
enum GTextAlignment { | |
GTextAlignmentLeft | |
GTextAlignmentCenter | |
GTextAlignmentRight | |
} | |
typedef struct TextLayout TextLayout | |
typedef TextLayout * GTextLayoutCacheRef | |
- Fonts | |
GFont fonts_get_system_font(const char * font_key) | |
GFont fonts_load_custom_font(ResHandle handle) | |
void fonts_unload_custom_font(GFont font) | |
typedef void * GFont | |
- Graphics Context | |
void graphics_context_set_stroke_color(GContext * ctx, GColor color) | |
void graphics_context_set_fill_color(GContext * ctx, GColor color) | |
void graphics_context_set_text_color(GContext * ctx, GColor color) | |
void graphics_context_set_compositing_mode(GContext * ctx, GCompOp mode) | |
- Graphics types | |
bool gpoint_equal(const GPoint *const point_a, const GPoint *const point_b) | |
bool gsize_equal(const GSize * size_a, const GSize * size_b) | |
bool grect_equal(const GRect *const rect_a, const GRect *const rect_b) | |
bool grect_is_empty(const GRect *const rect) | |
void grect_standardize(GRect * rect) | |
void grect_clip(GRect *const rect_to_clip, const GRect *const rect_clipper) | |
bool grect_contains_point(const GRect * rect, const GPoint * point) | |
GPoint grect_center_point(const GRect * rect) | |
GRect grect_crop(GRect rect, const int32_t crop_size_px) | |
GBitmap * gbitmap_create_with_resource(uint32_t resource_id) | |
GBitmap * gbitmap_create_with_data(const uint8_t * data) | |
GBitmap * gbitmap_create_as_sub_bitmap(const GBitmap * base_bitmap, GRect sub_rect) | |
GBitmap * __gbitmap_create_blank(GSize size) | |
void gbitmap_destroy(GBitmap * bitmap) | |
void grect_align(GRect * rect, const GRect * inside_rect, const GAlign alignment, const bool clip) | |
struct GBitmap { | |
void * addr | |
uint16_t row_size_bytes | |
GRect bounds | |
} | |
struct GDrawState { | |
GRect clip_box | |
GRect drawing_box | |
GColor stroke_color | |
GColor fill_color | |
GColor text_color | |
GCompOp compositing_mode | |
} | |
struct GPoint { | |
int16_t x | |
int16_t y | |
} | |
struct GRect { | |
GPoint origin | |
GSize size | |
} | |
struct GSize { | |
int16_t w | |
int16_t h | |
} | |
enum GColor { | |
GColorClear | |
GColorBlack | |
GColorWhite | |
} | |
enum GBitmapFormat { | |
GBitmapFormat1Bit | |
} | |
enum GAlign{ | |
GAlignCenter | |
GAlignTopLeft | |
GAlignTopRight | |
GAlignTop | |
GAlignLeft | |
GAlignBottom | |
GAlignRight | |
GAlignBottomRight | |
GAlignBottomLeft | |
} | |
enum GCompOp { | |
GCompOpAssign | |
GCompOpAssignInverted | |
GCompOpOr | |
GCompOpAnd | |
GCompOpClear | |
GCompOpSet | |
} | |
#define gcolor_equal(a, b) | |
#define COLOR_FALLBACK(color, bw) | |
#define GPoint(x, y) | |
#define GPointZero GPoint(0, 0) | |
#define GSize(w, h) | |
#define GSizeZero GSize(0, 0) | |
#define GRect(x, y, w, h) | |
#define GRectZero GRect(0, 0, 0, 0) | |
#define gbitmap_get_bytes_per_row(bmp) | |
#define gbitmap_get_format(bmp) | |
#define gbitmap_get_data(bmp) | |
#define gbitmap_set_data(bmp, data, fmt, rsb, fod) | |
#define gbitmap_get_bounds(bmp) | |
#define gbitmap_set_bounds(bmp, new_bounds) | |
#define gbitmap_create_blank(size, format) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment