summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralberth <alberth@openttd.org>2009-07-16 16:22:23 +0000
committeralberth <alberth@openttd.org>2009-07-16 16:22:23 +0000
commitd0a47fc1b417d697175b751d3236f66c4e325e91 (patch)
tree13681f47fc388cc4b331c11eca22c08c1b06fe83
parent3cba03c5eb540f3a29aee96a6d8426ab297aed9d (diff)
downloadopenttd-d0a47fc1b417d697175b751d3236f66c4e325e91.tar.xz
(svn r16845) -Codechange: Introduction of constants for describing the bits in a WWT_MATRIX data field.
-rw-r--r--src/ai/ai_gui.cpp11
-rw-r--r--src/autoreplace_gui.cpp4
-rw-r--r--src/bridge_gui.cpp2
-rw-r--r--src/build_vehicle_gui.cpp4
-rw-r--r--src/company_gui.cpp4
-rw-r--r--src/depot_gui.cpp12
-rw-r--r--src/group_gui.cpp8
-rw-r--r--src/industry_gui.cpp2
-rw-r--r--src/network/network_content_gui.cpp2
-rw-r--r--src/network/network_gui.cpp2
-rw-r--r--src/newgrf_gui.cpp2
-rw-r--r--src/vehicle_gui.cpp10
-rw-r--r--src/widget.cpp4
-rw-r--r--src/widget_type.h13
14 files changed, 46 insertions, 34 deletions
diff --git a/src/ai/ai_gui.cpp b/src/ai/ai_gui.cpp
index acfb93e4f..6e1826bef 100644
--- a/src/ai/ai_gui.cpp
+++ b/src/ai/ai_gui.cpp
@@ -53,7 +53,7 @@ struct AIListWindow : public Window {
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 @@ struct AIListWindow : public Window {
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 @@ struct AISettingsWindow : public Window {
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 @@ struct AISettingsWindow : public Window {
}
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 @@ struct AIConfigWindow : public Window {
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 @@ struct AIConfigWindow : public Window {
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()
diff --git a/src/autoreplace_gui.cpp b/src/autoreplace_gui.cpp
index 37ea2c51a..0b78db723 100644
--- a/src/autoreplace_gui.cpp
+++ b/src/autoreplace_gui.cpp
@@ -209,7 +209,7 @@ public:
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 @@ public:
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.
diff --git a/src/bridge_gui.cpp b/src/bridge_gui.cpp
index 8f5a39e2b..acf67083b 100644
--- a/src/bridge_gui.cpp
+++ b/src/bridge_gui.cpp
@@ -226,7 +226,7 @@ public:
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);
diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp
index 6eb77a645..5a8433ffa 100644
--- a/src/build_vehicle_gui.cpp
+++ b/src/build_vehicle_gui.cpp
@@ -790,7 +790,7 @@ struct BuildVehicleWindow : Window {
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 @@ struct BuildVehicleWindow : Window {
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);
}
};
diff --git a/src/company_gui.cpp b/src/company_gui.cpp
index e5d5bf5cc..d4e9fb685 100644
--- a/src/company_gui.cpp
+++ b/src/company_gui.cpp
@@ -642,7 +642,7 @@ public:
}
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 @@ static const NWidgetPart _nested_select_company_livery_widgets [] = {
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[] = {
diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp
index 8c6138c6f..b6d3ec13b 100644
--- a/src/depot_gui.cpp
+++ b/src/depot_gui.cpp
@@ -308,8 +308,8 @@ struct DepotWindow : Window {
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 @@ struct DepotWindow : Window {
{
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 @@ struct DepotWindow : Window {
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 @@ struct DepotWindow : Window {
{
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);
}
diff --git a/src/group_gui.cpp b/src/group_gui.cpp
index bf262b2ab..bb12e240e 100644
--- a/src/group_gui.cpp
+++ b/src/group_gui.cpp
@@ -241,8 +241,8 @@ public:
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 @@ public:
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)
diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp
index f71eabce6..e1c3f586b 100644
--- a/src/industry_gui.cpp
+++ b/src/industry_gui.cpp
@@ -356,7 +356,7 @@ public:
{
/* 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)
diff --git a/src/network/network_content_gui.cpp b/src/network/network_content_gui.cpp
index 652526def..9bcc195f6 100644
--- a/src/network/network_content_gui.cpp
+++ b/src/network/network_content_gui.cpp
@@ -693,7 +693,7 @@ public:
{
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());
diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp
index 46e623f45..9623ac11a 100644
--- a/src/network/network_gui.cpp
+++ b/src/network/network_gui.cpp
@@ -722,7 +722,7 @@ public:
{
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());
diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp
index deeb17f4a..aa7ba6699 100644
--- a/src/newgrf_gui.cpp
+++ b/src/newgrf_gui.cpp
@@ -705,7 +705,7 @@ struct NewGRFWindow : public Window {
}
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();
}
diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp
index a4fcf8811..1fcd3bb5a 100644
--- a/src/vehicle_gui.cpp
+++ b/src/vehicle_gui.cpp
@@ -414,7 +414,7 @@ struct RefitWindow : public Window {
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 @@ struct VehicleListWindow : public BaseVehicleListWindow {
}
- 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 @@ struct VehicleListWindow : public BaseVehicleListWindow {
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 @@ struct VehicleDetailsWindow : Window {
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 @@ struct VehicleDetailsWindow : Window {
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);
}
};
diff --git a/src/widget.cpp b/src/widget.cpp
index b3585a844..652876b2f 100644
--- a/src/widget.cpp
+++ b/src/widget.cpp
@@ -336,10 +336,10 @@ static inline void DrawMatrix(const Rect &r, Colours colour, bool clicked, uint1
{
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];
diff --git a/src/widget_type.h b/src/widget_type.h
index 8a496d9a8..20c89e6e6 100644
--- a/src/widget_type.h
+++ b/src/widget_type.h
@@ -65,6 +65,17 @@ enum {
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 @@ enum WidgetType {
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)