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

Drawing Paths

Functions to draw polygons into a graphics context.

Code example:

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...

Function Documentation

GPath * gpath_create(const GPathInfo * init)

Creates a new GPath on the heap based on a series of points described by a GPathInfo.

Values after initialization:

  • num_points and points pointer: copied from the GPathInfo.

  • rotation: 0

  • offset: (0, 0)

Returns

A pointer to the GPath. NULL if the GPath could not be created

void gpath_destroy(GPath * gpath)

Free a dynamically allocated gpath created with gpath_create()

void gpath_draw_filled(GContext * ctx, GPath * path)

Draws the fill of a path into a graphics context, using the current fill color, relative to the drawing area as set up by the layering system.

Parameters

ctx

The graphics context to draw into

path

The path to fill

See Also

graphics_context_set_fill_color()
void gpath_draw_outline(GContext * ctx, GPath * path)

Draws the outline of a path into a graphics context, using the current stroke color and width, relative to the drawing area as set up by the layering system. The first and last points in the path do have a line between them.

Parameters

ctx

The graphics context to draw into

path

The path to draw

See Also

graphics_context_set_stroke_color()
void gpath_rotate_to(GPath * path, int32_t angle)

Sets the absolute rotation of the path. The current rotation will be replaced by the specified angle.

Note

Setting a rotation does not affect the points in the path directly. The rotation is applied on-the-fly during drawing, either using gpath_draw_filled() or gpath_draw_outline().

Parameters

path

The path onto which to set the rotation

angle

The absolute angle of the rotation. The angle is represented in the same way that is used with sin_lookup(). See TRIG_MAX_ANGLE for more information.

void gpath_move_to(GPath * path, GPoint point)

Sets the absolute offset of the path. The current translation will be replaced by the specified offset.

Note

Setting a translation does not affect the points in the path directly. The translation is applied on-the-fly during drawing, either using gpath_draw_filled() or gpath_draw_outline().

Parameters

path

The path onto which to set the translation

point

The point which is used as the vector for the translation.

void gpath_draw_outline_open(GContext * ctx, GPath * path)

Draws an open outline of a path into a graphics context, using the current stroke color and width, relative to the drawing area as set up by the layering system. The first and last points in the path do not have a line between them.

Parameters

ctx

The graphics context to draw into

path

The path to draw

See Also

graphics_context_set_stroke_color()

Data Structure Documentation

struct GPath

Data structure describing a path, plus its rotation and translation.

Note

See the remark with GPathInfo

Data Fields

uint32_t num_points

The number of points in the points array.

GPoint * points

Pointer to an array of points.

int32_t rotation

The rotation that will be used when drawing the path with gpath_draw_filled() or gpath_draw_outline()

GPoint offset

The translation that will to be used when drawing the path with gpath_draw_filled() or gpath_draw_outline()

struct GPathInfo

Data structure describing a naked path.

Note

Note that this data structure only refers to an array of points; the points are not stored inside this data structure itself. In most cases, one cannot use a stack-allocated array of GPoints. Instead one often needs to provide longer-lived (static or "global") storage for the points.

Data Fields

uint32_t num_points

The number of points in the points array.

GPoint * points

Pointer to an array of points.

Need some help?

Functions

  • gpath_create
  • gpath_destroy
  • gpath_draw_filled
  • gpath_draw_outline
  • gpath_rotate_to
  • gpath_move_to
  • gpath_draw_outline_open

Data Structures

  • GPath
  • GPathInfo

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!