//draw dots static void layer_update_proc(Layer *layer, GContext *ctx) { GRect bounds = layer_get_bounds(layer); GRect frame = grect_inset(bounds, GEdgeInsets(3)); // Adjust geometry variables for inner ring frame = grect_inset(frame, GEdgeInsets(3 * DOTS_RADIUS)); // For loop that determines dot placement, color and prints dots for(int i = 0; i < vDOTS; i++) { int dot_angle = get_angle_for_dots(i); GPoint pos = gpoint_from_polar(frame, GOvalScaleModeFitCircle, DEG_TO_TRIGANGLE(dot_angle)); if (dot_angle <= 60){ graphics_context_set_fill_color(ctx, DOTS_COLOR1); } else if (dot_angle <= 120){ graphics_context_set_fill_color(ctx, DOTS_COLOR2); } else if (dot_angle <= 180){ graphics_context_set_fill_color(ctx, DOTS_COLOR3); } else if (dot_angle <= 240){ graphics_context_set_fill_color(ctx, DOTS_COLOR4); } else if (dot_angle <= 300){ graphics_context_set_fill_color(ctx, DOTS_COLOR5); } else { graphics_context_set_fill_color(ctx, DOTS_COLOR6); } graphics_fill_circle(ctx, pos, DOTS_RADIUS); } }
void pge_init() { // Start the game pge_begin(GColorWhite, game_logic, game_draw, game_click); // Keep a Window reference for adding other UI sg_window = pge_get_window(); sg_window_layer = window_get_root_layer(sg_window); sg_bounds = layer_get_bounds(sg_window_layer); sg_center = grect_center_point(&sg_bounds); // Create players player1.color = GColorBlue; player1.inset = GEdgeInsets(10); player1.velocity = 0; player1.loc = 0; player1.len = 10000; player2.color = GColorRed; player2.inset = GEdgeInsets(10); player2.velocity = 0.0; player2.loc = 0.0; player2.len = 10000; // create ball ball.color = GColorDarkCandyAppleRed; ball.center = sg_center; ball.vx = 1; ball.vy = 1; }
static void prv_draw_seconds_hand(GContext *ctx, const GRect *layer_bounds, const GPoint *center) { const SprinklesConfiguration *configuration = sprinkles_configuration_get_configuration(); const int32_t seconds_angle = s_app_data->current_seconds * TRIG_MAX_ANGLE / 60; graphics_context_set_stroke_color(ctx, configuration->seconds_hand_color); // Draw the thinner front part of the seconds hand const uint8_t seconds_forward_stroke_width = 1; graphics_context_set_stroke_width(ctx, seconds_forward_stroke_width); const GRect seconds_forward_rect = prv_get_seconds_forward_rect(layer_bounds); // Interpolate the seconds forward rect so that the seconds hand grows out to pierce the donut const int16_t inset = (int16_t)prv_interpolate_int64_linear(seconds_forward_rect.size.w / 2, 0, s_app_data->intro_animation_progress); const GRect interpolated_seconds_forward_rect = grect_inset(seconds_forward_rect, GEdgeInsets(inset)); const GPoint seconds_forward_point = gpoint_from_polar(interpolated_seconds_forward_rect, GOvalScaleModeFitCircle, seconds_angle); graphics_draw_line(ctx, (*center), seconds_forward_point); // Draw the thicker back part of the seconds hand const uint8_t seconds_backward_stroke_width = 2; graphics_context_set_stroke_width(ctx, seconds_backward_stroke_width); const GRect seconds_backward_rect = grect_inset( *layer_bounds, GEdgeInsets(seconds_forward_rect.size.w * 43 / 100)); const GPoint seconds_backward_point = gpoint_from_polar(seconds_backward_rect, GOvalScaleModeFitCircle, seconds_angle - (TRIG_MAX_ANGLE / 2)); graphics_draw_line(ctx, (*center), seconds_backward_point); }
static void layer_update_proc(Layer *layer, GContext *ctx) { if (!should_update) { APP_LOG(APP_LOG_LEVEL_INFO, "Skipped update"); return; } GRect bounds = layer_get_bounds(layer); // Draw battery line graphics_context_set_stroke_color(ctx, s_charge_percent <= 30 ? GColorYellow : GColorRed); graphics_context_set_stroke_width(ctx, 3); int lineSegment = (bounds.size.w - 56) * 10/100; for (int i = 0; i < s_charge_percent / 10; i+=1) { graphics_draw_line(ctx, GPoint(28 + i * lineSegment, 120), GPoint(26 + (lineSegment * (i + 1)), 120)); } // Draw arcs for each STEP_DIVS GRect inset_bounds = grect_inset(bounds,GEdgeInsets(1,3,2,2)); graphics_context_set_fill_color(ctx, color_from_active_status(check_active_status())); // Get the sum steps so far today HealthValue steps = health_service_sum_today(HealthMetricStepCount); int lapSteps = steps%STEPS_LAP; int lapSectionAngle = 360 / (STEPS_LAP / STEP_DIVS); int subLapSectionAngle = lapSectionAngle / 10; for (int i = 0; lapSteps > (STEP_DIVS / 10); i++) { if ( lapSteps > STEP_DIVS ) { int32_t add_Degrees = lapSectionAngle - 2; graphics_fill_radial(ctx, inset_bounds, GOvalScaleModeFitCircle, 9, DEG_TO_TRIGANGLE(lapSectionAngle * i), DEG_TO_TRIGANGLE(lapSectionAngle * i + add_Degrees )); lapSteps -= STEP_DIVS; } else { for (int j = 0; lapSteps > (STEP_DIVS / 10); j++) { int32_t add_Degrees = subLapSectionAngle - 1; graphics_fill_radial(ctx, inset_bounds, GOvalScaleModeFitCircle, ((j == 4) ? 13 : 9 ), DEG_TO_TRIGANGLE(lapSectionAngle * i + subLapSectionAngle * j), DEG_TO_TRIGANGLE(lapSectionAngle * i + subLapSectionAngle * j + add_Degrees )); lapSteps -= STEP_DIVS / 10; } } } GRect double_inset = grect_inset(inset_bounds, GEdgeInsets(15)); graphics_context_set_fill_color(ctx, GColorWhite); if (steps < STEPS_LAP) { steps += 150; return; } // draw step lap dots for (int i = 0; i < steps/STEPS_LAP; i++) { GRect xywh = grect_centered_from_polar(double_inset, GOvalScaleModeFitCircle, DEG_TO_TRIGANGLE(6 * i), GSize(5,5)); graphics_fill_radial(ctx, xywh, GOvalScaleModeFitCircle, 5, 0, TRIG_MAX_ANGLE); } steps += 33; }
static GRect prv_get_donut_orbit_rect(const GRect *layer_bounds) { const GRect seconds_forward_rect = prv_get_seconds_forward_rect(layer_bounds); const SprinklesConfiguration *configuration = sprinkles_configuration_get_configuration(); const unsigned int inset_factor_of_width = configuration->seconds_hand_enabled ? 10 : 5; return grect_inset(seconds_forward_rect, GEdgeInsets(seconds_forward_rect.size.w / inset_factor_of_width)); }
static void window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); s_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_DS_DIGIB_60)); int top = PBL_IF_ROUND_ELSE(5, -6); int left = PBL_IF_ROUND_ELSE(44, 32); s_time_layer = text_layer_create(grect_inset(bounds, GEdgeInsets(top, 0, 0, 0))); text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter); text_layer_set_text_color(s_time_layer, GColorWhite); text_layer_set_background_color(s_time_layer, GColorClear); text_layer_set_font(s_time_layer, s_font); layer_add_child(window_layer, text_layer_get_layer(s_time_layer)); top = PBL_IF_ROUND_ELSE(71, 61); s_unread_layer = text_layer_create(grect_inset(bounds, GEdgeInsets(top, 0, 0, left))); text_layer_set_text_alignment(s_unread_layer, GTextAlignmentLeft); text_layer_set_text_color(s_unread_layer, GColorWhite); text_layer_set_background_color(s_unread_layer, GColorClear); text_layer_set_font(s_unread_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD)); layer_add_child(window_layer, text_layer_get_layer(s_unread_layer)); top = PBL_IF_ROUND_ELSE(100, 90); int bottom = PBL_IF_ROUND_ELSE(27, 0); int right = PBL_IF_ROUND_ELSE(12, 0); s_event_layer = text_layer_create(grect_inset(bounds, GEdgeInsets(top, right, bottom, left))); text_layer_set_text_alignment(s_event_layer, GTextAlignmentLeft); text_layer_set_text_color(s_event_layer, GColorWhite); text_layer_set_background_color(s_event_layer, GColorClear); text_layer_set_font(s_event_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD)); text_layer_set_overflow_mode(s_event_layer, GTextOverflowModeTrailingEllipsis); layer_add_child(window_layer, text_layer_get_layer(s_event_layer)); s_icons_bitmap = gbitmap_create_with_resource(RESOURCE_ID_ICONS); GSize icons_size = gbitmap_get_bounds(s_icons_bitmap).size; top = PBL_IF_ROUND_ELSE(78, 68); left = PBL_IF_ROUND_ELSE(14, 3); bottom = bounds.size.h - top - icons_size.h; right = bounds.size.w - left - icons_size.w; s_icons_layer = bitmap_layer_create(grect_inset(bounds, GEdgeInsets(top, right, bottom, left))); bitmap_layer_set_compositing_mode(s_icons_layer, GCompOpSet); bitmap_layer_set_bitmap(s_icons_layer, s_icons_bitmap); layer_add_child(window_layer, bitmap_layer_get_layer(s_icons_layer)); }
static void battery_update_proc(Layer *layer, GContext *ctx) { GRect bounds = layer_get_bounds(layer); // Find the width of the bar float percent = ((float)s_battery_level / 100.0F); int width = (int)(float)(percent * bounds.size.w); // Draw the background GColor bgcolor = GColorFromHEX(persist_read_int(MESSAGE_KEY_BackgroundColor)); GColor batterycolor; //graphics_context_set_fill_color(ctx, GColorClear); //graphics_fill_rect(ctx, bounds, 0, GCornerNone); // Draw the bar int g = (255 * percent); int r = (255 * (1 - percent)); int b = 0; int rgb = createRGB(r, g, b); if (s_battery_level == 100) { r = 85; g = 255; } if (s_battery_level == 50) { rgb = 0xFFAA00; } int x = persist_read_int(MESSAGE_KEY_Battery); APP_LOG(APP_LOG_LEVEL_INFO, "Battery Preference: %d", x); if (persist_read_int(MESSAGE_KEY_Battery) != 102) { APP_LOG(APP_LOG_LEVEL_INFO, "RGB"); batterycolor = GColorFromHEX(rgb); } else { batterycolor = gcolor_legible_over(bgcolor); } PBL_IF_BW_ELSE(graphics_context_set_fill_color(ctx, batterycolor), graphics_context_set_fill_color(ctx, batterycolor)); //APP_LOG(APP_LOG_LEVEL_INFO, GColorFromHEX(rgb)); /* if (s_battery_level <= 20) { graphics_context_set_fill_color(ctx, PBL_IF_BW_ELSE(GColorBlack, GColorRed)); } else if (s_battery_level == 100) { graphics_context_set_fill_color(ctx, PBL_IF_BW_ELSE(GColorBlack, GColorBrightGreen)); } */ GRect frame = grect_inset(bounds, GEdgeInsets(10)); //graphics_context_set_fill_color(ctx, GColorBlack); PBL_IF_ROUND_ELSE(graphics_fill_radial(ctx, frame, GOvalScaleModeFitCircle, 5, DEG_TO_TRIGANGLE(125+((1-percent)*110)), DEG_TO_TRIGANGLE(235)), graphics_fill_rect(ctx, GRect(0, 0, width, bounds.size.h), 0, GCornerNone)); }
static void prv_window_load(Window *window) { GoalStarConfigurationWindowData *data = window_get_user_data(window); if (!data) { return; } Layer *window_root_layer = window_get_root_layer(window); const GRect window_root_layer_bounds = layer_get_bounds(window_root_layer); const GRect title_layer_frame = (GRect) { #if PBL_RECT // Adjust for font cap offset .origin = GPoint(0, -2), #endif .size = GSize(window_root_layer_bounds.size.w, STATUS_BAR_LAYER_HEIGHT), }; data->title_layer = text_layer_create(title_layer_frame); TextLayer *title_layer = data->title_layer; text_layer_set_text_alignment(title_layer, GTextAlignmentCenter); text_layer_set_overflow_mode(title_layer, GTextOverflowModeTrailingEllipsis); text_layer_set_background_color(title_layer, GColorClear); text_layer_set_text_color(title_layer, GColorBlack); text_layer_set_font(title_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14)); text_layer_set_text(title_layer, PBL_IF_RECT_ELSE("Goal Star Configuration", "Config")); layer_add_child(window_root_layer, text_layer_get_layer(title_layer)); const GEdgeInsets menu_layer_insets = PBL_IF_RECT_ELSE(GEdgeInsets(STATUS_BAR_LAYER_HEIGHT, 0, 0), GEdgeInsets(STATUS_BAR_LAYER_HEIGHT, 0)); const GRect menu_layer_frame = grect_inset(window_root_layer_bounds, menu_layer_insets); data->menu_layer = menu_layer_create(menu_layer_frame); MenuLayer *menu_layer = data->menu_layer; menu_layer_set_callbacks(menu_layer, data, (MenuLayerCallbacks) { .get_num_rows = prv_menu_layer_get_num_rows_callback, .draw_row = prv_menu_layer_draw_row_callback, #if PBL_ROUND .get_cell_height = prv_menu_layer_get_cell_height, #endif .select_click = prv_menu_layer_select_callback, }); menu_layer_set_normal_colors(menu_layer, GColorWhite, GColorBlack); menu_layer_set_highlight_colors(menu_layer, GColorCobaltBlue, GColorWhite); menu_layer_set_click_config_onto_window(menu_layer, window); layer_add_child(window_root_layer, menu_layer_get_layer(menu_layer)); }
void bipercent_draw_circle(Layer *layer, GContext *ctx) { BipercentLayerData *data = (BipercentLayerData*) layer_get_data(layer); int end_angle = data->percent * 360 / 100; GRect rect = layer_get_bounds(layer); graphics_fill_radial(ctx, rect, GOvalScaleModeFitCircle, RADIAL_R, DEG_TO_TRIGANGLE(0), DEG_TO_TRIGANGLE(end_angle)); graphics_draw_arc(ctx, rect, GOvalScaleModeFitCircle, DEG_TO_TRIGANGLE(end_angle), DEG_TO_TRIGANGLE(360)); graphics_draw_arc(ctx, grect_inset(layer_get_bounds(layer), GEdgeInsets(RADIAL_R)) , GOvalScaleModeFitCircle, DEG_TO_TRIGANGLE(end_angle), DEG_TO_TRIGANGLE(360)); }
static void main_window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); const int text_height = 20; const GEdgeInsets text_insets = GEdgeInsets((bounds.size.h - text_height) / 2, 0); s_output_layer = text_layer_create(grect_inset(bounds, text_insets)); text_layer_set_text(s_output_layer, "Press up or down."); text_layer_set_text_alignment(s_output_layer, GTextAlignmentCenter); layer_add_child(window_layer, text_layer_get_layer(s_output_layer)); }
void prv_draw_pupil(GContext *ctx, const GRect *eye_rect, const GPoint *perimeter_point) { const int16_t pupil_radius = 3; const GSize pupil_size = GSize(pupil_radius * 2, pupil_radius * 2); const GRect pupil_container_rect = grect_inset((*eye_rect), GEdgeInsets(2 * pupil_radius)); const GPoint pupil_center = grect_center_point(&pupil_container_rect); const int32_t pupil_angle = atan2_lookup(perimeter_point->y - pupil_center.y, perimeter_point->x - pupil_center.x) + DEG_TO_TRIGANGLE(90); const GRect pupil_rect = grect_centered_from_polar(pupil_container_rect, GOvalScaleModeFitCircle, pupil_angle, pupil_size); graphics_fill_radial(ctx, pupil_rect, GOvalScaleModeFitCircle, pupil_radius, 0, TRIG_MAX_ANGLE); }
static void dial_widget_layer_update(DialWidgetLayer *dial_widget_layer, GContext *ctx) { GRect bounds = layer_get_bounds(dial_widget_layer); DialWidgetData *data = (DialWidgetData*)layer_get_data(dial_widget_layer); uint16_t direction = data->vec->direction; // string formatting char center_text[MAX_CENTER_TEXT]; snprintf(center_text, MAX_CENTER_TEXT*sizeof(char), "%u\n%s", data->vec->magnitude, data->units); graphics_context_set_fill_color(ctx, GColorCobaltBlue); graphics_context_set_stroke_color(ctx, GColorBlack); // draw the dial outline graphics_draw_arc(ctx, grect_inset(bounds, GEdgeInsets(1)), GOvalScaleModeFitCircle, 0, DEG_TO_TRIGANGLE(360)); graphics_draw_arc(ctx, grect_inset(bounds, GEdgeInsets(8)), GOvalScaleModeFitCircle, 0, DEG_TO_TRIGANGLE(360)); // draw the arrow graphics_fill_radial(ctx, bounds, GOvalScaleModeFitCircle, 8, DEG_TO_TRIGANGLE(direction - 15), DEG_TO_TRIGANGLE(direction + 15)); // draw the center text GFont font = fonts_get_system_font(FONT_KEY_GOTHIC_14); graphics_context_set_text_color(ctx, GColorBlack); graphics_draw_text(ctx, center_text, font, grect_inset(bounds, GEdgeInsets(8)), GTextOverflowModeWordWrap, GTextAlignmentCenter, NULL); }
static void show_round_meter(GContext *ctx, GRect *bounds) { // radial GRect frame = grect_inset((*bounds), GEdgeInsets(0)); int minute_angle = (int)(360.0 * s_meter_time.minutes / 60.0); int32_t start_break = minute_angle + 360 * (CONCENTRATION_TIME) / 60 / 60; // 150 == 360 * 25 / 60 int32_t end_break = start_break + 360 * (REST_TIME) / 60 / 60; // 30 == 360 * 5 / 60 graphics_context_set_fill_color(ctx, CONCENTRATION_COLOR); graphics_fill_radial(ctx, frame, GOvalScaleModeFitCircle, METER_THICKNESS, DEG_TO_TRIGANGLE(minute_angle), DEG_TO_TRIGANGLE(start_break)); graphics_context_set_fill_color(ctx, REST_COLOR); graphics_fill_radial(ctx, frame, GOvalScaleModeFitCircle, METER_THICKNESS, DEG_TO_TRIGANGLE(start_break), DEG_TO_TRIGANGLE(end_break)); // hour dots static int s_hour_dot_radius = 2; frame = grect_inset(frame, GEdgeInsets(5 * s_hour_dot_radius)); for(int i = 0; i < 12; i++) { int hour_angle = i * 360 / 12; GPoint pos = gpoint_from_polar(frame, GOvalScaleModeFitCircle, DEG_TO_TRIGANGLE(hour_angle)); graphics_context_set_fill_color(ctx, GColorWhite); graphics_fill_circle(ctx, pos, s_hour_dot_radius); } }
static void prv_date_layer_update_proc(Layer *layer, GContext *ctx) { const SprinklesConfiguration *configuration = sprinkles_configuration_get_configuration(); if (!configuration->date_enabled) { return; } const GRect layer_bounds = layer_get_bounds(layer); GRect date_rect = (GRect) { .size = GSize(24, layer_bounds.size.h) }; grect_align(&date_rect, &layer_bounds, GAlignCenter, true /* clip */); graphics_context_set_fill_color(ctx, configuration->date_background_color); graphics_fill_rect(ctx, date_rect, 3, GCornersAll); // Push the date_rect up a little bit to account for the font cap offset date_rect.origin.y -= 4; graphics_context_set_text_color(ctx, configuration->date_text_color); const GFont font = fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD); char date_string[3] = {0}; const time_t current_time = time(NULL); struct tm *current_time_tm = localtime(¤t_time); strftime(date_string, ARRAY_LENGTH(date_string), "%d", current_time_tm); graphics_draw_text(ctx, date_string, font, date_rect, GTextOverflowModeTrailingEllipsis, GTextAlignmentCenter, NULL); } static void prv_homer_eyes_layer_update_proc(Layer *layer, GContext *ctx) { const GRect layer_bounds = layer_get_bounds(layer); const GPoint donut_orbit_perimeter_point = prv_get_donut_orbit_perimeter_point(&layer_bounds); const GEdgeInsets eye_rect_insets = GEdgeInsets(1); const GRect right_eye_rect = grect_inset(PBL_IF_ROUND_ELSE(GRect(53, 49, 33, 33), GRect(52, 45, 35, 32)), eye_rect_insets); prv_draw_pupil(ctx, &right_eye_rect, &donut_orbit_perimeter_point); const GRect left_eye_rect = grect_inset(PBL_IF_ROUND_ELSE(GRect(22, 48, 32, 31), GRect(22, 45, 32, 29)), eye_rect_insets); prv_draw_pupil(ctx, &left_eye_rect, &donut_orbit_perimeter_point); } static void prv_tick_timer_service_handler(struct tm *tick_time, TimeUnits units_changed) { s_app_data->current_hours = tick_time->tm_hour; s_app_data->current_minutes = tick_time->tm_min; s_app_data->current_seconds = tick_time->tm_sec; layer_mark_dirty(s_app_data->homer_eyes_layer); layer_mark_dirty(s_app_data->hands_layer); }
void pge_init() { // Allocate for(int z = 0; z < GRID_DEPTH; z++) { for(int y = 0; y < GRID_HEIGHT; y++) { for(int x = 0; x < GRID_WIDTH; x++) { s_block_array[vec2i(Vec3(x, y, z))] = block_create(Vec3(x * BLOCK_SIZE, y * BLOCK_SIZE, z * BLOCK_SIZE), GSize(BLOCK_SIZE, BLOCK_SIZE), COLOR_INVISIBLE); } } } for(int i = 0; i < MAX_CLOUDS; i++) { s_cloud_array[i] = cloud_create(Vec3(0, 0, SKY_HEIGHT), GSize(BLOCK_SIZE, BLOCK_SIZE), Vec3(GRID_WIDTH * BLOCK_SIZE, GRID_HEIGHT * BLOCK_SIZE, SKY_HEIGHT)); } // Set up world generate_world(); // Set up engine pge_isometric_set_projection_offset(PBL_IF_ROUND_ELSE(GPoint(90, 110), GPoint(72, 80))); pge_isometric_set_enabled(true); pge_set_framerate(FRAME_RATE_IDLE); pge_begin(GColorBlack, logic, render, click); s_main_window = pge_get_window(); s_status_layer = text_layer_create(grect_inset( layer_get_bounds((window_get_root_layer(s_main_window))), PBL_IF_ROUND_ELSE(GEdgeInsets(30, 0, 130, 0), GEdgeInsets(0, 0, 150, 0)))); text_layer_set_background_color(s_status_layer, GColorBlack); text_layer_set_text_color(s_status_layer, GColorWhite); text_layer_set_text_alignment(s_status_layer, PBL_IF_ROUND_ELSE(GTextAlignmentCenter, GTextAlignmentLeft)); layer_add_child(window_get_root_layer(s_main_window), text_layer_get_layer(s_status_layer)); update_status_text(); #ifdef BENCHMARK APP_LOG(APP_LOG_LEVEL_INFO, "Heap free: %dB after creating %d blocks (Size: %dB)", (int)heap_bytes_free(), (GRID_WIDTH * GRID_HEIGHT * GRID_DEPTH), get_world_size()); #endif }
static TextLayer* make_text_layer(int x_inset, int y_inset, char *font_key) { Layer *window_layer = window_get_root_layer(s_window); GRect bounds = layer_get_bounds(window_layer); TextLayer *this = text_layer_create(grect_inset(bounds, GEdgeInsets(y_inset, 0, 0, x_inset))); text_layer_set_text_alignment(this, GTextAlignmentCenter); text_layer_set_text_color(this, GColorWhite); text_layer_set_background_color(this, GColorClear); text_layer_set_font(this, fonts_get_system_font(font_key)); #if defined(PBL_ROUND) text_layer_enable_screen_text_flow_and_paging(this, 5); #endif return this; }
void bipercent_draw_legend(Layer *layer, GContext *ctx) { BipercentLayerData *data = (BipercentLayerData*) layer_get_data(layer); GRect rect = layer_get_bounds(layer); graphics_context_set_text_color(ctx, GColorBlack); int top_inset = (rect.size.h * 2 / 5); int left_inset = INDIC_SIZE; graphics_draw_text(ctx, data->key1, fonts_get_system_font(FONT_KEY_GOTHIC_14_BOLD), grect_inset(rect, GEdgeInsets(top_inset, 0, 0, left_inset)), GTextOverflowModeTrailingEllipsis, GTextAlignmentCenter, NULL); graphics_draw_text(ctx, data->key2, fonts_get_system_font(FONT_KEY_GOTHIC_14_BOLD), grect_inset(rect, GEdgeInsets(top_inset + LEGEND_PAD, 0, 0, left_inset)), GTextOverflowModeTrailingEllipsis, GTextAlignmentCenter, NULL); GRect rect1 = grect_inset(rect, GEdgeInsets(top_inset, 0, 0, rect.size.w / 3)); rect1.size.w = INDIC_SIZE; rect1.size.h = INDIC_SIZE; graphics_fill_rect(ctx, rect1, 0, GCornerNone); rect1.origin.y += LEGEND_PAD; graphics_draw_rect(ctx, rect1); }
static void initialise_ui(void) { s_window = window_create(); window_set_fullscreen(s_window, PBL_IF_ROUND_ELSE(true, false)); window_set_background_color(s_window, COLOUR_WINDOW); // s_menu GRect menu_bounds = layer_get_bounds(window_get_root_layer(s_window)); #ifdef PBL_ROUND menu_bounds = grect_inset(menu_bounds, GEdgeInsets(STATUS_BAR_LAYER_HEIGHT, 0)); #endif s_menu = menu_layer_create(menu_bounds); if(watch_info_get_firmware_version().major >= 3) { scroll_layer_set_shadow_hidden(menu_layer_get_scroll_layer(s_menu), true); } menu_set_colours(s_menu); #ifdef PBL_ROUND menu_layer_set_center_focused(s_menu, true); #endif menu_layer_set_click_config_onto_window(s_menu, s_window); layer_add_child(window_get_root_layer(s_window), (Layer *)s_menu); }
static void tick_handler(struct tm *tick_time, TimeUnits units_changed) { update_time(); layer_mark_dirty(s_hand_layer); int bhour = tick_time->tm_hour; int bmin = tick_time->tm_min; float angle = 30 * ((float)(bhour % 12) + ((float)bmin / 60)); if (debug) angle = 12 * tick_time->tm_sec; GRect frame = layer_get_frame(s_face_layer); GRect frame2 = layer_get_frame(s_hand_layer); float size = (frame.size.w + frame2.size.w) / 2; GPoint origin = gpoint_from_polar(grect_inset(frame2, GEdgeInsets(-150)), GOvalScaleModeFitCircle , DEG_TO_TRIGANGLE(angle + 180)); frame.origin = origin; frame.origin.x -= frame.size.w / 2; frame.origin.y -= frame.size.w / 2; layer_set_frame(s_face_layer, frame); }
static void window_load(Window *window) { Layer *root_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(root_layer); int origin = PBL_IF_ROUND_ELSE(59, 49); GRect frame = grect_inset(bounds, GEdgeInsets(origin, -10, 0, -10)); s_brackets_layer = make_text_layer(frame, FontSizeLarge); text_layer_set_text(s_brackets_layer, "[ ]"); layer_add_child(root_layer, text_layer_get_layer(s_brackets_layer)); origin += 1; frame = grect_inset(bounds, GEdgeInsets(origin, 0)); s_date_layer = make_text_layer(frame, FontSizeMedium); layer_add_child(root_layer, text_layer_get_layer(s_date_layer)); origin += 28; frame = grect_inset(bounds, GEdgeInsets(origin, 0, 0, 0)); s_time_layer = make_text_layer(frame, FontSizeMedium); layer_add_child(root_layer, text_layer_get_layer(s_time_layer)); origin += 52; frame = grect_inset(bounds, GEdgeInsets(origin, 0, 0, 0)); s_battery_layer = make_text_layer(frame, FontSizeSmall); layer_add_child(root_layer, text_layer_get_layer(s_battery_layer)); origin -= PBL_IF_ROUND_ELSE(12, 10); s_dashes_layer = layer_create(grect_inset(bounds, GEdgeInsets(origin, 0, 0, 0))); layer_set_update_proc(s_dashes_layer, dashes_update_proc); layer_add_child(root_layer, s_dashes_layer); const int gap = 5; const int y_margin = (bounds.size.h - gap) / 2; s_bt_layer = layer_create(grect_inset(bounds, GEdgeInsets(y_margin, 0))); layer_set_update_proc(s_bt_layer, bt_update_proc); layer_add_child(root_layer, s_bt_layer); }
PinWindow* pin_window_create(PinWindowCallbacks callbacks, PinWindowData data) { PinWindow *pin_window = (PinWindow*)malloc(sizeof(PinWindow)); if (data.nb_digits==0) data.nb_digits = PIN_WINDOW_NUM_CELLS; if (pin_window) { pin_window->window = window_create(); pin_window->callbacks = callbacks; if (pin_window->window) { pin_window->field_selection = 0; for(int i = 0; i < data.nb_digits; i++) { pin_window->pin.digits[i] = data.init_pin->digits[i]; } // Get window parameters Layer *window_layer = window_get_root_layer(pin_window->window); GRect bounds = layer_get_bounds(window_layer); // Main TextLayer const GEdgeInsets main_text_insets = {.top = 30}; pin_window->main_text = text_layer_create(grect_inset(bounds, main_text_insets)); text_layer_set_text(pin_window->main_text, data.main_text); text_layer_set_font(pin_window->main_text, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); text_layer_set_text_alignment(pin_window->main_text, GTextAlignmentCenter); layer_add_child(window_layer, text_layer_get_layer(pin_window->main_text)); // Separators layer const GEdgeInsets sep_text_insets = {.top = 75}; pin_window->sep_text = text_layer_create(grect_inset(bounds, sep_text_insets)); if(data.nb_digits==3) text_layer_set_text(pin_window->sep_text, " : : "); else text_layer_set_text(pin_window->sep_text, " : "); text_layer_set_font(pin_window->sep_text, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); text_layer_set_text_alignment(pin_window->sep_text, GTextAlignmentCenter); layer_add_child(window_layer, text_layer_get_layer(pin_window->sep_text)); // Sub TextLayer const GEdgeInsets sub_text_insets = {.top = 115, .right = 5, .bottom = 10, .left = 5}; pin_window->sub_text = text_layer_create(grect_inset(bounds, sub_text_insets)); text_layer_set_text(pin_window->sub_text, data.sub_text); text_layer_set_text_alignment(pin_window->sub_text, GTextAlignmentCenter); text_layer_set_font(pin_window->sub_text, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); layer_add_child(window_layer, text_layer_get_layer(pin_window->sub_text)); // Create selection layer const GEdgeInsets selection_insets = GEdgeInsets( (bounds.size.h - PIN_WINDOW_SIZE.h) / 2, (bounds.size.w - (40 * data.nb_digits)) / 2); pin_window->selection = selection_layer_create(grect_inset(bounds, selection_insets), data.nb_digits); for (int i = 0; i < data.nb_digits; i++) { selection_layer_set_cell_width(pin_window->selection, i, 40); } selection_layer_set_cell_padding(pin_window->selection, 4); selection_layer_set_active_bg_color(pin_window->selection, GColorRed); selection_layer_set_inactive_bg_color(pin_window->selection, GColorDarkGray); selection_layer_set_click_config_onto_window(pin_window->selection, pin_window->window); selection_layer_set_callbacks(pin_window->selection, pin_window, (SelectionLayerCallbacks) { .get_cell_text = selection_handle_get_text, .complete = selection_handle_complete, .increment = selection_handle_inc, .decrement = selection_handle_dec, }); layer_add_child(window_get_root_layer(pin_window->window), pin_window->selection); // Create status bar pin_window->status = status_bar_layer_create(); status_bar_layer_set_colors(pin_window->status, GColorClear, GColorBlack); layer_add_child(window_layer, status_bar_layer_get_layer(pin_window->status)); return pin_window; } } APP_LOG(APP_LOG_LEVEL_ERROR, "Failed to create PinWindow"); return NULL; } void pin_window_destroy(PinWindow *pin_window) { if (pin_window) { status_bar_layer_destroy(pin_window->status); selection_layer_destroy(pin_window->selection); text_layer_destroy(pin_window->sub_text); text_layer_destroy(pin_window->main_text); text_layer_destroy(pin_window->sep_text); free(pin_window); pin_window = NULL; return; } } void pin_window_push(PinWindow *pin_window, bool animated) { window_stack_push(pin_window->window, animated); }
static void prv_window_load(Window *window) { GoalStarNumberWindow *number_window = window_get_user_data(window); if (!number_window) { return; } Layer *window_root_layer = window_get_root_layer(window); const GRect window_root_layer_bounds = layer_get_bounds(window_root_layer); number_window->checkmark_icon = gbitmap_create_with_resource(RESOURCE_ID_CHECKMARK); number_window->up_icon = gbitmap_create_with_resource(RESOURCE_ID_UP); number_window->down_icon = gbitmap_create_with_resource(RESOURCE_ID_DOWN); const GTextAlignment text_layer_alignment = GTextAlignmentRight; const GTextOverflowMode text_layer_overflow_mode = GTextOverflowModeTrailingEllipsis; const GFont label_text_font = fonts_get_system_font(FONT_KEY_GOTHIC_14); const int16_t label_text_font_height = 14; const int16_t value_text_max_font_height = 36; const int16_t horizontal_padding = 5; GRect text_container_frame = grect_inset(window_root_layer_bounds, GEdgeInsets(0, ACTION_BAR_WIDTH + horizontal_padding, 0, horizontal_padding)); text_container_frame.size.h = label_text_font_height + value_text_max_font_height; grect_align(&text_container_frame, &window_root_layer_bounds, GAlignLeft, true /* clip */); text_container_frame.origin.y -= gbitmap_get_bounds(number_window->checkmark_icon).size.h / 2; GRect label_text_layer_frame = (GRect) { .size = GSize(text_container_frame.size.w, label_text_font_height), }; grect_align(&label_text_layer_frame, &text_container_frame, GAlignTop, true /* clip */); number_window->label_text_layer = text_layer_create(label_text_layer_frame); TextLayer *label_text_layer = number_window->label_text_layer; text_layer_set_text(label_text_layer, number_window->label); text_layer_set_text_color(label_text_layer, GColorBlack); text_layer_set_background_color(label_text_layer, GColorClear); text_layer_set_font(label_text_layer, label_text_font); text_layer_set_overflow_mode(label_text_layer, text_layer_overflow_mode); text_layer_set_text_alignment(label_text_layer, text_layer_alignment); layer_add_child(window_root_layer, text_layer_get_layer(label_text_layer)); GRect value_text_layer_frame = (GRect) { .size = GSize(text_container_frame.size.w, value_text_max_font_height), }; grect_align(&value_text_layer_frame, &text_container_frame, GAlignBottom, true /* clip */); number_window->value_text_layer = text_layer_create(value_text_layer_frame); TextLayer *value_text_layer = number_window->value_text_layer; prv_update_value_text_layer(number_window); text_layer_set_text_color(value_text_layer, GColorBlack); text_layer_set_background_color(value_text_layer, GColorClear); text_layer_set_overflow_mode(value_text_layer, text_layer_overflow_mode); text_layer_set_text_alignment(value_text_layer, text_layer_alignment); layer_add_child(window_root_layer, text_layer_get_layer(value_text_layer)); number_window->action_bar_layer = action_bar_layer_create(); ActionBarLayer *action_bar_layer = number_window->action_bar_layer; action_bar_layer_set_click_config_provider(action_bar_layer, prv_click_config_provider); action_bar_layer_set_context(action_bar_layer, number_window); action_bar_layer_set_icon(action_bar_layer, BUTTON_ID_SELECT, number_window->checkmark_icon); action_bar_layer_set_icon(action_bar_layer, BUTTON_ID_UP, number_window->up_icon); action_bar_layer_set_icon(action_bar_layer, BUTTON_ID_DOWN, number_window->down_icon); action_bar_layer_add_to_window(action_bar_layer, window); } static void prv_window_unload(Window *window) { GoalStarNumberWindow *number_window = window_get_user_data(window); if (number_window) { text_layer_destroy(number_window->label_text_layer); text_layer_destroy(number_window->value_text_layer); action_bar_layer_destroy(number_window->action_bar_layer); gbitmap_destroy(number_window->checkmark_icon); gbitmap_destroy(number_window->up_icon); gbitmap_destroy(number_window->down_icon); } } static void prv_goal_star_number_window_init(GoalStarNumberWindow *number_window, const char *label, GoalStarNumberWindowCallbacks callbacks, void *callback_context) { if (!number_window) { return; } *number_window = (GoalStarNumberWindow) { .label = label, .value = 0, .min = GOAL_STAR_NUMBER_WINDOW_MIN, .max = GOAL_STAR_NUMBER_WINDOW_MAX, .step_size = 1, .callbacks = callbacks, .callback_context = callback_context, }; number_window->window = window_create(); Window *window = number_window->window; window_set_window_handlers(window, (WindowHandlers) { .load = prv_window_load, .unload = prv_window_unload, }); window_set_background_color(window, GColorLightGray); window_set_user_data(window, number_window); } GoalStarNumberWindow *goal_star_number_window_create(const char *label, GoalStarNumberWindowCallbacks callbacks, void *callback_context) { GoalStarNumberWindow *number_window = calloc(1, sizeof(*number_window)); prv_goal_star_number_window_init(number_window, label, callbacks, callback_context); return number_window; }
static GRect prv_get_seconds_forward_rect(const GRect *layer_bounds) { return grect_inset(*layer_bounds, GEdgeInsets(2)); }
static void bg_update_proc(Layer *layer, GContext *ctx) { GRect bounds = layer_get_bounds(layer); GRect frame = grect_inset(bounds, GEdgeInsets(4 * INSET)); GRect inner_hour_frame = grect_inset(bounds, GEdgeInsets((4 * INSET) + 8)); GRect inner_minute_frame = grect_inset(bounds, GEdgeInsets((4 * INSET) + 6)); graphics_context_set_stroke_color(ctx, gcolor_hour_marks); graphics_context_set_stroke_width(ctx, 3); // Hours marks for(int i = 0; i < 12; i++) { int hour_angle = get_angle_for_hour(i); GPoint p0 = gpoint_from_polar(frame, GOvalScaleModeFitCircle, DEG_TO_TRIGANGLE(hour_angle)); GPoint p1 = gpoint_from_polar(inner_hour_frame, GOvalScaleModeFitCircle, DEG_TO_TRIGANGLE(hour_angle)); graphics_draw_line(ctx, p0, p1); } // Minute Marks graphics_context_set_stroke_color(ctx, gcolor_minute_marks); graphics_context_set_stroke_width(ctx, 1); for(int i = 0; i < 60; i++) { if (i % 5) { int minute_angle = get_angle_for_minute(i); GPoint p0 = gpoint_from_polar(frame, GOvalScaleModeFitCircle, DEG_TO_TRIGANGLE(minute_angle)); GPoint p1 = gpoint_from_polar(inner_minute_frame, GOvalScaleModeFitCircle, DEG_TO_TRIGANGLE(minute_angle)); graphics_draw_line(ctx, p0, p1); } } // numbers if (b_show_numbers) { graphics_context_set_text_color(ctx, gcolor_numbers); #ifdef PBL_RECT graphics_draw_text(ctx, "12", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(63, 18, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentCenter, NULL); graphics_draw_text(ctx, "1", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(85, 23, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentRight, NULL); graphics_draw_text(ctx, "2", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(104, 43, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentRight, NULL); graphics_draw_text(ctx, "3", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(112, 68, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentRight, NULL); graphics_draw_text(ctx, "4", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(104, 93, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentRight, NULL); graphics_draw_text(ctx, "5", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(85, 110, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentRight, NULL); graphics_draw_text(ctx, "6", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(62, 118, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentCenter, NULL); graphics_draw_text(ctx, "7", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(39, 110, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentLeft, NULL); graphics_draw_text(ctx, "8", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(20, 93, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentLeft, NULL); graphics_draw_text(ctx, "9", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(14, 68, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentLeft, NULL); graphics_draw_text(ctx, "10", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(20, 43, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentLeft, NULL); graphics_draw_text(ctx, "11", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(39, 23, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentLeft, NULL); #else graphics_draw_text(ctx, "12", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(80, 10, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentCenter, NULL); graphics_draw_text(ctx, "1", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(107, 20, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentRight, NULL); graphics_draw_text(ctx, "2", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(130, 43, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentRight, NULL); graphics_draw_text(ctx, "3", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(140, 74, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentRight, NULL); graphics_draw_text(ctx, "4", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(130, 106, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentRight, NULL); graphics_draw_text(ctx, "5", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(107, 126, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentRight, NULL); graphics_draw_text(ctx, "6", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(81, 136, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentCenter, NULL); graphics_draw_text(ctx, "7", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(53, 124, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentLeft, NULL); graphics_draw_text(ctx, "8", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(29, 106, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentLeft, NULL); graphics_draw_text(ctx, "9", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(20, 74, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentLeft, NULL); graphics_draw_text(ctx, "10", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(28, 42, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentLeft, NULL); graphics_draw_text(ctx, "11", fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD), GRect(50, 22, 20, 20), GTextOverflowModeWordWrap, GTextAlignmentLeft, NULL); #endif } }
TimeWindow* time_window_create(TimeWindowCallbacks callbacks, ETimeState state) { TimeWindow *time_window = (TimeWindow*)malloc(sizeof(TimeWindow)); if (time_window) { time_window->window = window_create(); time_window->callbacks = callbacks; if (time_window->window) { time_t current_time = time(NULL); struct tm* current_tm = localtime(¤t_time); time_window->field_selection = 0; time_window->state = state; time_window->time.digits[0] = current_tm->tm_hour; time_window->time.digits[1] = current_tm->tm_min; // for(int i = 0; i < TIME_WINDOW_NUM_CELLS; i++) { // time_window->time.digits[i] = 0; // } // Get window parameters Layer *window_layer = window_get_root_layer(time_window->window); GRect bounds = layer_get_bounds(window_layer); // Main TextLayer const GEdgeInsets main_text_insets = {.top = 30}; time_window->main_text = text_layer_create(grect_inset(bounds, main_text_insets)); text_layer_set_text(time_window->main_text, "Time Required"); text_layer_set_font(time_window->main_text, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); text_layer_set_text_alignment(time_window->main_text, GTextAlignmentCenter); layer_add_child(window_layer, text_layer_get_layer(time_window->main_text)); // Sub TextLayer const GEdgeInsets sub_text_insets = {.top = 115, .right = 5, .bottom = 10, .left = 5}; time_window->sub_text = text_layer_create(grect_inset(bounds, sub_text_insets)); text_layer_set_text(time_window->sub_text, "up/down to change time"); text_layer_set_text_alignment(time_window->sub_text, GTextAlignmentCenter); text_layer_set_font(time_window->sub_text, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); layer_add_child(window_layer, text_layer_get_layer(time_window->sub_text)); // Create selection layer const GEdgeInsets selection_insets = GEdgeInsets( (bounds.size.h - TIME_WINDOW_SIZE.h) / 2, (bounds.size.w - TIME_WINDOW_SIZE.w) / 2); time_window->selection = selection_layer_create(grect_inset(bounds, selection_insets), TIME_WINDOW_NUM_CELLS); for (int i = 0; i < TIME_WINDOW_NUM_CELLS; i++) { selection_layer_set_cell_width(time_window->selection, i, 60); } selection_layer_set_cell_padding(time_window->selection, 6); selection_layer_set_active_bg_color(time_window->selection, GColorRed); selection_layer_set_inactive_bg_color(time_window->selection, GColorDarkGray); selection_layer_set_click_config_onto_window(time_window->selection, time_window->window); selection_layer_set_callbacks(time_window->selection, time_window, (SelectionLayerCallbacks) { .get_cell_text = selection_handle_get_text, .complete = selection_handle_complete, .increment = selection_handle_inc, .decrement = selection_handle_dec, }); layer_add_child(window_get_root_layer(time_window->window), time_window->selection); // Create status bar time_window->status = status_bar_layer_create(); status_bar_layer_set_colors(time_window->status, GColorClear, GColorBlack); layer_add_child(window_layer, status_bar_layer_get_layer(time_window->status)); return time_window; } } APP_LOG(APP_LOG_LEVEL_ERROR, "Failed to create TimeWindow"); return NULL; }
static void draw_debug_arc(GRect bounds, GContext *ctx, int32_t theta) { GRect frame = grect_inset(bounds, GEdgeInsets(25)); graphics_fill_radial(ctx, frame, GOvalScaleModeFitCircle, 1, 0, theta); }