Pebble Foundation Classes  0.2.0
C++ for Pebble
Pebble::GContext Class Reference
Collaboration diagram for Pebble::GContext:

Public Member Functions

 GContext (::GContext *ctx)
 Wraps an existing graphics context.
 
 operator::GContext * () const
 Instances of this class can be automatically converted to Pebble GContext pointer.
 
void SetStrokeColor (GColor color) const
 
void SetFillColor (GColor color) const
 
void SetTextColor (GColor color) const
 
void SetCompositingMode (GCompOp mode) const
 
void SetAntialiased (bool enable) const
 
void SetStrokeWidth (uint8_t stroke_width) const
 
void DrawText (const char *text, GFont const font, const GRect box, const GTextOverflowMode overflow_mode=GTextOverflowModeWordWrap, const GTextAlignment alignment=GTextAlignmentLeft) const
 
void DrawText (const char *text, GFont const font, const GRect box, const GTextOverflowMode overflow_mode, const GTextAlignment alignment, const GTextAttributes &text_attributes) const
 
void DrawText (const std::string &text, GFont const font, const GRect box, const GTextOverflowMode overflow_mode=GTextOverflowModeWordWrap, const GTextAlignment alignment=GTextAlignmentLeft) const
 
void DrawText (const std::string &text, GFont const font, const GRect box, const GTextOverflowMode overflow_mode, const GTextAlignment alignment, const GTextAttributes &text_attributes) const
 
void DrawPixel (GPoint point) const
 
void DrawLine (GPoint p0, GPoint p1) const
 
void DrawRect (GRect rect) const
 
void FillRect (GRect rect, uint16_t corner_radius, GCornerMask corner_mask) const
 
void DrawCircle (GPoint p, uint16_t radius) const
 
void FillCircle (GPoint p, uint16_t radius) const
 
void DrawRoundRect (GRect rect, uint16_t radius) const
 
void DrawBitmapInRect (const GBitmap &bitmap, GRect rect) const
 
GBitmap CaptureFrameBuffer ()
 A shortcut to capture the framebuffer in the native format of the watch.
 
GBitmap CaptureFrameBuffer (GBitmapFormat format)
 
bool ReleaseFrameBuffer (const GBitmap &buffer)
 
bool FrameBufferIsCaptured ()
 
void DrawRotatedBitmap (const GBitmap &src, GPoint src_ic, int rotation, GPoint dest_ic) const
 
void DrawArc (GRect rect, GOvalScaleMode scale_mode, int32_t angle_start, int32_t angle_end) const
 
void FillRadial (GRect rect, GOvalScaleMode scale_mode, uint16_t inset_thickness, int32_t angle_start, int32_t angle_end) const
 

Static Public Member Functions

static GSize GetContentSize (const char *text, GFont const font, const GRect box, const GTextOverflowMode overflow_mode=GTextOverflowModeWordWrap, const GTextAlignment alignment=GTextAlignmentLeft)
 
static GSize GetContentSize (const char *text, GFont const font, const GRect box, const GTextOverflowMode overflow_mode, const GTextAlignment alignment, const GTextAttributes &text_attributes)
 
static GSize GetContentSize (const std::string &text, GFont const font, const GRect box, const GTextOverflowMode overflow_mode=GTextOverflowModeWordWrap, const GTextAlignment alignment=GTextAlignmentLeft)
 
static GSize GetContentSize (const std::string &text, GFont const font, const GRect box, const GTextOverflowMode overflow_mode, const GTextAlignment alignment, const GTextAttributes &text_attributes)
 

Protected Attributes

::GContextgcontext_
 

Member Function Documentation

◆ CaptureFrameBuffer()

GBitmap Pebble::GContext::CaptureFrameBuffer ( GBitmapFormat  format)
inline

Captures the frame buffer for direct access, using the given format. Graphics functions will not affect the frame buffer while it is captured. The frame buffer is released when ReleaseFrameBuffer is called. The frame buffer must be released before the end of a layer's .update_proc for the layer to be drawn properly.

While the frame buffer is captured calling CaptureFrameBuffer will fail and return and invalid GBitmap

Note
When writing to the frame buffer, you should respect the visible boundaries of a window on the screen. Use layer_get_frame(window_get_root_layer(window)).origin to obtain its position relative to the frame buffer. For example, drawing to (5, 5) in the frame buffer while the window is transitioning to the left with its origin at (-20, 0) would effectively draw that point at (25, 5) relative to the window. For this reason you should consider the window's root layer frame when calculating drawing coordinates.
See also
GBitmap
GBitmapFormat
layer_get_frame
window_get_root_layer
Parameters
ctxThe graphics context providing the frame buffer
formatThe format in which the framebuffer should be captured. Supported formats are GBitmapFormat1Bit and GBitmapFormat8Bit.
Returns
A pointer to the frame buffer. Invalid if failed.

