Changeset - r13685:2a5277694d65
[Not reviewed]
master
0 14 0
alberth - 15 years ago 2009-11-22 13:22:53
alberth@openttd.org
(svn r18220) -Codechange: Reduce number of nested widget dynamic casts.
14 files changed with 48 insertions and 42 deletions:
0 comments (0 inline, 0 general)
src/ai/ai_gui.cpp
Show inline comments
 
@@ -203,8 +203,9 @@ struct AIListWindow : public Window {
 

	
 
	virtual void OnResize()
 
	{
 
		this->vscroll.SetCapacity(this->GetWidget<NWidgetCore>(AIL_WIDGET_LIST)->current_y / this->line_height);
 
		this->GetWidget<NWidgetCore>(AIL_WIDGET_LIST)->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
 
		NWidgetCore *nwi = this->GetWidget<NWidgetCore>(AIL_WIDGET_LIST);
 
		this->vscroll.SetCapacity(nwi->current_y / this->line_height);
 
		nwi->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
 
	}
 
};
 

	
 
@@ -408,8 +409,9 @@ struct AISettingsWindow : public Window 
 

	
 
	virtual void OnResize()
 
	{
 
		this->vscroll.SetCapacity(this->GetWidget<NWidgetCore>(AIS_WIDGET_BACKGROUND)->current_y / this->line_height);
 
		this->GetWidget<NWidgetCore>(AIS_WIDGET_BACKGROUND)->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
 
		NWidgetCore *nwi = this->GetWidget<NWidgetCore>(AIS_WIDGET_BACKGROUND);
 
		this->vscroll.SetCapacity(nwi->current_y / this->line_height);
 
		nwi->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
 
	}
 

	
 
	virtual void OnTick()
 
