summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2012-06-01 14:41:09 +0000
committerfrosch <frosch@openttd.org>2012-06-01 14:41:09 +0000
commit056f779334baf1857686453a8b382daf079311de (patch)
treeb1aee9f3e86b072ac264e88e7be885a4b9fc64b7
parent198de5397ed4a217273bda29dae8ddf60ba48f1d (diff)
downloadopenttd-056f779334baf1857686453a8b382daf079311de.tar.xz
(svn r24310) -Codechange: Add named constants for the dimensions of settings buttons, and generally make their usage more consistent.
-rw-r--r--src/ai/ai_gui.cpp10
-rw-r--r--src/cheat_gui.cpp14
-rw-r--r--src/industry_gui.cpp10
-rw-r--r--src/newgrf_gui.cpp10
-rw-r--r--src/settings_gui.cpp26
-rw-r--r--src/settings_gui.h3
6 files changed, 38 insertions, 35 deletions
diff --git a/src/ai/ai_gui.cpp b/src/ai/ai_gui.cpp
index 82ceb1641..0dd0b56cf 100644
--- a/src/ai/ai_gui.cpp
+++ b/src/ai/ai_gui.cpp
@@ -355,9 +355,9 @@ struct AISettingsWindow : public Window {
for (; !this->vscroll->IsVisible(i); i++) it++;
bool rtl = _current_text_dir == TD_RTL;
- uint buttons_left = rtl ? r.right - 23 : r.left + 4;
- uint text_left = r.left + (rtl ? WD_FRAMERECT_LEFT : 28);
- uint text_right = r.right - (rtl ? 28 : WD_FRAMERECT_RIGHT);
+ uint buttons_left = rtl ? r.right - SETTING_BUTTON_WIDTH - 3 : r.left + 4;
+ uint text_left = r.left + (rtl ? WD_FRAMERECT_LEFT : SETTING_BUTTON_WIDTH + 8);
+ uint text_right = r.right - (rtl ? SETTING_BUTTON_WIDTH + 8 : WD_FRAMERECT_RIGHT);
int y = r.top;
@@ -437,12 +437,12 @@ struct AISettingsWindow : public Window {
if (_current_text_dir == TD_RTL) x = wid->current_x - x;
x -= 4;
/* One of the arrows is clicked (or green/red rect in case of bool value) */
- if (IsInsideMM(x, 0, 21)) {
+ if (IsInsideMM(x, 0, SETTING_BUTTON_WIDTH)) {
int new_val = this->ai_config->GetSetting(config_item.name);
int old_val = new_val;
if (bool_item) {
new_val = !new_val;
- } else if (x >= 10) {
+ } else if (x >= SETTING_BUTTON_WIDTH / 2) {
/* Increase button clicked */
new_val += config_item.step_size;
if (new_val > config_item.max_value) new_val = config_item.max_value;
diff --git a/src/cheat_gui.cpp b/src/cheat_gui.cpp
index 33d9ae20e..40e153de8 100644
--- a/src/cheat_gui.cpp
+++ b/src/cheat_gui.cpp
@@ -184,9 +184,9 @@ struct CheatWindow : Window {
bool rtl = _current_text_dir == TD_RTL;
uint box_left = rtl ? r.right - 12 : r.left + 5;
- uint button_left = rtl ? r.right - 40 : r.left + 20;
- uint text_left = r.left + (rtl ? WD_FRAMERECT_LEFT: 50);
- uint text_right = r.right - (rtl ? 50 : WD_FRAMERECT_RIGHT);
+ uint button_left = rtl ? r.right - 20 - SETTING_BUTTON_WIDTH : r.left + 20;
+ uint text_left = r.left + (rtl ? WD_FRAMERECT_LEFT : 30 + SETTING_BUTTON_WIDTH);
+ uint text_right = r.right - (rtl ? 30 + SETTING_BUTTON_WIDTH : WD_FRAMERECT_RIGHT);
for (int i = 0; i != lengthof(_cheats_ui); i++) {
const CheatEntry *ce = &_cheats_ui[i];
@@ -291,7 +291,7 @@ struct CheatWindow : Window {
int value = (int32)ReadValue(ce->variable, ce->type);
int oldvalue = value;
- if (btn == CHT_CHANGE_DATE && x >= 40) {
+ if (btn == CHT_CHANGE_DATE && x >= 20 + SETTING_BUTTON_WIDTH) {
/* Click at the date text directly. */
SetDParam(0, value);
ShowQueryString(STR_JUST_INT, STR_CHEAT_CHANGE_DATE_QUERY_CAPT, 8, this, CS_NUMERAL, QSF_ACCEPT_UNCHANGED);
@@ -299,7 +299,7 @@ struct CheatWindow : Window {
}
/* Not clicking a button? */
- if (!IsInsideMM(x, 20, 40)) return;
+ if (!IsInsideMM(x, 20, 20 + SETTING_BUTTON_WIDTH)) return;
*ce->been_used = true;
@@ -311,10 +311,10 @@ struct CheatWindow : Window {
default:
/* Take whatever the function returns */
- value = ce->proc(value + ((x >= 30) ? 1 : -1), (x >= 30) ? 1 : -1);
+ value = ce->proc(value + ((x >= 20 + SETTING_BUTTON_WIDTH / 2) ? 1 : -1), (x >= 20 + SETTING_BUTTON_WIDTH / 2) ? 1 : -1);
/* The first cheat (money), doesn't return a different value. */
- if (value != oldvalue || btn == CHT_MONEY) this->clicked = btn * 2 + 1 + ((x >= 30) != rtl ? 1 : 0);
+ if (value != oldvalue || btn == CHT_MONEY) this->clicked = btn * 2 + 1 + ((x >= 20 + SETTING_BUTTON_WIDTH / 2) != rtl ? 1 : 0);
break;
}
diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp
index 8b182dbd9..5a180bef5 100644
--- a/src/industry_gui.cpp
+++ b/src/industry_gui.cpp
@@ -749,7 +749,7 @@ public:
SetDParam(1, i->last_month_production[j]);
SetDParamStr(2, cargo_suffix[j]);
SetDParam(3, ToPercent8(i->last_month_pct_transported[j]));
- uint x = left + WD_FRAMETEXT_LEFT + (this->editable == EA_RATE ? 30 : 0);
+ uint x = left + WD_FRAMETEXT_LEFT + (this->editable == EA_RATE ? SETTING_BUTTON_WIDTH + 10 : 0);
DrawString(x, right - WD_FRAMERECT_RIGHT, y, STR_INDUSTRY_VIEW_TRANSPORTED);
/* Let's put out those buttons.. */
if (this->editable == EA_RATE) {
@@ -764,7 +764,7 @@ public:
y += WD_PAR_VSEP_WIDE;
this->production_offset_y = y;
SetDParam(0, RoundDivSU(i->prod_level * 100, PRODLEVEL_DEFAULT));
- uint x = left + WD_FRAMETEXT_LEFT + 30;
+ uint x = left + WD_FRAMETEXT_LEFT + SETTING_BUTTON_WIDTH + 10;
DrawString(x, right - WD_FRAMERECT_RIGHT, y, STR_INDUSTRY_VIEW_PRODUCTION_LEVEL);
DrawArrowButtons(left + WD_FRAMETEXT_LEFT, y, COLOUR_YELLOW, (this->clicked_line == IL_MULTIPLIER) ? this->clicked_button : 0,
i->prod_level > PRODLEVEL_MINIMUM, i->prod_level < PRODLEVEL_MAXIMUM);
@@ -838,9 +838,9 @@ public:
NWidgetBase *nwi = this->GetWidget<NWidgetBase>(widget);
int left = nwi->pos_x + WD_FRAMETEXT_LEFT;
int right = nwi->pos_x + nwi->current_x - 1 - WD_FRAMERECT_RIGHT;
- if (IsInsideMM(pt.x, left, left + 20)) {
+ if (IsInsideMM(pt.x, left, left + SETTING_BUTTON_WIDTH)) {
/* Clicked buttons, decrease or increase production */
- byte button = (pt.x < left + 10) ? 1 : 2;
+ byte button = (pt.x < left + SETTING_BUTTON_WIDTH / 2) ? 1 : 2;
switch (this->editable) {
case EA_MULTIPLIER:
if (button == 1) {
@@ -872,7 +872,7 @@ public:
this->SetTimeout();
this->clicked_line = line;
this->clicked_button = button;
- } else if (IsInsideMM(pt.x, left + 30, right)) {
+ } else if (IsInsideMM(pt.x, left + SETTING_BUTTON_WIDTH + 10, right)) {
/* clicked the text */
this->editbox_line = line;
switch (this->editable) {
diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp
index 447345ef0..d36513ca9 100644
--- a/src/newgrf_gui.cpp
+++ b/src/newgrf_gui.cpp
@@ -247,9 +247,9 @@ struct NewGRFParametersWindow : public Window {
}
bool rtl = _current_text_dir == TD_RTL;
- uint buttons_left = rtl ? r.right - 23 : r.left + 4;
- uint text_left = r.left + (rtl ? WD_FRAMERECT_LEFT : 28);
- uint text_right = r.right - (rtl ? 28 : WD_FRAMERECT_RIGHT);
+ uint buttons_left = rtl ? r.right - SETTING_BUTTON_WIDTH - 3 : r.left + 4;
+ uint text_left = r.left + (rtl ? WD_FRAMERECT_LEFT : SETTING_BUTTON_WIDTH + 8);
+ uint text_right = r.right - (rtl ? SETTING_BUTTON_WIDTH + 8 : WD_FRAMERECT_RIGHT);
int y = r.top;
for (uint i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < this->vscroll->GetCount(); i++) {
@@ -327,13 +327,13 @@ struct NewGRFParametersWindow : public Window {
if (par_info == NULL) par_info = GetDummyParameterInfo(num);
/* One of the arrows is clicked */
- if (IsInsideMM(x, 0, 21)) {
+ if (IsInsideMM(x, 0, SETTING_BUTTON_WIDTH)) {
uint32 val = par_info->GetValue(this->grf_config);
uint32 old_val = val;
if (par_info->type == PTYPE_BOOL) {
val = !val;
} else {
- if (x >= 10) {
+ if (x >= SETTING_BUTTON_WIDTH / 2) {
/* Increase button clicked */
if (val < par_info->max_value) val++;
this->clicked_increase = true;
diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp
index d066284a8..55dcf9b8f 100644
--- a/src/settings_gui.cpp
+++ b/src/settings_gui.cpp
@@ -1318,10 +1318,10 @@ void SettingEntry::DrawSetting(GameSettings *settings_ptr, int left, int right,
bool editable = true;
bool rtl = _current_text_dir == TD_RTL;
- uint buttons_left = rtl ? right - 19 : left;
- uint text_left = left + (rtl ? 0 : 25);
- uint text_right = right - (rtl ? 25 : 0);
- uint button_y = y + (SETTING_HEIGHT - 11) / 2;
+ uint buttons_left = rtl ? right + 1 - SETTING_BUTTON_WIDTH : left;
+ uint text_left = left + (rtl ? 0 : SETTING_BUTTON_WIDTH + 5);
+ uint text_right = right - (rtl ? SETTING_BUTTON_WIDTH + 5 : 0);
+ uint button_y = y + (SETTING_HEIGHT - SETTING_BUTTON_HEIGHT) / 2;
/* We do not allow changes of some items when we are a client in a networkgame */
if (!(sd->save.conv & SLF_NO_NETWORK_SYNC) && _networking && !_network_server && !(sdb->flags & SGF_PER_COMPANY)) editable = false;
@@ -1822,7 +1822,7 @@ struct GameSettingsWindow : Window {
int32 value = (int32)ReadValue(var, sd->save.conv);
/* clicked on the icon on the left side. Either scroller or bool on/off */
- if (x < 21) {
+ if (x < SETTING_BUTTON_WIDTH) {
this->SetDisplayedHelpText(pe);
const SettingDescBase *sdb = &sd->desc;
int32 oldvalue = value;
@@ -1845,7 +1845,7 @@ struct GameSettingsWindow : Window {
}
/* Increase or decrease the value and clamp it to extremes */
- if (x >= 10) {
+ if (x >= SETTING_BUTTON_WIDTH / 2) {
value += step;
if (sdb->min < 0) {
assert((int32)sdb->max >= 0);
@@ -1865,7 +1865,7 @@ struct GameSettingsWindow : Window {
this->clicked_entry->SetButtons(0);
}
this->clicked_entry = pe;
- this->clicked_entry->SetButtons((x >= 10) != (_current_text_dir == TD_RTL) ? SEF_RIGHT_DEPRESSED : SEF_LEFT_DEPRESSED);
+ this->clicked_entry->SetButtons((x >= SETTING_BUTTON_WIDTH / 2) != (_current_text_dir == TD_RTL) ? SEF_RIGHT_DEPRESSED : SEF_LEFT_DEPRESSED);
this->SetTimeout();
_left_button_clicked = false;
}
@@ -1990,18 +1990,18 @@ void DrawArrowButtons(int x, int y, Colours button_colour, byte state, bool clic
{
int colour = _colour_gradient[button_colour][2];
- DrawFrameRect(x, y + 1, x + 9, y + 9, button_colour, (state == 1) ? FR_LOWERED : FR_NONE);
- DrawFrameRect(x + 10, y + 1, x + 19, y + 9, button_colour, (state == 2) ? FR_LOWERED : FR_NONE);
+ 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);
DrawSprite(SPR_ARROW_LEFT, PAL_NONE, x + WD_IMGBTN_LEFT, y + WD_IMGBTN_TOP);
- DrawSprite(SPR_ARROW_RIGHT, PAL_NONE, x + WD_IMGBTN_LEFT + 10, y + WD_IMGBTN_TOP);
+ DrawSprite(SPR_ARROW_RIGHT, PAL_NONE, x + WD_IMGBTN_LEFT + SETTING_BUTTON_WIDTH / 2, 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 + 1, x + 1 + 8, y + 8, colour, FILLRECT_CHECKER);
+ GfxFillRect(x + 1, y, x + SETTING_BUTTON_WIDTH / 2 - 1, y + SETTING_BUTTON_HEIGHT - 2, colour, FILLRECT_CHECKER);
}
if (rtl ? !clickable_left : !clickable_right) {
- GfxFillRect(x + 11, y + 1, x + 11 + 8, y + 8, colour, FILLRECT_CHECKER);
+ GfxFillRect(x + SETTING_BUTTON_WIDTH / 2 + 1, y, x + SETTING_BUTTON_WIDTH - 1, y + SETTING_BUTTON_HEIGHT - 2, colour, FILLRECT_CHECKER);
}
}
@@ -2015,7 +2015,7 @@ void DrawArrowButtons(int x, int y, Colours button_colour, byte state, bool clic
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);
+ DrawFrameRect(x, y, x + SETTING_BUTTON_WIDTH - 1, y + SETTING_BUTTON_HEIGHT - 1, _bool_ctabs[state][clickable], state ? FR_LOWERED : FR_NONE);
}
struct CustomCurrencyWindow : Window {
diff --git a/src/settings_gui.h b/src/settings_gui.h
index 18af89f6a..5d6cfe8a9 100644
--- a/src/settings_gui.h
+++ b/src/settings_gui.h
@@ -14,6 +14,9 @@
#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
+
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);