Changeset - r13611:2261669e23c7
[Not reviewed]
master
0 2 0
rubidium - 15 years ago 2009-11-17 16:03:51
rubidium@openttd.org
(svn r18145) -Codechange: pass the 'proper' left and right values to DrawVehicleInDepot
2 files changed with 20 insertions and 14 deletions:
0 comments (0 inline, 0 general)
src/depot_gui.cpp
Show inline comments
 
@@ -244,38 +244,38 @@ struct DepotWindow : Window {
 
	{
 
		DeleteWindowById(WC_BUILD_VEHICLE, this->window_number);
 
	}
 

	
 
	/** Draw a vehicle in the depot window in the box with the top left corner at x,y.
 
	 * @param v     Vehicle to draw.
 
	 * @param x     Left side of the box to draw in.
 
	 * @param left  Left side of the box to draw in.
 
	 * @param right Right side of the box to draw in.
 
	 * @param y     Top of the box to draw in.
 
	 * @param left  Left edge of the widget.
 
	 * @param right Right edge of the widget.
 
	 */
 
	void DrawVehicleInDepot(const Vehicle *v, int x, int y, int left, int right) const
 
	void DrawVehicleInDepot(const Vehicle *v, int left, int right, int y) const
 
	{
 
		bool free_wagon = false;
 
		int sprite_y = y + this->resize.step_height - GetVehicleHeight(v->type);
 
		int x = left + 2;
 

	
 
		switch (v->type) {
 
			case VEH_TRAIN: {
 
				const Train *u = Train::From(v);
 
				free_wagon = u->IsFreeWagon();
 

	
 
				uint x_space = free_wagon ? TRAININFO_DEFAULT_VEHICLE_WIDTH : 0;
 
				DrawTrainImage(u, x + 24 + x_space, x + 24 + this->hscroll.GetCapacity() - 1, sprite_y - 1, this->sel, this->hscroll.GetPosition());
 
				DrawTrainImage(u, x + 24 + x_space, right - 10, sprite_y - 1, this->sel, this->hscroll.GetPosition());
 

	
 
				/* Number of wagons relative to a standard length wagon (rounded up) */
 
				SetDParam(0, (u->tcache.cached_total_length + 7) / 8);
 
				DrawString(left, right - 1, y + 4, STR_TINY_BLACK_COMA, TC_FROMSTRING, SA_RIGHT); // Draw the counter
 
				break;
 
			}
 

	
 
			case VEH_ROAD:     DrawRoadVehImage( v, x + 24, x + 24 + ROADVEHINFO_DEFAULT_VEHICLE_WIDTH - 1, sprite_y, this->sel); break;
 
			case VEH_SHIP:     DrawShipImage(    v, x + 19, right, sprite_y - 1, this->sel); break;
 
			case VEH_ROAD:     DrawRoadVehImage( v, x + 24, right, sprite_y, this->sel); break;
 
			case VEH_SHIP:     DrawShipImage(    v, x + 12, right, sprite_y - 1, this->sel); break;
 
			case VEH_AIRCRAFT: {
 
				const Sprite *spr = GetSprite(v->GetImage(DIR_W), ST_NORMAL);
 
				DrawAircraftImage(v, x + 12, right,
 
									y + max(spr->height + spr->y_offs - 14, 0), // tall sprites needs an y offset
 
									this->sel);
 
			} break;
 
@@ -310,27 +310,28 @@ struct DepotWindow : Window {
 
		uint16 mat_data = this->GetWidget<NWidgetCore>(DEPOT_WIDGET_MATRIX)->widget_data;
 
		uint16 rows_in_display   = GB(mat_data, MAT_ROW_START, MAT_ROW_BITS);
 
		uint16 boxes_in_each_row = GB(mat_data, MAT_COL_START, MAT_COL_BITS);
 

	
 
		uint16 num = this->vscroll.GetPosition() * boxes_in_each_row;
 
		int maxval = min(this->vehicle_list.Length(), num + (rows_in_display * boxes_in_each_row));
 
		int x, y;
 
		for (x = r.left + 2, y = r.top + 1; num < maxval; y += this->resize.step_height, x = r.left + 2) { // Draw the rows
 
		int y;
 
		for (y = r.top + 1; num < maxval; y += this->resize.step_height) { // Draw the rows
 
			int x = r.left;
 
			for (byte i = 0; i < boxes_in_each_row && num < maxval; i++, num++, x += this->resize.step_width) {
 
				/* Draw all vehicles in the current row */
 
				const Vehicle *v = this->vehicle_list[num];
 
				this->DrawVehicleInDepot(v, x, y, r.left, r.right);
 
				this->DrawVehicleInDepot(v, x, (boxes_in_each_row == 1) ? r.right : x + this->resize.step_width - 1, y);
 
			}
 
		}
 

	
 
		maxval = min(this->vehicle_list.Length() + this->wagon_list.Length(), (this->vscroll.GetPosition() * boxes_in_each_row) + (rows_in_display * boxes_in_each_row));
 

	
 
		/* draw the train wagons, that do not have an engine in front */
 
		for (; num < maxval; num++, y += 14) {
 
			const Vehicle *v = this->wagon_list[num - this->vehicle_list.Length()];
 
			this->DrawVehicleInDepot(v, x, y, r.left, r.right);
 
			this->DrawVehicleInDepot(v, r.left, r.right, y);
 
		}
 
	}
 

	
 
	void SetStringParameters(int widget) const
 
	{
 
		if (widget != DEPOT_WIDGET_CAPTION) return;
 
@@ -895,15 +896,19 @@ struct DepotWindow : Window {
 
		}
 
	}
 

	
 
	virtual void OnResize()
 
	{
 
		this->vscroll.SetCapacity(this->GetWidget<NWidgetCore>(DEPOT_WIDGET_MATRIX)->current_y / (int)this->resize.step_height);
 
		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->type == VEH_TRAIN ? 1 : this->hscroll.GetCapacity()) << MAT_COL_START);
 
		if (this->type == VEH_TRAIN) {
 
			this->hscroll.SetCapacity(this->GetWidget<NWidgetCore>(DEPOT_WIDGET_MATRIX)->current_x - 36);
 
			this->GetWidget<NWidgetCore>(DEPOT_WIDGET_MATRIX)->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);
 
		}
 
	}
 

	
 
	virtual EventState OnCTRLStateChange()
 
	{
 
		if (this->sel != INVALID_VEHICLE) {
 
			_cursor.vehchain = _ctrl_pressed;
src/roadveh_gui.cpp
Show inline comments
 
@@ -144,12 +144,13 @@ void DrawRoadVehImage(const Vehicle *v, 
 
		int width = u->GetDisplayImageWidth(&offset);
 

	
 
		SpriteID pal = (u->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(u);
 
		DrawSprite(u->GetImage(dir), pal, pos + (rtl ? -offset.x : offset.x), y + 6 + offset.y);
 

	
 
		pos += rtl ? -width : width;
 
		spent_width += max_width;
 
	}
 

	
 
	if (v->index == selection) {
 
		DrawFrameRect((rtl ? pos : left) - 1, y - 1, (rtl ? pos : right) - 1, y + 12, COLOUR_WHITE, FR_BORDERONLY);
 
	}
 
}
0 comments (0 inline, 0 general)