Pebble Foundation Classes  0.2.0
C++ for Pebble
pebble_graphics_context.hpp
1 #pragma once
2 
3 #include "pebble.hpp"
4 
5 namespace Pebble {
6 
17 
19 {
20 public:
23 
25  operator ::GTextAttributes*() { return text_attributes_; }
26  operator ::GTextAttributes*() const { return text_attributes_; }
27 
29  virtual ~GTextAttributes()
30  {
32  }
33 
38 
45 
50 
61  inline void EnablePaging(GPoint content_origin_on_screen, GRect paging_on_screen) { graphics_text_attributes_enable_paging(text_attributes_, content_origin_on_screen, paging_on_screen); }
62 
63 protected:
66 };
68 
69 
72 
73 class GContext
74 {
75 public:
77  GContext(::GContext *ctx) : gcontext_(ctx) {};
78 
79  virtual ~GContext() { }
80 
82  operator ::GContext*() const { return gcontext_; }
83 
86  inline void SetStrokeColor(GColor color) const { graphics_context_set_stroke_color(gcontext_, color); }
87 
90  inline void SetFillColor(GColor color) const { graphics_context_set_fill_color(gcontext_, color); }
91 
94  inline void SetTextColor(GColor color) const { graphics_context_set_text_color(gcontext_, color); }
95 
104  inline void SetCompositingMode(GCompOp mode) const { graphics_context_set_compositing_mode(gcontext_, mode); }
105 
109  inline void SetAntialiased(bool enable) const { graphics_context_set_antialiased(gcontext_, enable); }
110 
117  inline void SetStrokeWidth(uint8_t stroke_width) const { graphics_context_set_stroke_width(gcontext_, stroke_width); }
118 
129  inline void DrawText(const char* text, GFont const font, const GRect box, const GTextOverflowMode overflow_mode = GTextOverflowModeWordWrap, const GTextAlignment alignment = GTextAlignmentLeft) const
130  {
131  graphics_draw_text(gcontext_, text, font, box, overflow_mode, alignment, nullptr);
132  }
133 
145  inline void DrawText(const char* text, GFont const font, const GRect box, const GTextOverflowMode overflow_mode, const GTextAlignment alignment, const GTextAttributes& text_attributes ) const
146  {
147  graphics_draw_text(gcontext_, text, font, box, overflow_mode, alignment, text_attributes);
148  }
149 
160  inline void DrawText(const std::string& text, GFont const font, const GRect box, const GTextOverflowMode overflow_mode = GTextOverflowModeWordWrap, const GTextAlignment alignment = GTextAlignmentLeft) const
161  {
162  graphics_draw_text(gcontext_, text.c_str(), font, box, overflow_mode, alignment, nullptr);
163  }
164 
176  inline void DrawText(const std::string& text, GFont const font, const GRect box, const GTextOverflowMode overflow_mode, const GTextAlignment alignment, const GTextAttributes& text_attributes) const
177  {
178  graphics_draw_text(gcontext_, text.c_str(), font, box, overflow_mode, alignment, text_attributes);
179  }
180 
191  static inline GSize GetContentSize(const char* text, GFont const font, const GRect box, const GTextOverflowMode overflow_mode = GTextOverflowModeWordWrap, const GTextAlignment alignment = GTextAlignmentLeft)
192  {
193  return graphics_text_layout_get_content_size(text, font, box, overflow_mode, alignment);
194  }
195 
207  static inline GSize GetContentSize(const char* text, GFont const font, const GRect box, const GTextOverflowMode overflow_mode, const GTextAlignment alignment, const GTextAttributes& text_attributes)
208  {
209  return graphics_text_layout_get_content_size_with_attributes(text, font, box, overflow_mode, alignment, text_attributes);
210  }
211 
222  static inline GSize GetContentSize(const std::string& text, GFont const font, const GRect box, const GTextOverflowMode overflow_mode = GTextOverflowModeWordWrap, const GTextAlignment alignment = GTextAlignmentLeft)
223  {
224  return graphics_text_layout_get_content_size(text.c_str(), font, box, overflow_mode, alignment);
225  }
226 
238  static inline GSize GetContentSize(const std::string& text, GFont const font, const GRect box, const GTextOverflowMode overflow_mode, const GTextAlignment alignment, const GTextAttributes& text_attributes)
239  {
240  return graphics_text_layout_get_content_size_with_attributes(text.c_str(), font, box, overflow_mode, alignment, text_attributes);
241  }
242 
245  inline void DrawPixel(GPoint point) const { graphics_draw_pixel(gcontext_, point); }
246 
250  inline void DrawLine(GPoint p0, GPoint p1) const { graphics_draw_line(gcontext_, p0, p1); }
251 
254  inline void DrawRect(GRect rect) const { graphics_draw_rect(gcontext_, rect); }
255 
263  inline void FillRect(GRect rect, uint16_t corner_radius, GCornerMask corner_mask) const { graphics_fill_rect(gcontext_, rect, corner_radius, corner_mask); }
264 
268  inline void DrawCircle(GPoint p, uint16_t radius) const { graphics_draw_circle(gcontext_, p, radius); }
269 
273  inline void FillCircle(GPoint p, uint16_t radius) const { graphics_fill_circle(gcontext_, p, radius); }
274 
278  inline void DrawRoundRect(GRect rect, uint16_t radius) const { graphics_draw_round_rect(gcontext_, rect, radius); }
279 
290  inline void DrawBitmapInRect(const GBitmap& bitmap, GRect rect) const { graphics_draw_bitmap_in_rect(gcontext_, bitmap, rect); }
291 
294 
317  inline GBitmap CaptureFrameBuffer(GBitmapFormat format) { return graphics_capture_frame_buffer_format(gcontext_, format); }
318 
326  inline bool ReleaseFrameBuffer(const GBitmap& buffer) { return graphics_release_frame_buffer(gcontext_, buffer); }
327 
332  inline bool FrameBufferIsCaptured() { return graphics_frame_buffer_is_captured(gcontext_); }
333 
344  inline void DrawRotatedBitmap(const GBitmap& src, GPoint src_ic, int rotation, GPoint dest_ic) const
345  {
346  graphics_draw_rotated_bitmap(gcontext_, src, src_ic, rotation, dest_ic);
347  }
348 
357  inline void DrawArc(GRect rect, GOvalScaleMode scale_mode, int32_t angle_start, int32_t angle_end) const
358  {
359  graphics_draw_arc(gcontext_, rect, scale_mode, angle_start, angle_end);
360  }
361 
376  inline void FillRadial(GRect rect, GOvalScaleMode scale_mode, uint16_t inset_thickness, int32_t angle_start, int32_t angle_end) const
377  {
378  graphics_fill_radial(gcontext_, rect, scale_mode, inset_thickness, angle_start, angle_end);
379  }
380 
381 protected:
382  ::GContext* gcontext_;
383 };
384 
386 
387 }
graphics_context_set_antialiased
void graphics_context_set_antialiased(GContext *ctx, bool enable)
graphics_draw_pixel
void graphics_draw_pixel(GContext *ctx, GPoint point)
graphics_text_attributes_destroy
void graphics_text_attributes_destroy(GTextAttributes *text_attributes)
Destroys a previously created instance of GTextAttributes.
graphics_draw_arc
void graphics_draw_arc(GContext *ctx, GRect rect, GOvalScaleMode scale_mode, int32_t angle_start, int32_t angle_end)
Pebble::GContext::GetContentSize
static GSize GetContentSize(const std::string &text, GFont const font, const GRect box, const GTextOverflowMode overflow_mode, const GTextAlignment alignment, const GTextAttributes &text_attributes)
Definition: pebble_graphics_context.hpp:238
graphics_draw_circle
void graphics_draw_circle(GContext *ctx, GPoint p, uint16_t radius)
Pebble::GContext::DrawText
void DrawText(const char *text, GFont const font, const GRect box, const GTextOverflowMode overflow_mode, const GTextAlignment alignment, const GTextAttributes &text_attributes) const
Definition: pebble_graphics_context.hpp:145
Pebble::GContext::DrawText
void DrawText(const std::string &text, GFont const font, const GRect box, const GTextOverflowMode overflow_mode=GTextOverflowModeWordWrap, const GTextAlignment alignment=GTextAlignmentLeft) const
Definition: pebble_graphics_context.hpp:160
Pebble::GContext::GetContentSize
static GSize GetContentSize(const char *text, GFont const font, const GRect box, const GTextOverflowMode overflow_mode, const GTextAlignment alignment, const GTextAttributes &text_attributes)
Definition: pebble_graphics_context.hpp:207
Pebble::GContext::CaptureFrameBuffer
GBitmap CaptureFrameBuffer()
A shortcut to capture the framebuffer in the native format of the watch.
Definition: pebble_graphics_context.hpp:293
Pebble::GContext::DrawCircle
void DrawCircle(GPoint p, uint16_t radius) const
Definition: pebble_graphics_context.hpp:268
Pebble::GContext::DrawBitmapInRect
void DrawBitmapInRect(const GBitmap &bitmap, GRect rect) const
Definition: pebble_graphics_context.hpp:290
graphics_text_attributes_enable_paging
void graphics_text_attributes_enable_paging(GTextAttributes *text_attributes, GPoint content_origin_on_screen, GRect paging_on_screen)
Pebble::GContext::DrawArc
void DrawArc(GRect rect, GOvalScaleMode scale_mode, int32_t angle_start, int32_t angle_end) const
Definition: pebble_graphics_context.hpp:357
Pebble::GTextAttributes::RestoreDefaultPaging
void RestoreDefaultPaging()
Definition: pebble_graphics_context.hpp:49
graphics_text_attributes_restore_default_paging
void graphics_text_attributes_restore_default_paging(GTextAttributes *text_attributes)
GFont
FontInfo * GFont
Definition: pebble.h:4615
Pebble::GContext::SetStrokeWidth
void SetStrokeWidth(uint8_t stroke_width) const
Definition: pebble_graphics_context.hpp:117
graphics_frame_buffer_is_captured
bool graphics_frame_buffer_is_captured(GContext *ctx)
graphics_text_attributes_create
GTextAttributes * graphics_text_attributes_create(void)
Pebble::GContext::GetContentSize
static GSize GetContentSize(const char *text, GFont const font, const GRect box, const GTextOverflowMode overflow_mode=GTextOverflowModeWordWrap, const GTextAlignment alignment=GTextAlignmentLeft)
Definition: pebble_graphics_context.hpp:191
graphics_capture_frame_buffer
GBitmap * graphics_capture_frame_buffer(GContext *ctx)
Pebble::GContext::FillCircle
void FillCircle(GPoint p, uint16_t radius) const
Definition: pebble_graphics_context.hpp:273
Pebble::GContext::GContext
GContext(::GContext *ctx)
Wraps an existing graphics context.
Definition: pebble_graphics_context.hpp:77
graphics_fill_rect
void graphics_fill_rect(GContext *ctx, GRect rect, uint16_t corner_radius, GCornerMask corner_mask)
Pebble::GContext::DrawText
void DrawText(const char *text, GFont const font, const GRect box, const GTextOverflowMode overflow_mode=GTextOverflowModeWordWrap, const GTextAlignment alignment=GTextAlignmentLeft) const
Definition: pebble_graphics_context.hpp:129
GOvalScaleMode
GOvalScaleMode
Definition: pebble.h:4099
graphics_draw_bitmap_in_rect
void graphics_draw_bitmap_in_rect(GContext *ctx, const GBitmap *bitmap, GRect rect)
Pebble::GBitmap
An unowned bitmap.
Definition: pebble_graphics_types.hpp:286
graphics_draw_line
void graphics_draw_line(GContext *ctx, GPoint p0, GPoint p1)
graphics_text_layout_get_content_size_with_attributes
GSize graphics_text_layout_get_content_size_with_attributes(const char *text, GFont const font, const GRect box, const GTextOverflowMode overflow_mode, const GTextAlignment alignment, GTextAttributes *text_attributes)
GTextAlignment
GTextAlignment
Definition: pebble.h:4676
Pebble::GTextAttributes::RestoreDefaultTextFlow
void RestoreDefaultTextFlow()
Definition: pebble_graphics_context.hpp:37
graphics_context_set_stroke_color
void graphics_context_set_stroke_color(GContext *ctx, GColor color)
Pebble::GContext::SetAntialiased
void SetAntialiased(bool enable) const
Definition: pebble_graphics_context.hpp:109
graphics_context_set_stroke_width
void graphics_context_set_stroke_width(GContext *ctx, uint8_t stroke_width)
GBitmapFormat
GBitmapFormat
The format of a GBitmap can either be 1-bit or 8-bit.
Definition: pebble.h:3428
Pebble::GTextAttributes::~GTextAttributes
virtual ~GTextAttributes()
Destroys the underlying pebble GTextAttributes.
Definition: pebble_graphics_context.hpp:29
Pebble::GContext::DrawRect
void DrawRect(GRect rect) const
Definition: pebble_graphics_context.hpp:254
graphics_draw_text
void graphics_draw_text(GContext *ctx, const char *text, GFont const font, const GRect box, const GTextOverflowMode overflow_mode, const GTextAlignment alignment, GTextAttributes *text_attributes)
graphics_draw_rotated_bitmap
void graphics_draw_rotated_bitmap(GContext *ctx, GBitmap *src, GPoint src_ic, int rotation, GPoint dest_ic)
Pebble::GContext::FillRect
void FillRect(GRect rect, uint16_t corner_radius, GCornerMask corner_mask) const
Definition: pebble_graphics_context.hpp:263
Pebble::GTextAttributes::text_attributes_
::GTextAttributes * text_attributes_
Underlying GTextAttributes.
Definition: pebble_graphics_context.hpp:65
graphics_fill_radial
void graphics_fill_radial(GContext *ctx, GRect rect, GOvalScaleMode scale_mode, uint16_t inset_thickness, int32_t angle_start, int32_t angle_end)
Pebble::GSize
Definition: pebble_graphics_types.hpp:5
GCornerMask
GCornerMask
Definition: pebble.h:3955
Pebble::GContext::FillRadial
void FillRadial(GRect rect, GOvalScaleMode scale_mode, uint16_t inset_thickness, int32_t angle_start, int32_t angle_end) const
Definition: pebble_graphics_context.hpp:376
GTextAlignmentLeft
@ GTextAlignmentLeft
Aligns the text to the left of the drawing box.
Definition: pebble.h:4678
Pebble::GContext::GetContentSize
static GSize GetContentSize(const std::string &text, GFont const font, const GRect box, const GTextOverflowMode overflow_mode=GTextOverflowModeWordWrap, const GTextAlignment alignment=GTextAlignmentLeft)
Definition: pebble_graphics_context.hpp:222
graphics_context_set_compositing_mode
void graphics_context_set_compositing_mode(GContext *ctx, GCompOp mode)
graphics_capture_frame_buffer_format
GBitmap * graphics_capture_frame_buffer_format(GContext *ctx, GBitmapFormat format)
Pebble::GContext::DrawText
void DrawText(const std::string &text, GFont const font, const GRect box, const GTextOverflowMode overflow_mode, const GTextAlignment alignment, const GTextAttributes &text_attributes) const
Definition: pebble_graphics_context.hpp:176
graphics_release_frame_buffer
bool graphics_release_frame_buffer(GContext *ctx, GBitmap *buffer)
graphics_draw_round_rect
void graphics_draw_round_rect(GContext *ctx, GRect rect, uint16_t radius)
graphics_context_set_text_color
void graphics_context_set_text_color(GContext *ctx, GColor color)
Pebble::GContext::DrawLine
void DrawLine(GPoint p0, GPoint p1) const
Definition: pebble_graphics_context.hpp:250
Pebble::GRect
Definition: pebble_graphics_types.hpp:71
Pebble::GContext
Definition: pebble_graphics_context.hpp:73
Pebble::GTextAttributes::EnableScreenTextFlow
void EnableScreenTextFlow(uint8_t inset)
Definition: pebble_graphics_context.hpp:44
Pebble::GContext::ReleaseFrameBuffer
bool ReleaseFrameBuffer(const GBitmap &buffer)
Definition: pebble_graphics_context.hpp:326
Pebble::GContext::CaptureFrameBuffer
GBitmap CaptureFrameBuffer(GBitmapFormat format)
Definition: pebble_graphics_context.hpp:317
GCompOp
GCompOp
Definition: pebble.h:3761
graphics_context_set_fill_color
void graphics_context_set_fill_color(GContext *ctx, GColor color)
graphics_text_layout_get_content_size
GSize graphics_text_layout_get_content_size(const char *text, GFont const font, const GRect box, const GTextOverflowMode overflow_mode, const GTextAlignment alignment)
Pebble::GTextAttributes::EnablePaging
void EnablePaging(GPoint content_origin_on_screen, GRect paging_on_screen)
Definition: pebble_graphics_context.hpp:61
Pebble::GContext::SetFillColor
void SetFillColor(GColor color) const
Definition: pebble_graphics_context.hpp:90
Pebble::GContext::SetCompositingMode
void SetCompositingMode(GCompOp mode) const
Definition: pebble_graphics_context.hpp:104
Pebble::GContext::FrameBufferIsCaptured
bool FrameBufferIsCaptured()
Definition: pebble_graphics_context.hpp:332
Pebble::GTextAttributes
Definition: pebble_graphics_context.hpp:18
graphics_text_attributes_enable_screen_text_flow
void graphics_text_attributes_enable_screen_text_flow(GTextAttributes *text_attributes, uint8_t inset)
Pebble::GContext::DrawPixel
void DrawPixel(GPoint point) const
Definition: pebble_graphics_context.hpp:245
Pebble::GTextAttributes::GTextAttributes
GTextAttributes()
Creates an instance of GTextAttributes for advanced control when rendering text.
Definition: pebble_graphics_context.hpp:22
Pebble::GPoint
Definition: pebble_graphics_types.hpp:33
Pebble::GContext::SetStrokeColor
void SetStrokeColor(GColor color) const
Definition: pebble_graphics_context.hpp:86
GTextOverflowModeWordWrap
@ GTextOverflowModeWordWrap
Definition: pebble.h:4663
Pebble::GContext::SetTextColor
void SetTextColor(GColor color) const
Definition: pebble_graphics_context.hpp:94
GColor8
Definition: pebble.h:3268
graphics_fill_circle
void graphics_fill_circle(GContext *ctx, GPoint p, uint16_t radius)
graphics_text_attributes_restore_default_text_flow
void graphics_text_attributes_restore_default_text_flow(GTextAttributes *text_attributes)
Pebble::GContext::DrawRotatedBitmap
void DrawRotatedBitmap(const GBitmap &src, GPoint src_ic, int rotation, GPoint dest_ic) const
Definition: pebble_graphics_context.hpp:344
GTextOverflowMode
GTextOverflowMode
Definition: pebble.h:4660
Pebble::GContext::DrawRoundRect
void DrawRoundRect(GRect rect, uint16_t radius) const
Definition: pebble_graphics_context.hpp:278
graphics_draw_rect
void graphics_draw_rect(GContext *ctx, GRect rect)