(svn r23757) -Codechange: Unify the drawing of toggle buttons for boolean settings.

This commit is contained in:
frosch
2012-01-05 19:32:51 +00:00
parent 2fb393fcd0
commit 69e197c87f
5 changed files with 18 additions and 5 deletions

View File

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