File diff r2106:c87c9f2f4751 → r2107:9afd88815f5d
gfx.c
Show inline comments
 
@@ -240,93 +240,93 @@ void GfxDrawLine(int x, int y, int x2, i
 
// 3-7 -
 
// 8 - TINYFONT
 
// 9 - BIGFONT
 
// 10 - newline
 
// 11-14 -
 
// 15-31 - 17 colors
 

	
 

	
 
enum {
 
	ASCII_SETX = 1,
 
	ASCII_SETXY = 2,
 

	
 
	ASCII_TINYFONT = 8,
 
	ASCII_BIGFONT = 9,
 
	ASCII_NL = 10,
 

	
 
	ASCII_COLORSTART = 15,
 
};
 

	
 
/** Truncate a given string to a maximum width if neccessary.
 
 * If the string is truncated, add three dots ('...') to show this.
 
 * @param *dest string that is checked and possibly truncated
 
 * @param maxw maximum width in pixels of the string
 
 * @return new width of (truncated) string */
 
static int TruncateString(char *str, uint maxw)
 
static uint TruncateString(char *str, uint maxw)
 
{
 
	int w = 0;
 
	uint w = 0;
 
	int base = _stringwidth_base;
 
	int ddd, ddd_w;
 

	
 
	byte c;
 
	char *ddd_pos;
 

	
 
	base = _stringwidth_base;
 
	ddd_w = ddd = GetCharacterWidth(base + '.') * 3;
 

	
 
	for (c = *str, ddd_pos = str; *str != '\0'; c = (*++str)) {
 
		if (c >= ASCII_LETTERSTART) {
 
			w += GetCharacterWidth(base + c);
 

	
 
			if (w >= maxw) {
 
				// string got too big... insert dotdotdot
 
				ddd_pos[0] = ddd_pos[1] = ddd_pos[2] = '.';
 
				ddd_pos[3] = 0;
 
				return ddd_w;
 
			}
 
		} else {
 
			if (c == ASCII_SETX) str++;
 
			else if (c == ASCII_SETXY) str += 2;
 
			else if (c == ASCII_TINYFONT) {
 
				base = 224;
 
				ddd = GetCharacterWidth(base + '.') * 3;
 
			} else if (c == ASCII_BIGFONT) {
 
				base = 448;
 
				ddd = GetCharacterWidth(base + '.') * 3;
 
			}
 
		}
 

	
 
		// Remember the last position where three dots fit.
 
		if (w + ddd < maxw) {
 
			ddd_w = w + ddd;
 
			ddd_pos = str + 1;
 
		}
 
	}
 

	
 
	return w;
 
}
 

	
 
static inline int TruncateStringID(StringID src, char *dest, uint maxw)
 
static inline uint TruncateStringID(StringID src, char *dest, uint maxw)
 
{
 
	GetString(dest, src);
 
	return TruncateString(dest, maxw);
 
}
 

	
 
/* returns right coordinate */
 
int DrawString(int x, int y, StringID str, uint16 color)
 
{
 
	char buffer[512];
 

	
 
	GetString(buffer, str);
 
	return DoDrawString(buffer, x, y, color);
 
}
 

	
 
int DrawStringTruncated(int x, int y, StringID str, uint16 color, uint maxw)
 
{
 
	char buffer[512];
 
	TruncateStringID(str, buffer, maxw);
 
	return DoDrawString(buffer, x, y, color);
 
}
 

	
 

	
 
void DrawStringRightAligned(int x, int y, StringID str, uint16 color)
 
{
 
@@ -340,49 +340,49 @@ void DrawStringRightAlignedTruncated(int
 
{
 
	char buffer[512];
 

	
 
	TruncateStringID(str, buffer, maxw);
 
	DoDrawString(buffer, x - GetStringWidth(buffer), y, color);
 
}
 

	
 

	
 
int DrawStringCentered(int x, int y, StringID str, uint16 color)
 
{
 
	char buffer[512];
 
	int w;
 

	
 
	GetString(buffer, str);
 

	
 
	w = GetStringWidth(buffer);
 
	DoDrawString(buffer, x - w / 2, y, color);
 

	
 
	return w;
 
}
 

	
 
int DrawStringCenteredTruncated(int x, int y, StringID str, uint16 color, uint maxw)
 
{
 
	char buffer[512];
 
	int w = TruncateStringID(str, buffer, maxw);
 
	uint w = TruncateStringID(str, buffer, maxw);
 
	return DoDrawString(buffer, x - (w / 2), y, color);
 
}
 

	
 
void DrawStringCenterUnderline(int x, int y, StringID str, uint16 color)
 
{
 
	int w = DrawStringCentered(x, y, str, color);
 
	GfxFillRect(x - (w >> 1), y + 10, x - (w >> 1) + w, y + 10, _string_colorremap[1]);
 
}
 

	
 
void DrawStringCenterUnderlineTruncated(int x, int y, StringID str, uint16 color, uint maxw)
 
{
 
	int w = DrawStringCenteredTruncated(x, y, str, color, maxw);
 
	GfxFillRect(x - (w >> 1), y + 10, x - (w >> 1) + w, y + 10, _string_colorremap[1]);
 
}
 

	
 
static uint32 FormatStringLinebreaks(char *str, int maxw)
 
{
 
	int num = 0;
 
	int base = _stringwidth_base;
 
	int w;
 
	char *last_space;
 
	byte c;
 

	
 
	for(;;) {