◆ DrawArc()

void Pebble::GContext::DrawArc ( GRect  rect,
GOvalScaleMode  scale_mode,
int32_t  angle_start,
int32_t  angle_end 
) const
inline

Draws a line arc clockwise between angle_start and angle_end, where 0° is the top of the circle. If the difference between angle_start and angle_end is greater than 360°, a full circle will be drawn.

Parameters
rectThe reference rectangle to derive the center point and radius (see scale_mode).
scale_modeDetermines how rect will be used to derive the center point and radius.
angle_startRadial starting angle. Use DEG_TO_TRIGANGLE to easily convert degrees to the appropriate value.
angle_endRadial finishing angle. If smaller than angle_start, nothing will be drawn.

◆ DrawBitmapInRect()

void Pebble::GContext::DrawBitmapInRect ( const GBitmap bitmap,
GRect  rect 
) const
inline

Draws a bitmap into the graphics context, inside the specified rectangle

Parameters
bitmapThe bitmap to draw
rectThe rectangle in which to draw the bitmap
Note
If the size of rect is smaller than the size of the bitmap, the bitmap will be clipped on right and bottom edges. If the size of rect is larger than the size of the bitmap, the bitmap will be tiled automatically in both horizontal and vertical directions, effectively drawing a repeating pattern.
See also
GBitmap
GContext

◆ DrawCircle()

void Pebble::GContext::DrawCircle ( GPoint  p,
uint16_t  radius 
) const
inline

Draws the outline of a circle in the current stroke color

Parameters
pThe center point of the circle
radiusThe radius in pixels

◆ DrawLine()

void Pebble::GContext::DrawLine ( GPoint  p0,
GPoint  p1 
) const
inline

Draws line in the current stroke color, current stroke width and AA flag

Parameters
p0The starting point of the line
p1The ending point of the line

◆ DrawPixel()

void Pebble::GContext::DrawPixel ( GPoint  point) const
inline

Draws a pixel at given point in the current stroke color

Parameters
pointThe point at which to draw the pixel

◆ DrawRect()

void Pebble::GContext::DrawRect ( GRect  rect) const
inline

Draws a 1-pixel wide rectangle outline in the current stroke color

Parameters
rectThe rectangle for which to draw the outline

◆ DrawRotatedBitmap()

void Pebble::GContext::DrawRotatedBitmap ( const GBitmap src,
GPoint  src_ic,
int  rotation,
GPoint  dest_ic 
) const
inline

Draws a rotated bitmap with a memory-sensitive 2x anti-aliasing technique (using ray-finding instead of super-sampling), which is thresholded into a b/w bitmap for 1-bit and color blended for 8-bit.

Note
This API has performance limitations that can degrade user experience. Use sparingly.
Parameters
srcThe source bitmap to draw
src_icInstance center (single point unaffected by rotation) relative to source bitmap
rotationAngle of rotation. Rotation is an integer between 0 (no rotation) and TRIG_MAX_ANGLE (360 degree rotation). Use DEG_TO_TRIGANGLE to easily convert degrees to the appropriate value.
dest_icWhere to draw the instance center of the rotated bitmap in the context.

◆ DrawRoundRect()

void Pebble::GContext::DrawRoundRect ( GRect  rect,
uint16_t  radius 
) const
inline

Draws the outline of a rounded rectangle in the current stroke color

Parameters
rectThe rectangle defining the dimensions of the rounded rectangle to draw
radiusThe corner radius in pixels

◆ DrawText() [1/4]

void Pebble::GContext::DrawText ( const char *  text,
GFont const  font,
const GRect  box,
const GTextOverflowMode  overflow_mode,
const GTextAlignment  alignment,
const GTextAttributes text_attributes 
) const
inline

Draw text into the current graphics context, using the context's current text color. The text will be drawn inside a box with the specified dimensions and configuration, with clipping occuring automatically.

Parameters
textThe zero terminated UTF-8 string to draw
fontThe font in which the text should be set
boxThe bounding box in which to draw the text. The first line of text will be drawn against the top of the box.
overflow_modeThe overflow behavior, in case the text is larger than what fits inside the box.
alignmentThe horizontal alignment of the text
text_attributesOptional text attributes to describe the characteristics of the text

◆ DrawText() [2/4]

void Pebble::GContext::DrawText ( const char *  text,
GFont const  font,
const GRect  box,
const GTextOverflowMode  overflow_mode = GTextOverflowModeWordWrap,
const GTextAlignment  alignment = GTextAlignmentLeft 
) const
inline

Draw text into the current graphics context, using the context's current text color. The text will be drawn inside a box with the specified dimensions and configuration, with clipping occuring automatically.

