summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/aircraft_gui.cpp2
-rw-r--r--src/build_vehicle_gui.cpp2
-rw-r--r--src/gfx.cpp177
-rw-r--r--src/gfx_func.h1
-rw-r--r--src/newgrf_text.cpp9
-rw-r--r--src/roadveh_gui.cpp2
-rw-r--r--src/ship_gui.cpp2
-rw-r--r--src/string.cpp10
-rw-r--r--src/strings.cpp24
-rw-r--r--src/table/control_codes.h2
-rw-r--r--src/train_gui.cpp4
11 files changed, 45 insertions, 190 deletions
diff --git a/src/aircraft_gui.cpp b/src/aircraft_gui.cpp
index fe94b0fd2..6db75d3af 100644
--- a/src/aircraft_gui.cpp
+++ b/src/aircraft_gui.cpp
@@ -39,7 +39,7 @@ void DrawAircraftDetails(const Aircraft *v, int left, int right, int y)
SetDParam(0, u->engine_type);
SetDParam(1, u->build_year);
SetDParam(2, u->value);
- DrawString(left, right, y, STR_VEHICLE_INFO_BUILT_VALUE, TC_FROMSTRING, SA_LEFT | SA_STRIP);
+ DrawString(left, right, y, STR_VEHICLE_INFO_BUILT_VALUE);
SetDParam(0, u->cargo_type);
SetDParam(1, u->cargo_cap);
diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp
index 3677d0afe..9bc11e8af 100644
--- a/src/build_vehicle_gui.cpp
+++ b/src/build_vehicle_gui.cpp
@@ -911,7 +911,7 @@ void DrawEngineList(VehicleType type, int l, int r, int y, const GUIEngineList *
const uint num_engines = GetGroupNumEngines(_local_company, selected_group, engine);
SetDParam(0, engine);
- DrawString(text_left, text_right, y + normal_text_y_offset, STR_ENGINE_NAME, engine == selected_id ? TC_WHITE : TC_BLACK, SA_STRIP | (rtl ? SA_RIGHT : SA_LEFT));
+ DrawString(text_left, text_right, y + normal_text_y_offset, STR_ENGINE_NAME, engine == selected_id ? TC_WHITE : TC_BLACK, (rtl ? SA_RIGHT : SA_LEFT));
DrawVehicleEngine(l, r, sprite_x, y + sprite_y_offset, engine, (show_count && num_engines == 0) ? PALETTE_CRASH : GetEnginePalette(engine, _local_company), EIT_PURCHASE);
if (show_count) {
SetDParam(0, num_engines);
diff --git a/src/gfx.cpp b/src/gfx.cpp
index 49c9ba12d..e698d9254 100644
--- a/src/gfx.cpp
+++ b/src/gfx.cpp
@@ -437,11 +437,10 @@ static WChar *HandleBiDiAndArabicShapes(WChar *buffer)
* If the string is truncated, add three dots ('...') to show this.
* @param *str string that is checked and possibly truncated
* @param maxw maximum width in pixels of the string
- * @param ignore_setxy whether to ignore SETX(Y) or not
* @param start_fontsize Fontsize to start the text with
* @return new width of (truncated) string
*/
-static int TruncateString(char *str, int maxw, bool ignore_setxy, FontSize start_fontsize)
+static int TruncateString(char *str, int maxw, FontSize start_fontsize)
{
int w = 0;
FontSize size = start_fontsize;
@@ -464,13 +463,7 @@ static int TruncateString(char *str, int maxw, bool ignore_setxy, FontSize start
return ddd_w;
}
} else {
- if (c == SCC_SETX) {
- if (!ignore_setxy) w = *str;
- str++;
- } else if (c == SCC_SETXY) {
- if (!ignore_setxy) w = *str;
- str += 2;
- } else if (c == SCC_TINYFONT) {
+ if (c == SCC_TINYFONT) {
size = FS_SMALL;
ddd = GetCharacterWidth(size, '.') * 3;
} else if (c == SCC_BIGFONT) {
@@ -514,11 +507,6 @@ static int GetStringWidth(const WChar *str, FontSize start_fontsize)
width += GetCharacterWidth(size, c);
} else {
switch (c) {
- case SCC_SETX:
- case SCC_SETXY:
- /* At this point there is no SCC_SETX(Y) anymore */
- NOT_REACHED();
- break;
case SCC_TINYFONT: size = FS_SMALL; break;
case SCC_BIGFONT: size = FS_LARGE; break;
case '\n':
@@ -551,135 +539,54 @@ static int GetStringWidth(const WChar *str, FontSize start_fontsize)
*/
static int DrawString(int left, int right, int top, char *str, const char *last, DrawStringParams &params, StringAlignment align, bool underline = false, bool truncate = true)
{
- /* We need the outer limits of both left/right */
- int min_left = INT32_MAX;
- int max_right = INT32_MIN;
-
- int initial_left = left;
- int initial_right = right;
- int initial_top = top;
-
- if (truncate) TruncateString(str, right - left + 1, (align & SA_STRIP) == SA_STRIP, params.fontsize);
-
- /*
- * To support SETX and SETXY properly with RTL languages we have to
- * calculate the offsets from the right. To do this we need to split
- * the string and draw the parts separated by SETX(Y).
- * So here we split
- */
- static SmallVector<WChar *, 4> setx_offsets;
- setx_offsets.Clear();
+ if (truncate) TruncateString(str, right - left + 1, params.fontsize);
WChar draw_buffer[DRAW_STRING_BUFFER];
WChar *p = draw_buffer;
- *setx_offsets.Append() = p;
-
- char *loc = str;
- for (;;) {
- WChar c;
- /* We cannot use Utf8Consume as we need the location of the SETX(Y) */
- size_t len = Utf8Decode(&c, loc);
+ const char *text = str;
+ for (WChar c = Utf8Consume(&text); c != '\0'; c = Utf8Consume(&text)) {
*p++ = c;
-
- if (c == '\0') break;
- if (p >= lastof(draw_buffer) - 3) {
- /* Make sure we never overflow (even if copying SCC_SETX(Y)). */
- *p = '\0';
- break;
- }
- if (c != SCC_SETX && c != SCC_SETXY) {
- loc += len;
- continue;
- }
-
- if (align & SA_STRIP) {
- /* We do not want to keep the SETX(Y)!. It was already copied, so
- * remove it and undo the incrementing of the pointer! */
- *p-- = '\0';
- loc += len + (c == SCC_SETXY ? 2 : 1);
- continue;
- }
-
- if ((align & SA_HOR_MASK) != SA_LEFT) {
- DEBUG(grf, 1, "Using SETX and/or SETXY when not aligned to the left. Fixing alignment...");
-
- /* For left alignment and change the left so it will roughly be in the
- * middle. This will never cause the string to be completely centered,
- * but once SETX is used you cannot be sure the actual content of the
- * string is centered, so it doesn't really matter. */
- align = SA_LEFT | SA_FORCE;
- initial_left = left = max(left, (left + right - (int)GetStringBoundingBox(str).width) / 2);
- }
-
- /* We add the begin of the string, but don't add it twice */
- if (p != draw_buffer) {
- *setx_offsets.Append() = p;
- p[-1] = '\0';
- *p++ = c;
- }
-
- /* Skip the SCC_SETX(Y) ... */
- loc += len;
- /* ... copy the x coordinate ... */
- *p++ = *loc++;
- /* ... and finally copy the y coordinate if it exists */
- if (c == SCC_SETXY) *p++ = *loc++;
}
+ *p++ = '\0';
/* In case we have a RTL language we swap the alignment. */
- if (!(align & SA_FORCE) && _current_text_dir == TD_RTL && !(align & SA_STRIP) && (align & SA_HOR_MASK) != SA_HOR_CENTER) align ^= SA_RIGHT;
-
- for (WChar **iter = setx_offsets.Begin(); iter != setx_offsets.End(); iter++) {
- WChar *to_draw = *iter;
- int offset = 0;
+ if (!(align & SA_FORCE) && _current_text_dir == TD_RTL && (align & SA_HOR_MASK) != SA_HOR_CENTER) align ^= SA_RIGHT;
- /* Skip the SETX(Y) and set the appropriate offsets. */
- if (*to_draw == SCC_SETX || *to_draw == SCC_SETXY) {
- to_draw++;
- offset = *to_draw++;
- if (*to_draw == SCC_SETXY) top = initial_top + *to_draw++;
- }
-
- to_draw = HandleBiDiAndArabicShapes(to_draw);
- int w = GetStringWidth(to_draw, params.fontsize);
-
- /* right is the right most position to draw on. In this case we want to do
- * calculations with the width of the string. In comparison right can be
- * seen as lastof(todraw) and width as lengthof(todraw). They differ by 1.
- * So most +1/-1 additions are to move from lengthof to 'indices'.
- */
- switch (align & SA_HOR_MASK) {
- case SA_LEFT:
- /* right + 1 = left + w */
- left = initial_left + offset;
- right = left + w - 1;
- break;
+ WChar *to_draw = HandleBiDiAndArabicShapes(draw_buffer);
+ int w = GetStringWidth(to_draw, params.fontsize);
- case SA_HOR_CENTER:
- left = RoundDivSU(initial_right + 1 + initial_left - w, 2);
- /* right + 1 = left + w */
- right = left + w - 1;
- break;
+ /* right is the right most position to draw on. In this case we want to do
+ * calculations with the width of the string. In comparison right can be
+ * seen as lastof(todraw) and width as lengthof(todraw). They differ by 1.
+ * So most +1/-1 additions are to move from lengthof to 'indices'.
+ */
+ switch (align & SA_HOR_MASK) {
+ case SA_LEFT:
+ /* right + 1 = left + w */
+ right = left + w - 1;
+ break;
- case SA_RIGHT:
- left = initial_right + 1 - w - offset;
- break;
+ case SA_HOR_CENTER:
+ left = RoundDivSU(right + 1 + left - w, 2);
+ /* right + 1 = left + w */
+ right = left + w - 1;
+ break;
- default:
- NOT_REACHED();
- }
+ case SA_RIGHT:
+ left = right + 1 - w;
+ break;
- min_left = min(left, min_left);
- max_right = max(right, max_right);
+ default:
+ NOT_REACHED();
+ }
- ReallyDoDrawString(to_draw, left, top, params, !truncate);
- if (underline) {
- GfxFillRect(left, top + FONT_HEIGHT_NORMAL, right, top + FONT_HEIGHT_NORMAL, _string_colourremap[1]);
- }
+ ReallyDoDrawString(to_draw, left, top, params, !truncate);
+ if (underline) {
+ GfxFillRect(left, top + FONT_HEIGHT_NORMAL, right, top + FONT_HEIGHT_NORMAL, _string_colourremap[1]);
}
- return (align & SA_HOR_MASK) == SA_RIGHT ? min_left : max_right;
+ return (align & SA_HOR_MASK) == SA_RIGHT ? left : right;
}
/**
@@ -811,8 +718,6 @@ uint32 FormatStringLinebreaks(char *str, const char *last, int maxw, FontSize si
} else {
switch (c) {
case '\0': return num + (size << 16);
- case SCC_SETX: str++; break;
- case SCC_SETXY: str += 2; break;
case SCC_TINYFONT: size = FS_SMALL; break;
case SCC_BIGFONT: size = FS_LARGE; break;
case '\n': goto end_of_inner_loop;
@@ -855,8 +760,6 @@ static int GetMultilineStringHeight(const char *src, int num, FontSize start_fon
switch (c) {
case 0: y += fh; if (--num < 0) return maxy; break;
case '\n': y += fh; break;
- case SCC_SETX: src++; break;
- case SCC_SETXY: src++; y = (int)*src++; break;
case SCC_TINYFONT: fh = GetCharacterHeight(FS_SMALL); break;
case SCC_BIGFONT: fh = GetCharacterHeight(FS_LARGE); break;
default: maxy = max<int>(maxy, y + fh); break;
@@ -1019,10 +922,6 @@ static int DrawStringMultiLine(int left, int right, int top, int bottom, char *s
WChar c = Utf8Consume(&src);
if (c == 0) {
break;
- } else if (c == SCC_SETX) {
- src++;
- } else if (c == SCC_SETXY) {
- src += 2;
} else if (skip_lines > 0) {
/* Skipped drawing, so do additional processing to update params. */
if (c >= SCC_BLUE && c <= SCC_BLACK) {
@@ -1111,11 +1010,6 @@ Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
br.width += GetCharacterWidth(size, c);
} else {
switch (c) {
- case SCC_SETX: br.width = max((uint)*str++, br.width); break;
- case SCC_SETXY:
- br.width = max((uint)*str++, br.width);
- br.height = max((uint)*str++, br.height);
- break;
case SCC_TINYFONT: size = FS_SMALL; break;
case SCC_BIGFONT: size = FS_LARGE; break;
case '\n':
@@ -1229,9 +1123,6 @@ skip_cont:;
} else if (c == SCC_PREVIOUS_COLOUR) { // revert to the previous colour
params.SetPreviousColour();
goto switch_colour;
- } else if (c == SCC_SETX || c == SCC_SETXY) { // {SETX}/{SETXY}
- /* The characters are handled before calling this. */
- NOT_REACHED();
} else if (c == SCC_TINYFONT) { // {TINYFONT}
params.SetFontSize(FS_SMALL);
} else if (c == SCC_BIGFONT) { // {BIGFONT}
diff --git a/src/gfx_func.h b/src/gfx_func.h
index 3dcba4497..88d6e9336 100644
--- a/src/gfx_func.h
+++ b/src/gfx_func.h
@@ -105,7 +105,6 @@ enum StringAlignment {
SA_CENTER = SA_HOR_CENTER | SA_VERT_CENTER, ///< Center both horizontally and vertically.
SA_FORCE = 1 << 4, ///< Force the alignment, i.e. don't swap for RTL languages.
- SA_STRIP = 1 << 5, ///< Strip the SETX/SETXY commands from the string
};
DECLARE_ENUM_AS_BIT_SET(StringAlignment)
diff --git a/src/newgrf_text.cpp b/src/newgrf_text.cpp
index 4b2f75f42..9cb1c1898 100644
--- a/src/newgrf_text.cpp
+++ b/src/newgrf_text.cpp
@@ -432,8 +432,8 @@ char *TranslateTTDPatchCodes(uint32 grfid, uint8 language_id, bool allow_newline
switch (c) {
case 0x01:
if (str[0] == '\0') goto string_end;
- d += Utf8Encode(d, SCC_SETX);
- *d++ = *str++;
+ d += Utf8Encode(d, ' ');
+ str++;
break;
case 0x0A: break;
case 0x0D:
@@ -447,9 +447,8 @@ char *TranslateTTDPatchCodes(uint32 grfid, uint8 language_id, bool allow_newline
case 0x0F: d += Utf8Encode(d, SCC_BIGFONT); break;
case 0x1F:
if (str[0] == '\0' || str[1] == '\0') goto string_end;
- d += Utf8Encode(d, SCC_SETXY);
- *d++ = *str++;
- *d++ = *str++;
+ d += Utf8Encode(d, ' ');
+ str += 2;
break;
case 0x7B:
case 0x7C:
diff --git a/src/roadveh_gui.cpp b/src/roadveh_gui.cpp
index eea416659..bf837bbad 100644
--- a/src/roadveh_gui.cpp
+++ b/src/roadveh_gui.cpp
@@ -35,7 +35,7 @@ void DrawRoadVehDetails(const Vehicle *v, int left, int right, int y)
SetDParam(0, v->engine_type);
SetDParam(1, v->build_year);
SetDParam(2, v->value);
- DrawString(left, right, y + y_offset, STR_VEHICLE_INFO_BUILT_VALUE, TC_FROMSTRING, SA_LEFT | SA_STRIP);
+ DrawString(left, right, y + y_offset, STR_VEHICLE_INFO_BUILT_VALUE);
if (v->HasArticulatedPart()) {
CargoArray max_cargo;
diff --git a/src/ship_gui.cpp b/src/ship_gui.cpp
index 6a55c8154..10cf78922 100644
--- a/src/ship_gui.cpp
+++ b/src/ship_gui.cpp
@@ -62,7 +62,7 @@ void DrawShipDetails(const Vehicle *v, int left, int right, int y)
SetDParam(0, v->engine_type);
SetDParam(1, v->build_year);
SetDParam(2, v->value);
- DrawString(left, right, y, STR_VEHICLE_INFO_BUILT_VALUE, TC_FROMSTRING, SA_LEFT | SA_STRIP);
+ DrawString(left, right, y, STR_VEHICLE_INFO_BUILT_VALUE);
SetDParam(0, v->cargo_type);
SetDParam(1, v->cargo_cap);
diff --git a/src/string.cpp b/src/string.cpp
index 32f45ade8..7557f6d1d 100644
--- a/src/string.cpp
+++ b/src/string.cpp
@@ -248,16 +248,6 @@ void str_validate(char *str, const char *last, StringValidationSettings settings
/* Replace the undesirable character with a question mark */
str += len;
if ((settings & SVS_REPLACE_WITH_QUESTION_MARK) != 0) *dst++ = '?';
-
- /* In case of these two special cases assume that they really
- * mean SETX/SETXY and also "eat" the parameter. If this was
- * not the case the string was broken to begin with and this
- * would not break much more. */
- if (c == SCC_SETX) {
- str++;
- } else if (c == SCC_SETXY) {
- str += 2;
- }
}
}
diff --git a/src/strings.cpp b/src/strings.cpp
index 204e20687..5ea914035 100644
--- a/src/strings.cpp
+++ b/src/strings.cpp
@@ -1003,21 +1003,6 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
break;
}
- case SCC_SETX: // {SETX}
- if (buff + Utf8CharLen(SCC_SETX) + 1 < last) {
- buff += Utf8Encode(buff, SCC_SETX);
- *buff++ = *str++;
- }
- break;
-
- case SCC_SETXY: // {SETXY}
- if (buff + Utf8CharLen(SCC_SETXY) + 2 < last) {
- buff += Utf8Encode(buff, SCC_SETXY);
- *buff++ = *str++;
- *buff++ = *str++;
- }
- break;
-
case SCC_REVISION: // {REV}
buff = strecpy(buff, _openttd_revision, last);
break;
@@ -2036,14 +2021,7 @@ bool MissingGlyphSearcher::FindMissingGlyphs(const char **str)
FontSize size = this->DefaultSize();
if (str != NULL) *str = text;
for (WChar c = Utf8Consume(&text); c != '\0'; c = Utf8Consume(&text)) {
- if (c == SCC_SETX) {
- /* SetX is, together with SetXY as special character that
- * uses the next (two) characters as data points. We have
- * to skip those, otherwise the UTF8 reading will go haywire. */
- text++;
- } else if (c == SCC_SETXY) {
- text += 2;
- } else if (c == SCC_TINYFONT) {
+ if (c == SCC_TINYFONT) {
size = FS_SMALL;
} else if (c == SCC_BIGFONT) {
size = FS_LARGE;
diff --git a/src/table/control_codes.h b/src/table/control_codes.h
index 50233d5f6..2c616ab9d 100644
--- a/src/table/control_codes.h
+++ b/src/table/control_codes.h
@@ -27,8 +27,6 @@ enum StringControlCode {
SCC_ENCODED = SCC_CONTROL_START,
/* Display control codes */
- SCC_SETX,
- SCC_SETXY,
SCC_TINYFONT, ///< Switch to small font
SCC_BIGFONT, ///< Switch to large font
diff --git a/src/train_gui.cpp b/src/train_gui.cpp
index 866eab745..24cecd5f1 100644
--- a/src/train_gui.cpp
+++ b/src/train_gui.cpp
@@ -215,12 +215,12 @@ static void TrainDetailsInfoTab(const Vehicle *v, int left, int right, int y)
if (RailVehInfo(v->engine_type)->railveh_type == RAILVEH_WAGON) {
SetDParam(0, v->engine_type);
SetDParam(1, v->value);
- DrawString(left, right, y, STR_VEHICLE_DETAILS_TRAIN_WAGON_VALUE, TC_FROMSTRING, SA_LEFT | SA_STRIP);
+ DrawString(left, right, y, STR_VEHICLE_DETAILS_TRAIN_WAGON_VALUE);
} else {
SetDParam(0, v->engine_type);
SetDParam(1, v->build_year);
SetDParam(2, v->value);
- DrawString(left, right, y, STR_VEHICLE_DETAILS_TRAIN_ENGINE_BUILT_AND_VALUE, TC_FROMSTRING, SA_LEFT | SA_STRIP);
+ DrawString(left, right, y, STR_VEHICLE_DETAILS_TRAIN_ENGINE_BUILT_AND_VALUE);
}
}