All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
Graphics Context

Detailed Description

The graphics context is the "canvas" to draw into.

The graphics engine of Pebble OS is inspired by several great graphics systems that have been developed by others, notably Apple’s Quartz 2D and its predecessor QuickDraw. Although Apple’s documentation is not directly applicable, it can be an informing and interesting to read about the source of inspiration for Pebble’s graphics system.

Graphics Context

The drawing model revolves around the idea of a “graphics context”. The graphics context is the “target” into which graphics functions can paint using drawing routines (see Drawing Primitives, Drawing Paths and Drawing Text). It holds a reference to the bitmap into which to paint. It also holds the current drawing state, like the current fill color, stroke color, clipping box, drawing box, compositing mode, etc. The GContext struct is the type representing the graphics context.

Pebble OS requests your app to render

You (almost) never need to create a GContext yourself. In most cases, it is provided by Pebble OS as an argument that is passed into a render callback (the .update_proc of a Layer). It’s important to realize that Pebble OS will request your app to render. Your app cannot call drawing functions at any given point in time. Most frequently, your app will be calling out to graphics functions in the .update_proc callback of a Layer.

See Also
Layers
Drawing Primitives
Drawing Paths
Drawing Text

Function Documentation

void graphics_context_set_compositing_mode ( GContext *  ctx,
GCompOp  mode 
)

Sets the current bitmap compositing mode of the graphics context.

Parameters
ctxThe graphics context onto which to set the compositing mode
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() and anything that uses that –, but it currently does not affect the filling or stroking operations.
void graphics_context_set_fill_color ( GContext *  ctx,
GColor  color 
)

Sets the current fill color of the graphics context.

Parameters
ctxThe graphics context onto which to set the fill color
colorThe new fill color
void graphics_context_set_stroke_color ( GContext *  ctx,
GColor  color 
)

Sets the current stroke color of the graphics context.

Parameters
ctxThe graphics context onto which to set the stroke color
colorThe new stroke color
void graphics_context_set_text_color ( GContext *  ctx,
GColor  color 
)

Sets the current text color of the graphics context.

Parameters
ctxThe graphics context onto which to set the text color
colorThe new text color