changeset 13606:970b84e754e3 draft

(svn r18130) -Codechange: initial steps into making the vehicle/group lists big font and RTL aware
author rubidium <rubidium@openttd.org>
date Mon, 16 Nov 2009 21:28:12 +0000
parents 1cb90620906a
children f3a701fc6824
files src/group_gui.cpp src/vehicle_gui.cpp src/vehicle_gui_base.h src/window.cpp
diffstat 4 files changed, 62 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/src/group_gui.cpp
+++ b/src/group_gui.cpp
@@ -104,9 +104,9 @@
 			NWidget(WWT_PANEL, COLOUR_GREY, GRP_WIDGET_ALL_VEHICLES), SetMinimalSize(200, 13), EndContainer(),
 			NWidget(WWT_PANEL, COLOUR_GREY, GRP_WIDGET_DEFAULT_VEHICLES), SetMinimalSize(200, 13), EndContainer(),
 			NWidget(NWID_HORIZONTAL),
-				NWidget(WWT_MATRIX, COLOUR_GREY, GRP_WIDGET_LIST_GROUP), SetMinimalSize(188, 117), SetDataTip(0x701, STR_GROUPS_CLICK_ON_GROUP_FOR_TOOLTIP),
+				NWidget(WWT_MATRIX, COLOUR_GREY, GRP_WIDGET_LIST_GROUP), SetMinimalSize(188, 0), SetDataTip(0x701, STR_GROUPS_CLICK_ON_GROUP_FOR_TOOLTIP),
 						SetFill(true, false), SetResize(0, 1),
-				NWidget(WWT_SCROLL2BAR, COLOUR_GREY, GRP_WIDGET_LIST_GROUP_SCROLLBAR), SetMinimalSize(12, 117),
+				NWidget(WWT_SCROLL2BAR, COLOUR_GREY, GRP_WIDGET_LIST_GROUP_SCROLLBAR), SetMinimalSize(12, 0),
 			EndContainer(),
 			NWidget(NWID_HORIZONTAL),
 				NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, GRP_WIDGET_CREATE_GROUP), SetMinimalSize(24, 25), SetFill(false, true),
@@ -129,8 +129,8 @@
 				NWidget(WWT_PANEL, COLOUR_GREY, GRP_WIDGET_EMPTY_TOP_RIGHT), SetMinimalSize(12, 12), SetResize(1, 0), EndContainer(),
 			EndContainer(),
 			NWidget(NWID_HORIZONTAL),
-				NWidget(WWT_MATRIX, COLOUR_GREY, GRP_WIDGET_LIST_VEHICLE), SetMinimalSize(248, 156), SetDataTip(0x701, STR_NULL), SetResize(1, 1), SetFill(true, false),
-				NWidget(WWT_SCROLLBAR, COLOUR_GREY, GRP_WIDGET_LIST_VEHICLE_SCROLLBAR), SetMinimalSize(12, 156),
+				NWidget(WWT_MATRIX, COLOUR_GREY, GRP_WIDGET_LIST_VEHICLE), SetMinimalSize(248, 0), SetDataTip(0x701, STR_NULL), SetResize(1, 1), SetFill(true, false),
+				NWidget(WWT_SCROLLBAR, COLOUR_GREY, GRP_WIDGET_LIST_VEHICLE_SCROLLBAR), SetMinimalSize(12, 0),
 			EndContainer(),
 			NWidget(NWID_HORIZONTAL),
 				NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, GRP_WIDGET_AVAILABLE_VEHICLES), SetMinimalSize(106, 12), SetFill(false, true),
@@ -154,6 +154,7 @@
 	VehicleID vehicle_sel; ///< Selected vehicle
 	GroupID group_rename;  ///< Group being renamed, INVALID_GROUP if none
 	GUIGroupList groups;   ///< List of groups
