Changeset - r13609:2f40c5be339d
[Not reviewed]
master
0 2 0
rubidium - 15 years ago 2009-11-17 15:25:40
rubidium@openttd.org
(svn r18143) -Codechange: allow stripping/ignoring of SETX(Y) during DrawString
2 files changed with 14 insertions and 4 deletions:
0 comments (0 inline, 0 general)
src/gfx.cpp
Show inline comments
 
@@ -327,9 +327,10 @@ static UChar *HandleBiDiAndArabicShapes(
 
 * 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 @@ static int TruncateString(char *str, int
 
			}
 
		} 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 @@ static int DrawString(int left, int righ
 
	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 @@ static int DrawString(int left, int righ
 
			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...");
 

	
src/gfx_func.h
Show inline comments
 
@@ -100,6 +100,7 @@ enum StringAlignment {
 
	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);
 

	
0 comments (0 inline, 0 general)