@@ -520,9 +522,10 @@ struct AIConfigWindow : public Window {
 
	{
 
		this->InitNested(&_ai_config_desc); // Initializes 'this->line_height' as a side effect.
 
		this->selected_slot = INVALID_COMPANY;
 
		this->vscroll.SetCapacity(this->GetWidget<NWidgetBase>(AIC_WIDGET_LIST)->current_y / this->line_height);
 
		NWidgetCore *nwi = this->GetWidget<NWidgetCore>(AIC_WIDGET_LIST);
 
		this->vscroll.SetCapacity(nwi->current_y / this->line_height);
 
		this->vscroll.SetCount(MAX_COMPANIES);
 
		this->GetWidget<NWidgetCore>(AIC_WIDGET_LIST)->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
 
		nwi->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
 
		this->OnInvalidateData(0);
 
	}
 

	
src/autoreplace_gui.cpp
Show inline comments
 
@@ -376,7 +376,7 @@ public:
 
		/* Draw details panels. */
 
		for (int side = 0; side < 2; side++) {
 
			if (this->sel_engine[side] != INVALID_ENGINE) {
 
				NWidgetCore *nwi = this->GetWidget<NWidgetCore>(side == 0 ? RVW_WIDGET_LEFT_DETAILS : RVW_WIDGET_RIGHT_DETAILS);
 
				NWidgetBase *nwi = this->GetWidget<NWidgetBase>(side == 0 ? RVW_WIDGET_LEFT_DETAILS : RVW_WIDGET_RIGHT_DETAILS);
 
				int text_end = DrawVehiclePurchaseInfo(nwi->pos_x + WD_FRAMETEXT_LEFT, nwi->pos_x + nwi->current_x - WD_FRAMETEXT_RIGHT,
 
						nwi->pos_y + WD_FRAMERECT_TOP, this->sel_engine[side]);
 
				needed_height = max(needed_height, text_end - (int)nwi->pos_y + WD_FRAMERECT_BOTTOM);
src/build_vehicle_gui.cpp
Show inline comments
 
@@ -1017,7 +1017,7 @@ struct BuildVehicleWindow : Window {
 
				break;
 

	
 
			case BUILD_VEHICLE_WIDGET_LIST: {
 
				uint i = (pt.y - this->GetWidget<NWidgetCore>(BUILD_VEHICLE_WIDGET_LIST)->pos_y) / this->resize.step_height + this->vscroll.GetPosition();
 
				uint i = (pt.y - this->GetWidget<NWidgetBase>(BUILD_VEHICLE_WIDGET_LIST)->pos_y) / this->resize.step_height + this->vscroll.GetPosition();
 
				size_t num_items = this->eng_list.Length();
 
				this->sel_engine = (i < num_items) ? this->eng_list[i] : INVALID_ENGINE;
 
				this->SetDirty();
 
@@ -1124,7 +1124,7 @@ struct BuildVehicleWindow : Window {
 
		/* Draw details panels. */
 
		for (int side = 0; side < 2; side++) {
 
			if (this->sel_engine != INVALID_ENGINE) {
 
				NWidgetCore *nwi = this->GetWidget<NWidgetCore>(BUILD_VEHICLE_WIDGET_PANEL);
 
				NWidgetBase *nwi = this->GetWidget<NWidgetBase>(BUILD_VEHICLE_WIDGET_PANEL);
 
				int text_end = DrawVehiclePurchaseInfo(nwi->pos_x + WD_FRAMETEXT_LEFT, nwi->pos_x + nwi->current_x - WD_FRAMETEXT_RIGHT,
 
						nwi->pos_y + WD_FRAMERECT_TOP, this->sel_engine);
 
				needed_height = max(needed_height, text_end - (int)nwi->pos_y + WD_FRAMERECT_BOTTOM);
 
@@ -1178,8 +1178,9 @@ struct BuildVehicleWindow : Window {
 

	
 
	virtual void OnResize()
 
	{
 
		this->vscroll.SetCapacity((this->GetWidget<NWidgetCore>(BUILD_VEHICLE_WIDGET_LIST)->current_y) / this->resize.step_height);
 
		this->GetWidget<NWidgetCore>(BUILD_VEHICLE_WIDGET_LIST)->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
 
		NWidgetCore *nwi = this->GetWidget<NWidgetCore>(BUILD_VEHICLE_WIDGET_LIST);
 
		this->vscroll.SetCapacity(nwi->current_y / this->resize.step_height);
 
		nwi->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
 
	}
 
};
 

	
src/cheat_gui.cpp
Show inline comments
 
@@ -273,7 +273,7 @@ struct CheatWindow : Window {
 

	
 
	virtual void OnClick(Point pt, int widget)
 
	{
 
		const NWidgetCore *wid = this->GetWidget<NWidgetCore>(CW_PANEL);
 
		const NWidgetBase *wid = this->GetWidget<NWidgetBase>(CW_PANEL);
 
		uint btn = (pt.y - wid->pos_y - WD_FRAMERECT_TOP - this->header_height) / (FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL);
 
		uint x = pt.x - wid->pos_x;
 
		bool rtl = _dynlang.text_dir == TD_RTL;
src/company_gui.cpp
Show inline comments
 
@@ -413,7 +413,7 @@ struct CompanyFinancesWindow : Window {
 
		if (!small) {
 
			/* Check that the expenses panel height matches the height needed for the layout. */
 
			int type = _settings_client.gui.expenses_layout;
 
			if (_expenses_list_types[type].GetHeight() != this->GetWidget<NWidgetCore>(CFW_EXPS_CATEGORY)->current_y) {
 
			if (_expenses_list_types[type].GetHeight() != this->GetWidget<NWidgetBase>(CFW_EXPS_CATEGORY)->current_y) {
 
				this->SetupWidgets();
 
				this->ReInit();
 
				return;
src/depot_gui.cpp
Show inline comments
 
@@ -942,13 +942,14 @@ struct DepotWindow : Window {
 

	
 
	virtual void OnResize()
 
	{
 
		this->vscroll.SetCapacity(this->GetWidget<NWidgetCore>(DEPOT_WIDGET_MATRIX)->current_y / (int)this->resize.step_height);
 
		NWidgetCore *nwi = this->GetWidget<NWidgetCore>(DEPOT_WIDGET_MATRIX);
 
		this->vscroll.SetCapacity(nwi->current_y / (int)this->resize.step_height);
 
		if (this->type == VEH_TRAIN) {
 
			this->hscroll.SetCapacity(this->GetWidget<NWidgetCore>(DEPOT_WIDGET_MATRIX)->current_x - this->header_width - this->count_width);
 
			this->GetWidget<NWidgetCore>(DEPOT_WIDGET_MATRIX)->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
 
			this->hscroll.SetCapacity(nwi->current_x - this->header_width - this->count_width);
 
			nwi->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
 
		} else {
 
			this->hscroll.SetCapacity(this->GetWidget<NWidgetCore>(DEPOT_WIDGET_MATRIX)->current_x / (int)this->resize.step_width);
 
			this->GetWidget<NWidgetCore>(DEPOT_WIDGET_MATRIX)->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (this->hscroll.GetCapacity() << MAT_COL_START);
 
			this->hscroll.SetCapacity(nwi->current_x / (int)this->resize.step_width);
 
			nwi->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (this->hscroll.GetCapacity() << MAT_COL_START);
 
		}
 
	}
 

	
src/genworld_gui.cpp
Show inline comments
 
@@ -481,7 +481,7 @@ struct GenerateLandscapeWindow : public 
 
				 * spaced without doing much magic. The space we can draw on is
 
				 * covered by both the spacer and text widgets, so take their
 
				 * outer most boundaries (left and right) as draw locations. */
 
				const NWidgetCore *nwi_spacer = this->GetWidget<NWidgetCore>(GLAND_HEIGHTMAP_NAME_SPACER);
 
				const NWidgetBase *nwi_spacer = this->GetWidget<NWidgetBase>(GLAND_HEIGHTMAP_NAME_SPACER);
 
				DrawString(min(r.left, nwi_spacer->pos_x), max<int>(r.right, nwi_spacer->pos_x + nwi_spacer->current_x), r.top, this->name, TC_ORANGE);
 
			} break;
 
		}
src/graph_gui.cpp
Show inline comments
 
@@ -465,7 +465,7 @@ public:
 
	{
 
		this->DrawWidgets();
 

	
 
		NWidgetCore *nwid = this->GetWidget<NWidgetCore>(this->graph_widget);
 
		NWidgetBase *nwid = this->GetWidget<NWidgetBase>(this->graph_widget);
 
		Rect r;
 
		r.left = nwid->pos_x;
 
		r.right = nwid->pos_x + nwid->current_x - 1;
src/industry_gui.cpp
Show inline comments
 
@@ -594,7 +594,7 @@ public:
 
	{
 
		this->DrawWidgets();
 

	
 
		NWidgetCore *nwi = this->GetWidget<NWidgetCore>(IVW_INFO);
 
		NWidgetBase *nwi = this->GetWidget<NWidgetBase>(IVW_INFO);
 
		uint expected = this->DrawInfo(nwi->pos_x, nwi->pos_x + nwi->current_x - 1, nwi->pos_y) - nwi->pos_y;
 
		if (expected > nwi->current_y - 1) {
 
			this->info_height = expected + 1;
 
@@ -720,7 +720,7 @@ public:
 
				uint x = pt.x;
 
				int line = (pt.y - this->production_offset_y) / FONT_HEIGHT_NORMAL;
 
				if (pt.y >= this->production_offset_y && IsInsideMM(line, 0, 2) && i->produced_cargo[line] != CT_INVALID) {
 
					NWidgetCore *nwi = this->GetWidget<NWidgetCore>(widget);
 
					NWidgetBase *nwi = this->GetWidget<NWidgetBase>(widget);
 
					uint left = nwi->pos_x + WD_FRAMETEXT_LEFT;
 
					uint right = nwi->pos_x + nwi->current_x - 1 - WD_FRAMERECT_RIGHT;
 
					if (IsInsideMM(x, left, left + 20) ) {
src/network/network_content_gui.cpp
Show inline comments
 
@@ -439,9 +439,9 @@ public:
 

	
 
	void DrawMatrix(const Rect &r) const
 
	{
 
		const NWidgetCore *nwi_checkbox = this->GetWidget<NWidgetCore>(NCLWW_CHECKBOX);
 
		const NWidgetCore *nwi_name = this->GetWidget<NWidgetCore>(NCLWW_NAME);
 
		const NWidgetCore *nwi_type = this->GetWidget<NWidgetCore>(NCLWW_TYPE);
 
		const NWidgetBase *nwi_checkbox = this->GetWidget<NWidgetBase>(NCLWW_CHECKBOX);
 
		const NWidgetBase *nwi_name = this->GetWidget<NWidgetBase>(NCLWW_NAME);
 
		const NWidgetBase *nwi_type = this->GetWidget<NWidgetBase>(NCLWW_TYPE);
 

	
 

	
 
		/* Fill the matrix with the information */
 
@@ -608,7 +608,7 @@ public:
 
				this->selected = *this->content.Get(id_v);
 
				this->list_pos = id_v;
 

	
 
				if (pt.x <= (int)(this->GetWidget<NWidgetCore>(NCLWW_CHECKBOX)->pos_y + this->GetWidget<NWidgetCore>(NCLWW_CHECKBOX)->current_y)) {
 
				if (pt.x <= (int)(this->GetWidget<NWidgetBase>(NCLWW_CHECKBOX)->pos_y + this->GetWidget<NWidgetBase>(NCLWW_CHECKBOX)->current_y)) {
 
					_network_content_client.ToggleSelectedState(this->selected);
 
					this->content.ForceResort();
 
				}
src/network/network_gui.cpp
Show inline comments
 
@@ -368,8 +368,8 @@ protected:
 
	 */
 
	void DrawServerLine(const NetworkGameList *cur_item, uint y, bool highlight) const
 
	{
 
		const NWidgetCore *nwi_name = this->GetWidget<NWidgetCore>(NGWW_NAME);
 
		const NWidgetCore *nwi_info = this->GetWidget<NWidgetCore>(NGWW_INFO);
 
		const NWidgetBase *nwi_name = this->GetWidget<NWidgetBase>(NGWW_NAME);
 
		const NWidgetBase *nwi_info = this->GetWidget<NWidgetBase>(NGWW_INFO);
 

	
 
		/* show highlighted item with a different colour */
 
		if (highlight) GfxFillRect(nwi_name->pos_x + 1, y - 2, nwi_info->pos_x + nwi_info->current_x - 2, y + FONT_HEIGHT_NORMAL - 1, 10);
 
@@ -381,7 +381,7 @@ protected:
 
			const NWidgetServerListHeader *nwi_header = this->GetWidget<NWidgetServerListHeader>(NGWW_HEADER);
 

	
 
			if (nwi_header->IsWidgetVisible(NGWW_CLIENTS)) {
 
				const NWidgetCore *nwi_clients = this->GetWidget<NWidgetCore>(NGWW_CLIENTS);
 
				const NWidgetBase *nwi_clients = this->GetWidget<NWidgetBase>(NGWW_CLIENTS);
 
				SetDParam(0, cur_item->info.clients_on);
 
				SetDParam(1, cur_item->info.clients_max);
 
				SetDParam(2, cur_item->info.companies_on);
 
@@ -391,7 +391,7 @@ protected:
 

	
 
			if (nwi_header->IsWidgetVisible(NGWW_MAPSIZE)) {
 
				/* map size */
 
				const NWidgetCore *nwi_mapsize = this->GetWidget<NWidgetCore>(NGWW_MAPSIZE);
 
				const NWidgetBase *nwi_mapsize = this->GetWidget<NWidgetBase>(NGWW_MAPSIZE);
 
				SetDParam(0, cur_item->info.map_width);
 
				SetDParam(1, cur_item->info.map_height);
 
				DrawString(nwi_mapsize->pos_x, nwi_mapsize->pos_x + nwi_mapsize->current_x - 1, y, STR_NETWORK_SERVER_LIST_MAP_SIZE_SHORT, TC_FROMSTRING, SA_CENTER);
 
@@ -399,7 +399,7 @@ protected:
 

	
 
			if (nwi_header->IsWidgetVisible(NGWW_DATE)) {
 
				/* current date */
 
				const NWidgetCore *nwi_date = this->GetWidget<NWidgetCore>(NGWW_DATE);
 
				const NWidgetBase *nwi_date = this->GetWidget<NWidgetBase>(NGWW_DATE);
 
				YearMonthDay ymd;
 
				ConvertDateToYMD(cur_item->info.game_date, &ymd);
 
				SetDParam(0, ymd.year);
 
@@ -408,7 +408,7 @@ protected:
 

	
 
			if (nwi_header->IsWidgetVisible(NGWW_YEARS)) {
 
				/* number of years the game is running */
 
				const NWidgetCore *nwi_years = this->GetWidget<NWidgetCore>(NGWW_YEARS);
 
				const NWidgetBase *nwi_years = this->GetWidget<NWidgetBase>(NGWW_YEARS);
 
				YearMonthDay ymd_cur, ymd_start;
 
				ConvertDateToYMD(cur_item->info.game_date, &ymd_cur);
 
				ConvertDateToYMD(cur_item->info.start_date, &ymd_start);
 
@@ -694,7 +694,7 @@ public:
 
				break;
 

	
 
			case NGWW_MATRIX: { // Matrix to show networkgames
 
				uint32 id_v = (pt.y - this->GetWidget<NWidgetCore>(NGWW_MATRIX)->pos_y) / this->resize.step_height;
 
				uint32 id_v = (pt.y - this->GetWidget<NWidgetBase>(NGWW_MATRIX)->pos_y) / this->resize.step_height;
 

	
 
				if (id_v >= this->vscroll.GetCapacity()) return; // click out of bounds
 
				id_v += this->vscroll.GetPosition();
 
@@ -1185,7 +1185,7 @@ struct NetworkStartServerWindow : public
 
				break;
 

	
 
			case NSSW_SELMAP: { // Select map
 
				int y = (pt.y - this->GetWidget<NWidgetCore>(NSSW_SELMAP)->pos_y - WD_FRAMERECT_TOP) / FONT_HEIGHT_NORMAL;
 
				int y = (pt.y - this->GetWidget<NWidgetBase>(NSSW_SELMAP)->pos_y - WD_FRAMERECT_TOP) / FONT_HEIGHT_NORMAL;
 

	
 
				y += this->vscroll.GetPosition();
 
				if (y >= this->vscroll.GetCount()) return;
 
@@ -1645,7 +1645,7 @@ struct NetworkLobbyWindow : public Windo
 
				break;
 

	
 
			case NLWW_MATRIX: { // Company list
 
				uint32 id_v = (pt.y - this->GetWidget<NWidgetCore>(NLWW_MATRIX)->pos_y) / this->resize.step_height;
 
				uint32 id_v = (pt.y - this->GetWidget<NWidgetBase>(NLWW_MATRIX)->pos_y) / this->resize.step_height;
 

	
 
				if (id_v >= this->vscroll.GetCapacity()) break;
 

	
src/newgrf_gui.cpp
Show inline comments
 
@@ -609,8 +609,9 @@ struct NewGRFWindow : public Window {
 

	
 
	virtual void OnResize()
 
	{
 
		this->vscroll.SetCapacity(this->GetWidget<NWidgetCore>(SNGRFS_FILE_LIST)->current_y / this->resize.step_height);
 
		this->GetWidget<NWidgetCore>(SNGRFS_FILE_LIST)->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
 
		NWidgetCore *nwi = this->GetWidget<NWidgetCore>(SNGRFS_FILE_LIST);
 
		this->vscroll.SetCapacity(nwi->current_y / this->resize.step_height);
 
		nwi->widget_data = (this->vscroll.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
 
	}
 

	
 
	virtual void SetStringParameters(int widget) const
src/settings_gui.cpp
Show inline comments
 
@@ -1504,7 +1504,7 @@ struct GameSettingsWindow : Window {
 
	{
 
		if (widget != SETTINGSEL_OPTIONSPANEL) return;
 

	
 
		int y = pt.y - this->GetWidget<NWidgetCore>(widget)->pos_y - SETTINGTREE_TOP_OFFSET;  // Shift y coordinate
 
		int y = pt.y - this->GetWidget<NWidgetBase>(widget)->pos_y - SETTINGTREE_TOP_OFFSET;  // Shift y coordinate
 
		if (y < 0) return;  // Clicked above first entry
 

	
 
		byte btn = this->vscroll.GetPosition() + y / this->resize.step_height;  // Compute which setting is selected
 
@@ -1767,7 +1767,7 @@ struct CustomCurrencyWindow : Window {
 
			case CUSTCURR_SEPARATOR_EDIT:
 
			case CUSTCURR_PREFIX_EDIT:
 
			case CUSTCURR_SUFFIX_EDIT:
 
				size->width  = this->GetWidget<NWidgetCore>(CUSTCURR_RATE_DOWN)->smallest_x + this->GetWidget<NWidgetCore>(CUSTCURR_RATE_UP)->smallest_x;
 
				size->width  = this->GetWidget<NWidgetBase>(CUSTCURR_RATE_DOWN)->smallest_x + this->GetWidget<NWidgetBase>(CUSTCURR_RATE_UP)->smallest_x;
 
				break;
 

	
 
			/* Make sure the window is wide enough for the widest exchange rate */
src/smallmap_gui.cpp
Show inline comments
 
@@ -1016,7 +1016,7 @@ public:
 
				/* If industry type small map*/
 
				if (this->map_type == SMT_INDUSTRY) {
 
					/* If click on industries label, find right industry type and enable/disable it */
 
					const NWidgetCore *wi = this->GetWidget<NWidgetCore>(SM_WIDGET_LEGEND); // Label panel
 
					const NWidgetBase *wi = this->GetWidget<NWidgetBase>(SM_WIDGET_LEGEND); // Label panel
 
					uint line = (pt.y - wi->pos_y - WD_FRAMERECT_TOP) / FONT_HEIGHT_SMALL;
 
					if (line >= this->number_of_rows) break;
 

	
 
@@ -1103,7 +1103,7 @@ public:
 
			}
 
		}
 

	
 
		const NWidgetCore *wi = this->GetWidget<NWidgetCore>(SM_WIDGET_MAP);
 
		const NWidgetBase *wi = this->GetWidget<NWidgetBase>(SM_WIDGET_MAP);
 
		int hx = wi->current_x / 2;
 
		int hy = wi->current_y / 2;
 
		int hvx = hx * -4 + hy * 8;
 
@@ -1135,7 +1135,7 @@ public:
 
	void SmallMapCenterOnCurrentPos()
 
	{
 
		const ViewPort *vp = FindWindowById(WC_MAIN_WINDOW, 0)->viewport;
 
		const NWidgetCore *wi = this->GetWidget<NWidgetCore>(SM_WIDGET_MAP);
 
		const NWidgetBase *wi = this->GetWidget<NWidgetBase>(SM_WIDGET_MAP);
 

	
 
		int x = ((vp->virtual_width  - (int)wi->current_x * TILE_SIZE) / 2 + vp->virtual_left) / 4;
 
		int y = ((vp->virtual_height - (int)wi->current_y * TILE_SIZE) / 2 + vp->virtual_top ) / 2 - TILE_SIZE * 2;
0 comments (0 inline, 0 general)