+	uint tiny_step_height; ///< Step height for the group list
 
 	/**
 	 * (Re)Build the group list.
@@ -252,13 +253,20 @@
 	{
 		switch (widget) {
 			case GRP_WIDGET_LIST_GROUP:
-				resize->height = PLY_WND_PRC__SIZE_OF_ROW_TINY;
-				size->height = this->vscroll2.GetCapacity() * resize->height;
+				this->tiny_step_height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP;
+				resize->height = this->tiny_step_height;
+				/* Minimum height is the height of the list widget minus all and default vehicles and a bit for the bottom bar */
+				size->height =  4 * GetVehicleListHeight(this->vehicle_type, this->tiny_step_height) - 3 * this->tiny_step_height;
+				break;
+
+			case GRP_WIDGET_ALL_VEHICLES:
+			case GRP_WIDGET_DEFAULT_VEHICLES:
+				size->height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP;
 				break;
 
 			case GRP_WIDGET_LIST_VEHICLE:
-				resize->height = (this->vehicle_type == VEH_TRAIN || this->vehicle_type == VEH_ROAD) ? PLY_WND_PRC__SIZE_OF_ROW_SMALL : PLY_WND_PRC__SIZE_OF_ROW_BIG;
-				size->height = this->vscroll.GetCapacity() * resize->height;
+				resize->height = GetVehicleListHeight(this->vehicle_type, FONT_HEIGHT_NORMAL + WD_MATRIX_TOP);
+				size->height = 4 * resize->height;
 				break;
 		}
 	}
@@ -392,7 +400,7 @@
 					SetDParam(0, g->num_vehicle);
 					DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y1 + 1, STR_TINY_COMMA, (this->group_sel == g->index) ? TC_WHITE : TC_BLACK, SA_RIGHT);
 
-					y1 += PLY_WND_PRC__SIZE_OF_ROW_TINY;
+					y1 += this->tiny_step_height;
 				}
 				break;
 			}
@@ -436,7 +444,7 @@
 				break;
 
 			case GRP_WIDGET_LIST_GROUP: { // Matrix Group
-				uint16 id_g = (pt.y - this->GetWidget<NWidgetBase>(GRP_WIDGET_LIST_GROUP)->pos_y) / PLY_WND_PRC__SIZE_OF_ROW_TINY;
+				uint16 id_g = (pt.y - this->GetWidget<NWidgetBase>(GRP_WIDGET_LIST_GROUP)->pos_y) / (int)this->tiny_step_height;
 
 				if (id_g >= this->vscroll2.GetCapacity()) return;
 
@@ -529,7 +537,7 @@
 				break;
 
 			case GRP_WIDGET_LIST_GROUP: { // Maxtrix group
-				uint16 id_g = (pt.y - this->GetWidget<NWidgetBase>(GRP_WIDGET_LIST_GROUP)->pos_y) / PLY_WND_PRC__SIZE_OF_ROW_TINY;
+				uint16 id_g = (pt.y - this->GetWidget<NWidgetBase>(GRP_WIDGET_LIST_GROUP)->pos_y) / (int)this->tiny_step_height;
 				const VehicleID vindex = this->vehicle_sel;
 
 				this->vehicle_sel = INVALID_VEHICLE;
@@ -579,7 +587,7 @@
 	virtual void OnResize()
 	{
 		NWidgetCore *nwi = this->GetWidget<NWidgetCore>(GRP_WIDGET_LIST_GROUP);
-		this->vscroll2.SetCapacity(nwi->current_y / PLY_WND_PRC__SIZE_OF_ROW_TINY);
+		this->vscroll2.SetCapacity(nwi->current_y / this->tiny_step_height);
 		nwi->widget_data = (this->vscroll2.GetCapacity() << MAT_ROW_START) + (1 << MAT_COL_START);
 
 		nwi = this->GetWidget<NWidgetCore>(GRP_WIDGET_LIST_VEHICLE);
--- a/src/vehicle_gui.cpp
+++ b/src/vehicle_gui.cpp
@@ -723,8 +723,8 @@
 	EndContainer(),
 
 	NWidget(NWID_HORIZONTAL),
-		NWidget(WWT_MATRIX, COLOUR_GREY, VLW_WIDGET_LIST), SetMinimalSize(248, 156), SetResize(1,1), // vertical resize step size will be modified
-		NWidget(WWT_SCROLLBAR, COLOUR_GREY, VLW_WIDGET_SCROLLBAR), SetMinimalSize(12, 156),
+		NWidget(WWT_MATRIX, COLOUR_GREY, VLW_WIDGET_LIST), SetMinimalSize(248, 0), SetResize(1,1), // vertical resize step size will be modified
+		NWidget(WWT_SCROLLBAR, COLOUR_GREY, VLW_WIDGET_SCROLLBAR), SetMinimalSize(12, 0),
 	EndContainer(),
 
 	NWidget(NWID_HORIZONTAL),
@@ -789,6 +789,22 @@
 }
 
 /**
+ * Get the height of a vehicle in the vehicle list GUIs.
+ * @param type    the vehicle type to look at
+ * @param divisor the resulting height must be dividable by this
+ * @return the height
+ */
+uint GetVehicleListHeight(VehicleType type, uint divisor)
+{
+	uint base = GetVehicleHeight(type) + 2 * FONT_HEIGHT_SMALL;
+	if (divisor == 1) return base;
+
+	/* Make sure the height is dividable by divisor */
+	uint rem = base % divisor;
+	return base + (rem == 0 ? 0 : divisor - rem);
+}
+
+/**
  * Draw all the vehicle list items.
  * @param selected_vehicle The vehicle that is to be highlighted.
  * @param line_height      Height of a single item line.
@@ -798,6 +814,16 @@
 {
 	int left = r.left + WD_MATRIX_LEFT;
 	int right = r.right - WD_MATRIX_RIGHT;
+	bool rtl = _dynlang.text_dir == TD_RTL;
+
+	int text_left  = left  + (rtl ?  0 : 19);
+	int text_right = right - (rtl ? 19 :  0);
+
+	int orderlist_left  = left  + (rtl ?   0 : 138);
+	int orderlist_right = right - (rtl ? 138 :   0);
+
+	int vehicle_button_x = rtl ? right - 8 : left;
+
 	int y = r.top;
 	uint max = min(this->vscroll.GetPosition() + this->vscroll.GetCapacity(), this->vehicles.Length());
 	for (uint i = this->vscroll.GetPosition(); i < max; ++i) {
@@ -807,20 +833,20 @@
 		SetDParam(0, v->GetDisplayProfitThisYear());
 		SetDParam(1, v->GetDisplayProfitLastYear());
 
-		DrawVehicleImage(v, left + 19, y + 5, selected_vehicle, right - left + 1 - 19, 0);
-		DrawString(left + 19, right, y + line_height - 8, STR_VEHICLE_LIST_PROFIT_THIS_YEAR_LAST_YEAR);
+		DrawVehicleImage(v, text_left, y + FONT_HEIGHT_SMALL - 1, selected_vehicle, text_right - text_left + 1, 0);
+		DrawString(text_left, text_right, y + line_height - FONT_HEIGHT_SMALL - WD_FRAMERECT_BOTTOM - 1, STR_VEHICLE_LIST_PROFIT_THIS_YEAR_LAST_YEAR);
 
 		if (v->name != NULL) {
 			/* The vehicle got a name so we will print it */
 			SetDParam(0, v->index);
-			DrawString(left + 19, right, y, STR_TINY_BLACK_VEHICLE);
+			DrawString(text_left, text_right, y, STR_TINY_BLACK_VEHICLE);
 		} else if (v->group_id != DEFAULT_GROUP) {
 			/* The vehicle has no name, but is member of a group, so print group name */
 			SetDParam(0, v->group_id);
-			DrawString(left + 19, right, y, STR_TINY_GROUP, TC_BLACK);
+			DrawString(text_left, text_right, y, STR_TINY_GROUP, TC_BLACK);
 		}
 
-		if (line_height == PLY_WND_PRC__SIZE_OF_ROW_BIG) DrawSmallOrderList(v, left + 138, right, y);
+		if (vehicle_type >= VEH_SHIP) DrawSmallOrderList(v, orderlist_left, orderlist_right, y);
 
 		if (v->IsInDepot()) {
 			str = STR_BLUE_COMMA;
@@ -831,7 +857,7 @@
 		SetDParam(0, v->unitnumber);
 		DrawString(left, right, y + 2, str);
 
-		DrawVehicleProfitButton(v, left, y + 13);
+		DrawVehicleProfitButton(v, vehicle_button_x, y + FONT_HEIGHT_NORMAL + 3);
 
 		y += line_height;
 	}
@@ -907,17 +933,17 @@
 		if (widget != VLW_WIDGET_LIST) return;
 
 		resize->width = 0;
+		resize->height = GetVehicleListHeight(this->vehicle_type, 1);
+
 		switch (this->vehicle_type) {
 			case VEH_TRAIN:
 				resize->width = 1;
 				/* Fallthrough */
 			case VEH_ROAD:
-				resize->height = PLY_WND_PRC__SIZE_OF_ROW_SMALL;
 				size->height = 6 * resize->height;
 				break;
 			case VEH_SHIP:
 			case VEH_AIRCRAFT:
-				resize->height = PLY_WND_PRC__SIZE_OF_ROW_BIG;
 				size->height = 4 * resize->height;
 				break;
 			default: NOT_REACHED();
--- a/src/vehicle_gui_base.h
+++ b/src/vehicle_gui_base.h
@@ -14,13 +14,6 @@
 
 #include "sortlist_type.h"
 
-/** Start of functions regarding vehicle list windows */
-enum {
-	PLY_WND_PRC__SIZE_OF_ROW_TINY  = 13,  ///< Height of rows in group list
-	PLY_WND_PRC__SIZE_OF_ROW_SMALL = 26,  ///< Height of rows in train/roadvehicle list
-	PLY_WND_PRC__SIZE_OF_ROW_BIG   = 39,  ///< Height of rows in ship/aircraft list
-};
-
 typedef GUIList<const Vehicle*> GUIVehicleList;
 
 struct BaseVehicleListWindow: public Window {
@@ -41,6 +34,8 @@
 	void BuildVehicleList(Owner owner, uint16 index, uint16 window_type);
 };
 
+uint GetVehicleListHeight(VehicleType type, uint divisor = 1);
+
 struct Sorting {
 	Listing aircraft;
 	Listing roadveh;
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -29,6 +29,7 @@
 #include "network/network.h"
 #include "querystring_gui.h"
 #include "widgets/dropdown_func.h"
+#include "strings_func.h"
 
 #include "table/sprites.h"
 
@@ -499,7 +500,7 @@
 
 	/* Re-initialize the window from the ground up. No need to change the nested_array, as all widgets stay where they are. */
 	this->nested_root->SetupSmallestSize(this, false);
-	this->nested_root->AssignSizePosition(ST_SMALLEST, 0, 0, this->nested_root->smallest_x, this->nested_root->smallest_y, false, false, false);
+	this->nested_root->AssignSizePosition(ST_SMALLEST, 0, 0, this->nested_root->smallest_x, this->nested_root->smallest_y, false, false, _dynlang.text_dir == TD_RTL);
 	this->width  = this->nested_root->smallest_x;
 	this->height = this->nested_root->smallest_y;
 	this->resize.width  = this->nested_root->smallest_x;
@@ -785,7 +786,7 @@
 		this->nested_root->SetupSmallestSize(this, false);
 	}
 	/* Initialize to smallest size. */
-	this->nested_root->AssignSizePosition(ST_SMALLEST, 0, 0, this->nested_root->smallest_x, this->nested_root->smallest_y, false, false, false);
+	this->nested_root->AssignSizePosition(ST_SMALLEST, 0, 0, this->nested_root->smallest_x, this->nested_root->smallest_y, false, false, _dynlang.text_dir == TD_RTL);
 
 	/* Further set up window properties,
 	 * this->left, this->top, this->width, this->height, this->resize.width, and this->resize.height are initialized later. */
@@ -1358,7 +1359,7 @@
 	assert(w->nested_root->resize_x == 0 || new_xinc % w->nested_root->resize_x == 0);
 	assert(w->nested_root->resize_y == 0 || new_yinc % w->nested_root->resize_y == 0);
 
-	w->nested_root->AssignSizePosition(ST_RESIZE, 0, 0, w->nested_root->smallest_x + new_xinc, w->nested_root->smallest_y + new_yinc, false, false, false);
+	w->nested_root->AssignSizePosition(ST_RESIZE, 0, 0, w->nested_root->smallest_x + new_xinc, w->nested_root->smallest_y + new_yinc, false, false, _dynlang.text_dir == TD_RTL);
 	w->width  = w->nested_root->current_x;
 	w->height = w->nested_root->current_y;
 	w->SetDirty();