Changeset - r19393:fb056f72c99f
[Not reviewed]
master
0 6 0
frosch - 12 years ago 2012-06-01 14:41:09
frosch@openttd.org
(svn r24310) -Codechange: Add named constants for the dimensions of settings buttons, and generally make their usage more consistent.
6 files changed with 38 insertions and 35 deletions:
0 comments (0 inline, 0 general)
src/ai/ai_gui.cpp
Show inline comments
 
@@ -352,15 +352,15 @@ struct AISettingsWindow : public Window 
 
		ScriptConfig *config = this->ai_config;
 
		VisibleSettingsList::const_iterator it = this->visible_settings.begin();
 
		int i = 0;
 
		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;
 
		for (; this->vscroll->IsVisible(i) && it != visible_settings.end(); i++, it++) {
 
			const ScriptConfigItem &config_item = **it;
 
			int current_value = config->GetSetting((config_item).name);
 
@@ -434,18 +434,18 @@ struct AISettingsWindow : public Window 
 
				bool bool_item = (config_item.flags & SCRIPTCONFIG_BOOLEAN) != 0;
 

	
 
				int x = pt.x - wid->pos_x;
 
				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;
 
						this->clicked_increase = true;
 
					} else {
 
						/* Decrease button clicked */
src/cheat_gui.cpp
Show inline comments
 
@@ -181,15 +181,15 @@ struct CheatWindow : Window {
 

	
 
		int y = r.top + WD_FRAMERECT_TOP + this->header_height;
 
		DrawStringMultiLine(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_LEFT, r.top + WD_FRAMERECT_TOP, y, STR_CHEATS_WARNING, TC_FROMSTRING, SA_CENTER);
 

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

	
 
			DrawSprite((*ce->been_used) ? SPR_BOX_CHECKED : SPR_BOX_EMPTY, PAL_NONE, box_left, y + 2);
 

	
 
@@ -288,36 +288,36 @@ struct CheatWindow : Window {
 
		if (btn >= lengthof(_cheats_ui)) return;
 

	
 
		const CheatEntry *ce = &_cheats_ui[btn];
 
		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);
 
			return;
 
		}
 

	
 
		/* Not clicking a button? */
 
		if (!IsInsideMM(x, 20, 40)) return;
 
		if (!IsInsideMM(x, 20, 20 + SETTING_BUTTON_WIDTH)) return;
 

	
 
		*ce->been_used = true;
 

	
 
		switch (ce->type) {
 
			case SLE_BOOL:
 
				value ^= 1;
 
				if (ce->proc != NULL) ce->proc(value, 0);
 
				break;
 

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

	
 
		if (value != oldvalue) WriteValue(ce->variable, ce->type, (int64)value);
 

	
 
		this->SetTimeout();
src/industry_gui.cpp
Show inline comments
 
@@ -746,13 +746,13 @@ public:
 
			}
 

	
 
			SetDParam(0, i->produced_cargo[j]);
 
			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) {
 
				DrawArrowButtons(left + WD_FRAMETEXT_LEFT, y, COLOUR_YELLOW, (this->clicked_line == IL_RATE1 + j) ? this->clicked_button : 0,
 
						i->production_rate[j] > 0, i->production_rate[j] < 255);
 
			}
 
@@ -761,13 +761,13 @@ public:
 

	
 
		/* Display production multiplier if editable */
 
		if (this->editable == EA_MULTIPLIER) {
 
			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);
 
			y += FONT_HEIGHT_NORMAL;
 
		}
 

	
 
