From 1d67094863fc03aa2307a5b336b7be41720a22d0 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Mon, 23 Jun 2025 08:24:49 +0100 Subject: [PATCH] Add: Buttons to change picker preview image height. (#14373) Adjusted height is remembered per picker type, but not saved. --- src/lang/english.txt | 5 +++++ src/picker_gui.cpp | 23 +++++++++++++++++++++-- src/picker_gui.h | 16 +++++++++++----- src/widgets/picker_widget.h | 2 ++ 4 files changed, 39 insertions(+), 7 deletions(-) diff --git a/src/lang/english.txt b/src/lang/english.txt index 21d0e08940..1d949265c2 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -2833,6 +2833,11 @@ STR_PICKER_MODE_USED_TOOLTIP :Toggle showing STR_PICKER_MODE_SAVED :Saved STR_PICKER_MODE_SAVED_TOOLTIP :Toggle showing only saved items +STR_PICKER_PREVIEW_SHRINK :- +STR_PICKER_PREVIEW_SHRINK_TOOLTIP :Reduce the height of preview images. Ctrl+Click to reduce to minimum +STR_PICKER_PREVIEW_EXPAND :+ +STR_PICKER_PREVIEW_EXPAND_TOOLTIP :Increase the height of preview images. Ctrl+Click to increase to maximum + STR_PICKER_STATION_CLASS_TOOLTIP :Select a station class to display STR_PICKER_STATION_TYPE_TOOLTIP :Select a station type to build. Ctrl+Click to add or remove in saved items STR_PICKER_WAYPOINT_CLASS_TOOLTIP :Select a waypoint class to display diff --git a/src/picker_gui.cpp b/src/picker_gui.cpp index 68c547ebfb..196d5d7b9d 100644 --- a/src/picker_gui.cpp +++ b/src/picker_gui.cpp @@ -181,6 +181,8 @@ void PickerWindow::ConstructWindow() /* Test if pickers should be active.*/ bool is_active = this->callbacks.IsActive(); + this->preview_height = std::max(this->callbacks.preview_height, PREVIEW_HEIGHT); + /* Functionality depends on widgets being present, not window class. */ this->has_class_picker = is_active && this->GetWidget(WID_PW_CLASS_LIST) != nullptr && this->callbacks.HasClassChoice(); this->has_type_picker = is_active && this->GetWidget(WID_PW_TYPE_MATRIX) != nullptr; @@ -286,7 +288,7 @@ void PickerWindow::UpdateWidgetSize(WidgetID widget, Dimension &size, const Dime /* Type picker */ case WID_PW_TYPE_ITEM: size.width = ScaleGUITrad(PREVIEW_WIDTH) + WidgetDimensions::scaled.fullbevel.Horizontal(); - size.height = ScaleGUITrad(PREVIEW_HEIGHT) + WidgetDimensions::scaled.fullbevel.Vertical(); + size.height = ScaleGUITrad(this->preview_height) + WidgetDimensions::scaled.fullbevel.Vertical(); break; case WID_PW_CONFIGURE_BADGES: @@ -332,7 +334,7 @@ void PickerWindow::DrawWidget(const Rect &r, WidgetID widget) const if (FillDrawPixelInfo(&tmp_dpi, ir)) { AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi); int x = (ir.Width() - ScaleSpriteTrad(PREVIEW_WIDTH)) / 2 + ScaleSpriteTrad(PREVIEW_LEFT); - int y = (ir.Height() + ScaleSpriteTrad(PREVIEW_HEIGHT)) / 2 - ScaleSpriteTrad(PREVIEW_BOTTOM); + int y = (ir.Height() + ScaleSpriteTrad(this->preview_height)) / 2 - ScaleSpriteTrad(PREVIEW_BOTTOM); this->callbacks.DrawType(x, y, item.class_index, item.index); @@ -398,6 +400,18 @@ void PickerWindow::OnClick(Point pt, WidgetID widget, int) this->InvalidateData({PickerInvalidation::Class, PickerInvalidation::Type, PickerInvalidation::Position}); break; + case WID_PW_SHRINK: + this->callbacks.preview_height = this->preview_height = _ctrl_pressed ? PREVIEW_HEIGHT : std::max(PREVIEW_HEIGHT, this->preview_height - STEP_PREVIEW_HEIGHT); + this->InvalidateData({}); + this->ReInit(); + break; + + case WID_PW_EXPAND: + this->callbacks.preview_height = this->preview_height = _ctrl_pressed ? MAX_PREVIEW_HEIGHT : std::min(MAX_PREVIEW_HEIGHT, this->preview_height + STEP_PREVIEW_HEIGHT); + this->InvalidateData({}); + this->ReInit(); + break; + /* Type Picker */ case WID_PW_TYPE_ITEM: { int sel = this->GetWidget(widget)->GetParentWidget()->GetCurrentElement(); @@ -501,6 +515,9 @@ void PickerWindow::OnInvalidateData(int data, bool gui_scope) SetWidgetLoweredState(WID_PW_MODE_USED, HasBit(this->callbacks.mode, PFM_USED)); SetWidgetLoweredState(WID_PW_MODE_SAVED, HasBit(this->callbacks.mode, PFM_SAVED)); } + + SetWidgetDisabledState(WID_PW_SHRINK, this->preview_height == PREVIEW_HEIGHT); + SetWidgetDisabledState(WID_PW_EXPAND, this->preview_height == MAX_PREVIEW_HEIGHT); } EventState PickerWindow::OnHotkey(int hotkey) @@ -758,6 +775,8 @@ std::unique_ptr MakePickerTypeWidgets() NWidget(WWT_TEXTBTN, COLOUR_DARK_GREEN, WID_PW_MODE_ALL), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_PICKER_MODE_ALL, STR_PICKER_MODE_ALL_TOOLTIP), NWidget(WWT_TEXTBTN, COLOUR_DARK_GREEN, WID_PW_MODE_USED), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_PICKER_MODE_USED, STR_PICKER_MODE_USED_TOOLTIP), NWidget(WWT_TEXTBTN, COLOUR_DARK_GREEN, WID_PW_MODE_SAVED), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_PICKER_MODE_SAVED, STR_PICKER_MODE_SAVED_TOOLTIP), + NWidget(WWT_PUSHTXTBTN, COLOUR_DARK_GREEN, WID_PW_SHRINK), SetAspect(WidgetDimensions::ASPECT_UP_DOWN_BUTTON), SetStringTip(STR_PICKER_PREVIEW_SHRINK, STR_PICKER_PREVIEW_SHRINK_TOOLTIP), + NWidget(WWT_PUSHTXTBTN, COLOUR_DARK_GREEN, WID_PW_EXPAND), SetAspect(WidgetDimensions::ASPECT_UP_DOWN_BUTTON), SetStringTip(STR_PICKER_PREVIEW_EXPAND, STR_PICKER_PREVIEW_EXPAND_TOOLTIP), EndContainer(), NWidget(NWID_HORIZONTAL), NWidget(WWT_PANEL, COLOUR_DARK_GREEN), SetScrollbar(WID_PW_TYPE_SCROLL), diff --git a/src/picker_gui.h b/src/picker_gui.h index 0fd5f6d6bf..2651f72f08 100644 --- a/src/picker_gui.h +++ b/src/picker_gui.h @@ -96,6 +96,8 @@ public: const std::string ini_group; ///< Ini Group for saving favourites. uint8_t mode = 0; ///< Bitmask of \c PickerFilterModes. + int preview_height = 0; ///< Previously adjusted height. + std::set used; ///< Set of items used in the current game by the current company. std::set saved; ///< Set of saved favourite items. }; @@ -171,15 +173,19 @@ public: static constexpr PickerInvalidations PICKER_INVALIDATION_ALL{PickerInvalidation::Class, PickerInvalidation::Type, PickerInvalidation::Position, PickerInvalidation::Validate}; - static const int PREVIEW_WIDTH = 64; ///< Width of each preview button. - static const int PREVIEW_HEIGHT = 48; ///< Height of each preview button. - static const int PREVIEW_LEFT = 31; ///< Offset from left edge to draw preview. - static const int PREVIEW_BOTTOM = 31; ///< Offset from bottom edge to draw preview. + static constexpr int PREVIEW_WIDTH = 64; ///< Width of each preview button. + static constexpr int PREVIEW_HEIGHT = 48; ///< Height of each preview button. + static constexpr int PREVIEW_LEFT = 31; ///< Offset from left edge to draw preview. + static constexpr int PREVIEW_BOTTOM = 31; ///< Offset from bottom edge to draw preview. - static const uint EDITBOX_MAX_SIZE = 16; ///< The maximum number of characters for the filter edit box. + static constexpr int STEP_PREVIEW_HEIGHT = 16; ///< Step for decreasing or increase preivew button height. + static constexpr int MAX_PREVIEW_HEIGHT = PREVIEW_HEIGHT * 3; ///< Maximum height of each preview button. + + static constexpr uint EDITBOX_MAX_SIZE = 16; ///< The maximum number of characters for the filter edit box. bool has_class_picker = false; ///< Set if this window has a class picker 'component'. bool has_type_picker = false; ///< Set if this window has a type picker 'component'. + int preview_height = 0; ///< Height of preview images. PickerWindow(WindowDesc &desc, Window *parent, int window_number, PickerCallbacks &callbacks); void OnInit() override; diff --git a/src/widgets/picker_widget.h b/src/widgets/picker_widget.h index 1cc5db48a5..f58d4aae62 100644 --- a/src/widgets/picker_widget.h +++ b/src/widgets/picker_widget.h @@ -24,6 +24,8 @@ enum PickerClassWindowWidgets : WidgetID { WID_PW_MODE_ALL, ///< Toggle "Show all" filter mode. WID_PW_MODE_USED, ///< Toggle showing only used types. WID_PW_MODE_SAVED, ///< Toggle showing only saved types. + WID_PW_SHRINK, ///< Button to reduce preview image height. + WID_PW_EXPAND, ///< Button to increase preview image height. WID_PW_TYPE_MATRIX, ///< Matrix with items. WID_PW_TYPE_ITEM, ///< A single item. WID_PW_TYPE_SCROLL, ///< Scrollbar for the matrix.