Skip to content

Commit

Permalink
Improved the drawing of draw_from_to().
Browse files Browse the repository at this point in the history
  • Loading branch information
CocoaBob committed Mar 11, 2016
1 parent ee305a7 commit 74487e0
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 25 deletions.
32 changes: 16 additions & 16 deletions src/ui_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ void draw_from_to(GContext* ctx, Layer *display_layer,
TextScrollData **ptr_text_scroll_data, Layer *redraw_layer, bool is_selected,
#endif
bool is_inverted,
GColor bg_color, GColor fg_color,
GColor fg_color,
DataModelFromTo from_to
#if MINI_TIMETABLE_IS_ENABLED
,
Expand Down Expand Up @@ -191,45 +191,45 @@ void draw_from_to(GContext* ctx, Layer *display_layer,
icon_center_to.x = icon_angle_point_to.x;
#endif

// Draw icons
// Draw circle 1
graphics_context_set_stroke_width(ctx, 1);
graphics_draw_circle(ctx, icon_center_from, icon_radius);
if (is_from_to) {
// Draw circle 2
graphics_draw_circle(ctx, icon_center_to, icon_radius);

// Draw line
graphics_context_set_stroke_width(ctx, 2);
#ifdef PBL_ROUND
if (icon_angle_point_from.y >= 0 && icon_angle_point_from.y <= ROUND_SCREEN_SIZE &&
icon_angle_point_to.y >= 0 && icon_angle_point_to.y <= ROUND_SCREEN_SIZE) {
int32_t quad_circle = TRIG_MAX_ANGLE / 4;
int32_t radius_trigangle = DEG_TO_TRIGANGLE(2);

int32_t angle_from = atan2_lookup(ABS(ROUND_SCREEN_RADIUS - icon_angle_point_from.y), ABS(ROUND_SCREEN_RADIUS - icon_angle_point_from.x));
angle_from = (icon_angle_point_from.y > ROUND_SCREEN_RADIUS) ? (-quad_circle-angle_from) : (angle_from-quad_circle);
angle_from -= radius_trigangle;

int32_t angle_to = atan2_lookup(ABS(ROUND_SCREEN_RADIUS - icon_angle_point_to.y), ABS(ROUND_SCREEN_RADIUS - icon_angle_point_to.x));
angle_to = (icon_angle_point_to.y > ROUND_SCREEN_RADIUS) ? (-quad_circle-angle_to) : (angle_to-quad_circle);
angle_to += radius_trigangle;

GRect draw_rect = window_bounds;
GPoint layer_origin_screen = layer_convert_point_to_screen(display_layer, GPointZero);
draw_rect.origin.x -= layer_origin_screen.x;
draw_rect.origin.y -= layer_origin_screen.y;
draw_rect = grect_inset(draw_rect, GEdgeInsets1(CELL_MARGIN_2-1));

// graphics_draw_arc(ctx, draw_rect, GOvalScaleModeFillCircle, angle_to, angle_from);
graphics_context_set_fill_color(ctx, fg_color);
graphics_fill_radial(ctx, draw_rect, GOvalScaleModeFillCircle, 3, angle_to, angle_from);
}
#else
graphics_context_set_stroke_width(ctx, 2);
icon_center_from.y += icon_radius + 1;
icon_center_to.y -= icon_radius + 1;
graphics_draw_line(ctx, icon_center_from, icon_center_to);
#endif
}

graphics_context_set_fill_color(ctx, bg_color);
graphics_fill_circle(ctx, icon_center_from, icon_radius);
if (is_from_to) {
graphics_fill_circle(ctx, icon_center_to, icon_radius);
}
graphics_context_set_stroke_width(ctx, 1);
graphics_draw_circle(ctx, icon_center_from, icon_radius);
if (is_from_to) {
graphics_draw_circle(ctx, icon_center_to, icon_radius);
}

////////////////////////////
// Draw stations
////////////////////////////
Expand Down Expand Up @@ -521,7 +521,7 @@ void common_menu_layer_draw_background_callback(GContext* ctx, const Layer *bg_l
// MARK: Push windows

bool ui_can_push_window() {
printf("1 Heap Total <%4dB> Used <%4dB> Free <%4dB>",heap_bytes_used()+heap_bytes_free(),heap_bytes_used(),heap_bytes_free());
// printf("1 Heap Total <%4dB> Used <%4dB> Free <%4dB>",heap_bytes_used()+heap_bytes_free(),heap_bytes_used(),heap_bytes_free());

#if !defined(PBL_PLATFORM_APLITE)
size_t critical_memory = 4800;
Expand Down
2 changes: 1 addition & 1 deletion src/ui_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void draw_from_to(GContext* ctx, Layer *drawing_layer,
TextScrollData **ptr_text_scroll_data, Layer *redraw_layer, bool is_selected,
#endif
bool is_inverted,
GColor bg_color, GColor fg_color,
GColor fg_color,
DataModelFromTo from_to
#if MINI_TIMETABLE_IS_ENABLED
,
Expand Down
4 changes: 1 addition & 3 deletions src/window_main_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,9 @@ static void menu_layer_draw_row_callback(GContext *ctx, Layer *cell_layer, MenuI

#ifdef PBL_COLOR
bool is_inverted = settings_is_dark_theme() || is_selected;
GColor bg_color = is_selected?HIGHLIGHT_COLOR:curr_bg_color();
GColor fg_color = (is_selected && !settings_is_dark_theme())?curr_bg_color():curr_fg_color();
#else
bool is_inverted = settings_is_dark_theme()?!is_selected:is_selected;
GColor bg_color = is_selected?curr_fg_color():curr_bg_color();
GColor fg_color = is_selected?curr_bg_color():curr_fg_color();
#endif

Expand All @@ -144,7 +142,7 @@ static void menu_layer_draw_row_callback(GContext *ctx, Layer *cell_layer, MenuI
&user_info->text_scroll_data, menu_layer_get_layer(user_info->menu_layer), is_selected,
#endif
is_inverted,
bg_color, fg_color,
fg_color,
favorite
#if MINI_TIMETABLE_IS_ENABLED
,
Expand Down
4 changes: 1 addition & 3 deletions src/window_next_trains.c
Original file line number Diff line number Diff line change
Expand Up @@ -458,11 +458,9 @@ static void menu_layer_draw_row_callback(GContext *ctx, Layer *cell_layer, MenuI

#ifdef PBL_COLOR
bool is_inverted = settings_is_dark_theme() || is_selected;
GColor bg_color = is_selected?HIGHLIGHT_COLOR:curr_bg_color();
GColor fg_color = (is_selected && !settings_is_dark_theme())?curr_bg_color():curr_fg_color();
#else
bool is_inverted = settings_is_dark_theme()?!is_selected:is_selected;
GColor bg_color = is_selected?curr_fg_color():curr_bg_color();
GColor fg_color = is_selected?curr_bg_color():curr_fg_color();
#endif

Expand All @@ -472,7 +470,7 @@ static void menu_layer_draw_row_callback(GContext *ctx, Layer *cell_layer, MenuI
&user_info->text_scroll_data, menu_layer_get_layer(user_info->menu_layer), is_selected,
#endif
is_inverted,
bg_color, fg_color,
fg_color,
user_info->from_to
#if MINI_TIMETABLE_IS_ENABLED
,
Expand Down
4 changes: 2 additions & 2 deletions src/window_search_station.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,10 @@ static void panel_layer_proc(Layer *layer, GContext *ctx) {
#endif
#ifdef PBL_COLOR
true,
bg_color, GColorWhite,
GColorWhite,
#else
settings_is_dark_theme()?!layer_data->is_active:layer_data->is_active,
bg_color, fg_color,
fg_color,
#endif
layer_data->from_to
#if MINI_TIMETABLE_IS_ENABLED
Expand Down

0 comments on commit 74487e0

Please sign in to comment.