From 04e07dff844dc958c2e96d568a72f58ec5164f76 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Fri, 23 May 2025 17:44:17 +0100 Subject: [PATCH] Codechange: Add Up/Down buttons, to fit in with the settings-button style. --- src/settings_gui.cpp | 27 +++++++++++++++++++++++++++ src/settings_gui.h | 1 + 2 files changed, 28 insertions(+) diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 0ea49bea67..70f390fbdf 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -1877,6 +1877,33 @@ void DrawArrowButtons(int x, int y, Colours button_colour, uint8_t state, bool c } } +/** + * Draw [^][v] buttons + * @param x the x position to draw + * @param y the y position to draw + * @param button_colour the colour of the button + * @param state 0 = none clicked, 1 = first clicked, 2 = second clicked + * @param clickable_up is the up button clickable? + * @param clickable_down is the down button clickable? + */ +void DrawUpDownButtons(int x, int y, Colours button_colour, uint8_t state, bool clickable_up, bool clickable_down) +{ + int colour = GetColourGradient(button_colour, SHADE_DARKER); + + Rect r = {x, y, x + SETTING_BUTTON_WIDTH - 1, y + SETTING_BUTTON_HEIGHT - 1}; + Rect ur = r.WithWidth(SETTING_BUTTON_WIDTH / 2, (_current_text_dir == TD_RTL)); + Rect dr = r.WithWidth(SETTING_BUTTON_WIDTH / 2, (_current_text_dir != TD_RTL)); + + DrawFrameRect(ur, button_colour, (state == 1) ? FrameFlag::Lowered : FrameFlags{}); + DrawFrameRect(dr, button_colour, (state == 2) ? FrameFlag::Lowered : FrameFlags{}); + DrawSpriteIgnorePadding(SPR_ARROW_UP, PAL_NONE, ur, SA_CENTER); + DrawSpriteIgnorePadding(SPR_ARROW_DOWN, PAL_NONE, dr, SA_CENTER); + + /* Grey out the buttons that aren't clickable */ + if (!clickable_up) GfxFillRect(ur.Shrink(WidgetDimensions::scaled.bevel), colour, FILLRECT_CHECKER); + if (!clickable_down) GfxFillRect(dr.Shrink(WidgetDimensions::scaled.bevel), colour, FILLRECT_CHECKER); +} + /** * Draw a dropdown button. * @param x the x position to draw diff --git a/src/settings_gui.h b/src/settings_gui.h index 936d9b6de7..77b11759fb 100644 --- a/src/settings_gui.h +++ b/src/settings_gui.h @@ -19,6 +19,7 @@ #define SETTING_BUTTON_HEIGHT ((int)NWidgetScrollbar::GetHorizontalDimension().height) void DrawArrowButtons(int x, int y, Colours button_colour, uint8_t state, bool clickable_left, bool clickable_right); +void DrawUpDownButtons(int x, int y, Colours button_colour, uint8_t state, bool clickable_up, bool clickable_down); void DrawDropDownButton(int x, int y, Colours button_colour, bool state, bool clickable); void DrawBoolButton(int x, int y, Colours button_colour, Colours background, bool state, bool clickable);