changeset 12411:9fdbb4594b82 draft

(svn r16845) -Codechange: Introduction of constants for describing the bits in a WWT_MATRIX data field.
author alberth <alberth@openttd.org>
date Thu, 16 Jul 2009 16:22:23 +0000 (2009-07-16)
parents 06313eaa49f1
children 3026261b2299
files src/ai/ai_gui.cpp src/autoreplace_gui.cpp src/bridge_gui.cpp src/build_vehicle_gui.cpp src/company_gui.cpp src/depot_gui.cpp src/group_gui.cpp src/industry_gui.cpp src/network/network_content_gui.cpp src/network/network_gui.cpp src/newgrf_gui.cpp src/vehicle_gui.cpp src/widget.cpp src/widget_type.h
diffstat 14 files changed, 46 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/src/ai/ai_gui.cpp
+++ b/src/ai/ai_gui.cpp
@@ -53,7 +53,7 @@
 		this->ai_info_list = AI::GetUniqueInfoList();
 		this->resize.step_height = 14;
 		this->vscroll.cap = (this->widget[AIL_WIDGET_LIST].bottom - this->widget[AIL_WIDGET_LIST].top) / 14 + 1;
-		this->widget[AIL_WIDGET_LIST].data = (this->vscroll.cap << 8) + 1;
+		this->widget[AIL_WIDGET_LIST].data = (this->vscroll.cap << MAT_ROW_START) + (1 << MAT_COL_START);
 		SetVScrollCount(this, (int)this->ai_info_list->size() + 1);
 
 		/* Try if we can find the currently selected AI */
@@ -181,7 +181,7 @@
 
 		this->vscroll.cap += delta.y / 14;
 		SetVScrollCount(this, (int)this->ai_info_list->size() + 1);
-		this->widget[AIL_WIDGET_LIST].data = (this->vscroll.cap << 8) + 1;
+		this->widget[AIL_WIDGET_LIST].data = (this->vscroll.cap << MAT_ROW_START) + (1 << MAT_COL_START);
 	}
 };
 
@@ -265,7 +265,7 @@
 		this->ai_config = AIConfig::GetConfig(slot);
 		this->resize.step_height = 14;
 		this->vscroll.cap = (this->widget[AIS_WIDGET_BACKGROUND].bottom - this->widget[AIS_WIDGET_BACKGROUND].top) / 14 + 1;
-		this->widget[AIS_WIDGET_BACKGROUND].data = (this->vscroll.cap << 8) + 1;
+		this->widget[AIS_WIDGET_BACKGROUND].data = (this->vscroll.cap << MAT_ROW_START) + (1 << MAT_COL_START);
 		SetVScrollCount(this, (int)this->ai_config->GetConfigList()->size());
 		this->FindWindowPlacementAndResize(desc);
 	}
@@ -378,7 +378,7 @@
 		}
 
 		this->vscroll.cap += delta.y / 14;
-		this->widget[AIS_WIDGET_BACKGROUND].data = (this->vscroll.cap << 8) + 1;
+		this->widget[AIS_WIDGET_BACKGROUND].data = (this->vscroll.cap << MAT_ROW_START) + (1 << MAT_COL_START);
 	}
 
 	virtual void OnTick()
@@ -505,6 +505,7 @@
 		this->resize.step_height = 14;
 		this->vscroll.cap = (this->widget[AIC_WIDGET_LIST].bottom - this->widget[AIC_WIDGET_LIST].top) / 14 + 1;
 		this->widget[AIC_WIDGET_LIST].data = (this->vscroll.cap << 8) + 1;
+		this->widget[AIC_WIDGET_LIST].data = (this->vscroll.cap << MAT_ROW_START) + (1 << MAT_COL_START);
 		SetVScrollCount(this, MAX_COMPANIES);
 		this->FindWindowPlacementAndResize(&_ai_config_desc);
 	}
@@ -597,7 +598,7 @@
 	virtual void OnResize(Point delta)
 	{
 		this->vscroll.cap += delta.y / 14;
-		this->widget[AIC_WIDGET_LIST].data = (this->vscroll.cap << 8) + 1;
+		this->widget[AIC_WIDGET_LIST].data = (this->vscroll.cap << MAT_ROW_START) + (1 << MAT_COL_START);
 	}
 
 	virtual void OnTick()
--- a/src/autoreplace_gui.cpp
+++ b/src/autoreplace_gui.cpp
@@ -209,7 +209,7 @@
 		this->vscroll.cap = this->resize.step_height == 14 ? 8 : 4;
 
 		Widget *widget = this->widget;
-		widget[RVW_WIDGET_LEFT_MATRIX].data = widget[RVW_WIDGET_RIGHT_MATRIX].data = (this->vscroll.cap << 8) + 1;
+		widget[RVW_WIDGET_LEFT_MATRIX].data = widget[RVW_WIDGET_RIGHT_MATRIX].data = (this->vscroll.cap << MAT_ROW_START) + (1 << MAT_COL_START);
 
 		if (vehicletype != VEH_TRAIN) {
 			/* Since it's not a train we will hide the train only widgets. */
@@ -409,7 +409,7 @@
 
 		Widget *widget = this->widget;
 
-		widget[RVW_WIDGET_LEFT_MATRIX].data = widget[RVW_WIDGET_RIGHT_MATRIX].data = (this->vscroll2.cap << 8) + 1;
+		widget[RVW_WIDGET_LEFT_MATRIX].data = widget[RVW_WIDGET_RIGHT_MATRIX].data = (this->vscroll.cap << MAT_ROW_START) + (1 << MAT_COL_START);
 
 		if (delta.x != 0) {
 			/* We changed the width of the window so we have to resize the lists.
--- a/src/bridge_gui.cpp
+++ b/src/bridge_gui.cpp
@@ -226,7 +226,7 @@
 	virtual void OnResize(Point delta)
 	{
 		this->vscroll.cap += delta.y / (int)this->resize.step_height;
-		this->widget[BBSW_BRIDGE_LIST].data = (this->vscroll.cap << 8) + 1;
+		this->widget[BBSW_BRIDGE_LIST].data = (this->vscroll.cap << MAT_ROW_START) + (1 << MAT_COL_START);
 		SetVScrollCount(this, this->bridges->Length());
 
 		this->last_size = max(this->vscroll.cap, this->last_size);
--- a/src/build_vehicle_gui.cpp
+++ b/src/build_vehicle_gui.cpp
@@ -790,7 +790,7 @@
 		ResizeWindow(this, 0, vlh - 14);
 		this->resize.step_height = vlh;
 		this->vscroll.cap = 1;
-		this->widget[BUILD_VEHICLE_WIDGET_LIST].data = 0x101;
+		this->widget[BUILD_VEHICLE_WIDGET_LIST].data = (1 << MAT_ROW_START) | (1 << MAT_COL_START);
 
 		this->resize.width  = this->width;
 		this->resize.height = this->height;
@@ -1248,7 +1248,7 @@
 		if (delta.y == 0) return;
 
 		this->vscroll.cap += delta.y / (int)GetVehicleListHeight(this->vehicle_type);
-		this->widget[BUILD_VEHICLE_WIDGET_LIST].data = (this->vscroll.cap << 8) + 1;
+		this->widget[BUILD_VEHICLE_WIDGET_LIST].data = (this->vscroll.cap << MAT_ROW_START) + (1 << MAT_COL_START);
 	}
 };
 
--- a/src/company_gui.cpp
+++ b/src/company_gui.cpp
@@ -642,7 +642,7 @@
 				}
 				this->height = 49 + livery_height[this->livery_class] * 14;
 				this->widget[SCLW_WIDGET_MATRIX].bottom = this->height - 1;
-				this->widget[SCLW_WIDGET_MATRIX].data = livery_height[this->livery_class] << 8 | 1;
+				this->widget[SCLW_WIDGET_MATRIX].data = (livery_height[this->livery_class] << MAT_ROW_START) | (1 << MAT_COL_START);
 				MarkWholeScreenDirty();
 				break;
 			}
@@ -719,7 +719,7 @@
 		NWidget(WWT_DROPDOWN, COLOUR_GREY, SCLW_WIDGET_PRI_COL_DROPDOWN), SetMinimalSize(125, 12), SetDataTip(STR_BLACK_STRING, STR_LIVERY_PRIMARY_TIP),
 		NWidget(WWT_DROPDOWN, COLOUR_GREY, SCLW_WIDGET_SEC_COL_DROPDOWN), SetMinimalSize(125, 12), SetDataTip(STR_GAME_OPTIONS_CURRENCY_UNITS_DROPDOWN, STR_LIVERY_SECONDARY_TIP),
 	EndContainer(),
-	NWidget(WWT_MATRIX, COLOUR_GREY, SCLW_WIDGET_MATRIX), SetMinimalSize(400, 15), SetDataTip((1 << 8) | 1, STR_LIVERY_PANEL_TIP),
+	NWidget(WWT_MATRIX, COLOUR_GREY, SCLW_WIDGET_MATRIX), SetMinimalSize(400, 15), SetDataTip((1 << MAT_ROW_START) | (1 << MAT_COL_START), STR_LIVERY_PANEL_TIP),
 };
 
 static const Widget _select_company_livery_widgets[] = {
--- a/src/depot_gui.cpp
+++ b/src/depot_gui.cpp
@@ -308,8 +308,8 @@
 		uint16 hnum;
 
 		/* Set the row and number of boxes in each row based on the number of boxes drawn in the matrix */
-		uint16 rows_in_display   = this->widget[DEPOT_WIDGET_MATRIX].data >> 8;
-		uint16 boxes_in_each_row = this->widget[DEPOT_WIDGET_MATRIX].data & 0xFF;
+		uint16 rows_in_display   = GB(this->widget[DEPOT_WIDGET_MATRIX].data, MAT_ROW_START, MAT_ROW_BITS);
+		uint16 boxes_in_each_row = GB(this->widget[DEPOT_WIDGET_MATRIX].data, MAT_COL_START, MAT_COL_BITS);
 
 		/* setup disabled buttons */
 		this->SetWidgetsDisabledState(!IsTileOwner(tile, _local_company),
@@ -397,7 +397,7 @@
 	{
 		uint xt, row, xm = 0, ym = 0;
 		int pos, skip = 0;
-		uint16 boxes_in_each_row = this->widget[DEPOT_WIDGET_MATRIX].data & 0xFF;
+		uint16 boxes_in_each_row = GB(this->widget[DEPOT_WIDGET_MATRIX].data, MAT_COL_START, MAT_COL_BITS);
 
 		if (this->type == VEH_TRAIN) {
 			xt = 0;
@@ -727,8 +727,8 @@
 		this->SetupStringsForDepotWindow(type);
 
 		this->widget[DEPOT_WIDGET_MATRIX].data =
-			(this->vscroll.cap * 0x100) // number of rows to draw on the background
-			+ (type == VEH_TRAIN ? 1 : this->hscroll.cap); // number of boxes in each row. Trains always have just one
+			(this->vscroll.cap << MAT_ROW_START) // number of rows to draw on the background
+			+ ((type == VEH_TRAIN ? 1 : this->hscroll.cap) << MAT_COL_START); // number of boxes in each row. Trains always have just one
 
 
 		this->SetWidgetsHiddenState(type != VEH_TRAIN,
@@ -1001,7 +1001,7 @@
 	{
 		this->vscroll.cap += delta.y / (int)this->resize.step_height;
 		this->hscroll.cap += delta.x / (int)this->resize.step_width;
-		this->widget[DEPOT_WIDGET_MATRIX].data = (this->vscroll.cap << 8) + (this->type == VEH_TRAIN ? 1 : this->hscroll.cap);
+		this->widget[DEPOT_WIDGET_MATRIX].data = (this->vscroll.cap << MAT_ROW_START) + ((this->type == VEH_TRAIN ? 1 : this->hscroll.cap) << MAT_COL_START);
 		ResizeDepotButtons(this);
 	}
 
--- a/src/group_gui.cpp
+++ b/src/group_gui.cpp
@@ -241,8 +241,8 @@
 				break;
 		}
 
-		this->widget[GRP_WIDGET_LIST_GROUP].data = (this->vscroll2.cap << 8) + 1;
-		this->widget[GRP_WIDGET_LIST_VEHICLE].data = (this->vscroll.cap << 8) + 1;
+		this->widget[GRP_WIDGET_LIST_GROUP].data = (this->vscroll2.cap << MAT_ROW_START) + (1 << MAT_COL_START);
+		this->widget[GRP_WIDGET_LIST_VEHICLE].data = (this->vscroll.cap << MAT_ROW_START) + (1 << MAT_COL_START);
 
 		switch (this->vehicle_type) {
 			default: NOT_REACHED();
@@ -671,8 +671,8 @@
 		this->vscroll2.cap += delta.y / PLY_WND_PRC__SIZE_OF_ROW_TINY;
 		this->vscroll.cap += delta.y / (int)this->resize.step_height;
 
-		this->widget[GRP_WIDGET_LIST_GROUP].data = (this->vscroll2.cap << 8) + 1;
-		this->widget[GRP_WIDGET_LIST_VEHICLE].data = (this->vscroll.cap << 8) + 1;
+		this->widget[GRP_WIDGET_LIST_GROUP].data = (this->vscroll2.cap << MAT_ROW_START) + (1 << MAT_COL_START);
+		this->widget[GRP_WIDGET_LIST_VEHICLE].data = (this->vscroll.cap << MAT_ROW_START) + (1 << MAT_COL_START);
 	}
 
 	virtual void OnDropdownSelect(int widget, int index)
--- a/src/industry_gui.cpp
+++ b/src/industry_gui.cpp
@@ -356,7 +356,7 @@
 	{
 		/* Adjust the number of items in the matrix depending of the rezise */
 		this->vscroll.cap  += delta.y / (int)this->resize.step_height;
-		this->widget[DPIW_MATRIX_WIDGET].data = (this->vscroll.cap << 8) + 1;
+		this->widget[DPIW_MATRIX_WIDGET].data = (this->vscroll.cap << MAT_ROW_START) + (1 << MAT_COL_START);
 	}
 
 	virtual void OnPlaceObject(Point pt, TileIndex tile)
--- a/src/network/network_content_gui.cpp
+++ b/src/network/network_content_gui.cpp
@@ -693,7 +693,7 @@
 	{
 		this->vscroll.cap += delta.y / (int)this->resize.step_height;
 
-		this->widget[NCLWW_MATRIX].data = (this->vscroll.cap << 8) + 1;
+		this->widget[NCLWW_MATRIX].data = (this->vscroll.cap << MAT_ROW_START) + (1 << MAT_COL_START);
 
 		SetVScrollCount(this, this->content.Length());
 
--- a/src/network/network_gui.cpp
+++ b/src/network/network_gui.cpp
@@ -722,7 +722,7 @@
 	{
 		this->vscroll.cap += delta.y / (int)this->resize.step_height;
 
-		this->widget[NGWW_MATRIX].data = (this->vscroll.cap << 8) + 1;
+		this->widget[NGWW_MATRIX].data = (this->vscroll.cap << MAT_ROW_START) + (1 << MAT_COL_START);
 
 		SetVScrollCount(this, this->servers.Length());
 
--- a/src/newgrf_gui.cpp
+++ b/src/newgrf_gui.cpp
@@ -705,7 +705,7 @@
 		}
 
 		this->vscroll.cap += delta.y / 14;
-		this->widget[SNGRFS_FILE_LIST].data = (this->vscroll.cap << 8) + 1;
+		this->widget[SNGRFS_FILE_LIST].data = (this->vscroll.cap << MAT_ROW_START) + (1 << MAT_COL_START);
 
 		this->SetupNewGRFWindow();
 	}
--- a/src/vehicle_gui.cpp
+++ b/src/vehicle_gui.cpp
@@ -414,7 +414,7 @@
 	virtual void OnResize(Point delta)
 	{
 		this->vscroll.cap += delta.y / (int)this->resize.step_height;
-		this->widget[VRW_MATRIX].data = (this->vscroll.cap << 8) + 1;
+		this->widget[VRW_MATRIX].data = (this->vscroll.cap << MAT_ROW_START) + (1 << MAT_COL_START);
 	}
 };
 
@@ -967,7 +967,7 @@
 		}
 
 
-		this->widget[VLW_WIDGET_LIST].data = (this->vscroll.cap << 8) + 1;
+		this->widget[VLW_WIDGET_LIST].data = (this->vscroll.cap << MAT_ROW_START) + (1 << MAT_COL_START);
 
 		/* Set up sorting. Make the window-specific _sorting variable
 		 * point to the correct global _sorting struct so we are freed
@@ -1184,7 +1184,7 @@
 	virtual void OnResize(Point delta)
 	{
 		this->vscroll.cap += delta.y / (int)this->resize.step_height;
-		this->widget[VLW_WIDGET_LIST].data = (this->vscroll.cap << 8) + 1;
+		this->widget[VLW_WIDGET_LIST].data = (this->vscroll.cap << MAT_ROW_START) + (1 << MAT_COL_START);
 	}
 
 	virtual void OnInvalidateData(int data)
@@ -1399,7 +1399,7 @@
 			this->widget[VLD_WIDGET_MIDDLE_DETAILS].right += 12;
 		}
 
-		this->widget[VLD_WIDGET_MIDDLE_DETAILS].data = (this->vscroll.cap << 8) + 1;
+		this->widget[VLD_WIDGET_MIDDLE_DETAILS].data = (this->vscroll.cap << MAT_ROW_START) + (1 << MAT_COL_START);
 		this->owner = v->owner;
 
 		this->tab = TDW_TAB_CARGO;
@@ -1603,7 +1603,7 @@
 		if (delta.y == 0) return;
 
 		this->vscroll.cap += delta.y / 14;
-		this->widget[VLD_WIDGET_MIDDLE_DETAILS].data = (this->vscroll.cap << 8) + 1;
+		this->widget[VLD_WIDGET_MIDDLE_DETAILS].data = (this->vscroll.cap << MAT_ROW_START) + (1 << MAT_COL_START);
 	}
 };
 
--- a/src/widget.cpp
+++ b/src/widget.cpp
@@ -336,10 +336,10 @@
 {
 	DrawFrameRect(r.left, r.top, r.right, r.bottom, colour, (clicked) ? FR_LOWERED : FR_NONE);
 
-	int num_columns = GB(data, 0, 8);  // Lower 8 bits of the widget data: Number of columns in the matrix.
+	int num_columns = GB(data, MAT_COL_START, MAT_COL_BITS);  // Lower 8 bits of the widget data: Number of columns in the matrix.
 	int column_width = (r.right - r.left + 1) / num_columns; // Width of a single column in the matrix.
 
-	int num_rows = GB(data, 8, 8); // Upper 8 bits of the widget data: Number of rows in the matrix.
+	int num_rows = GB(data, MAT_ROW_START, MAT_ROW_BITS); // Upper 8 bits of the widget data: Number of rows in the matrix.
 	int row_height = (r.bottom - r.top + 1) / num_rows; // Height of a single row in the matrix.
 
 	int col = _colour_gradient[colour & 0xF][6];
--- a/src/widget_type.h
+++ b/src/widget_type.h
@@ -65,6 +65,17 @@
 	WIDGET_LIST_END = -1, ///< indicate the end of widgets' list for vararg functions
 };
 
+/** Bits of the #WWT_MATRIX widget data. */
+enum MatrixWidgetValues {
+	/* Number of column bits of the WWT_MATRIX widget data. */
+	MAT_COL_START = 0, ///< Lowest bit of the number of columns.
+	MAT_COL_BITS  = 8, ///< Number of bits for the number of columns in the matrix.
+
+	/* Number of row bits of the WWT_MATRIX widget data. */
+	MAT_ROW_START = 8, ///< Lowest bit of the number of rows.
+	MAT_ROW_BITS  = 8, ///< Number of bits for the number of rows in the matrix.
+};
+
 /**
  * Window widget types, nested widget types, and nested widget part types.
  */
@@ -81,7 +92,7 @@
 	WWT_TEXTBTN_2,  ///< Button with diff text when clicked
 	WWT_LABEL,      ///< Centered label
 	WWT_TEXT,       ///< Pure simple text
-	WWT_MATRIX,     ///< Grid of rows and columns. Lower 8 bit of the widget data are the number of columns, upper 8 bit are the number of rows.
+	WWT_MATRIX,     ///< Grid of rows and columns. @see MatrixWidgetValues
 	WWT_SCROLLBAR,  ///< Vertical scrollbar
 	WWT_FRAME,      ///< Frame
 	WWT_CAPTION,    ///< Window caption (window title between closebox and stickybox)