From c86dbd2ebe2f93694f03d9c3c68b63a7c4e2ba16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=28=C2=B4=E3=83=BB=CF=89=E3=83=BB=EF=BD=80=29?= Date: Tue, 22 Sep 2020 03:20:07 +0900 Subject: [PATCH] CHG: Route bar has a unique design --- display/simgraph.h | 1 + display/simgraph0.cc | 4 +++ display/simgraph16.cc | 12 +++++++ gui/components/gui_speedbar.cc | 63 ++++++++++++++++++++++++++++++++++ gui/components/gui_speedbar.h | 26 ++++++++++++++ gui/convoi_info_t.cc | 20 ++++++++++- gui/convoi_info_t.h | 2 +- 7 files changed, 126 insertions(+), 2 deletions(-) diff --git a/display/simgraph.h b/display/simgraph.h index 8f55d51920..d49a2e106c 100644 --- a/display/simgraph.h +++ b/display/simgraph.h @@ -391,6 +391,7 @@ void display_direct_line_rgb(const KOORD_VAL x, const KOORD_VAL y, const KOORD_V void display_direct_line_dotted_rgb(const KOORD_VAL x, const KOORD_VAL y, const KOORD_VAL xx, const KOORD_VAL yy, const KOORD_VAL draw, const KOORD_VAL dontDraw, const PIXVAL color); void display_circle_rgb(KOORD_VAL x0, KOORD_VAL y0, int radius, const PIXVAL color); void display_filled_circle_rgb(KOORD_VAL x0, KOORD_VAL y0, int radius, const PIXVAL color); +void display_right_triangle_rgb(KOORD_VAL x, KOORD_VAL y, uint8 height, const PIXVAL colval, const bool dirty); void draw_bezier_rgb(KOORD_VAL Ax, KOORD_VAL Ay, KOORD_VAL Bx, KOORD_VAL By, KOORD_VAL ADx, KOORD_VAL ADy, KOORD_VAL BDx, KOORD_VAL BDy, const PIXVAL colore, KOORD_VAL draw, KOORD_VAL dontDraw); int display_fluctuation_triangle_rgb(KOORD_VAL x, KOORD_VAL y, uint8 height, const bool dirty, sint64 value=0); diff --git a/display/simgraph0.cc b/display/simgraph0.cc index e8d8309650..df8b203655 100644 --- a/display/simgraph0.cc +++ b/display/simgraph0.cc @@ -427,6 +427,10 @@ void display_filled_circle_rgb(KOORD_VAL, KOORD_VAL, int, const PIXVAL) { } +void display_right_triangle_rgb(KOORD_VAL, KOORD_VAL, uint8, const PIXVAL, const bool) +{ +} + int display_fluctuation_triangle_rgb(KOORD_VAL, KOORD_VAL, uint8, const bool, sint64) { return 0; diff --git a/display/simgraph16.cc b/display/simgraph16.cc index 48bc1ce47f..d9a5410014 100644 --- a/display/simgraph16.cc +++ b/display/simgraph16.cc @@ -5083,6 +5083,18 @@ void display_filled_circle_rgb(KOORD_VAL x0, KOORD_VAL y0, int radius, const PI } +// Currently, only right-facing equilateral triangles are supported. Can be expanded if needed to accommodate another direction. +// The horizontal size is sqrt(3) times the height. - Ranran +void display_right_triangle_rgb(KOORD_VAL x, KOORD_VAL y, uint8 height, const PIXVAL colval, const bool dirty) +{ + double sqrt3 = sqrt(3); + for (uint x0 = 0; x0 <= int(0.99 + height * (sqrt3)); x0++) + { + display_vline_wh_rgb(x + x0, y + int(0.99 + x0 / sqrt3), height - int(0.99 + x0 / sqrt3) * 2, colval, dirty); + } +} + + int display_fluctuation_triangle_rgb(KOORD_VAL x, KOORD_VAL y, uint8 height, const bool dirty, sint64 value) { if (!value) { return 0; } // nothing to draw diff --git a/gui/components/gui_speedbar.cc b/gui/components/gui_speedbar.cc index 54e782fef4..087d37b066 100644 --- a/gui/components/gui_speedbar.cc +++ b/gui/components/gui_speedbar.cc @@ -157,3 +157,66 @@ void gui_tile_occupancybar_t::draw(scr_coord offset) } } + +void gui_routebar_t::set_base(sint32 base) +{ + this->base = base != 0 ? base : 1; +} + +void gui_routebar_t::init(const sint32 *value, uint8 state) +{ + this->value = value; + this->state = state; +} + +void gui_routebar_t::set_state(uint8 state) +{ + this->state = state; +} + + +void gui_routebar_t::draw(scr_coord offset) +{ + uint8 h = size.h % 2 ? size.h : size.h-1; + if (h < 5) { h = 5; set_size( scr_size(size.w, h) ); } + const uint16 w = size.w - h; + + offset += pos; + display_fillbox_wh_clip_rgb(offset.x+h/2, offset.y+h/2-1, w, 3, color_idx_to_rgb(MN_GREY1), true); + + PIXVAL col; + for (uint8 i = 0; i<5; i++) { + col = i % 2 ? COL_GREY4-1 : MN_GREY0; + display_vline_wh_rgb(offset.x + h/2 + w*i/4, offset.y+i%2, h-(i%2)*2, color_idx_to_rgb(col), true); + } + sint32 const to = min(*value, base) * w / base; + + display_fillbox_wh_clip_rgb(offset.x+h/2, offset.y+h/2-1, to, 3, color_idx_to_rgb(43), true); + + switch (state) + { + case 1: + display_fillbox_wh_clip_rgb(offset.x + to + 1, offset.y + 1, h - 2, h - 2, color_idx_to_rgb(COL_YELLOW), true); + break; + case 2: + display_fillbox_wh_clip_rgb(offset.x + to + 1, offset.y + 1, h - 2, h - 2, color_idx_to_rgb(COL_ORANGE), true); + break; + case 3: + display_fillbox_wh_clip_rgb(offset.x + to + 1, offset.y + 1, h - 2, h - 2, color_idx_to_rgb(COL_RED), true); + break; + case 0: + default: + display_right_triangle_rgb(offset.x + to, offset.y, h, color_idx_to_rgb(COL_GREEN), true); + break; + } +} + +scr_size gui_routebar_t::get_min_size() const +{ + return scr_size(D_INDICATOR_WIDTH, size.h); +} + +scr_size gui_routebar_t::get_max_size() const +{ + return scr_size(scr_size::inf.w, size.h); +} diff --git a/gui/components/gui_speedbar.h b/gui/components/gui_speedbar.h index c7ad73154e..d51b45403f 100644 --- a/gui/components/gui_speedbar.h +++ b/gui/components/gui_speedbar.h @@ -86,4 +86,30 @@ class gui_tile_occupancybar_t : public gui_component_t void draw(scr_coord offset); }; + +// route progress bar +class gui_routebar_t : public gui_component_t +{ +private: + const sint32 *value; + sint32 base; + uint8 state; + +public: + gui_routebar_t() { base = 100; state = 0; } + void set_base(sint32 base); + void init(const sint32 *value, uint8 state); + + void set_state(uint8 state); + + /** + * Draw the component + */ + void draw(scr_coord offset); + + scr_size get_min_size() const OVERRIDE; + + scr_size get_max_size() const OVERRIDE; +}; + #endif diff --git a/gui/convoi_info_t.cc b/gui/convoi_info_t.cc index adabe10fb7..6dc4376cc7 100644 --- a/gui/convoi_info_t.cc +++ b/gui/convoi_info_t.cc @@ -325,7 +325,8 @@ void convoi_info_t::init(convoihandle_t cnv) speed_bar.add_color_value(&mean_convoi_speed, color_idx_to_rgb(COL_GREEN)); // we update this ourself! - route_bar.add_color_value(&cnv_route_index, color_idx_to_rgb(COL_GREEN)); + route_bar.init(&cnv_route_index, 0); + route_bar.set_height(9); update_labels(); @@ -347,6 +348,23 @@ convoi_info_t::~convoi_info_t() void convoi_info_t::update_labels() { + switch (cnv->get_state()) + { + case convoi_t::DRIVING: + route_bar.set_state(0); + break; + case convoi_t::WAITING_FOR_CLEARANCE_ONE_MONTH: + case convoi_t::WAITING_FOR_CLEARANCE_TWO_MONTHS: + case convoi_t::CAN_START_ONE_MONTH: + case convoi_t::CAN_START_TWO_MONTHS: + route_bar.set_state(2); + case convoi_t::NO_ROUTE: + route_bar.set_state(3); + break; + default: + route_bar.set_state(1); + break; + } // use median speed to avoid flickering mean_convoi_speed += speed_to_kmh(cnv->get_akt_speed() * 4); mean_convoi_speed /= 2; diff --git a/gui/convoi_info_t.h b/gui/convoi_info_t.h index 36d02d23c5..278d8044bb 100644 --- a/gui/convoi_info_t.h +++ b/gui/convoi_info_t.h @@ -66,8 +66,8 @@ class convoi_info_t : public gui_frame_t, private action_listener_t gui_textinput_t input; gui_speedbar_t filled_bar; gui_speedbar_t speed_bar; - gui_speedbar_t route_bar; + gui_routebar_t route_bar; gui_chart_t chart; button_t button; button_t follow_button;