pebble
  • Tutorials
  • Get the SDK
  • Guides
  • Documentation
  • Examples
  • Community
  • Blog
  • More
Privacy
Cookies
Publish

Pebble C API

  • Pebble C API
  • Pebble JavaScript API
  • PebbleKit JS
  • PebbleKit iOS
  • PebbleKit Android
  • Foundation
    • App
    • App Communication
    • App Glance
    • AppMessage
    • AppSync
    • AppWorker
    • DataLogging
    • DataStructures
      • UUID
    • Dictation
    • Dictionary
    • Event Service
      • AccelerometerService
      • AppFocusService
      • BatteryStateService
      • CompassService
      • ConnectionService
      • HealthService
      • TickTimerService
    • Exit Reason
    • Internationalization
    • Launch Reason
    • Logging
    • Math
    • Memory Management
    • Platform
    • Resources
      • File Formats
    • Storage
    • Timer
    • Wakeup
    • Wall Time
    • WatchInfo
    • Rocky
  • Graphics
    • Draw Commands
    • Drawing Paths
    • Drawing Primitives
    • Drawing Text
    • Fonts
    • Graphics Context
    • Graphics Types
      • Color Definitions
  • User Interface
    • Animation
      • PropertyAnimation
    • Clicks
    • Layers
      • ActionBarLayer
      • BitmapLayer
      • MenuLayer
      • RotBitmapLayer
      • ScrollLayer
      • SimpleMenuLayer
      • StatusBarLayer
      • TextLayer
    • Light
    • Preferences
    • UnobstructedArea
    • Vibes
    • Window
      • ActionMenu
      • NumberWindow
    • Window Stack
  • Standard C
    • Format
    • Locale
    • Math
    • Memory
    • String
    • Time

Graphics Context

The "canvas" into which an application draws.

The Pebble OS graphics engine, inspired by several notable graphics systems, including Apple’s Quartz 2D and its predecessor QuickDraw, provides your app with a canvas into which to draw, namely, the graphics context. A graphics context is the target into which graphics functions can paint, using Pebble drawing routines (see Drawing Primitives, Drawing Paths and Drawing Text).

A graphics context 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, and so on. The GContext struct is the type representing the graphics context.

For drawing in your Pebble watchface or watchapp, you won't need to create a GContext yourself. In most cases, it is provided by Pebble OS as an argument passed into a render callback (the .update_proc of a Layer).

Your app can’t call drawing functions at any given point in time: Pebble OS will request your app to render. Typically, your app will be calling out to graphics functions in the .update_proc callback of a Layer.

Function Documentation

void graphics_context_set_stroke_color(GContext * ctx, GColor color)

Sets the current stroke color of the graphics context.

Parameters

ctx

The graphics context onto which to set the stroke color

color

The new stroke color

void graphics_context_set_fill_color(GContext * ctx, GColor color)

Sets the current fill color of the graphics context.

Parameters

ctx

The graphics context onto which to set the fill color

color

The new fill color

void graphics_context_set_text_color(GContext * ctx, GColor color)

Sets the current text color of the graphics context.

Parameters

ctx

The graphics context onto which to set the text color

color

The new text color

void graphics_context_set_compositing_mode(GContext * ctx, GCompOp mode)

Sets the current bitmap compositing mode of the graphics context.

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.

Parameters

ctx

The graphics context onto which to set the compositing mode

mode

The new compositing mode

See Also

GCompOp
void graphics_context_set_antialiased(GContext * ctx, bool enable)

Sets whether antialiasing is applied to stroke drawing.

Note

Default value is true.

Parameters

ctx

The graphics context onto which to set the antialiasing

enable

True = antialiasing enabled, False = antialiasing disabled

void graphics_context_set_stroke_width(GContext * ctx, uint8_t stroke_width)

Sets the width of the stroke for drawing routines.

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.

Parameters

ctx

The graphics context onto which to set the stroke width

stroke_width

Width in pixels of the stroke.

Need some help?

Functions

  • graphics_context_set_stroke_color
  • graphics_context_set_fill_color
  • graphics_context_set_text_color
  • graphics_context_set_compositing_mode
  • graphics_context_set_antialiased
  • graphics_context_set_stroke_width

Getting Help

Do you have questions about the Pebble SDK?

Do you need some help understanding something on this page?

You can either take advantage of our awesome developer community and check out the SDK Help forums, or you can send us a message through the website!