separated background/ticks and hands into layers
parent
18223442d0
commit
adfcf45283
99
src/main.c
99
src/main.c
|
@ -47,7 +47,7 @@ typedef struct {
|
|||
} Time;
|
||||
|
||||
static Window *s_main_window;
|
||||
static Layer *s_canvas_layer;
|
||||
static Layer *bg_canvas_layer, *s_canvas_layer;
|
||||
|
||||
static GPoint s_center;
|
||||
static Time s_last_time;
|
||||
|
@ -110,6 +110,9 @@ static void inbox_received_handler(DictionaryIterator *iter, void *context) {
|
|||
persist_write_bool(KEY_RECT_TICKS, false);
|
||||
rectticks = false;
|
||||
}
|
||||
if(bg_canvas_layer) {
|
||||
layer_mark_dirty(s_canvas_layer);
|
||||
}
|
||||
if(s_canvas_layer) {
|
||||
layer_mark_dirty(s_canvas_layer);
|
||||
}
|
||||
|
@ -170,56 +173,16 @@ static int32_t get_angle_for_hour(int hour, int minute) {
|
|||
return (((hour * 360) / 12)+(get_angle_for_minute(minute)/12));
|
||||
}
|
||||
|
||||
static void update_proc(Layer *layer, GContext *ctx) {
|
||||
static void bg_update_proc(Layer *layer, GContext *ctx) {
|
||||
GRect bounds = layer_get_bounds(layer);
|
||||
GRect bounds_h = bounds;
|
||||
bounds_h.size.w = bounds_h.size.h;
|
||||
bounds_h.origin.x -= (bounds_h.size.w-bounds.size.w)/2;
|
||||
int maxradius = bounds_h.size.w;
|
||||
if (bounds_h.size.h < maxradius) { maxradius = bounds_h.size.h; }
|
||||
maxradius /= 2;
|
||||
int animradius = maxradius-((maxradius*animpercent)/100);
|
||||
#if defined(PBL_RECT)
|
||||
int platform_margin_m = (HAND_MARGIN_M/1.5);
|
||||
#elif defined(PBL_ROUND)
|
||||
int platform_margin_m = HAND_MARGIN_M;
|
||||
#endif
|
||||
int outer_m = animradius+platform_margin_m;
|
||||
int outer_h = animradius+HAND_MARGIN_H;
|
||||
|
||||
if (outer_m < platform_margin_m) {
|
||||
outer_m = platform_margin_m;
|
||||
}
|
||||
if (outer_h < HAND_MARGIN_H) {
|
||||
outer_h = HAND_MARGIN_H;
|
||||
}
|
||||
if (outer_m > maxradius) {
|
||||
outer_m = maxradius;
|
||||
}
|
||||
if (outer_h > maxradius) {
|
||||
outer_h = maxradius;
|
||||
}
|
||||
GRect bounds_mo = grect_inset(bounds_h, GEdgeInsets(outer_m));
|
||||
GRect bounds_ho = grect_inset(bounds_h, GEdgeInsets(outer_h));
|
||||
graphics_context_set_fill_color(ctx, gcolorbg);
|
||||
graphics_fill_rect(ctx, bounds, 0, GCornerNone);
|
||||
graphics_context_set_antialiased(ctx, ANTIALIASING);
|
||||
|
||||
// Use current time while animating
|
||||
Time mode_time = s_last_time;
|
||||
|
||||
// Adjust for minutes through the hour
|
||||
float hour_deg = get_angle_for_hour(mode_time.hours, mode_time.minutes);
|
||||
float minute_deg = get_angle_for_minute(mode_time.minutes);
|
||||
|
||||
GPoint minute_hand_outer = gpoint_from_polar(bounds_mo, GOvalScaleModeFillCircle, DEG_TO_TRIGANGLE(minute_deg));
|
||||
GPoint hour_hand_outer = gpoint_from_polar(bounds_ho, GOvalScaleModeFillCircle, DEG_TO_TRIGANGLE(hour_deg));
|
||||
|
||||
if (ticks > 0) {
|
||||
graphics_context_set_fill_color(ctx, gcolort);
|
||||
#if defined(PBL_RECT)
|
||||
if (rectticks) {
|
||||
int dist_v = 41;
|
||||
int dist_v = 39;
|
||||
int dist_h = 46;
|
||||
int halfwidth = (bounds.size.w/2)-1;
|
||||
int halfheight = (bounds.size.h/2)-1;
|
||||
|
@ -260,7 +223,51 @@ static void update_proc(Layer *layer, GContext *ctx) {
|
|||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
static void update_proc(Layer *layer, GContext *ctx) {
|
||||
GRect bounds = layer_get_bounds(layer);
|
||||
GRect bounds_h = bounds;
|
||||
bounds_h.size.w = bounds_h.size.h;
|
||||
bounds_h.origin.x -= (bounds_h.size.w-bounds.size.w)/2;
|
||||
int maxradius = bounds_h.size.w;
|
||||
if (bounds_h.size.h < maxradius) { maxradius = bounds_h.size.h; }
|
||||
maxradius /= 2;
|
||||
int animradius = maxradius-((maxradius*animpercent)/100);
|
||||
#if defined(PBL_RECT)
|
||||
int platform_margin_m = (HAND_MARGIN_M/1.5);
|
||||
#elif defined(PBL_ROUND)
|
||||
int platform_margin_m = HAND_MARGIN_M;
|
||||
#endif
|
||||
int outer_m = animradius+platform_margin_m;
|
||||
int outer_h = animradius+HAND_MARGIN_H;
|
||||
|
||||
if (outer_m < platform_margin_m) {
|
||||
outer_m = platform_margin_m;
|
||||
}
|
||||
if (outer_h < HAND_MARGIN_H) {
|
||||
outer_h = HAND_MARGIN_H;
|
||||
}
|
||||
if (outer_m > maxradius) {
|
||||
outer_m = maxradius;
|
||||
}
|
||||
if (outer_h > maxradius) {
|
||||
outer_h = maxradius;
|
||||
}
|
||||
GRect bounds_mo = grect_inset(bounds_h, GEdgeInsets(outer_m));
|
||||
GRect bounds_ho = grect_inset(bounds_h, GEdgeInsets(outer_h));
|
||||
graphics_context_set_antialiased(ctx, ANTIALIASING);
|
||||
|
||||
// Use current time while animating
|
||||
Time mode_time = s_last_time;
|
||||
|
||||
// Adjust for minutes through the hour
|
||||
float hour_deg = get_angle_for_hour(mode_time.hours, mode_time.minutes);
|
||||
float minute_deg = get_angle_for_minute(mode_time.minutes);
|
||||
|
||||
GPoint minute_hand_outer = gpoint_from_polar(bounds_mo, GOvalScaleModeFillCircle, DEG_TO_TRIGANGLE(minute_deg));
|
||||
GPoint hour_hand_outer = gpoint_from_polar(bounds_ho, GOvalScaleModeFillCircle, DEG_TO_TRIGANGLE(hour_deg));
|
||||
|
||||
if(shadows) {
|
||||
graphics_context_set_stroke_color(ctx, gcolorshadow);
|
||||
graphics_context_set_stroke_width(ctx, HAND_WIDTH);
|
||||
|
@ -340,12 +347,16 @@ static void window_load(Window *window) {
|
|||
rectticks = false;
|
||||
}
|
||||
|
||||
bg_canvas_layer = layer_create(window_bounds);
|
||||
s_canvas_layer = layer_create(window_bounds);
|
||||
layer_set_update_proc(bg_canvas_layer, bg_update_proc);
|
||||
layer_set_update_proc(s_canvas_layer, update_proc);
|
||||
layer_add_child(window_layer, s_canvas_layer);
|
||||
layer_add_child(window_layer, bg_canvas_layer);
|
||||
layer_add_child(bg_canvas_layer, s_canvas_layer);
|
||||
}
|
||||
|
||||
static void window_unload(Window *window) {
|
||||
layer_destroy(bg_canvas_layer);
|
||||
layer_destroy(s_canvas_layer);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue