summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2012-01-05 19:32:51 +0000
committerfrosch <frosch@openttd.org>2012-01-05 19:32:51 +0000
commit69e197c87fc23e5492f4b59f8e1ba8757d65c41e (patch)
tree667e2d8a3efff34d87d9fcea1fb946279fb38afd
parent2fb393fcd0a45c9c34e080714f4bdf7d77ca4fbd (diff)
downloadopenttd-69e197c87fc23e5492f4b59f8e1ba8757d65c41e.tar.xz
(svn r23757) -Codechange: Unify the drawing of toggle buttons for boolean settings.
-rw-r--r--src/ai/ai_gui.cpp2
-rw-r--r--src/cheat_gui.cpp2
-rw-r--r--src/gui.h1
-rw-r--r--src/newgrf_gui.cpp2
-rw-r--r--src/settings_gui.cpp16
5 files changed, 18 insertions, 5 deletions
diff --git a/src/ai/ai_gui.cpp b/src/ai/ai_gui.cpp
index 3620dfc75..603c0569b 100644
--- a/src/ai/ai_gui.cpp
+++ b/src/ai/ai_gui.cpp
@@ -384,7 +384,7 @@ struct AISettingsWindow : public Window {
}
if ((config_item.flags & SCRIPTCONFIG_BOOLEAN) != 0) {
- DrawFrameRect(buttons_left, y + 2, buttons_left + 19, y + 10, (current_value != 0) ? COLOUR_GREEN : COLOUR_RED, (current_value != 0) ? FR_LOWERED : FR_NONE);
+ DrawBoolButton(buttons_left, y + 2, current_value != 0, editable);
SetDParam(idx++, current_value == 0 ? STR_CONFIG_SETTING_OFF : STR_CONFIG_SETTING_ON);
} else {
DrawArrowButtons(buttons_left, y + 2, COLOUR_YELLOW, (this->clicked_button == i) ? 1 + (this->clicked_increase != rtl) : 0, editable && current_value > config_item.min_value, editable && current_value < config_item.max_value);
diff --git a/src/cheat_gui.cpp b/src/cheat_gui.cpp
index aad1d8fe5..be4f57399 100644
--- a/src/cheat_gui.cpp
+++ b/src/cheat_gui.cpp
@@ -197,7 +197,7 @@ struct CheatWindow : Window {
case SLE_BOOL: {
bool on = (*(bool*)ce->variable);
- DrawFrameRect(button_left, y + 1, button_left + 20 - 1, y + FONT_HEIGHT_NORMAL - 1, on ? COLOUR_GREEN : COLOUR_RED, on ? FR_LOWERED : FR_NONE);
+ DrawBoolButton(button_left, y, on, true);
SetDParam(0, on ? STR_CONFIG_SETTING_ON : STR_CONFIG_SETTING_OFF);
break;
}
diff --git a/src/gui.h b/src/gui.h
index 0346dc3bd..c57c9a19a 100644
--- a/src/gui.h
+++ b/src/gui.h
@@ -29,6 +29,7 @@ void ShowGameOptions();
void ShowGameDifficulty();
void ShowGameSettings();
void DrawArrowButtons(int x, int y, Colours button_colour, byte state, bool clickable_left, bool clickable_right);
+void DrawBoolButton(int x, int y, bool state, bool clickable);
/* train_gui.cpp */
void ShowOrdersWindow(const Vehicle *v);
diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp
index f53f49db6..f404737ad 100644
--- a/src/newgrf_gui.cpp
+++ b/src/newgrf_gui.cpp
@@ -247,7 +247,7 @@ struct NewGRFParametersWindow : public Window {
bool selected = (i == this->clicked_row);
if (par_info->type == PTYPE_BOOL) {
- DrawFrameRect(buttons_left, y + 2, buttons_left + 19, y + 10, (current_value != 0) ? COLOUR_GREEN : COLOUR_RED, (current_value != 0) ? FR_LOWERED : FR_NONE);
+ DrawBoolButton(buttons_left, y + 2, current_value != 0, true);
SetDParam(2, par_info->GetValue(this->grf_config) == 0 ? STR_CONFIG_SETTING_OFF : STR_CONFIG_SETTING_ON);
} else if (par_info->type == PTYPE_UINT_ENUM) {
DrawArrowButtons(buttons_left, y + 2, COLOUR_YELLOW, (this->clicked_button == i) ? 1 + (this->clicked_increase != rtl) : 0, current_value > par_info->min_value, current_value < par_info->max_value);
diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp
index 3d2fe9024..53217bb04 100644
--- a/src/settings_gui.cpp
+++ b/src/settings_gui.cpp
@@ -1197,11 +1197,10 @@ void SettingEntry::DrawSetting(GameSettings *settings_ptr, const SettingDesc *sd
if ((sdb->flags & SGF_NO_NETWORK) && _networking) editable = false;
if (sdb->cmd == SDT_BOOLX) {
- static const Colours _bool_ctabs[2][2] = {{COLOUR_CREAM, COLOUR_RED}, {COLOUR_DARK_GREEN, COLOUR_GREEN}};
/* Draw checkbox for boolean-value either on/off */
bool on = ReadValue(var, sd->save.conv) != 0;
- DrawFrameRect(buttons_left, button_y, buttons_left + 19, button_y + 8, _bool_ctabs[!!on][!!editable], on ? FR_LOWERED : FR_NONE);
+ DrawBoolButton(buttons_left, button_y, on, editable);
SetDParam(0, on ? STR_CONFIG_SETTING_ON : STR_CONFIG_SETTING_OFF);
} else {
int32 value;
@@ -1822,6 +1821,19 @@ void DrawArrowButtons(int x, int y, Colours button_colour, byte state, bool clic
}
}
+/**
+ * Draw a toggle button.
+ * @param x the x position to draw
+ * @param y the y position to draw
+ * @param state true = lowered
+ * @param clickable is the button clickable?
+ */
+void DrawBoolButton(int x, int y, bool state, bool clickable)
+{
+ static const Colours _bool_ctabs[2][2] = {{COLOUR_CREAM, COLOUR_RED}, {COLOUR_DARK_GREEN, COLOUR_GREEN}};
+ DrawFrameRect(x, y + 1, x + 19, y + 9, _bool_ctabs[state][clickable], state ? FR_LOWERED : FR_NONE);
+}
+
struct CustomCurrencyWindow : Window {
int query_widget;