├── LICENSE ├── README.md ├── appinfo.json ├── resources └── commands │ └── image.pdc ├── screenshots └── screenshot.png ├── src └── main.c └── wscript /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Pebble Examples 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # pdc-image 2 | 3 | ![screenshot](screenshots/screenshot.png) 4 | 5 | A simple example Pebble project demonstrating how to use the 6 | [`Draw Commands`](https://developer.getpebble.com/docs/c/Graphics/Draw_Commands/) 7 | API to load and display a vector file in the Pebble Drawing Commands format. 8 | 9 | See the [`cards-example`](https://github.com/pebble-examples/cards-example) 10 | repository for a similar example as well as tools to create PDC vector files. -------------------------------------------------------------------------------- /appinfo.json: -------------------------------------------------------------------------------- 1 | { 2 | "uuid": "595AEAF8-2580-4897-95E9-62FD07EAA2FE", 3 | "shortName": "pdc-image", 4 | "longName": "pdc-image", 5 | "companyName": "Pebble", 6 | "versionCode": 1, 7 | "versionLabel": "1.0", 8 | "sdkVersion": "3", 9 | "targetPlatforms": ["aplite", "basalt", "chalk"], 10 | "watchapp": { 11 | "watchface": false 12 | }, 13 | "appKeys": { 14 | "dummy": 0 15 | }, 16 | "resources": { 17 | "media": [ 18 | { 19 | "type": "raw", 20 | "name": "DRAW_COMMAND", 21 | "file": "commands/image.pdc" 22 | } 23 | ] 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /resources/commands/image.pdc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pebble-examples/pdc-image/b4069d0ba2d820eef79c59d3c83218d649e1aa9e/resources/commands/image.pdc -------------------------------------------------------------------------------- /screenshots/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pebble-examples/pdc-image/b4069d0ba2d820eef79c59d3c83218d649e1aa9e/screenshots/screenshot.png -------------------------------------------------------------------------------- /src/main.c: -------------------------------------------------------------------------------- 1 | /** 2 | * main.c - Sets up a Window and Layer that draws the GDrawCommandImage 3 | * in its LayerUpdateProc. 4 | */ 5 | 6 | #include 7 | 8 | static Window *s_main_window; 9 | static Layer *s_canvas_layer; 10 | 11 | static GDrawCommandImage *s_command_image; 12 | 13 | static void update_proc(Layer *layer, GContext *ctx) { 14 | // Place image in the center of the Window 15 | GSize img_size = gdraw_command_image_get_bounds_size(s_command_image); 16 | GRect bounds = layer_get_bounds(layer); 17 | 18 | const GEdgeInsets frame_insets = { 19 | .top = (bounds.size.h - img_size.h) / 2, 20 | .left = (bounds.size.w - img_size.w) / 2 21 | }; 22 | 23 | // If the image was loaded successfully... 24 | if (s_command_image) { 25 | // Draw it 26 | gdraw_command_image_draw(ctx, s_command_image, grect_inset(bounds, frame_insets).origin); 27 | } 28 | } 29 | 30 | static void window_load(Window *window) { 31 | Layer *window_layer = window_get_root_layer(window); 32 | GRect bounds = layer_get_bounds(window_layer); 33 | 34 | // Load the image and check it was succcessful 35 | s_command_image = gdraw_command_image_create_with_resource(RESOURCE_ID_DRAW_COMMAND); 36 | if (!s_command_image) { 37 | APP_LOG(APP_LOG_LEVEL_ERROR, "Image is NULL!"); 38 | } 39 | 40 | // Create canvas Layer and set up the update procedure 41 | s_canvas_layer = layer_create(bounds); 42 | layer_set_update_proc(s_canvas_layer, update_proc); 43 | layer_add_child(window_layer, s_canvas_layer); 44 | } 45 | 46 | static void window_unload(Window *window) { 47 | // Destroy canvas Layer 48 | layer_destroy(s_canvas_layer); 49 | 50 | // Destroy the image 51 | gdraw_command_image_destroy(s_command_image); 52 | } 53 | 54 | static void init() { 55 | // Set up main Window 56 | s_main_window = window_create(); 57 | window_set_background_color(s_main_window, PBL_IF_COLOR_ELSE(GColorJazzberryJam, GColorWhite)); 58 | window_set_window_handlers(s_main_window, (WindowHandlers) { 59 | .load = window_load, 60 | .unload = window_unload, 61 | }); 62 | window_stack_push(s_main_window, true); 63 | } 64 | 65 | static void deinit() { 66 | // Destroy main Window 67 | window_destroy(s_main_window); 68 | } 69 | 70 | int main() { 71 | init(); 72 | app_event_loop(); 73 | deinit(); 74 | } 75 | -------------------------------------------------------------------------------- /wscript: -------------------------------------------------------------------------------- 1 | 2 | # 3 | # This file is the default set of rules to compile a Pebble project. 4 | # 5 | # Feel free to customize this to your needs. 6 | # 7 | 8 | import os.path 9 | 10 | top = '.' 11 | out = 'build' 12 | 13 | def options(ctx): 14 | ctx.load('pebble_sdk') 15 | 16 | def configure(ctx): 17 | ctx.load('pebble_sdk') 18 | 19 | def build(ctx): 20 | ctx.load('pebble_sdk') 21 | 22 | build_worker = os.path.exists('worker_src') 23 | binaries = [] 24 | 25 | for p in ctx.env.TARGET_PLATFORMS: 26 | ctx.set_env(ctx.all_envs[p]) 27 | ctx.set_group(ctx.env.PLATFORM_NAME) 28 | app_elf='{}/pebble-app.elf'.format(ctx.env.BUILD_DIR) 29 | ctx.pbl_program(source=ctx.path.ant_glob('src/**/*.c'), 30 | target=app_elf) 31 | 32 | if build_worker: 33 | worker_elf='{}/pebble-worker.elf'.format(ctx.env.BUILD_DIR) 34 | binaries.append({'platform': p, 'app_elf': app_elf, 'worker_elf': worker_elf}) 35 | ctx.pbl_worker(source=ctx.path.ant_glob('worker_src/**/*.c'), 36 | target=worker_elf) 37 | else: 38 | binaries.append({'platform': p, 'app_elf': app_elf}) 39 | 40 | ctx.set_group('bundle') 41 | ctx.pbl_bundle(binaries=binaries, js=ctx.path.ant_glob('src/js/**/*.js')) 42 | --------------------------------------------------------------------------------