示例#1
0
void draw_ticks(GContext *ctx, GPoint center, int radius, int num_ticks, int ticks_modulo, int thick) {
    graphics_context_set_stroke_color(ctx, GColorWhite);
    graphics_context_set_fill_color(ctx, GColorWhite);
    for (int i = 0; i < num_ticks; i += 1) {
        GPoint p = tick_point(center, radius, i * 360 / num_ticks);
        if (i % ticks_modulo == 0) {
            if (thick) {
                graphics_fill_rect(ctx, GRect(p.x - 1, p.y - 1, 3, 3), 0, GCornerNone);
            } else {
                GPoint p1 = tick_point(center, radius + 1, i * 360 / num_ticks);
                GPoint p2 = tick_point(center, radius - 1, i * 360 / num_ticks);
                graphics_context_set_stroke_width(ctx, 1);
                graphics_draw_line(ctx, p1, p2);
            }
        } else {
            graphics_draw_pixel(ctx, p);
        }
    }
}
void tick_init(Window* window) {
  Layer *window_layer = window_get_root_layer(window);
  GRect bounds = layer_get_bounds(window_layer);
  const GPoint center = grect_center_point(&bounds);

  tick_setup(&tick_path_1, center, 1);
  tick_setup(&tick_path_3, center, 3);
  tick_setup(&tick_path_5, center, 5);
  tick_setup(&tick_path_7, center, 7);
  tick_setup(&tick_path_9, center, 9);
  tick_setup(&tick_path_11, center, 11);

  tick_point_2 = tick_point(center, 2);
  tick_point_4 = tick_point(center, 4);
  tick_point_6 = tick_point(center, 6);
  tick_point_8 = tick_point(center, 8);
  tick_point_10 = tick_point(center, 10);
  tick_point_12 = tick_point(center, 12);
}
void tick_setup(GPath **path, GPoint center, uint16_t hour) {
  *path = gpath_create(&TICK_POINTS);
  gpath_rotate_to(*path, TRIG_MAX_ANGLE * hour / 12);
  gpath_move_to(*path, tick_point(center, hour));
}