@@ -835,15 +835,15 @@ public:
 
				}
 
				if (line == IL_NONE) return;
 

	
 
				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) {
 
								if (i->prod_level <= PRODLEVEL_MINIMUM) return;
 
								i->prod_level = max<uint>(i->prod_level / 2, PRODLEVEL_MINIMUM);
 
							} else {
 
@@ -869,13 +869,13 @@ public:
 

	
 
					UpdateIndustryProduction(i);
 
					this->SetDirty();
 
					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) {
 
						case EA_MULTIPLIER:
 
							SetDParam(0, RoundDivSU(i->prod_level * 100, PRODLEVEL_DEFAULT));
 
							ShowQueryString(STR_JUST_INT, STR_CONFIG_GAME_PRODUCTION_LEVEL, 10, this, CS_ALPHANUMERAL, QSF_NONE);
src/newgrf_gui.cpp
Show inline comments
 
@@ -244,15 +244,15 @@ struct NewGRFParametersWindow : public W
 
			return;
 
		} else if (widget != WID_NP_BACKGROUND) {
 
			return;
 
		}
 

	
 
		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++) {
 
			GRFParameterInfo *par_info = (i < this->grf_config->param_info.Length()) ? this->grf_config->param_info[i] : NULL;
 
			if (par_info == NULL) par_info = GetDummyParameterInfo(i);
 
			uint32 current_value = par_info->GetValue(this->grf_config);
 
@@ -324,19 +324,19 @@ struct NewGRFParametersWindow : public W
 
				x -= 4;
 

	
 
				GRFParameterInfo *par_info = (num < this->grf_config->param_info.Length()) ? this->grf_config->param_info[num] : NULL;
 
				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;
 
						} else {
 
							/* Decrease button clicked */
 
							if (val > par_info->min_value) val--;
src/settings_gui.cpp
Show inline comments
 
@@ -1315,16 +1315,16 @@ void SettingEntry::DrawSetting(GameSetti
 
	const SettingDesc *sd = this->d.entry.setting;
 
	const SettingDescBase *sdb = &sd->desc;
 
	const void *var = ResolveVariableAddress(settings_ptr, sd);
 
	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;
 
	if ((sdb->flags & SGF_NETWORK_ONLY) && !_networking) editable = false;
 
	if ((sdb->flags & SGF_NO_NETWORK) && _networking) editable = false;
 

	
 
@@ -1819,13 +1819,13 @@ struct GameSettingsWindow : Window {
 
		}
 

	
 
		const void *var = ResolveVariableAddress(settings_ptr, sd);
 
		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;
 

	
 
			switch (sdb->cmd) {
 
				case SDT_BOOLX: value ^= 1; break;
 
@@ -1842,13 +1842,13 @@ struct GameSettingsWindow : Window {
 
					if ((this->flags & WF_TIMEOUT) && this->timeout_timer > 1) {
 
						_left_button_clicked = false;
 
						return;
 
					}
 

	
 
					/* 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);
 
							if (value > (int32)sdb->max) value = (int32)sdb->max;
 
						} else {
 
							if ((uint32)value > sdb->max) value = (int32)sdb->max;
 
@@ -1862,13 +1862,13 @@ struct GameSettingsWindow : Window {
 
					/* Set up scroller timeout for numeric values */
 
					if (value != oldvalue && !(sd->desc.flags & SGF_MULTISTRING)) {
 
						if (this->clicked_entry != NULL) { // Release previous buttons if any
 
							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;
 
					}
 
					break;
 
				}
 

	
 
@@ -1987,24 +1987,24 @@ void ShowGameSettings()
 
 * @param clickable_right is the right button clickable?
 
 */
 
void DrawArrowButtons(int x, int y, Colours button_colour, byte state, bool clickable_left, bool clickable_right)
 
{
 
	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);
 
	}
 
}
 

	
 
/**
 
 * Draw a toggle button.
 
 * @param x the x position to draw
 
@@ -2012,13 +2012,13 @@ void DrawArrowButtons(int x, int y, Colo
 
 * @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);
 
	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 {
 
	int query_widget;
 

	
 
	CustomCurrencyWindow(const WindowDesc *desc) : Window()
src/settings_gui.h
Show inline comments
 
@@ -11,11 +11,14 @@
 

	
 
#ifndef SETTING_GUI_H
 
#define SETTING_GUI_H
 

	
 
#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);
 

	
 
#endif /* SETTING_GUI_H */
 

	
0 comments (0 inline, 0 general)