mirror of https://github.com/OpenTTD/OpenTTD
Change: Draw boolean toggle as a slider widget.
This improves usability as the slider position indicates the state instead of a red/green colour change.pull/14004/head
parent
e3858e81dc
commit
e3d2d68bd4
|
@ -286,7 +286,7 @@ struct CheatWindow : Window {
|
||||||
case SLE_BOOL: {
|
case SLE_BOOL: {
|
||||||
bool on = (*(bool*)ce->variable);
|
bool on = (*(bool*)ce->variable);
|
||||||
|
|
||||||
DrawBoolButton(button_left, y + button_y_offset, on, true);
|
DrawBoolButton(button_left, y + button_y_offset, COLOUR_YELLOW, COLOUR_GREY, on, true);
|
||||||
str = GetString(ce->str, on ? STR_CONFIG_SETTING_ON : STR_CONFIG_SETTING_OFF);
|
str = GetString(ce->str, on ? STR_CONFIG_SETTING_ON : STR_CONFIG_SETTING_OFF);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -354,7 +354,7 @@ struct CheatWindow : Window {
|
||||||
int32_t value = sd->Read(&GetGameSettings());
|
int32_t value = sd->Read(&GetGameSettings());
|
||||||
if (sd->IsBoolSetting()) {
|
if (sd->IsBoolSetting()) {
|
||||||
/* Draw checkbox for boolean-value either on/off */
|
/* Draw checkbox for boolean-value either on/off */
|
||||||
DrawBoolButton(buttons.left, buttons.top, value != 0, editable);
|
DrawBoolButton(buttons.left, buttons.top, COLOUR_YELLOW, COLOUR_GREY, value != 0, editable);
|
||||||
} else if (sd->flags.Test(SettingFlag::GuiDropdown)) {
|
} else if (sd->flags.Test(SettingFlag::GuiDropdown)) {
|
||||||
/* Draw [v] button for settings of an enum-type */
|
/* Draw [v] button for settings of an enum-type */
|
||||||
DrawDropDownButton(buttons.left, buttons.top, COLOUR_YELLOW, state != 0, editable);
|
DrawDropDownButton(buttons.left, buttons.top, COLOUR_YELLOW, state != 0, editable);
|
||||||
|
|
|
@ -195,7 +195,7 @@ struct GSConfigWindow : public Window {
|
||||||
bool editable = this->IsEditableItem(config_item);
|
bool editable = this->IsEditableItem(config_item);
|
||||||
|
|
||||||
if (config_item.flags.Test(ScriptConfigFlag::Boolean)) {
|
if (config_item.flags.Test(ScriptConfigFlag::Boolean)) {
|
||||||
DrawBoolButton(br.left, y + button_y_offset, current_value != 0, editable);
|
DrawBoolButton(br.left, y + button_y_offset, COLOUR_YELLOW, COLOUR_MAUVE, current_value != 0, editable);
|
||||||
} else {
|
} else {
|
||||||
int i = static_cast<int>(std::distance(std::begin(this->visible_settings), it));
|
int i = static_cast<int>(std::distance(std::begin(this->visible_settings), it));
|
||||||
if (config_item.complete_labels) {
|
if (config_item.complete_labels) {
|
||||||
|
|
|
@ -301,7 +301,7 @@ struct NewGRFParametersWindow : public Window {
|
||||||
bool selected = (i == this->clicked_row);
|
bool selected = (i == this->clicked_row);
|
||||||
|
|
||||||
if (par_info.type == PTYPE_BOOL) {
|
if (par_info.type == PTYPE_BOOL) {
|
||||||
DrawBoolButton(buttons_left, ir.top + button_y_offset, current_value != 0, this->editable);
|
DrawBoolButton(buttons_left, ir.top + button_y_offset, COLOUR_YELLOW, COLOUR_MAUVE, current_value != 0, this->editable);
|
||||||
} else if (par_info.type == PTYPE_UINT_ENUM) {
|
} else if (par_info.type == PTYPE_UINT_ENUM) {
|
||||||
if (par_info.complete_labels) {
|
if (par_info.complete_labels) {
|
||||||
DrawDropDownButton(buttons_left, ir.top + button_y_offset, COLOUR_YELLOW, this->clicked_row == i && this->clicked_dropdown, this->editable);
|
DrawDropDownButton(buttons_left, ir.top + button_y_offset, COLOUR_YELLOW, this->clicked_row == i && this->clicked_dropdown, this->editable);
|
||||||
|
|
|
@ -375,7 +375,7 @@ struct ScriptSettingsWindow : public Window {
|
||||||
bool editable = this->IsEditableItem(config_item);
|
bool editable = this->IsEditableItem(config_item);
|
||||||
|
|
||||||
if (config_item.flags.Test(ScriptConfigFlag::Boolean)) {
|
if (config_item.flags.Test(ScriptConfigFlag::Boolean)) {
|
||||||
DrawBoolButton(br.left, y + button_y_offset, current_value != 0, editable);
|
DrawBoolButton(br.left, y + button_y_offset, COLOUR_YELLOW, COLOUR_MAUVE, current_value != 0, editable);
|
||||||
} else {
|
} else {
|
||||||
int i = static_cast<int>(std::distance(std::begin(this->visible_settings), it));
|
int i = static_cast<int>(std::distance(std::begin(this->visible_settings), it));
|
||||||
if (config_item.complete_labels) {
|
if (config_item.complete_labels) {
|
||||||
|
|
|
@ -293,7 +293,7 @@ void SettingEntry::DrawSetting(GameSettings *settings_ptr, int left, int right,
|
||||||
int32_t value = sd->Read(ResolveObject(settings_ptr, sd));
|
int32_t value = sd->Read(ResolveObject(settings_ptr, sd));
|
||||||
if (sd->IsBoolSetting()) {
|
if (sd->IsBoolSetting()) {
|
||||||
/* Draw checkbox for boolean-value either on/off */
|
/* Draw checkbox for boolean-value either on/off */
|
||||||
DrawBoolButton(buttons_left, button_y, value != 0, editable);
|
DrawBoolButton(buttons_left, button_y, COLOUR_YELLOW, COLOUR_MAUVE, value != 0, editable);
|
||||||
} else if (sd->flags.Test(SettingFlag::GuiDropdown)) {
|
} else if (sd->flags.Test(SettingFlag::GuiDropdown)) {
|
||||||
/* Draw [v] button for settings of an enum-type */
|
/* Draw [v] button for settings of an enum-type */
|
||||||
DrawDropDownButton(buttons_left, button_y, COLOUR_YELLOW, state != 0, editable);
|
DrawDropDownButton(buttons_left, button_y, COLOUR_YELLOW, state != 0, editable);
|
||||||
|
|
|
@ -1870,15 +1870,20 @@ void DrawDropDownButton(int x, int y, Colours button_colour, bool state, bool cl
|
||||||
* Draw a toggle button.
|
* Draw a toggle button.
|
||||||
* @param x the x position to draw
|
* @param x the x position to draw
|
||||||
* @param y the y position to draw
|
* @param y the y position to draw
|
||||||
|
* @param button_colour the colour of the button.
|
||||||
|
* @param background background colour.
|
||||||
* @param state true = lowered
|
* @param state true = lowered
|
||||||
* @param clickable is the button clickable?
|
* @param clickable is the button clickable?
|
||||||
*/
|
*/
|
||||||
void DrawBoolButton(int x, int y, bool state, bool clickable)
|
void DrawBoolButton(int x, int y, Colours button_colour, Colours background, bool state, bool clickable)
|
||||||
{
|
{
|
||||||
static const Colours _bool_ctabs[2][2] = {{COLOUR_CREAM, COLOUR_RED}, {COLOUR_DARK_GREEN, COLOUR_GREEN}};
|
|
||||||
|
|
||||||
Rect r = {x, y, x + SETTING_BUTTON_WIDTH - 1, y + SETTING_BUTTON_HEIGHT - 1};
|
Rect r = {x, y, x + SETTING_BUTTON_WIDTH - 1, y + SETTING_BUTTON_HEIGHT - 1};
|
||||||
DrawFrameRect(r, _bool_ctabs[state][clickable], state ? FrameFlag::Lowered : FrameFlags{});
|
DrawFrameRect(r, state ? COLOUR_GREEN : background, state ? FrameFlags{FrameFlag::Lowered} : FrameFlags{FrameFlag::Lowered, FrameFlag::BorderOnly});
|
||||||
|
Rect button_rect = r.WithWidth(SETTING_BUTTON_WIDTH / 3, state ^ (_current_text_dir == TD_RTL));
|
||||||
|
DrawFrameRect(button_rect, button_colour, {});
|
||||||
|
if (!clickable) {
|
||||||
|
GfxFillRect(button_rect.Shrink(WidgetDimensions::scaled.bevel), GetColourGradient(button_colour, SHADE_DARKER), FILLRECT_CHECKER);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct CustomCurrencyWindow : Window {
|
struct CustomCurrencyWindow : Window {
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
|
|
||||||
void DrawArrowButtons(int x, int y, Colours button_colour, uint8_t state, bool clickable_left, bool clickable_right);
|
void DrawArrowButtons(int x, int y, Colours button_colour, uint8_t state, bool clickable_left, bool clickable_right);
|
||||||
void DrawDropDownButton(int x, int y, Colours button_colour, bool state, bool clickable);
|
void DrawDropDownButton(int x, int y, Colours button_colour, bool state, bool clickable);
|
||||||
void DrawBoolButton(int x, int y, bool state, bool clickable);
|
void DrawBoolButton(int x, int y, Colours button_colour, Colours background, bool state, bool clickable);
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
DropDownList BuildSetDropDownList(int *selected_index);
|
DropDownList BuildSetDropDownList(int *selected_index);
|
||||||
|
|
Loading…
Reference in New Issue