void ClockArea_init(Window* window) { // record the screen size, since we NEVER GET IT AGAIN screen_rect = layer_get_bounds(window_get_root_layer(window)); GRect bounds; bounds = GRect(0, 0, screen_rect.size.w, screen_rect.size.h); // init the clock area layer clock_area_layer = layer_create(bounds); layer_add_child(window_get_root_layer(window), clock_area_layer); layer_set_update_proc(clock_area_layer, update_clock_area_layer); // allocate fonts avenir = ffont_create_from_resource(RESOURCE_ID_AVENIR_REGULAR_FFONT); avenir_bold = ffont_create_from_resource(RESOURCE_ID_AVENIR_BOLD_FFONT); leco = ffont_create_from_resource(RESOURCE_ID_LECO_REGULAR_FFONT); // select fonts based on settings update_fonts(); }
static void init() { #if RESMEM size_t font_size = resource_size(resource_get_handle(RESOURCE_ID_NARROW_FFONT)); size_t body_size = sizeof(FPath) + resource_size(resource_get_handle(RESOURCE_ID_BODY_FPATH)); size_t hour_size = sizeof(FPath) + resource_size(resource_get_handle(RESOURCE_ID_HOUR_FPATH)); size_t minute_size = sizeof(FPath) + resource_size(resource_get_handle(RESOURCE_ID_MINUTE_FPATH)); size_t resource_size = font_size + body_size + hour_size + minute_size; void* g_resource_memory = malloc(resource_size); void* resptr = g_resource_memory; g_font = ffont_load_from_resource_into_buffer(RESOURCE_ID_NARROW_FFONT, resptr); resptr += font_size; g_body = fpath_load_from_resource_into_buffer(RESOURCE_ID_BODY_FPATH, resptr); resptr += body_size; g_hour = fpath_load_from_resource_into_buffer(RESOURCE_ID_HOUR_FPATH, resptr); resptr += hour_size; g_minute = fpath_load_from_resource_into_buffer(RESOURCE_ID_MINUTE_FPATH, resptr); resptr += minute_size; #else g_font = ffont_create_from_resource(RESOURCE_ID_NARROW_FFONT); g_body = fpath_create_from_resource(RESOURCE_ID_BODY_FPATH); g_hour = fpath_create_from_resource(RESOURCE_ID_HOUR_FPATH); g_minute = fpath_create_from_resource(RESOURCE_ID_MINUTE_FPATH); #endif g_window = window_create(); window_set_background_color(g_window, GColorWhite); window_stack_push(g_window, true); Layer* window_layer = window_get_root_layer(g_window); GRect window_frame = layer_get_frame(window_layer); g_layer = layer_create(window_frame); layer_set_update_proc(g_layer, &on_layer_update); layer_add_child(window_layer, g_layer); time_t now = time(NULL); g_local_time = *localtime(&now); tick_timer_service_subscribe(MINUTE_UNIT, &on_tick_timer); }