From c381b6a69d517a09d73ec2e8c3c48869d738251d 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: Mon, 22 Jul 2024 08:27:35 +0900 Subject: [PATCH 1/7] CHG: Make it possible to jump by clicking on the coord cell --- gui/components/sortable_table.h | 5 ++++- gui/components/sortable_table_header.cc | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/gui/components/sortable_table.h b/gui/components/sortable_table.h index f545b6702b..5f0154f6c3 100644 --- a/gui/components/sortable_table.h +++ b/gui/components/sortable_table.h @@ -26,7 +26,8 @@ class table_cell_item_t : virtual public gui_component_t cell_no_sorting = 0, cell_value = 1, cell_values = 2, - cell_text = 3 + cell_text = 3, + cell_coord = 4 }; enum align_t { @@ -87,6 +88,8 @@ class coord_cell_t : public text_cell_t coord_cell_t(const char* text = NULL, koord coord=koord::invalid, PIXVAL color = SYSCOL_TEXT, align_t align = left); koord get_coord() const { return coord; } + + const uint8 get_type() const OVERRIDE { return cell_coord; } }; diff --git a/gui/components/sortable_table_header.cc b/gui/components/sortable_table_header.cc index 984faf3274..5df5db4064 100644 --- a/gui/components/sortable_table_header.cc +++ b/gui/components/sortable_table_header.cc @@ -129,7 +129,7 @@ bool gui_sort_table_header_t::infowin_event(const event_t* ev) { bool swallowed = gui_container_t::infowin_event(ev); - if (IS_LEFTRELEASE(ev) && getroffen(ev->mouse_pos)) { + if (!swallowed && IS_LEFTRELEASE(ev) && getroffen(ev->mouse_pos)) { uint idx=0; for (auto& cell : owned_cells) { if (cell->getroffen(ev->mouse_pos)) { From a4aacd8ff4ada1bccfc280d17da51fa97767998a 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: Thu, 25 Jul 2024 00:29:10 +0900 Subject: [PATCH 2/7] FIX: missing compare coord_cell --- gui/components/sortable_table.cc | 16 ++++++++++++++++ gui/components/sortable_table.h | 1 + 2 files changed, 17 insertions(+) diff --git a/gui/components/sortable_table.cc b/gui/components/sortable_table.cc index b818ff9e60..c71c078e65 100644 --- a/gui/components/sortable_table.cc +++ b/gui/components/sortable_table.cc @@ -320,6 +320,19 @@ int gui_sort_table_row_t::compare_text(const table_cell_item_t* a, const table_c return STRICMP(a_text, b_text); } +int gui_sort_table_row_t::compare_coord(const table_cell_item_t* a, const table_cell_item_t* b) +{ + int cmp = 0; + const coord_cell_t* cell_a = dynamic_cast(a); + const coord_cell_t* cell_b = dynamic_cast(b); + cmp = cell_a->get_coord().x - cell_b->get_coord().x; + if (cmp == 0) { + cmp = cell_a->get_coord().y - cell_b->get_coord().y; + } + return cmp; +} + + int gui_sort_table_row_t::compare(const table_cell_item_t* a, const table_cell_item_t* b) { sint64 cmp = 0; @@ -336,6 +349,9 @@ int gui_sort_table_row_t::compare(const table_cell_item_t* a, const table_cell_i case table_cell_item_t::cell_text: cmp = gui_sort_table_row_t::compare_text(a, b); break; + case table_cell_item_t::cell_coord: + cmp = gui_sort_table_row_t::compare_coord(a, b); + break; case table_cell_item_t::cell_no_sorting: default: // nothing to do diff --git a/gui/components/sortable_table.h b/gui/components/sortable_table.h index 5f0154f6c3..2a6b2c9e54 100644 --- a/gui/components/sortable_table.h +++ b/gui/components/sortable_table.h @@ -141,6 +141,7 @@ class gui_sort_table_row_t : public gui_container_t, public gui_scrolled_list_t: static sint64 compare_value(const table_cell_item_t* a, const table_cell_item_t* b); static sint64 compare_values(const table_cell_item_t* a, const table_cell_item_t* b); static int compare_text(const table_cell_item_t* a, const table_cell_item_t* b); + static int compare_coord(const table_cell_item_t* a, const table_cell_item_t* b); protected: From c7781a89d0ac201bf2550099b18d4738f383713c 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: Thu, 25 Jul 2024 00:30:41 +0900 Subject: [PATCH 3/7] CHG: text_cell can be underlined --- gui/components/sortable_table.cc | 8 ++++++-- gui/components/sortable_table.h | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/gui/components/sortable_table.cc b/gui/components/sortable_table.cc index c71c078e65..f1efc4c9ff 100644 --- a/gui/components/sortable_table.cc +++ b/gui/components/sortable_table.cc @@ -61,11 +61,12 @@ void table_cell_item_t::draw(scr_coord offset) -text_cell_t::text_cell_t(const char* text_, PIXVAL col, align_t align_) +text_cell_t::text_cell_t(const char* text_, PIXVAL col, align_t align_, bool underlined_) { text= text_; color= col; align=align_; + underlined = underlined_; min_size = scr_size(proportional_string_width(translator::translate(text)), LINESPACE); set_size(min_size); } @@ -76,10 +77,13 @@ void text_cell_t::draw(scr_coord offset) offset+=pos; display_proportional_clip_rgb(offset.x+ draw_offset.x, offset.y+ draw_offset.y, translator::translate(text), ALIGN_LEFT, color, false); + if (underlined) { + display_fillbox_wh_clip_rgb(offset.x + draw_offset.x, offset.y + draw_offset.y + LINESPACE-1, min_size.w, 1, color, false); + } } coord_cell_t::coord_cell_t(const char* text, koord coord_, PIXVAL color, align_t align) - : text_cell_t((text==NULL && coord_!=koord::invalid) ? coord.get_fullstr() : text, color, align) + : text_cell_t((text==NULL && coord_!=koord::invalid) ? coord.get_fullstr() : text, color, align, coord_ == koord::invalid ? false : true) { coord = coord_; min_size = scr_size(proportional_string_width(translator::translate(get_text())), LINESPACE); diff --git a/gui/components/sortable_table.h b/gui/components/sortable_table.h index 2a6b2c9e54..17711e2912 100644 --- a/gui/components/sortable_table.h +++ b/gui/components/sortable_table.h @@ -66,10 +66,11 @@ class text_cell_t : public table_cell_item_t { const char* text; // only for direct access of non-translatable things. Do not use! PIXVAL color; + bool underlined; // bool is_bold; public: - text_cell_t(const char* text = NULL, PIXVAL color = SYSCOL_TEXT, align_t align = left); + text_cell_t(const char* text = NULL, PIXVAL color = SYSCOL_TEXT, align_t align = left, bool underlined = false); const uint8 get_type() const OVERRIDE { return cell_text; } From 7479d50ddcd2981db37ad54ed894485b924933f3 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: Thu, 25 Jul 2024 00:31:43 +0900 Subject: [PATCH 4/7] =?UTF-8?q?CHG:=20can=20choose=20to=20display=20the=20?= =?UTF-8?q?values=20=E2=80=8B=E2=80=8Bcell=20in=20one=20or=20two=20lines.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gui/components/sortable_table.cc | 35 ++++++++++++++++++-------------- gui/components/sortable_table.h | 4 +++- 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/gui/components/sortable_table.cc b/gui/components/sortable_table.cc index f1efc4c9ff..c4c80b74d8 100644 --- a/gui/components/sortable_table.cc +++ b/gui/components/sortable_table.cc @@ -189,7 +189,7 @@ void value_cell_t::draw(scr_coord offset) } -values_cell_t::values_cell_t(sint64 value_, sint64 sub_value_, PIXVAL col) +values_cell_t::values_cell_t(sint64 value_, sint64 sub_value_, PIXVAL col, bool single_line_) : value_cell_t(value_) { buf.clear(); @@ -198,11 +198,10 @@ values_cell_t::values_cell_t(sint64 value_, sint64 sub_value_, PIXVAL col) color = col; min_size.h = LINESPACE; align = centered; + single_line = single_line_; sub_value=sub_value_; - bool two_lines = false; - if (value==0 && sub_value==0) { buf.append("-"); color = SYSCOL_TEXT_WEAK; @@ -212,20 +211,22 @@ values_cell_t::values_cell_t(sint64 value_, sint64 sub_value_, PIXVAL col) } if (sub_value != 0) { if (value != 0) { - // display two lines - sub_buf.printf("(%i)", sub_value); - min_size.h += LINESPACE; - two_lines = true; + if (single_line) { + buf.printf(" (%i)", sub_value); + } + else { + // display two lines + sub_buf.printf("(%i)", sub_value); + min_size.h += LINESPACE; + sub_draw_offset_x = proportional_string_width(sub_buf) / 2; + min_size.w = max(proportional_string_width(buf), sub_draw_offset_x * 2 + 1); + } } else { buf.printf("(%i)", sub_value); } } - if (two_lines) { - sub_draw_offset_x = proportional_string_width(sub_buf) / 2; - min_size.w = max(proportional_string_width(buf), sub_draw_offset_x * 2 + 1); - } - else { + if (single_line) { min_size.w = proportional_string_width(buf); } set_size(min_size); @@ -233,10 +234,14 @@ values_cell_t::values_cell_t(sint64 value_, sint64 sub_value_, PIXVAL col) void values_cell_t::set_width(scr_coord_val new_width) { - const scr_coord_val row1_width = proportional_string_width(buf); - size.w = new_width + L_CELL_PADDING * 2; - draw_offset.x = (size.w - row1_width) / 2; + if (single_line) { + draw_offset.x = (size.w - min_size.w) / 2; + } + else { + draw_offset.x = (size.w - proportional_string_width(buf)) / 2; + } + } void values_cell_t::draw(scr_coord offset) diff --git a/gui/components/sortable_table.h b/gui/components/sortable_table.h index 17711e2912..b3533be0b0 100644 --- a/gui/components/sortable_table.h +++ b/gui/components/sortable_table.h @@ -122,9 +122,11 @@ class values_cell_t : public value_cell_t cbuffer_t sub_buf; sint64 sub_value; scr_coord_val sub_draw_offset_x = 0; + bool single_line; public: - values_cell_t(sint64 value, sint64 sub_value, PIXVAL color = SYSCOL_TEXT); + // single_line: Displaying two values ​​on the same line + values_cell_t(sint64 value, sint64 sub_value, PIXVAL color = SYSCOL_TEXT, bool single_line=false); void set_width(scr_coord_val new_width) OVERRIDE; From 03e6fbd71b2a1d531b7d7d66237c5bc2a0c54ced 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: Thu, 25 Jul 2024 07:50:44 +0900 Subject: [PATCH 5/7] CHG: The cell value can be updated externally later --- gui/components/sortable_table.cc | 42 ++++++++++++++++++++++++-------- gui/components/sortable_table.h | 15 +++++++++--- 2 files changed, 44 insertions(+), 13 deletions(-) diff --git a/gui/components/sortable_table.cc b/gui/components/sortable_table.cc index c4c80b74d8..331fc5e44f 100644 --- a/gui/components/sortable_table.cc +++ b/gui/components/sortable_table.cc @@ -91,11 +91,20 @@ coord_cell_t::coord_cell_t(const char* text, koord coord_, PIXVAL color, align_t } -value_cell_t::value_cell_t(sint64 value_, gui_chart_t::chart_suffix_t suffix, align_t align_, PIXVAL col) +value_cell_t::value_cell_t(sint64 value_, gui_chart_t::chart_suffix_t suffix_, align_t align_, PIXVAL col) { color = col; align = align_; - value=value_; + suffix= suffix_; + + set_value(value_); + set_size(min_size); +} + +void value_cell_t::set_value(sint64 value_) +{ + value = value_; + buf.clear(); switch(suffix) { @@ -177,7 +186,10 @@ value_cell_t::value_cell_t(sint64 value_, gui_chart_t::chart_suffix_t suffix, al break; } min_size = scr_size(proportional_string_width(buf), LINESPACE); - set_size(min_size); + if (min_size.w> (size.w - L_CELL_PADDING*2) ) { + dbg->warning("value_cell_t::set_value", "Cell's text width has been changed to %i, exceeding the column width of %i.", min_size.w, size.w); + } + set_width(size.w - L_CELL_PADDING*2); // recalc draw_offset.x } void value_cell_t::draw(scr_coord offset) @@ -190,19 +202,26 @@ void value_cell_t::draw(scr_coord offset) values_cell_t::values_cell_t(sint64 value_, sint64 sub_value_, PIXVAL col, bool single_line_) - : value_cell_t(value_) { - buf.clear(); - sub_buf.clear(); - color = col; min_size.h = LINESPACE; align = centered; single_line = single_line_; - sub_value=sub_value_; + set_values(value_, sub_value_); - if (value==0 && sub_value==0) { + set_size(min_size); +} + +void values_cell_t::set_values(sint64 value_, sint64 sub_value_) +{ + value = value_; + sub_value = sub_value_; + + buf.clear(); + sub_buf.clear(); + + if (value == 0 && sub_value == 0) { buf.append("-"); color = SYSCOL_TEXT_WEAK; } @@ -229,7 +248,10 @@ values_cell_t::values_cell_t(sint64 value_, sint64 sub_value_, PIXVAL col, bool if (single_line) { min_size.w = proportional_string_width(buf); } - set_size(min_size); + if (min_size.w > (size.w - L_CELL_PADDING * 2)) { + dbg->warning("values_cell_t::set_value", "Cell's text width has been changed to %i, exceeding the column width of %i.", min_size.w, size.w); + } + set_width(size.w - L_CELL_PADDING * 2); // recalc draw_offset.x } void values_cell_t::set_width(scr_coord_val new_width) diff --git a/gui/components/sortable_table.h b/gui/components/sortable_table.h index b3533be0b0..16099bb339 100644 --- a/gui/components/sortable_table.h +++ b/gui/components/sortable_table.h @@ -98,6 +98,7 @@ class coord_cell_t : public text_cell_t // Can specify a suffix. class value_cell_t : public table_cell_item_t { + gui_chart_t::chart_suffix_t suffix; protected: cbuffer_t buf; PIXVAL color; @@ -107,6 +108,9 @@ class value_cell_t : public table_cell_item_t public: value_cell_t(sint64 value, gui_chart_t::chart_suffix_t suffix= gui_chart_t::STANDARD, align_t align = left, PIXVAL color = SYSCOL_TEXT); + // When resetting the value, care must be taken not to increase the column width. + void set_value(sint64 value); + sint64 get_value() const { return value; } const uint8 get_type() const OVERRIDE { return cell_value; } @@ -116,11 +120,12 @@ class value_cell_t : public table_cell_item_t // The cell holds two values for sorting // There is no suffix -class values_cell_t : public value_cell_t +class values_cell_t : public table_cell_item_t { protected: - cbuffer_t sub_buf; - sint64 sub_value; + cbuffer_t buf, sub_buf; + PIXVAL color; + sint64 value, sub_value; scr_coord_val sub_draw_offset_x = 0; bool single_line; @@ -130,6 +135,10 @@ class values_cell_t : public value_cell_t void set_width(scr_coord_val new_width) OVERRIDE; + // When resetting the value, care must be taken not to increase the column width. + void set_values(sint64 value, sint64 sub_value=0); + + sint64 get_value() const { return value; } sint64 get_sub_value() const { return sub_value; } const uint8 get_type() const OVERRIDE { return cell_values; } From 9cb16ae47de36d56f2b23267452776945758a916 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: Thu, 25 Jul 2024 22:46:08 +0900 Subject: [PATCH 6/7] CHG: Preparing for value cell inheritance --- gui/components/sortable_table.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/gui/components/sortable_table.h b/gui/components/sortable_table.h index 16099bb339..0fc5e805a4 100644 --- a/gui/components/sortable_table.h +++ b/gui/components/sortable_table.h @@ -109,10 +109,12 @@ class value_cell_t : public table_cell_item_t value_cell_t(sint64 value, gui_chart_t::chart_suffix_t suffix= gui_chart_t::STANDARD, align_t align = left, PIXVAL color = SYSCOL_TEXT); // When resetting the value, care must be taken not to increase the column width. - void set_value(sint64 value); + virtual void set_value(sint64 value); sint64 get_value() const { return value; } + void set_color(PIXVAL color_) { color = color_; } + const uint8 get_type() const OVERRIDE { return cell_value; } void draw(scr_coord offset) OVERRIDE; From e336f6307248cc0962d2bc330145a4f5b0dff771 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: Fri, 26 Jul 2024 19:30:29 +0900 Subject: [PATCH 7/7] CHG: Highlight coordinate cells when selected --- gui/components/sortable_table.cc | 47 ++++++++++++++++++++++++++++++-- gui/components/sortable_table.h | 9 ++++-- 2 files changed, 51 insertions(+), 5 deletions(-) diff --git a/gui/components/sortable_table.cc b/gui/components/sortable_table.cc index 331fc5e44f..010a0e9145 100644 --- a/gui/components/sortable_table.cc +++ b/gui/components/sortable_table.cc @@ -12,6 +12,7 @@ #include "../../simworld.h" #include "../../simcolor.h" #include "../../display/simgraph.h" +#include "../../display/viewport.h" #include "../../dataobj/translator.h" @@ -82,14 +83,54 @@ void text_cell_t::draw(scr_coord offset) } } -coord_cell_t::coord_cell_t(const char* text, koord coord_, PIXVAL color, align_t align) - : text_cell_t((text==NULL && coord_!=koord::invalid) ? coord.get_fullstr() : text, color, align, coord_ == koord::invalid ? false : true) + +coord_cell_t::coord_cell_t(const char* alt_text, koord coord_, align_t align_) { coord = coord_; - min_size = scr_size(proportional_string_width(translator::translate(get_text())), LINESPACE); + align = align_; + if (alt_text != NULL) { + buf.printf("%s", alt_text); + } + else { + buf.append("-"); + } + min_size = scr_size(proportional_string_width(buf), LINESPACE); + set_size(min_size); +} + +coord_cell_t::coord_cell_t(koord coord_, align_t align_) +{ + coord = coord_; + align = align_; + if (coord != koord::invalid) { + buf.printf("%s", coord.get_str()); + show_posicon = true; + } + else { + buf.append("-"); + } + min_size = scr_size(proportional_string_width(buf) + (D_POS_BUTTON_WIDTH + 2) * show_posicon, show_posicon ? max(LINESPACE, D_POS_BUTTON_HEIGHT) : LINESPACE); set_size(min_size); } +void coord_cell_t::draw(scr_coord offset) +{ + table_cell_item_t::draw(offset); + + offset += pos; + PIXVAL text_col= SYSCOL_TEXT; + if (world()->get_viewport()->get_world_position() == coord) { + text_col=SYSCOL_TEXT_HIGHLIGHT; + if (show_posicon){ + display_color_img(skinverwaltung_t::posbutton->get_image_id(SKIN_BUTTON_POS_PRESSED), offset.x + draw_offset.x, offset.y + (size.h-D_POS_BUTTON_HEIGHT)/2, 0, false, false); + } + } + display_proportional_clip_rgb(offset.x + draw_offset.x + (D_POS_BUTTON_WIDTH+2) * show_posicon, offset.y + draw_offset.y, buf, ALIGN_LEFT, text_col, false); + if (coord != koord::invalid) { + display_fillbox_wh_clip_rgb(offset.x + draw_offset.x + (D_POS_BUTTON_WIDTH + 2) * show_posicon, offset.y + draw_offset.y + LINESPACE - 1, min_size.w - (D_POS_BUTTON_WIDTH + 2) * show_posicon, 1, text_col, false); + } +} + value_cell_t::value_cell_t(sint64 value_, gui_chart_t::chart_suffix_t suffix_, align_t align_, PIXVAL col) { diff --git a/gui/components/sortable_table.h b/gui/components/sortable_table.h index 0fc5e805a4..92da9d66ee 100644 --- a/gui/components/sortable_table.h +++ b/gui/components/sortable_table.h @@ -81,16 +81,21 @@ class text_cell_t : public table_cell_item_t // Hold the coordinates and click a cell to jump to the coordinates. -class coord_cell_t : public text_cell_t +class coord_cell_t : public table_cell_item_t { koord coord; + cbuffer_t buf; + bool show_posicon=false; public: - coord_cell_t(const char* text = NULL, koord coord=koord::invalid, PIXVAL color = SYSCOL_TEXT, align_t align = left); + coord_cell_t(const char* alt_text = NULL, koord coord=koord::invalid, align_t align = left); + coord_cell_t(koord coord = koord::invalid, align_t align = left); koord get_coord() const { return coord; } const uint8 get_type() const OVERRIDE { return cell_coord; } + + void draw(scr_coord offset) OVERRIDE; };