From 484956e006afc9370a07719a78fd144f219e5f89 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Mon, 16 Mar 2020 22:32:37 +0000 Subject: [PATCH 1/3] Fix #10928: File browser's date column is too narrow. --- distribution/changelog.txt | 1 + src/openrct2-ui/windows/LoadSave.cpp | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/distribution/changelog.txt b/distribution/changelog.txt index 2009f868b2..3ed28d76af 100644 --- a/distribution/changelog.txt +++ b/distribution/changelog.txt @@ -5,6 +5,7 @@ - Fix: [#475] Water sides drawn incorrectly (original bug). - Fix: [#6123, #7907, #9472, #11028] Cannot build some track designs with 4 stations (original bug). - Fix: [#7094] Back wall edge texture in water missing. +- Fix: [#10928] File browser's date column is too narrow. - Fix: [#11005] Company value overflows. - Fix: [#11027] Third color on walls becomes black when saving. diff --git a/src/openrct2-ui/windows/LoadSave.cpp b/src/openrct2-ui/windows/LoadSave.cpp index 04af9ad0b7..40cdf3dd8b 100644 --- a/src/openrct2-ui/windows/LoadSave.cpp +++ b/src/openrct2-ui/windows/LoadSave.cpp @@ -637,16 +637,16 @@ static void window_loadsave_textinput(rct_window* w, rct_widgetindex widgetIndex static void window_loadsave_compute_max_date_width() { - // Generate a time object for a relatively wide time: 2000-10-20 00:00:00 + // Generate a time object for a relatively wide time: 2000-02-20 00:00:00 std::tm tm; tm.tm_sec = 0; tm.tm_min = 0; tm.tm_hour = 0; tm.tm_mday = 20; - tm.tm_mon = 9; + tm.tm_mon = 2; tm.tm_year = 100; tm.tm_wday = 5; - tm.tm_yday = 294; + tm.tm_yday = 51; tm.tm_isdst = -1; std::time_t long_time = mktime(&tm); From 56216fd026ea72685d1d87acf6de5d05c2228cfc Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Tue, 17 Mar 2020 18:02:35 +0100 Subject: [PATCH 2/3] Add an additional check for locales that do not use leading zeros for dates. --- src/openrct2-ui/windows/LoadSave.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/openrct2-ui/windows/LoadSave.cpp b/src/openrct2-ui/windows/LoadSave.cpp index 40cdf3dd8b..769fe4e960 100644 --- a/src/openrct2-ui/windows/LoadSave.cpp +++ b/src/openrct2-ui/windows/LoadSave.cpp @@ -651,9 +651,20 @@ static void window_loadsave_compute_max_date_width() std::time_t long_time = mktime(&tm); + // Check how how this date is represented (e.g. 2000-02-20, or 00/02/20) std::string date = Platform::FormatShortDate(long_time); maxDateWidth = gfx_get_string_width(date.c_str()); + // Some locales do not use leading zeros for months and days, so let's try October, too. + tm.tm_mon = 10; + tm.tm_yday = 294; + long_time = mktime(&tm); + + // Again, check how how this date is represented (e.g. 2000-10-20, or 00/10/20) + date = Platform::FormatShortDate(long_time); + maxDateWidth = std::max(maxDateWidth, gfx_get_string_width(date.c_str())); + + // Time appears to be universally represented with two digits for minutes, so 12:00 or 00:00 should be representable. std::string time = Platform::FormatTime(long_time); maxTimeWidth = gfx_get_string_width(time.c_str()); } From 503fbefbebf088b50767d0bdc2e219d665535184 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Mon, 30 Mar 2020 21:09:07 +0200 Subject: [PATCH 3/3] Harmonise date and time gaps / anchors. Introduces the DATE_TIME_GAP constant. --- src/openrct2-ui/windows/LoadSave.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/openrct2-ui/windows/LoadSave.cpp b/src/openrct2-ui/windows/LoadSave.cpp index 769fe4e960..c1490e1fff 100644 --- a/src/openrct2-ui/windows/LoadSave.cpp +++ b/src/openrct2-ui/windows/LoadSave.cpp @@ -635,6 +635,8 @@ static void window_loadsave_textinput(rct_window* w, rct_widgetindex widgetIndex } } +constexpr uint16_t DATE_TIME_GAP = 2; + static void window_loadsave_compute_max_date_width() { // Generate a time object for a relatively wide time: 2000-02-20 00:00:00 @@ -653,7 +655,7 @@ static void window_loadsave_compute_max_date_width() // Check how how this date is represented (e.g. 2000-02-20, or 00/02/20) std::string date = Platform::FormatShortDate(long_time); - maxDateWidth = gfx_get_string_width(date.c_str()); + maxDateWidth = gfx_get_string_width(date.c_str()) + DATE_TIME_GAP; // Some locales do not use leading zeros for months and days, so let's try October, too. tm.tm_mon = 10; @@ -662,11 +664,11 @@ static void window_loadsave_compute_max_date_width() // Again, check how how this date is represented (e.g. 2000-10-20, or 00/10/20) date = Platform::FormatShortDate(long_time); - maxDateWidth = std::max(maxDateWidth, gfx_get_string_width(date.c_str())); + maxDateWidth = std::max(maxDateWidth, gfx_get_string_width(date.c_str()) + DATE_TIME_GAP); // Time appears to be universally represented with two digits for minutes, so 12:00 or 00:00 should be representable. std::string time = Platform::FormatTime(long_time); - maxTimeWidth = gfx_get_string_width(time.c_str()); + maxTimeWidth = gfx_get_string_width(time.c_str()) + DATE_TIME_GAP; } static void window_loadsave_invalidate(rct_window* w) @@ -681,8 +683,8 @@ static void window_loadsave_invalidate(rct_window* w) window_loadsave_widgets[WIDX_RESIZE].bottom = w->height - 1; rct_widget* date_widget = &window_loadsave_widgets[WIDX_SORT_DATE]; - date_widget->left = w->width - maxDateWidth - maxTimeWidth - 24; date_widget->right = w->width - 5; + date_widget->left = date_widget->right - (maxDateWidth + maxTimeWidth + (4 * DATE_TIME_GAP) + (SCROLLBAR_WIDTH + 1)); window_loadsave_widgets[WIDX_SORT_NAME].left = 4; window_loadsave_widgets[WIDX_SORT_NAME].right = window_loadsave_widgets[WIDX_SORT_DATE].left - 1; @@ -746,6 +748,7 @@ static void window_loadsave_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi, i { gfx_fill_rect(dpi, dpi->x, dpi->y, dpi->x + dpi->width - 1, dpi->y + dpi->height - 1, ColourMapA[w->colours[1]].mid_light); const int32_t listWidth = w->widgets[WIDX_SCROLL].right - w->widgets[WIDX_SCROLL].left; + const int32_t dateAnchor = w->widgets[WIDX_SORT_DATE].left + maxDateWidth + DATE_TIME_GAP; for (int32_t i = 0; i < w->no_list_items; i++) { @@ -780,14 +783,14 @@ static void window_loadsave_scrollpaint(rct_window* w, rct_drawpixelinfo* dpi, i // Print formatted modified date, if this is a file if (_listItems[i].type == TYPE_FILE) { - int32_t offset = w->widgets[WIDX_SORT_DATE].left + maxDateWidth; - set_format_arg(0, rct_string_id, STR_STRING); set_format_arg(2, char*, _listItems[i].date_formatted.c_str()); - gfx_draw_string_right_clipped(dpi, stringId, gCommonFormatArgs, COLOUR_BLACK, offset - 2, y, maxDateWidth); + gfx_draw_string_right_clipped( + dpi, stringId, gCommonFormatArgs, COLOUR_BLACK, dateAnchor - DATE_TIME_GAP, y, maxDateWidth); set_format_arg(2, char*, _listItems[i].time_formatted.c_str()); - gfx_draw_string_left_clipped(dpi, stringId, gCommonFormatArgs, COLOUR_BLACK, offset + 2, y, maxTimeWidth); + gfx_draw_string_left_clipped( + dpi, stringId, gCommonFormatArgs, COLOUR_BLACK, dateAnchor + DATE_TIME_GAP, y, maxTimeWidth); } } }