mirror of
https://github.com/OpenTTD/OpenTTD
synced 2025-12-23 13:12:40 +01:00
Codechange: Move settings entry size global variables. (#14644)
_setting_circle_size and (the incorrectly named) SETTING_HEIGHT variables are now static members of BaseSettingEntry. Neither of these are constants, so they no longer use constant naming style.
This commit is contained in:
@@ -94,22 +94,22 @@ uint BaseSettingEntry::Draw(GameSettings *settings_ptr, int left, int right, int
|
|||||||
if (cur_row >= max_row) return cur_row;
|
if (cur_row >= max_row) return cur_row;
|
||||||
|
|
||||||
bool rtl = _current_text_dir == TD_RTL;
|
bool rtl = _current_text_dir == TD_RTL;
|
||||||
int offset = (rtl ? -(int)_setting_circle_size.width : (int)_setting_circle_size.width) / 2;
|
int offset = (rtl ? -static_cast<int>(BaseSettingEntry::circle_size.width) : static_cast<int>(BaseSettingEntry::circle_size.width)) / 2;
|
||||||
int level_width = rtl ? -WidgetDimensions::scaled.hsep_indent : WidgetDimensions::scaled.hsep_indent;
|
int level_width = rtl ? -WidgetDimensions::scaled.hsep_indent : WidgetDimensions::scaled.hsep_indent;
|
||||||
|
|
||||||
int x = rtl ? right : left;
|
int x = rtl ? right : left;
|
||||||
if (cur_row >= first_row) {
|
if (cur_row >= first_row) {
|
||||||
PixelColour colour = GetColourGradient(COLOUR_ORANGE, SHADE_NORMAL);
|
PixelColour colour = GetColourGradient(COLOUR_ORANGE, SHADE_NORMAL);
|
||||||
y += (cur_row - first_row) * SETTING_HEIGHT; // Compute correct y start position
|
y += (cur_row - first_row) * BaseSettingEntry::line_height; // Compute correct y start position
|
||||||
|
|
||||||
/* Draw vertical for parent nesting levels */
|
/* Draw vertical for parent nesting levels */
|
||||||
for (uint lvl = 0; lvl < this->level; lvl++) {
|
for (uint lvl = 0; lvl < this->level; lvl++) {
|
||||||
if (!HasBit(parent_last, lvl)) GfxDrawLine(x + offset, y, x + offset, y + SETTING_HEIGHT - 1, colour);
|
if (!HasBit(parent_last, lvl)) GfxDrawLine(x + offset, y, x + offset, y + BaseSettingEntry::line_height - 1, colour);
|
||||||
x += level_width;
|
x += level_width;
|
||||||
}
|
}
|
||||||
/* draw own |- prefix */
|
/* draw own |- prefix */
|
||||||
int halfway_y = y + SETTING_HEIGHT / 2;
|
int halfway_y = y + BaseSettingEntry::line_height / 2;
|
||||||
int bottom_y = flags.Test(SettingEntryFlag::LastField) ? halfway_y : y + SETTING_HEIGHT - 1;
|
int bottom_y = flags.Test(SettingEntryFlag::LastField) ? halfway_y : y + BaseSettingEntry::line_height - 1;
|
||||||
GfxDrawLine(x + offset, y, x + offset, bottom_y, colour);
|
GfxDrawLine(x + offset, y, x + offset, bottom_y, colour);
|
||||||
/* Small horizontal line from the last vertical line */
|
/* Small horizontal line from the last vertical line */
|
||||||
GfxDrawLine(x + offset, halfway_y, x + level_width - (rtl ? -WidgetDimensions::scaled.hsep_normal : WidgetDimensions::scaled.hsep_normal), halfway_y, colour);
|
GfxDrawLine(x + offset, halfway_y, x + level_width - (rtl ? -WidgetDimensions::scaled.hsep_normal : WidgetDimensions::scaled.hsep_normal), halfway_y, colour);
|
||||||
@@ -274,7 +274,7 @@ void SettingEntry::DrawSetting(GameSettings *settings_ptr, int left, int right,
|
|||||||
uint buttons_left = rtl ? right + 1 - SETTING_BUTTON_WIDTH : left;
|
uint buttons_left = rtl ? right + 1 - SETTING_BUTTON_WIDTH : left;
|
||||||
uint text_left = left + (rtl ? 0 : SETTING_BUTTON_WIDTH + WidgetDimensions::scaled.hsep_wide);
|
uint text_left = left + (rtl ? 0 : SETTING_BUTTON_WIDTH + WidgetDimensions::scaled.hsep_wide);
|
||||||
uint text_right = right - (rtl ? SETTING_BUTTON_WIDTH + WidgetDimensions::scaled.hsep_wide : 0);
|
uint text_right = right - (rtl ? SETTING_BUTTON_WIDTH + WidgetDimensions::scaled.hsep_wide : 0);
|
||||||
uint button_y = y + (SETTING_HEIGHT - SETTING_BUTTON_HEIGHT) / 2;
|
uint button_y = y + (BaseSettingEntry::line_height - SETTING_BUTTON_HEIGHT) / 2;
|
||||||
|
|
||||||
/* We do not allow changes of some items when we are a client in a networkgame */
|
/* We do not allow changes of some items when we are a client in a networkgame */
|
||||||
bool editable = sd->IsEditable();
|
bool editable = sd->IsEditable();
|
||||||
@@ -293,7 +293,7 @@ void SettingEntry::DrawSetting(GameSettings *settings_ptr, int left, int right,
|
|||||||
editable && value != (sd->flags.Test(SettingFlag::GuiZeroIsSpecial) ? 0 : min_val), editable && static_cast<uint32_t>(value) != max_val);
|
editable && value != (sd->flags.Test(SettingFlag::GuiZeroIsSpecial) ? 0 : min_val), editable && static_cast<uint32_t>(value) != max_val);
|
||||||
}
|
}
|
||||||
auto [param1, param2] = sd->GetValueParams(value);
|
auto [param1, param2] = sd->GetValueParams(value);
|
||||||
DrawString(text_left, text_right, y + (SETTING_HEIGHT - GetCharacterHeight(FS_NORMAL)) / 2, GetString(sd->GetTitle(), STR_CONFIG_SETTING_VALUE, param1, param2), highlight ? TC_WHITE : TC_LIGHT_BLUE);
|
DrawString(text_left, text_right, y + (BaseSettingEntry::line_height - GetCharacterHeight(FS_NORMAL)) / 2, GetString(sd->GetTitle(), STR_CONFIG_SETTING_VALUE, param1, param2), highlight ? TC_WHITE : TC_LIGHT_BLUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* == SettingsContainer methods == */
|
/* == SettingsContainer methods == */
|
||||||
@@ -611,8 +611,8 @@ uint SettingsPage::Draw(GameSettings *settings_ptr, int left, int right, int y,
|
|||||||
void SettingsPage::DrawSetting(GameSettings *, int left, int right, int y, bool) const
|
void SettingsPage::DrawSetting(GameSettings *, int left, int right, int y, bool) const
|
||||||
{
|
{
|
||||||
bool rtl = _current_text_dir == TD_RTL;
|
bool rtl = _current_text_dir == TD_RTL;
|
||||||
DrawSprite((this->folded ? SPR_CIRCLE_FOLDED : SPR_CIRCLE_UNFOLDED), PAL_NONE, rtl ? right - _setting_circle_size.width : left, y + (SETTING_HEIGHT - _setting_circle_size.height) / 2);
|
DrawSprite((this->folded ? SPR_CIRCLE_FOLDED : SPR_CIRCLE_UNFOLDED), PAL_NONE, rtl ? right - BaseSettingEntry::circle_size.width : left, y + (BaseSettingEntry::line_height - BaseSettingEntry::circle_size.height) / 2);
|
||||||
DrawString(rtl ? left : left + _setting_circle_size.width + WidgetDimensions::scaled.hsep_normal, rtl ? right - _setting_circle_size.width - WidgetDimensions::scaled.hsep_normal : right, y + (SETTING_HEIGHT - GetCharacterHeight(FS_NORMAL)) / 2, this->title, TC_ORANGE);
|
DrawString(rtl ? left : left + BaseSettingEntry::circle_size.width + WidgetDimensions::scaled.hsep_normal, rtl ? right - BaseSettingEntry::circle_size.width - WidgetDimensions::scaled.hsep_normal : right, y + (BaseSettingEntry::line_height - GetCharacterHeight(FS_NORMAL)) / 2, this->title, TC_ORANGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Construct settings tree */
|
/** Construct settings tree */
|
||||||
|
|||||||
@@ -14,9 +14,6 @@
|
|||||||
#include "settings_internal.h"
|
#include "settings_internal.h"
|
||||||
#include "stringfilter_type.h"
|
#include "stringfilter_type.h"
|
||||||
|
|
||||||
extern Dimension _setting_circle_size;
|
|
||||||
extern int SETTING_HEIGHT;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Flags for #SettingEntry
|
* Flags for #SettingEntry
|
||||||
* @note The #SEF_BUTTONS_MASK matches expectations of the formal parameter 'state' of #DrawArrowButtons
|
* @note The #SEF_BUTTONS_MASK matches expectations of the formal parameter 'state' of #DrawArrowButtons
|
||||||
@@ -86,6 +83,9 @@ struct BaseSettingEntry {
|
|||||||
|
|
||||||
virtual uint Draw(GameSettings *settings_ptr, int left, int right, int y, uint first_row, uint max_row, BaseSettingEntry *selected, uint cur_row = 0, uint parent_last = 0) const;
|
virtual uint Draw(GameSettings *settings_ptr, int left, int right, int y, uint first_row, uint max_row, BaseSettingEntry *selected, uint cur_row = 0, uint parent_last = 0) const;
|
||||||
|
|
||||||
|
static inline Dimension circle_size; ///< Dimension of the circle +/- icon.
|
||||||
|
static inline int line_height; ///< Height of a single setting.
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void DrawSetting(GameSettings *settings_ptr, int left, int right, int y, bool highlight) const = 0;
|
virtual void DrawSetting(GameSettings *settings_ptr, int left, int right, int y, bool highlight) const = 0;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -84,8 +84,6 @@ static const uint32_t _autosave_dropdown_to_minutes[] = {
|
|||||||
120,
|
120,
|
||||||
};
|
};
|
||||||
|
|
||||||
Dimension _setting_circle_size; ///< Dimension of the circle +/- icon. This is here as not all users are within the class of the settings window.
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get index of the current screen resolution.
|
* Get index of the current screen resolution.
|
||||||
* @return Index of the current screen resolution if it is a known resolution, _resolutions.size() otherwise.
|
* @return Index of the current screen resolution if it is a known resolution, _resolutions.size() otherwise.
|
||||||
@@ -363,8 +361,6 @@ std::unique_ptr<NWidgetBase> MakeNWidgetSocialPlugins()
|
|||||||
return std::make_unique<NWidgetSocialPlugins>();
|
return std::make_unique<NWidgetSocialPlugins>();
|
||||||
}
|
}
|
||||||
|
|
||||||
int SETTING_HEIGHT = 11; ///< Height of a single setting in the tree view in pixels
|
|
||||||
|
|
||||||
static const StringID _game_settings_restrict_dropdown[] = {
|
static const StringID _game_settings_restrict_dropdown[] = {
|
||||||
STR_CONFIG_SETTING_RESTRICT_BASIC, // RM_BASIC
|
STR_CONFIG_SETTING_RESTRICT_BASIC, // RM_BASIC
|
||||||
STR_CONFIG_SETTING_RESTRICT_ADVANCED, // RM_ADVANCED
|
STR_CONFIG_SETTING_RESTRICT_ADVANCED, // RM_ADVANCED
|
||||||
@@ -453,7 +449,9 @@ struct GameOptionsWindow : Window {
|
|||||||
|
|
||||||
void OnInit() override
|
void OnInit() override
|
||||||
{
|
{
|
||||||
_setting_circle_size = maxdim(GetSpriteSize(SPR_CIRCLE_FOLDED), GetSpriteSize(SPR_CIRCLE_UNFOLDED));
|
BaseSettingEntry::circle_size = maxdim(GetSpriteSize(SPR_CIRCLE_FOLDED), GetSpriteSize(SPR_CIRCLE_UNFOLDED));
|
||||||
|
BaseSettingEntry::line_height = std::max({static_cast<int>(BaseSettingEntry::circle_size.height), SETTING_BUTTON_HEIGHT, GetCharacterHeight(FS_NORMAL)}) + WidgetDimensions::scaled.vsep_normal;
|
||||||
|
|
||||||
this->gui_scale = _gui_scale;
|
this->gui_scale = _gui_scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -709,7 +707,7 @@ struct GameOptionsWindow : Window {
|
|||||||
|
|
||||||
case WID_GO_OPTIONSPANEL: {
|
case WID_GO_OPTIONSPANEL: {
|
||||||
Rect tr = r.Shrink(WidgetDimensions::scaled.frametext, WidgetDimensions::scaled.framerect);
|
Rect tr = r.Shrink(WidgetDimensions::scaled.frametext, WidgetDimensions::scaled.framerect);
|
||||||
tr.top += this->warn_lines * SETTING_HEIGHT;
|
tr.top += this->warn_lines * BaseSettingEntry::line_height;
|
||||||
uint last_row = this->vscroll->GetPosition() + this->vscroll->GetCapacity() - this->warn_lines;
|
uint last_row = this->vscroll->GetPosition() + this->vscroll->GetCapacity() - this->warn_lines;
|
||||||
int next_row = GetSettingsTree().Draw(settings_ptr, tr.left, tr.right, tr.top,
|
int next_row = GetSettingsTree().Draw(settings_ptr, tr.left, tr.right, tr.top,
|
||||||
this->vscroll->GetPosition(), last_row, this->last_clicked);
|
this->vscroll->GetPosition(), last_row, this->last_clicked);
|
||||||
@@ -858,7 +856,7 @@ struct GameOptionsWindow : Window {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case WID_GO_OPTIONSPANEL:
|
case WID_GO_OPTIONSPANEL:
|
||||||
fill.height = resize.height = SETTING_HEIGHT = std::max({(int)_setting_circle_size.height, SETTING_BUTTON_HEIGHT, GetCharacterHeight(FS_NORMAL)}) + WidgetDimensions::scaled.vsep_normal;
|
fill.height = resize.height = BaseSettingEntry::line_height;
|
||||||
resize.width = 1;
|
resize.width = 1;
|
||||||
|
|
||||||
size.height = 8 * resize.height + WidgetDimensions::scaled.framerect.Vertical();
|
size.height = 8 * resize.height + WidgetDimensions::scaled.framerect.Vertical();
|
||||||
@@ -1271,7 +1269,7 @@ struct GameOptionsWindow : Window {
|
|||||||
Rect wi_rect;
|
Rect wi_rect;
|
||||||
wi_rect.left = pt.x - (_current_text_dir == TD_RTL ? SETTING_BUTTON_WIDTH - 1 - x : x);
|
wi_rect.left = pt.x - (_current_text_dir == TD_RTL ? SETTING_BUTTON_WIDTH - 1 - x : x);
|
||||||
wi_rect.right = wi_rect.left + SETTING_BUTTON_WIDTH - 1;
|
wi_rect.right = wi_rect.left + SETTING_BUTTON_WIDTH - 1;
|
||||||
wi_rect.top = pt.y - rel_y + (SETTING_HEIGHT - SETTING_BUTTON_HEIGHT) / 2;
|
wi_rect.top = pt.y - rel_y + (BaseSettingEntry::line_height - SETTING_BUTTON_HEIGHT) / 2;
|
||||||
wi_rect.bottom = wi_rect.top + SETTING_BUTTON_HEIGHT - 1;
|
wi_rect.bottom = wi_rect.top + SETTING_BUTTON_HEIGHT - 1;
|
||||||
|
|
||||||
/* For dropdowns we also have to check the y position thoroughly, the mouse may not above the just opening dropdown */
|
/* For dropdowns we also have to check the y position thoroughly, the mouse may not above the just opening dropdown */
|
||||||
|
|||||||
Reference in New Issue
Block a user