1
0
Fork 0

Codechange: Add Up/Down buttons, to fit in with the settings-button style.

pull/14300/head
Peter Nelson 2025-05-23 17:44:17 +01:00 committed by Peter Nelson
parent b82e32c360
commit 04e07dff84
2 changed files with 28 additions and 0 deletions

View File

@ -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

View File

@ -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);