mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-09 15:41:15 +00:00
(svn r15800) -Codechange: make the engine gui use the new multiline API.
This commit is contained in:
parent
3abddfe705
commit
a07fae67c3
@ -49,17 +49,17 @@ static const Widget _engine_preview_widgets[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
typedef void DrawEngineProc(int x, int y, EngineID engine, SpriteID pal);
|
typedef void DrawEngineProc(int x, int y, EngineID engine, SpriteID pal);
|
||||||
typedef void DrawEngineInfoProc(EngineID, int x, int y, int maxw);
|
typedef void DrawEngineInfoProc(EngineID, int left, int right, int top, int bottom);
|
||||||
|
|
||||||
struct DrawEngineInfo {
|
struct DrawEngineInfo {
|
||||||
DrawEngineProc *engine_proc;
|
DrawEngineProc *engine_proc;
|
||||||
DrawEngineInfoProc *info_proc;
|
DrawEngineInfoProc *info_proc;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void DrawTrainEngineInfo(EngineID engine, int x, int y, int maxw);
|
static void DrawTrainEngineInfo(EngineID engine, int left, int right, int top, int bottom);
|
||||||
static void DrawRoadVehEngineInfo(EngineID engine, int x, int y, int maxw);
|
static void DrawRoadVehEngineInfo(EngineID engine, int left, int right, int top, int bottom);
|
||||||
static void DrawShipEngineInfo(EngineID engine, int x, int y, int maxw);
|
static void DrawShipEngineInfo(EngineID engine, int left, int right, int top, int bottom);
|
||||||
static void DrawAircraftEngineInfo(EngineID engine, int x, int y, int maxw);
|
static void DrawAircraftEngineInfo(EngineID engine, int left, int right, int top, int bottom);
|
||||||
|
|
||||||
static const DrawEngineInfo _draw_engine_list[4] = {
|
static const DrawEngineInfo _draw_engine_list[4] = {
|
||||||
{ DrawTrainEngine, DrawTrainEngineInfo },
|
{ DrawTrainEngine, DrawTrainEngineInfo },
|
||||||
@ -80,7 +80,7 @@ struct EnginePreviewWindow : Window {
|
|||||||
|
|
||||||
EngineID engine = this->window_number;
|
EngineID engine = this->window_number;
|
||||||
SetDParam(0, GetEngineCategoryName(engine));
|
SetDParam(0, GetEngineCategoryName(engine));
|
||||||
DrawStringMultiCenter(150, 44, STR_8101_WE_HAVE_JUST_DESIGNED_A, 296);
|
DrawStringMultiLine(this->widget[EPW_BACKGROUND].left + 2, this->widget[EPW_BACKGROUND].right - 2, 14, 74, STR_8101_WE_HAVE_JUST_DESIGNED_A, SA_CENTER);
|
||||||
|
|
||||||
SetDParam(0, engine);
|
SetDParam(0, engine);
|
||||||
DrawString(this->widget[EPW_BACKGROUND].left + 2, this->widget[EPW_BACKGROUND].right - 2, 80, STR_ENGINE_NAME, TC_BLACK, SA_CENTER);
|
DrawString(this->widget[EPW_BACKGROUND].left + 2, this->widget[EPW_BACKGROUND].right - 2, 80, STR_ENGINE_NAME, TC_BLACK, SA_CENTER);
|
||||||
@ -89,7 +89,7 @@ struct EnginePreviewWindow : Window {
|
|||||||
|
|
||||||
int width = this->width;
|
int width = this->width;
|
||||||
dei->engine_proc(width >> 1, 100, engine, 0);
|
dei->engine_proc(width >> 1, 100, engine, 0);
|
||||||
dei->info_proc(engine, width >> 1, 130, width - 52);
|
dei->info_proc(engine, this->widget[EPW_BACKGROUND].left + 26, this->widget[EPW_BACKGROUND].right - 26, 100, 160);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void OnClick(Point pt, int widget)
|
virtual void OnClick(Point pt, int widget)
|
||||||
@ -130,7 +130,7 @@ uint GetTotalCapacityOfArticulatedParts(EngineID engine, VehicleType type)
|
|||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DrawTrainEngineInfo(EngineID engine, int x, int y, int maxw)
|
static void DrawTrainEngineInfo(EngineID engine, int left, int right, int top, int bottom)
|
||||||
{
|
{
|
||||||
const Engine *e = GetEngine(engine);
|
const Engine *e = GetEngine(engine);
|
||||||
|
|
||||||
@ -148,10 +148,10 @@ static void DrawTrainEngineInfo(EngineID engine, int x, int y, int maxw)
|
|||||||
} else {
|
} else {
|
||||||
SetDParam(5, CT_INVALID);
|
SetDParam(5, CT_INVALID);
|
||||||
}
|
}
|
||||||
DrawStringMultiCenter(x, y, STR_VEHICLE_INFO_COST_WEIGHT_SPEED_POWER, maxw);
|
DrawStringMultiLine(left, right, top, bottom, STR_VEHICLE_INFO_COST_WEIGHT_SPEED_POWER, SA_CENTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DrawAircraftEngineInfo(EngineID engine, int x, int y, int maxw)
|
static void DrawAircraftEngineInfo(EngineID engine, int left, int right, int top, int bottom)
|
||||||
{
|
{
|
||||||
const Engine *e = GetEngine(engine);
|
const Engine *e = GetEngine(engine);
|
||||||
CargoID cargo = e->GetDefaultCargoType();
|
CargoID cargo = e->GetDefaultCargoType();
|
||||||
@ -163,7 +163,7 @@ static void DrawAircraftEngineInfo(EngineID engine, int x, int y, int maxw)
|
|||||||
SetDParam(3, e->u.air.mail_capacity);
|
SetDParam(3, e->u.air.mail_capacity);
|
||||||
SetDParam(4, e->GetRunningCost());
|
SetDParam(4, e->GetRunningCost());
|
||||||
|
|
||||||
DrawStringMultiCenter(x, y, STR_A02E_COST_MAX_SPEED_CAPACITY, maxw);
|
DrawStringMultiLine(left, right, top, bottom, STR_A02E_COST_MAX_SPEED_CAPACITY, SA_CENTER);
|
||||||
} else {
|
} else {
|
||||||
SetDParam(0, e->GetCost());
|
SetDParam(0, e->GetCost());
|
||||||
SetDParam(1, e->GetDisplayMaxSpeed());
|
SetDParam(1, e->GetDisplayMaxSpeed());
|
||||||
@ -171,11 +171,11 @@ static void DrawAircraftEngineInfo(EngineID engine, int x, int y, int maxw)
|
|||||||
SetDParam(3, e->GetDisplayDefaultCapacity());
|
SetDParam(3, e->GetDisplayDefaultCapacity());
|
||||||
SetDParam(4, e->GetRunningCost());
|
SetDParam(4, e->GetRunningCost());
|
||||||
|
|
||||||
DrawStringMultiCenter(x, y, STR_982E_COST_MAX_SPEED_CAPACITY, maxw);
|
DrawStringMultiLine(left, right, top, bottom, STR_982E_COST_MAX_SPEED_CAPACITY, SA_CENTER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DrawRoadVehEngineInfo(EngineID engine, int x, int y, int maxw)
|
static void DrawRoadVehEngineInfo(EngineID engine, int left, int right, int top, int bottom)
|
||||||
{
|
{
|
||||||
const Engine *e = GetEngine(engine);
|
const Engine *e = GetEngine(engine);
|
||||||
|
|
||||||
@ -190,10 +190,10 @@ static void DrawRoadVehEngineInfo(EngineID engine, int x, int y, int maxw)
|
|||||||
SetDParam(3, CT_INVALID);
|
SetDParam(3, CT_INVALID);
|
||||||
}
|
}
|
||||||
|
|
||||||
DrawStringMultiCenter(x, y, STR_902A_COST_SPEED_RUNNING_COST, maxw);
|
DrawStringMultiLine(left, right, top, bottom, STR_902A_COST_SPEED_RUNNING_COST, SA_CENTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void DrawShipEngineInfo(EngineID engine, int x, int y, int maxw)
|
static void DrawShipEngineInfo(EngineID engine, int left, int right, int top, int bottom)
|
||||||
{
|
{
|
||||||
const Engine *e = GetEngine(engine);
|
const Engine *e = GetEngine(engine);
|
||||||
|
|
||||||
@ -202,7 +202,7 @@ static void DrawShipEngineInfo(EngineID engine, int x, int y, int maxw)
|
|||||||
SetDParam(2, e->GetDefaultCargoType());
|
SetDParam(2, e->GetDefaultCargoType());
|
||||||
SetDParam(3, e->GetDisplayDefaultCapacity());
|
SetDParam(3, e->GetDisplayDefaultCapacity());
|
||||||
SetDParam(4, e->GetRunningCost());
|
SetDParam(4, e->GetRunningCost());
|
||||||
DrawStringMultiCenter(x, y, STR_982E_COST_MAX_SPEED_CAPACITY, maxw);
|
DrawStringMultiLine(left, right, top, bottom, STR_982E_COST_MAX_SPEED_CAPACITY, SA_CENTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawNewsNewVehicleAvail(Window *w, const NewsItem *ni)
|
void DrawNewsNewVehicleAvail(Window *w, const NewsItem *ni)
|
||||||
@ -211,16 +211,16 @@ void DrawNewsNewVehicleAvail(Window *w, const NewsItem *ni)
|
|||||||
const DrawEngineInfo *dei = &_draw_engine_list[GetEngine(engine)->type];
|
const DrawEngineInfo *dei = &_draw_engine_list[GetEngine(engine)->type];
|
||||||
|
|
||||||
SetDParam(0, GetEngineCategoryName(engine));
|
SetDParam(0, GetEngineCategoryName(engine));
|
||||||
DrawStringMultiCenter(w->width >> 1, 20, STR_NEW_VEHICLE_NOW_AVAILABLE, w->width - 2);
|
DrawStringMultiLine(1, w->width - 2, 0, 40, STR_NEW_VEHICLE_NOW_AVAILABLE, SA_CENTER);
|
||||||
|
|
||||||
GfxFillRect(25, 56, w->width - 25, w->height - 2, 10);
|
GfxFillRect(25, 56, w->width - 25, w->height - 2, 10);
|
||||||
|
|
||||||
SetDParam(0, engine);
|
SetDParam(0, engine);
|
||||||
DrawStringMultiCenter(w->width >> 1, 57, STR_NEW_VEHICLE_TYPE, w->width - 2);
|
DrawStringMultiLine(1, w->width - 2, 40, 74, STR_NEW_VEHICLE_TYPE, SA_CENTER);
|
||||||
|
|
||||||
dei->engine_proc(w->width >> 1, 88, engine, 0);
|
dei->engine_proc(w->width >> 1, 88, engine, 0);
|
||||||
GfxFillRect(25, 56, w->width - 56, 112, PALETTE_TO_STRUCT_GREY, FILLRECT_RECOLOUR);
|
GfxFillRect(25, 56, w->width - 56, 112, PALETTE_TO_STRUCT_GREY, FILLRECT_RECOLOUR);
|
||||||
dei->info_proc(engine, w->width >> 1, 129, w->width - 52);
|
dei->info_proc(engine, 26, w->width - 26, 100, 160);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -637,7 +637,7 @@ int DrawStringMultiLine(int left, int right, int top, int bottom, StringID str,
|
|||||||
total_height = (num + 1) * mt;
|
total_height = (num + 1) * mt;
|
||||||
}
|
}
|
||||||
|
|
||||||
int y = top;
|
int y = (align == SA_CENTER) ? (bottom + top - num * mt) / 2 : top;
|
||||||
const char *src = buffer;
|
const char *src = buffer;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
@ -652,7 +652,7 @@ int DrawStringMultiLine(int left, int right, int top, int bottom, StringID str,
|
|||||||
y += mt;
|
y += mt;
|
||||||
if (--num < 0) {
|
if (--num < 0) {
|
||||||
_cur_fontsize = FS_NORMAL;
|
_cur_fontsize = FS_NORMAL;
|
||||||
return top + total_height;
|
return y + mt;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
} else if (c == SCC_SETX) {
|
} else if (c == SCC_SETX) {
|
||||||
@ -671,7 +671,7 @@ int DrawStringMultiLine(int left, int right, int top, int bottom, StringID str,
|
|||||||
* @param maxw Maximum width the string can have before it is wrapped */
|
* @param maxw Maximum width the string can have before it is wrapped */
|
||||||
void DrawStringMultiCenter(int x, int y, StringID str, int maxw)
|
void DrawStringMultiCenter(int x, int y, StringID str, int maxw)
|
||||||
{
|
{
|
||||||
DrawStringMultiLine(x - maxw / 2, x + maxw / 2, y, INT32_MAX, str, SA_CENTER);
|
DrawStringMultiLine(x - maxw / 2, x + maxw / 2, y - 1024, y + 1024, str, SA_CENTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Return the string dimension in pixels. The height and width are returned
|
/** Return the string dimension in pixels. The height and width are returned
|
||||||
|
Loading…
Reference in New Issue
Block a user