changeset 13619:640e42736ee8 draft

(svn r18143) -Codechange: allow stripping/ignoring of SETX(Y) during DrawString
author rubidium <rubidium@openttd.org>
date Tue, 17 Nov 2009 15:25:40 +0000
parents 7bfaf85c544c
children 9f8a77b7c0e9
files src/gfx.cpp src/gfx_func.h
diffstat 2 files changed, 14 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/gfx.cpp
+++ b/src/gfx.cpp
@@ -327,9 +327,10 @@
  * 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
  * @return new width of (truncated) string
  */
-static int TruncateString(char *str, int maxw)
+static int TruncateString(char *str, int maxw, bool ignore_setxy)
 {
 	int w = 0;
 	FontSize size = _cur_fontsize;
@@ -353,10 +354,10 @@
 			}
 		} else {
 			if (c == SCC_SETX) {
-				w = *str;
+				if (!ignore_setxy) w = *str;
 				str++;
 			} else if (c == SCC_SETXY) {
-				w = *str;
+				if (!ignore_setxy) w = *str;
 				str += 2;
 			} else if (c == SCC_TINYFONT) {
 				size = FS_SMALL;
@@ -446,7 +447,7 @@
 	int initial_right = right;
 	int initial_top = top;
 
-	if (truncate) TruncateString(str, right - left + 1);
+	if (truncate) TruncateString(str, right - left + 1, (align & SA_STRIP) == SA_STRIP);
 
 	/*
 	 * To support SETX and SETXY properly with RTL languages we have to
@@ -480,6 +481,14 @@
 			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_MASK) != SA_LEFT) {
 			DEBUG(grf, 1, "Using SETX and/or SETXY when not aligned to the left. Fixing alignment...");
 
--- a/src/gfx_func.h
+++ b/src/gfx_func.h
@@ -100,6 +100,7 @@
 	SA_RIGHT,     ///< Right align the text
 	SA_MASK  = 3, ///< Mask for base alignment
 	SA_FORCE = 4, ///< Force the alignment, i.e. don't swap for RTL languages.
+	SA_STRIP = 8, ///< Strip the SETX/SETXY commands from the string
 };
 DECLARE_ENUM_AS_BIT_SET(StringAlignment);