Parameters
textThe zero terminated UTF-8 string to draw
fontThe font in which the text should be set
boxThe bounding box in which to draw the text. The first line of text will be drawn against the top of the box.
overflow_modeThe overflow behavior, in case the text is larger than what fits inside the box.
alignmentThe horizontal alignment of the text

◆ DrawText() [3/4]

void Pebble::GContext::DrawText ( const std::string &  text,
GFont const  font,
const GRect  box,
const GTextOverflowMode  overflow_mode,
const GTextAlignment  alignment,
const GTextAttributes text_attributes 
) const
inline

Draw text into the current graphics context, using the context's current text color. The text will be drawn inside a box with the specified dimensions and configuration, with clipping occuring automatically.

Parameters
textThe zero terminated UTF-8 string to draw
fontThe font in which the text should be set
boxThe bounding box in which to draw the text. The first line of text will be drawn against the top of the box.
overflow_modeThe overflow behavior, in case the text is larger than what fits inside the box.
alignmentThe horizontal alignment of the text
text_attributesOptional text attributes to describe the characteristics of the text

◆ DrawText() [4/4]

void Pebble::GContext::DrawText ( const std::string &  text,
GFont const  font,
const GRect  box,
const GTextOverflowMode  overflow_mode = GTextOverflowModeWordWrap,
const GTextAlignment  alignment = GTextAlignmentLeft 
) const
inline

Draw text into the current graphics context, using the context's current text color. The text will be drawn inside a box with the specified dimensions and configuration, with clipping occuring automatically.

Parameters
textThe zero terminated UTF-8 string to draw
fontThe font in which the text should be set
boxThe bounding box in which to draw the text. The first line of text will be drawn against the top of the box.
overflow_modeThe overflow behavior, in case the text is larger than what fits inside the box.
alignmentThe horizontal alignment of the text

◆ FillCircle()

void Pebble::GContext::FillCircle ( GPoint  p,
uint16_t  radius 
) const
inline

Fills a circle in the current fill color

Parameters
pThe center point of the circle
radiusThe radius in pixels

◆ FillRadial()

void Pebble::GContext::FillRadial ( GRect  rect,
GOvalScaleMode  scale_mode,
uint16_t  inset_thickness,
int32_t  angle_start,
int32_t  angle_end 
) const
inline

Fills a circle clockwise between angle_start and angle_end, where 0° is the top of the circle. If the difference between angle_start and angle_end is greater than 360°, a full circle will be drawn and filled. If angle_start is greater than angle_end nothing will be drawn.

Note
A simple example is drawing a 'Pacman' shape, with a starting angle of -225°, and ending angle of 45°. By setting inset_thickness to a non-zero value (such as 30) this example will produce the letter C.
Parameters
rectThe reference rectangle to derive the center point and radius (see scale).
scale_modeDetermines how rect will be used to derive the center point and radius.
inset_thicknessDescribes how thick in pixels the radial will be drawn towards its center measured from the outside.
angle_startRadial starting angle. Use DEG_TO_TRIGANGLE to easily convert degrees to the appropriate value.
angle_endRadial finishing angle. If smaller than angle_start, nothing will be drawn.

◆ FillRect()

void Pebble::GContext::FillRect ( GRect  rect,
uint16_t  corner_radius,
GCornerMask  corner_mask 
) const
inline

Fills a rectangle with the current fill color, optionally rounding all or a selection of its corners.

Parameters
ctxThe destination graphics context in which to draw
rectThe rectangle to fill
corner_radiusThe rounding radius of the corners in pixels (maximum is 8 pixels)
corner_maskBitmask of the corners that need to be rounded.
See also
GCornerMask

◆ FrameBufferIsCaptured()

bool Pebble::GContext::FrameBufferIsCaptured ( )
inline

Whether or not the frame buffer has been captured by graphics_capture_frame_buffer. Graphics functions will not affect the frame buffer until it has been released by graphics_release_frame_buffer.

Returns
True if the frame buffer has been captured

◆ GetContentSize() [1/4]

static GSize Pebble::GContext::GetContentSize ( const char *  text,
GFont const  font,
const GRect  box,
const GTextOverflowMode  overflow_mode,
const GTextAlignment  alignment,
const GTextAttributes text_attributes 
)
inlinestatic

Obtain the maximum size that a text with given font, overflow mode and alignment occupies within a given rectangular constraint.

Parameters
textThe zero terminated UTF-8 string for which to calculate the size
fontThe font in which the text should be set while calculating the size
boxThe bounding box in which the text should be constrained
overflow_modeThe overflow behavior, in case the text is larger than what fits inside the box.
alignmentThe horizontal alignment of the text
text_attributesOptional text attributes to describe the characteristics of the text
Returns
The maximum size occupied by the text
See also
app_graphics_text_layout_get_content_size

