Advertisement
matejdro

GPath drawing test

Jun 3rd, 2013
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.71 KB | None | 0 0
  1. #include "pebble_os.h"
  2. #include "pebble_app.h"
  3. #include "pebble_fonts.h"
  4.  
  5.  
  6. #define MY_UUID { 0x0E, 0x12, 0x99, 0x94, 0x88, 0xAB, 0x4E, 0x08, 0xA2, 0x51, 0xFB, 0x33, 0xD0, 0xD5, 0xC9, 0xE2 }
  7. PBL_APP_INFO(MY_UUID,
  8.     "Graphics test", "matejdro",
  9.     1, 0, /* App version */
  10.     DEFAULT_MENU_ICON,
  11.     APP_INFO_STANDARD_APP);
  12.  
  13. Window window;
  14. Layer circle;
  15.  
  16. static const GPathInfo ARROW = {
  17. .num_points = 7,
  18. .points = (GPoint []) {{-30, -5}, {0, -35}, {30, -5}, {15, -5}, {15, 35}, {-15, 35}, {-15,-5}}
  19. };
  20. GPath arrow;
  21.  
  22. int16_t angle = 0;
  23.  
  24. void paint_circle(Layer *layer, GContext *ctx)
  25. {
  26.   graphics_context_set_fill_color(ctx, GColorBlack);
  27.  
  28.   graphics_fill_circle(ctx, GPoint(144 / 2, 95 / 2), 95 / 2);
  29.   graphics_context_set_fill_color(ctx, GColorWhite);
  30.  
  31.   gpath_init(&arrow, &ARROW);
  32.   gpath_move_to(&arrow, GPoint(144 / 2, 95 / 2));
  33.   gpath_rotate_to(&arrow, TRIG_MAX_ANGLE * angle / 360);
  34.   gpath_draw_filled(ctx, &arrow);
  35. }
  36.  
  37. void handle_init(AppContextRef ctx) {
  38.   (void)ctx;
  39.  
  40.   window_init(&window, "Test window");
  41.   window_stack_push(&window, true /* Animated */);
  42.  
  43.   Layer* topLayer = window_get_root_layer(&window);
  44.  
  45.   layer_init(&circle, GRect(0, 168 - 16 - 97, 144, 95)); //144*80
  46.   circle.update_proc = paint_circle;
  47.   layer_add_child(topLayer, &circle);
  48. }
  49.  
  50. void handle_tick(AppContextRef app_ctx, PebbleTickEvent *event) {
  51.    angle+= 20;
  52.    if (angle > 359)
  53.      angle -= 360;
  54.  
  55.    layer_mark_dirty(&circle);
  56.  
  57. }
  58.  
  59.  
  60. void pbl_main(void *params) {
  61.   PebbleAppHandlers handlers = {
  62.       .init_handler = &handle_init,
  63.       .tick_info = {
  64.             .tick_handler = &handle_tick,
  65.             .tick_units = SECOND_UNIT
  66.           },
  67.   };
  68.   app_event_loop(params, &handlers);
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement