Changeset - r21788:4129b833084f
[Not reviewed]
master
0 1 0
peter1138 - 10 years ago 2014-09-28 09:02:11
peter1138@openttd.org
(svn r26933) -Codechange: Resize engine preview window to fit vehicle sprite.
1 file changed with 24 insertions and 4 deletions:
0 comments (0 inline, 0 general)
src/engine_gui.cpp
Show inline comments
 
@@ -17,12 +17,16 @@
 
#include "engine_gui.h"
 
#include "articulated_vehicles.h"
 
#include "vehicle_func.h"
 
#include "company_func.h"
 
#include "rail.h"
 
#include "settings_type.h"
 
#include "train.h"
 
#include "roadveh.h"
 
#include "ship.h"
 
#include "aircraft.h"
 

	
 
#include "widgets/engine_widget.h"
 

	
 
#include "table/strings.h"
 

	
 
#include "safeguards.h"
 
@@ -58,13 +62,13 @@ static const NWidgetPart _nested_engine_
 
		EndContainer(),
 
		NWidget(NWID_SPACER), SetMinimalSize(0, 8),
 
	EndContainer(),
 
};
 

	
 
struct EnginePreviewWindow : Window {
 
	static const int VEHICLE_SPACE = 40; // The space to show the vehicle image
 
	int vehicle_space = 40; // The space to show the vehicle image
 

	
 
	EnginePreviewWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc)
 
	{
 
		this->InitNested(window_number);
 

	
 
		/* There is no way to recover the window; so disallow closure via DEL; unless SHIFT+DEL */
 
@@ -72,15 +76,31 @@ struct EnginePreviewWindow : Window {
 
	}
 

	
 
	virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
 
	{
 
		if (widget != WID_EP_QUESTION) return;
 

	
 
		/* Get size of engine sprite, on loan from depot_gui.cpp */
 
		EngineID engine = this->window_number;
 
		EngineImageType image_type = EIT_PURCHASE;
 
		uint x, y;
 
		int x_offs, y_offs;
 

	
 
		const Engine *e = Engine::Get(engine);
 
		switch (e->type) {
 
			default: NOT_REACHED();
 
			case VEH_TRAIN:    GetTrainSpriteSize(   engine, x, y, x_offs, y_offs, image_type); break;
 
			case VEH_ROAD:     GetRoadVehSpriteSize( engine, x, y, x_offs, y_offs, image_type); break;
 
			case VEH_SHIP:     GetShipSpriteSize(    engine, x, y, x_offs, y_offs, image_type); break;
 
			case VEH_AIRCRAFT: GetAircraftSpriteSize(engine, x, y, x_offs, y_offs, image_type); break;
 
		}
 
		this->vehicle_space = max<int>(this->vehicle_space, y - y_offs);
 

	
 
		size->width = max(size->width, x - x_offs);
 
		SetDParam(0, GetEngineCategoryName(engine));
 
		size->height = GetStringHeight(STR_ENGINE_PREVIEW_MESSAGE, size->width) + WD_PAR_VSEP_WIDE + FONT_HEIGHT_NORMAL + VEHICLE_SPACE;
 
		size->height = GetStringHeight(STR_ENGINE_PREVIEW_MESSAGE, size->width) + WD_PAR_VSEP_WIDE + FONT_HEIGHT_NORMAL + this->vehicle_space;
 
		SetDParam(0, engine);
 
		size->height += GetStringHeight(GetEngineInfoString(engine), size->width);
 
	}
 

	
 
	virtual void DrawWidget(const Rect &r, int widget) const
 
	{
 
@@ -92,15 +112,15 @@ struct EnginePreviewWindow : Window {
 
		y = DrawStringMultiLine(r.left, r.right, r.top, y, STR_ENGINE_PREVIEW_MESSAGE, TC_FROMSTRING, SA_CENTER) + WD_PAR_VSEP_WIDE;
 

	
 
		SetDParam(0, engine);
 
		DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_ENGINE_NAME, TC_BLACK, SA_HOR_CENTER);
 
		y += FONT_HEIGHT_NORMAL;
 

	
 
		DrawVehicleEngine(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, this->width >> 1, y + VEHICLE_SPACE / 2, engine, GetEnginePalette(engine, _local_company), EIT_PREVIEW);
 
		DrawVehicleEngine(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, this->width >> 1, y + this->vehicle_space / 2, engine, GetEnginePalette(engine, _local_company), EIT_PREVIEW);
 

	
 
		y += VEHICLE_SPACE;
 
		y += this->vehicle_space;
 
		DrawStringMultiLine(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, r.bottom, GetEngineInfoString(engine), TC_FROMSTRING, SA_CENTER);
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget, int click_count)
 
	{
 
		switch (widget) {
0 comments (0 inline, 0 general)