summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-03-22 09:34:06 +0000
committerrubidium <rubidium@openttd.org>2009-03-22 09:34:06 +0000
commite74dc1e1d6dc57b2d6b79ef921888c0204855139 (patch)
tree1266c6a78a4ae2bcbfd356af1e87bfdbb85fbe80 /src
parent70d0f8857e5b984d5f74dda353413dc2cd8221ba (diff)
downloadopenttd-e74dc1e1d6dc57b2d6b79ef921888c0204855139.tar.xz
(svn r15803) -Codechange: use the new text drawing API for multicenter
-Fix (r15800): off-by-one w.r.t. offsets
Diffstat (limited to 'src')
-rw-r--r--src/cheat_gui.cpp2
-rw-r--r--src/company_gui.cpp4
-rw-r--r--src/engine_gui.cpp10
-rw-r--r--src/gfx.cpp14
-rw-r--r--src/gfx_func.h1
-rw-r--r--src/highscore_gui.cpp6
-rw-r--r--src/misc_gui.cpp33
-rw-r--r--src/network/network_content_gui.cpp4
-rw-r--r--src/news_gui.cpp35
9 files changed, 40 insertions, 69 deletions
diff --git a/src/cheat_gui.cpp b/src/cheat_gui.cpp
index 444cf0bb8..dd2424c04 100644
--- a/src/cheat_gui.cpp
+++ b/src/cheat_gui.cpp
@@ -144,7 +144,7 @@ struct CheatWindow : Window {
virtual void OnPaint()
{
this->DrawWidgets();
- DrawStringMultiCenter(200, 25, STR_CHEATS_WARNING, width - 50);
+ DrawStringMultiLine(20, this->width - 40, 15, 45, STR_CHEATS_WARNING, SA_CENTER);
for (int i = 0, x = 0, y = 45; i != lengthof(_cheats_ui); i++) {
const CheatEntry *ce = &_cheats_ui[i];
diff --git a/src/company_gui.cpp b/src/company_gui.cpp
index 7e8ce5ffc..632b8742f 100644
--- a/src/company_gui.cpp
+++ b/src/company_gui.cpp
@@ -1312,7 +1312,7 @@ struct CompanyWindow : Window
/* "xxx (Manager)" */
SetDParam(0, c->index);
- DrawStringMultiCenter(48, 141, STR_7037_PRESIDENT, MAX_LENGTH_PRESIDENT_NAME_PIXELS);
+ DrawStringMultiLine(48 - MAX_LENGTH_PRESIDENT_NAME_PIXELS / 2, 48 + MAX_LENGTH_PRESIDENT_NAME_PIXELS / 2, 135, 157, STR_7037_PRESIDENT, SA_CENTER);
/* "Inaugurated:" */
SetDParam(0, c->inaugurated_year);
@@ -1489,7 +1489,7 @@ struct BuyCompanyWindow : Window {
SetDParam(0, c->index);
SetDParam(1, c->bankrupt_value);
- DrawStringMultiCenter(214, 65, STR_705B_WE_ARE_LOOKING_FOR_A_TRANSPORT, 238);
+ DrawStringMultiLine(95, 333, 26, 116, STR_705B_WE_ARE_LOOKING_FOR_A_TRANSPORT, SA_CENTER);
}
virtual void OnClick(Point pt, int widget)
diff --git a/src/engine_gui.cpp b/src/engine_gui.cpp
index 8c39d1ffe..9cc77a435 100644
--- a/src/engine_gui.cpp
+++ b/src/engine_gui.cpp
@@ -80,7 +80,7 @@ struct EnginePreviewWindow : Window {
EngineID engine = this->window_number;
SetDParam(0, GetEngineCategoryName(engine));
- DrawStringMultiLine(this->widget[EPW_BACKGROUND].left + 2, this->widget[EPW_BACKGROUND].right - 2, 14, 74, STR_8101_WE_HAVE_JUST_DESIGNED_A, SA_CENTER);
+ DrawStringMultiLine(this->widget[EPW_BACKGROUND].left + 2, this->widget[EPW_BACKGROUND].right - 2, 18, 80, STR_8101_WE_HAVE_JUST_DESIGNED_A, SA_CENTER);
SetDParam(0, engine);
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;
dei->engine_proc(width >> 1, 100, engine, 0);
- dei->info_proc(engine, this->widget[EPW_BACKGROUND].left + 26, this->widget[EPW_BACKGROUND].right - 26, 100, 160);
+ dei->info_proc(engine, this->widget[EPW_BACKGROUND].left + 26, this->widget[EPW_BACKGROUND].right - 26, 100, 170);
}
virtual void OnClick(Point pt, int widget)
@@ -211,16 +211,16 @@ void DrawNewsNewVehicleAvail(Window *w, const NewsItem *ni)
const DrawEngineInfo *dei = &_draw_engine_list[GetEngine(engine)->type];
SetDParam(0, GetEngineCategoryName(engine));
- DrawStringMultiLine(1, w->width - 2, 0, 40, STR_NEW_VEHICLE_NOW_AVAILABLE, SA_CENTER);
+ DrawStringMultiLine(1, w->width - 2, 0, 56, STR_NEW_VEHICLE_NOW_AVAILABLE, SA_CENTER);
GfxFillRect(25, 56, w->width - 25, w->height - 2, 10);
SetDParam(0, engine);
- DrawStringMultiLine(1, w->width - 2, 40, 74, STR_NEW_VEHICLE_TYPE, SA_CENTER);
+ DrawStringMultiLine(1, w->width - 2, 56, 88, STR_NEW_VEHICLE_TYPE, SA_CENTER);
dei->engine_proc(w->width >> 1, 88, engine, 0);
GfxFillRect(25, 56, w->width - 56, 112, PALETTE_TO_STRUCT_GREY, FILLRECT_RECOLOUR);
- dei->info_proc(engine, 26, w->width - 26, 100, 160);
+ dei->info_proc(engine, 26, w->width - 26, 100, 170);
}
diff --git a/src/gfx.cpp b/src/gfx.cpp
index 4fd448b95..be008c1c0 100644
--- a/src/gfx.cpp
+++ b/src/gfx.cpp
@@ -637,7 +637,7 @@ int DrawStringMultiLine(int left, int right, int top, int bottom, StringID str,
total_height = (num + 1) * mt;
}
- int y = (align == SA_CENTER) ? (bottom + top - num * mt) / 2 : top;
+ int y = (align == SA_CENTER) ? (bottom + top - total_height + 1) / 2 : top;
const char *src = buffer;
for (;;) {
@@ -652,7 +652,7 @@ int DrawStringMultiLine(int left, int right, int top, int bottom, StringID str,
y += mt;
if (--num < 0) {
_cur_fontsize = FS_NORMAL;
- return y + mt;
+ return y;
}
break;
} else if (c == SCC_SETX) {
@@ -664,16 +664,6 @@ int DrawStringMultiLine(int left, int right, int top, int bottom, StringID str,
}
}
-/** Draw a given string with the centre around the given (x,y) coordinates
- * @param x Centre the string around this pixel width
- * @param y Centre the string around this pixel height
- * @param str String to draw
- * @param maxw Maximum width the string can have before it is wrapped */
-void DrawStringMultiCenter(int x, int y, StringID str, int maxw)
-{
- 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
* in a single Dimension value. TINYFONT, BIGFONT modifiers are only
* supported as the first character of the string. The returned dimensions
diff --git a/src/gfx_func.h b/src/gfx_func.h
index 97ae75617..c54509f3d 100644
--- a/src/gfx_func.h
+++ b/src/gfx_func.h
@@ -108,7 +108,6 @@ Dimension GetStringBoundingBox(const char *str);
uint32 FormatStringLinebreaks(char *str, int maxw);
int GetStringHeight(StringID str, int maxw);
void LoadStringWidthTable();
-void DrawStringMultiCenter(int x, int y, StringID str, int maxw);
/**
* Let the dirty blocks repainting by the video driver.
diff --git a/src/highscore_gui.cpp b/src/highscore_gui.cpp
index 1aca9dcf5..462557cbc 100644
--- a/src/highscore_gui.cpp
+++ b/src/highscore_gui.cpp
@@ -102,11 +102,11 @@ struct EndGameWindow : EndGameHighScoreBaseWindow {
SetDParam(0, c->index);
SetDParam(1, c->index);
SetDParam(2, EndGameGetPerformanceTitleFromValue(c->old_economy[0].performance_history));
- DrawStringMultiCenter(x + (640 / 2), y + 107, STR_021C_OF_ACHIEVES_STATUS, 640);
+ DrawStringMultiLine(x, x + 640, y + 140, y + 206, STR_021C_OF_ACHIEVES_STATUS, SA_CENTER);
} else {
SetDParam(0, c->index);
SetDParam(1, EndGameGetPerformanceTitleFromValue(c->old_economy[0].performance_history));
- DrawStringMultiCenter(x + (640 / 2), y + 157, STR_021B_ACHIEVES_STATUS, 640);
+ DrawStringMultiLine(x, x + 640, y + 90, y + 210, STR_021B_ACHIEVES_STATUS, SA_CENTER);
}
}
};
@@ -144,7 +144,7 @@ struct HighScoreWindow : EndGameHighScoreBaseWindow {
SetDParam(0, ORIGINAL_END_YEAR);
SetDParam(1, this->window_number + STR_6801_EASY);
- DrawStringMultiCenter(x + (640 / 2), y + 62, !_networking ? STR_0211_TOP_COMPANIES_WHO_REACHED : STR_TOP_COMPANIES_NETWORK_GAME, 500);
+ DrawStringMultiLine(x + 70, x + 570, y, y + 140, !_networking ? STR_0211_TOP_COMPANIES_WHO_REACHED : STR_TOP_COMPANIES_NETWORK_GAME, SA_CENTER);
/* Draw Highscore peepz */
for (uint8 i = 0; i < lengthof(_highscore_table[0]); i++) {
diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp
index 7e1dce368..091bae308 100644
--- a/src/misc_gui.cpp
+++ b/src/misc_gui.cpp
@@ -89,11 +89,9 @@ public:
y += i == 0 ? 16 : 12;
}
- y += 6;
-
if (!StrEmpty(this->landinfo_data[LAND_INFO_MULTICENTER_LINE])) {
SetDParamStr(0, this->landinfo_data[LAND_INFO_MULTICENTER_LINE]);
- DrawStringMultiCenter(150, y, STR_JUST_RAW_STRING, this->width - 4);
+ DrawStringMultiLine(this->widget[LIW_BACKGROUND].left + 2, this->widget[LIW_BACKGROUND].right - 2, y, y + 22, STR_JUST_RAW_STRING, SA_CENTER);
}
}
@@ -436,7 +434,7 @@ private:
StringID message_2;
bool show_company_manager_face;
- int y[2];
+ int y[4];
public:
ErrmsgWindow(Point pt, int width, int height, StringID msg1, StringID msg2, const Widget *widget, bool show_company_manager_face) :
@@ -454,22 +452,23 @@ public:
assert(msg2 != INVALID_STRING_ID);
- int h2 = 3 + GetStringHeight(msg2, width - 2); // msg2 is printed first
- int h1 = (msg1 == INVALID_STRING_ID) ? 0 : 3 + GetStringHeight(msg1, width - 2);
+ int h2 = GetStringHeight(msg2, width - 2); // msg2 is printed first
+ int h1 = (msg1 == INVALID_STRING_ID) ? 0 : GetStringHeight(msg1, width - 2);
SwitchToNormalRefStack();
- int h = 15 + h1 + h2;
+ int h = 20 + h1 + h2;
height = max<int>(height, h);
if (msg1 == INVALID_STRING_ID) {
- /* only 1 line will be printed */
- y[1] = (height - 15) / 2 + 15 - 5;
+ y[2] = 14 + 1;
+ y[3] = height - 1;
} else {
- int over = (height - h) / 4;
-
- y[1] = 15 + h2 / 2 + 1 - 5 + over;
- y[0] = height - 3 - h1 / 2 - 5 - over;
+ int over = (height - 16 - h1 - h2) / 2;
+ y[1] = height - 1;
+ y[0] = y[1] - h1 - over;
+ y[2] = 14 + 1;
+ y[3] = y[2] + h2 + over;
}
this->FindWindowPlacementAndResize(width, height);
@@ -492,8 +491,8 @@ public:
DrawCompanyManagerFace(c->face, c->colour, 2, 16);
}
- DrawStringMultiCenter(this->width - 120, y[1], this->message_2, this->width - 2);
- if (this->message_1 != INVALID_STRING_ID) DrawStringMultiCenter(this->width - 120, y[0], this->message_1, this->width - 2);
+ DrawStringMultiLine(1, this->width - 1, y[2], y[3] , this->message_2, SA_CENTER);
+ if (this->message_1 != INVALID_STRING_ID) DrawStringMultiLine(1, this->width - 1, y[0], y[1], this->message_1, SA_CENTER);
/* Switch back to the normal text ref. stack for NewGRF texts */
SwitchToNormalRefStack();
@@ -664,7 +663,7 @@ struct TooltipsWindow : public Window
for (uint arg = 0; arg < this->paramcount; arg++) {
SetDParam(arg, this->params[arg]);
}
- DrawStringMultiCenter((this->width >> 1), (this->height >> 1) - 5, this->string_id, this->width - 2);
+ DrawStringMultiLine(1, this->width - 1, 0, this->height, this->string_id, SA_CENTER);
}
virtual void OnMouseLoop()
@@ -1279,7 +1278,7 @@ struct QueryWindow : public Window {
this->DrawWidgets();
CopyInDParam(0, this->params, lengthof(this->params));
- DrawStringMultiCenter(this->width / 2, (this->height / 2) - 10, this->message, this->width - 2);
+ DrawStringMultiLine(1, this->width - 1, 14, 62, this->message, SA_CENTER);
}
virtual void OnClick(Point pt, int widget)
diff --git a/src/network/network_content_gui.cpp b/src/network/network_content_gui.cpp
index 50cad09da..73df3c3a9 100644
--- a/src/network/network_content_gui.cpp
+++ b/src/network/network_content_gui.cpp
@@ -136,7 +136,7 @@ public:
SetDParamStr(0, this->name);
SetDParam(1, this->downloaded_files);
SetDParam(2, this->total_files);
- DrawStringMultiCenter(this->width / 2, 50, STR_CONTENT_DOWNLOAD_FILE, this->width);
+ DrawStringMultiLine(this->widget[NCDSWW_BACKGROUND].left + 2, this->widget[NCDSWW_BACKGROUND].right - 2, 43, 67, STR_CONTENT_DOWNLOAD_FILE, SA_CENTER);
} else {
DrawString(this->widget[NCDSWW_BACKGROUND].left + 2, this->widget[NCDSWW_BACKGROUND].right - 2, 50, STR_CONTENT_DOWNLOAD_INITIALISE, TC_GREY, SA_CENTER);
}
@@ -435,7 +435,7 @@ public:
if (this->selected == NULL) return;
/* And fill the rest of the details when there's information to place there */
- DrawStringMultiCenter((this->widget[NCLWW_DETAILS].left + this->widget[NCLWW_DETAILS].right) / 2, this->widget[NCLWW_DETAILS].top + 32, STR_CONTENT_DETAIL_SUBTITLE_UNSELECTED + this->selected->state, this->widget[NCLWW_DETAILS].right - this->widget[NCLWW_DETAILS].left - 10);
+ DrawStringMultiLine(this->widget[NCLWW_DETAILS].left + 5, this->widget[NCLWW_DETAILS].right - 5, this->widget[NCLWW_DETAILS].top + 25, this->widget[NCLWW_DETAILS].top + 50, STR_CONTENT_DETAIL_SUBTITLE_UNSELECTED + this->selected->state, SA_CENTER);
/* Also show the total download size, so keep some space from the bottom */
const uint max_y = this->widget[NCLWW_DETAILS].bottom - 15;
diff --git a/src/news_gui.cpp b/src/news_gui.cpp
index 52fe64e5b..0e274b95a 100644
--- a/src/news_gui.cpp
+++ b/src/news_gui.cpp
@@ -53,7 +53,7 @@ static void DrawNewsBankrupcy(Window *w, const NewsItem *ni)
GfxFillRect(3, 23, 3 + 91, 23 + 118, PALETTE_TO_STRUCT_GREY, FILLRECT_RECOLOUR);
SetDParamStr(0, cni->president_name);
- DrawStringMultiCenter(49, 148, STR_JUST_RAW_STRING, 94);
+ DrawStringMultiLine(49 - MAX_LENGTH_PRESIDENT_NAME_PIXELS / 2, 49 + MAX_LENGTH_PRESIDENT_NAME_PIXELS / 2, 141, 169, STR_JUST_RAW_STRING, SA_CENTER);
switch (ni->subtype) {
case NS_COMPANY_TROUBLE:
@@ -61,11 +61,7 @@ static void DrawNewsBankrupcy(Window *w, const NewsItem *ni)
SetDParam(0, ni->params[2]);
- DrawStringMultiCenter(
- ((w->width - 101) >> 1) + 98,
- 90,
- STR_7057_WILL_BE_SOLD_OFF_OR_DECLARED,
- w->width - 101);
+ DrawStringMultiLine(100, w->width - 2, 20, 169, STR_7057_WILL_BE_SOLD_OFF_OR_DECLARED, SA_CENTER);
break;
case NS_COMPANY_MERGER:
@@ -73,32 +69,20 @@ static void DrawNewsBankrupcy(Window *w, const NewsItem *ni)
SetDParam(0, ni->params[2]);
SetDParam(1, ni->params[3]);
SetDParam(2, ni->params[4]);
- DrawStringMultiCenter(
- ((w->width - 101) >> 1) + 98,
- 90,
- ni->params[4] == 0 ? STR_707F_HAS_BEEN_TAKEN_OVER_BY : STR_705A_HAS_BEEN_SOLD_TO_FOR,
- w->width - 101);
+ DrawStringMultiLine(100, w->width - 2, 20, 169, ni->params[4] == 0 ? STR_707F_HAS_BEEN_TAKEN_OVER_BY : STR_705A_HAS_BEEN_SOLD_TO_FOR, SA_CENTER);
break;
case NS_COMPANY_BANKRUPT:
DrawString(0, w->width, 1, STR_705C_BANKRUPT, TC_FROMSTRING, SA_CENTER);
SetDParam(0, ni->params[2]);
- DrawStringMultiCenter(
- ((w->width - 101) >> 1) + 98,
- 90,
- STR_705D_HAS_BEEN_CLOSED_DOWN_BY,
- w->width - 101);
+ DrawStringMultiLine(100, w->width - 2, 20, 169, STR_705D_HAS_BEEN_CLOSED_DOWN_BY, SA_CENTER);
break;
case NS_COMPANY_NEW:
DrawString(0, w->width, 1, STR_705E_NEW_TRANSPORT_COMPANY_LAUNCHED, TC_FROMSTRING, SA_CENTER);
SetDParam(0, ni->params[2]);
SetDParam(1, ni->params[3]);
- DrawStringMultiCenter(
- ((w->width - 101) >> 1) + 98,
- 90,
- STR_705F_STARTS_CONSTRUCTION_NEAR,
- w->width - 101);
+ DrawStringMultiLine(100, w->width - 2, 20, 169, STR_705F_STARTS_CONSTRUCTION_NEAR, SA_CENTER);
break;
default:
@@ -220,8 +204,7 @@ struct NewsWindow : Window {
if (!(this->ni->flags & NF_VIEWPORT)) {
CopyInDParam(0, this->ni->params, lengthof(this->ni->params));
- DrawStringMultiCenter(215, display_mode == NM_NORMAL ? 76 : 56,
- this->ni->string_id, this->width - 4);
+ DrawStringMultiLine(2, this->width - 2, 20, this->height, this->ni->string_id, SA_CENTER);
} else {
/* Back up transparency options to draw news view */
TransparencyOptionBits to_backup = _transparency_opt;
@@ -237,7 +220,7 @@ struct NewsWindow : Window {
);
CopyInDParam(0, this->ni->params, lengthof(this->ni->params));
- DrawStringMultiCenter(this->width / 2, 20, this->ni->string_id, this->width - 4);
+ DrawStringMultiLine(2, this->width - 2, 0, 58, this->ni->string_id, SA_CENTER);
}
break;
}
@@ -246,11 +229,11 @@ struct NewsWindow : Window {
this->DrawWidgets();
if (!(this->ni->flags & NF_VIEWPORT)) {
CopyInDParam(0, this->ni->params, lengthof(this->ni->params));
- DrawStringMultiCenter(140, 38, this->ni->string_id, 276);
+ DrawStringMultiLine(2, 278, 38, this->ni->string_id, SA_CENTER);
} else {
this->DrawViewport();
CopyInDParam(0, this->ni->params, lengthof(this->ni->params));
- DrawStringMultiCenter(this->width / 2, this->height - 16, this->ni->string_id, this->width - 4);
+ DrawStringMultiLine(2, this->width - 2, 64, this->height, this->ni->string_id, SA_CENTER);
}
break;
}