◆ GetContentSize() [2/4]

static GSize Pebble::GContext::GetContentSize ( const char *  text,
GFont const  font,
const GRect  box,
const GTextOverflowMode  overflow_mode = GTextOverflowModeWordWrap,
const GTextAlignment  alignment = GTextAlignmentLeft 
)
inlinestatic

Obtain the maximum size that a text with given font, overflow mode and alignment occupies within a given rectangular constraint.

Parameters
textThe zero terminated UTF-8 string for which to calculate the size
fontThe font in which the text should be set while calculating the size
boxThe bounding box in which the text should be constrained
overflow_modeThe overflow behavior, in case the text is larger than what fits inside the box.
alignmentThe horizontal alignment of the text
Returns
The maximum size occupied by the text
See also
app_graphics_text_layout_get_content_size_with_attributes

◆ GetContentSize() [3/4]

static GSize Pebble::GContext::GetContentSize ( const std::string &  text,
GFont const  font,
const GRect  box,
const GTextOverflowMode  overflow_mode,
const GTextAlignment  alignment,
const GTextAttributes text_attributes 
)
inlinestatic

Obtain the maximum size that a text with given font, overflow mode and alignment occupies within a given rectangular constraint.

Parameters
textThe zero terminated UTF-8 string for which to calculate the size
fontThe font in which the text should be set while calculating the size
boxThe bounding box in which the text should be constrained
overflow_modeThe overflow behavior, in case the text is larger than what fits inside the box.
alignmentThe horizontal alignment of the text
text_attributesOptional text attributes to describe the characteristics of the text
Returns
The maximum size occupied by the text
See also
app_graphics_text_layout_get_content_size

◆ GetContentSize() [4/4]

static GSize Pebble::GContext::GetContentSize ( const std::string &  text,
GFont const  font,
const GRect  box,
const GTextOverflowMode  overflow_mode = GTextOverflowModeWordWrap,
const GTextAlignment  alignment = GTextAlignmentLeft 
)
inlinestatic

Obtain the maximum size that a text with given font, overflow mode and alignment occupies within a given rectangular constraint.

Parameters
textThe zero terminated UTF-8 string for which to calculate the size
fontThe font in which the text should be set while calculating the size
boxThe bounding box in which the text should be constrained
overflow_modeThe overflow behavior, in case the text is larger than what fits inside the box.
alignmentThe horizontal alignment of the text
Returns
The maximum size occupied by the text
See also
app_graphics_text_layout_get_content_size_with_attributes

◆ ReleaseFrameBuffer()

bool Pebble::GContext::ReleaseFrameBuffer ( const GBitmap buffer)
inline

Releases the frame buffer. Must be called before the end of a layer's .update_proc for the layer to be drawn properly.

If buffer does not point to the address previously returned by graphics_capture_frame_buffer the frame buffer will not be released.

Parameters
bufferThe frame buffer bitmap
Returns
True if the frame buffer was released successfully

◆ SetAntialiased()

void Pebble::GContext::SetAntialiased ( bool  enable) const
inline

Sets whether antialiasing is applied to stroke drawing

Parameters
enableTrue = antialiasing enabled, False = antialiasing disabled
Note
Default value is true.

◆ SetCompositingMode()

void Pebble::GContext::SetCompositingMode ( GCompOp  mode) const
inline

Sets the current bitmap compositing mode of the graphics context.

Parameters
modeThe new compositing mode
See also
GCompOp
bitmap_layer_set_compositing_mode()
Note
At the moment, this only affects the bitmaps drawing operations – graphics_draw_bitmap_in_rect(), graphics_draw_rotated_bitmap, and anything that uses those APIs –, but it currently does not affect the filling or stroking operations.

◆ SetFillColor()

void Pebble::GContext::SetFillColor ( GColor  color) const
inline

Sets the current fill color of the graphics context.

Parameters
colorThe new fill color

◆ SetStrokeColor()

void Pebble::GContext::SetStrokeColor ( GColor  color) const
inline

Sets the current stroke color of the graphics context.

Parameters
colorThe new stroke color

◆ SetStrokeWidth()

void Pebble::GContext::SetStrokeWidth ( uint8_t  stroke_width) const
inline

Sets the width of the stroke for drawing routines

Parameters
stroke_widthWidth in pixels of the stroke.
Note
If stroke width of zero is passed, it will be ignored and will not change the value stored in GContext. Currently, only odd stroke_width values are supported. If an even value is passed in, the value will be stored as is, but the drawing routines will round down to the previous integral value when drawing. Default value is 1.

◆ SetTextColor()

void Pebble::GContext::SetTextColor ( GColor  color) const
inline

Sets the current text color of the graphics context.

Parameters
colorThe new text color

The documentation for this class was generated from the following file: