From 42c65264f8dd60805b6a42a495ea446332f13b16 Mon Sep 17 00:00:00 2001 From: peter1138 Date: Sat, 4 Oct 2014 20:34:43 +0000 Subject: [PATCH] (svn r26959) -Codechange: GUI-scale for settings window. --- src/settings_gui.cpp | 26 ++++++++++++++------------ src/settings_gui.h | 6 ++++-- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 9db76d9018..6e38c67a63 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -61,6 +61,8 @@ int _nb_orig_names = SPECSTR_TOWNNAME_LAST - SPECSTR_TOWNNAME_START + 1; ///< Nu static StringID *_grf_names = NULL; ///< Pointer to town names defined by NewGRFs. static int _nb_grf_names = 0; ///< Number of town names defined by NewGRFs. +static Dimension _circle_size; ///< Dimension of the circle +/- icon. This is here as not all users are within the class of the settings window. + static const void *ResolveVariableAddress(const GameSettings *settings_ptr, const SettingDesc *sd); /** Allocate memory for the NewGRF town names. */ @@ -1107,7 +1109,7 @@ void SettingEntry::DrawSetting(GameSettings *settings_ptr, int left, int right, editable && value != (sdb->flags & SGF_0ISDISABLED ? 0 : sdb->min), editable && (uint32)value != sdb->max); } this->SetValueDParams(1, value); - DrawString(text_left, text_right, y, sdb->str, highlight ? TC_WHITE : TC_LIGHT_BLUE); + DrawString(text_left, text_right, y + (SETTING_HEIGHT - FONT_HEIGHT_NORMAL) / 2, sdb->str, highlight ? TC_WHITE : TC_LIGHT_BLUE); } /* == SettingsContainer methods == */ @@ -1417,8 +1419,8 @@ uint SettingsPage::Draw(GameSettings *settings_ptr, int left, int right, int y, void SettingsPage::DrawSetting(GameSettings *settings_ptr, int left, int right, int y, bool highlight) const { bool rtl = _current_text_dir == TD_RTL; - DrawSprite((this->folded ? SPR_CIRCLE_FOLDED : SPR_CIRCLE_UNFOLDED), PAL_NONE, rtl ? right - 8 : left, y + (SETTING_HEIGHT - 11) / 2); - DrawString(rtl ? left : left + 12, rtl ? right - 12 : right, y, this->title); + DrawSprite((this->folded ? SPR_CIRCLE_FOLDED : SPR_CIRCLE_UNFOLDED), PAL_NONE, rtl ? right - _circle_size.width : left, y + (SETTING_HEIGHT - _circle_size.height) / 2); + DrawString(rtl ? left : left + _circle_size.width + 2, rtl ? right - _circle_size.width - 2 : right, y + (SETTING_HEIGHT - FONT_HEIGHT_NORMAL) / 2, this->title); } /** Construct settings tree */ @@ -1767,6 +1769,7 @@ struct GameSettingsWindow : Window { this->filter.type_hides = false; this->settings_ptr = &GetGameSettings(); + _circle_size = maxdim(GetSpriteSize(SPR_CIRCLE_FOLDED), GetSpriteSize(SPR_CIRCLE_UNFOLDED)); GetSettingsTree().FoldAll(); // Close all sub-pages this->valuewindow_entry = NULL; // No setting entry for which a entry window is opened @@ -1791,7 +1794,7 @@ struct GameSettingsWindow : Window { { switch (widget) { case WID_GS_OPTIONSPANEL: - resize->height = SETTING_HEIGHT = max(11, FONT_HEIGHT_NORMAL + 1); + resize->height = SETTING_HEIGHT = max(max(_circle_size.height, SETTING_BUTTON_HEIGHT), FONT_HEIGHT_NORMAL) + 1; resize->width = 1; size->height = 5 * resize->height + SETTINGTREE_TOP_OFFSET + SETTINGTREE_BOTTOM_OFFSET; @@ -2358,19 +2361,20 @@ void ShowGameSettings() void DrawArrowButtons(int x, int y, Colours button_colour, byte state, bool clickable_left, bool clickable_right) { int colour = _colour_gradient[button_colour][2]; + Dimension dim = NWidgetScrollbar::GetHorizontalDimension(); - DrawFrameRect(x, y, x + SETTING_BUTTON_WIDTH / 2 - 1, y + SETTING_BUTTON_HEIGHT - 1, button_colour, (state == 1) ? FR_LOWERED : FR_NONE); - DrawFrameRect(x + SETTING_BUTTON_WIDTH / 2, y, x + SETTING_BUTTON_WIDTH - 1, y + SETTING_BUTTON_HEIGHT - 1, button_colour, (state == 2) ? FR_LOWERED : FR_NONE); + DrawFrameRect(x, y, x + dim.width - 1, y + dim.height - 1, button_colour, (state == 1) ? FR_LOWERED : FR_NONE); + DrawFrameRect(x + dim.width, y, x + dim.width + dim.width - 1, y + dim.height - 1, button_colour, (state == 2) ? FR_LOWERED : FR_NONE); DrawSprite(SPR_ARROW_LEFT, PAL_NONE, x + WD_IMGBTN_LEFT, y + WD_IMGBTN_TOP); - DrawSprite(SPR_ARROW_RIGHT, PAL_NONE, x + WD_IMGBTN_LEFT + SETTING_BUTTON_WIDTH / 2, y + WD_IMGBTN_TOP); + DrawSprite(SPR_ARROW_RIGHT, PAL_NONE, x + WD_IMGBTN_LEFT + dim.width, y + WD_IMGBTN_TOP); /* Grey out the buttons that aren't clickable */ bool rtl = _current_text_dir == TD_RTL; if (rtl ? !clickable_right : !clickable_left) { - GfxFillRect(x + 1, y, x + SETTING_BUTTON_WIDTH / 2 - 1, y + SETTING_BUTTON_HEIGHT - 2, colour, FILLRECT_CHECKER); + GfxFillRect(x + 1, y, x + dim.width - 1, y + dim.height - 2, colour, FILLRECT_CHECKER); } if (rtl ? !clickable_left : !clickable_right) { - GfxFillRect(x + SETTING_BUTTON_WIDTH / 2 + 1, y, x + SETTING_BUTTON_WIDTH - 1, y + SETTING_BUTTON_HEIGHT - 2, colour, FILLRECT_CHECKER); + GfxFillRect(x + dim.width + 1, y, x + dim.width + dim.width - 1, y + dim.height - 2, colour, FILLRECT_CHECKER); } } @@ -2384,12 +2388,10 @@ void DrawArrowButtons(int x, int y, Colours button_colour, byte state, bool clic */ void DrawDropDownButton(int x, int y, Colours button_colour, bool state, bool clickable) { - static const char *DOWNARROW = "\xEE\x8A\xAA"; - int colour = _colour_gradient[button_colour][2]; DrawFrameRect(x, y, x + SETTING_BUTTON_WIDTH - 1, y + SETTING_BUTTON_HEIGHT - 1, button_colour, state ? FR_LOWERED : FR_NONE); - DrawString(x + (state ? 1 : 0), x + SETTING_BUTTON_WIDTH - (state ? 0 : 1), y + (state ? 2 : 1), DOWNARROW, TC_BLACK, SA_HOR_CENTER); + DrawSprite(SPR_ARROW_DOWN, PAL_NONE, x + (SETTING_BUTTON_WIDTH - NWidgetScrollbar::GetVerticalDimension().width) / 2 + state, y + 2 + state); if (!clickable) { GfxFillRect(x + 1, y, x + SETTING_BUTTON_WIDTH - 1, y + SETTING_BUTTON_HEIGHT - 2, colour, FILLRECT_CHECKER); diff --git a/src/settings_gui.h b/src/settings_gui.h index 2ca418b11f..05955aa557 100644 --- a/src/settings_gui.h +++ b/src/settings_gui.h @@ -14,8 +14,10 @@ #include "gfx_type.h" -static const int SETTING_BUTTON_WIDTH = 20; ///< Width of setting buttons -static const int SETTING_BUTTON_HEIGHT = 10; ///< Height of setting buttons +/** Width of setting buttons */ +#define SETTING_BUTTON_WIDTH ((int)NWidgetScrollbar::GetHorizontalDimension().width * 2) +/** Height of setting buttons */ +#define SETTING_BUTTON_HEIGHT ((int)NWidgetScrollbar::GetHorizontalDimension().height) void DrawArrowButtons(int x, int y, Colours button_colour, byte state, bool clickable_left, bool clickable_right); void DrawDropDownButton(int x, int y, Colours button_colour, bool state, bool clickable);