|
|
@ -375,25 +375,6 @@ static int TruncateString(char *str, int maxw)
|
|
|
|
return w;
|
|
|
|
return w;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Draw string starting at position (x,y).
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param x X position to start drawing
|
|
|
|
|
|
|
|
* @param y Y position to start drawing
|
|
|
|
|
|
|
|
* @param str String to draw
|
|
|
|
|
|
|
|
* @param colour Colour used for drawing the string, see DoDrawString() for details
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return Horizontal coordinate after drawing the string
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
int DrawString(int x, int y, StringID str, TextColour colour)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
char buffer[DRAW_STRING_BUFFER];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GetString(buffer, str, lastof(buffer));
|
|
|
|
|
|
|
|
HandleBiDiAndArabicShapes(buffer, lastof(buffer));
|
|
|
|
|
|
|
|
return ReallyDoDrawString(buffer, x, y, colour);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Draw string, possibly truncated to make it fit in its allocated space
|
|
|
|
* Draw string, possibly truncated to make it fit in its allocated space
|
|
|
|
*
|
|
|
|
*
|
|
|
@ -411,9 +392,9 @@ int DrawString(int x, int y, StringID str, TextColour colour)
|
|
|
|
* @return In case of left or center alignment the right most pixel we have drawn to.
|
|
|
|
* @return In case of left or center alignment the right most pixel we have drawn to.
|
|
|
|
* In case of right alignment the left most pixel we have drawn to.
|
|
|
|
* In case of right alignment the left most pixel we have drawn to.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
static int DrawString(int left, int right, int top, char *str, const char *last, TextColour colour, StringAlignment align, bool underline = false)
|
|
|
|
static int DrawString(int left, int right, int top, char *str, const char *last, TextColour colour, StringAlignment align, bool underline = false, bool truncate = true)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
TruncateString(str, right - left);
|
|
|
|
if (truncate) TruncateString(str, right - left);
|
|
|
|
HandleBiDiAndArabicShapes(str, last);
|
|
|
|
HandleBiDiAndArabicShapes(str, last);
|
|
|
|
|
|
|
|
|
|
|
|
int w = GetStringBoundingBox(str).width;
|
|
|
|
int w = GetStringBoundingBox(str).width;
|
|
|
@ -435,7 +416,7 @@ static int DrawString(int left, int right, int top, char *str, const char *last,
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
NOT_REACHED();
|
|
|
|
NOT_REACHED();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ReallyDoDrawString(str, left, top, colour);
|
|
|
|
ReallyDoDrawString(str, left, top, colour, !truncate);
|
|
|
|
if (underline) {
|
|
|
|
if (underline) {
|
|
|
|
GfxFillRect(left, top + 10, right, top + 10, _string_colourremap[1]);
|
|
|
|
GfxFillRect(left, top + 10, right, top + 10, _string_colourremap[1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -443,6 +424,21 @@ static int DrawString(int left, int right, int top, char *str, const char *last,
|
|
|
|
return align == SA_RIGHT ? left : right;
|
|
|
|
return align == SA_RIGHT ? left : right;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Draw string starting at position (x,y).
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param x X position to start drawing
|
|
|
|
|
|
|
|
* @param y Y position to start drawing
|
|
|
|
|
|
|
|
* @param str String to draw
|
|
|
|
|
|
|
|
* @param colour Colour used for drawing the string, see DoDrawString() for details
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return Horizontal coordinate after drawing the string
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
int DrawString(int x, int y, StringID str, TextColour colour)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return DrawString(x, INT32_MAX, y, str, colour);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Draw string, possibly truncated to make it fit in its allocated space
|
|
|
|
* Draw string, possibly truncated to make it fit in its allocated space
|
|
|
|
*
|
|
|
|
*
|
|
|
@ -604,73 +600,34 @@ int GetStringHeight(StringID str, int maxw)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Draw a given string with the centre around the given (x,y) coordinates
|
|
|
|
/**
|
|
|
|
* @param x Centre the string around this pixel width
|
|
|
|
* Draw string, possibly over multiple lines.
|
|
|
|
* @param y Centre the string around this pixel height
|
|
|
|
*
|
|
|
|
* @param str String to draw
|
|
|
|
* @param left The left most position to draw on.
|
|
|
|
* @param maxw Maximum width the string can have before it is wrapped */
|
|
|
|
* @param right The right most position to draw on.
|
|
|
|
void DrawStringMultiCenter(int x, int y, StringID str, int maxw)
|
|
|
|
* @param top The top most position to draw on.
|
|
|
|
|
|
|
|
* @param bottom The bottom most position to draw on.
|
|
|
|
|
|
|
|
* @param str String to draw.
|
|
|
|
|
|
|
|
* @param colour Colour used for drawing the string, see DoDrawString() for details
|
|
|
|
|
|
|
|
* @param align The alignment of the string when drawing left-to-right. In the
|
|
|
|
|
|
|
|
* case a right-to-left language is chosen this is inverted so it
|
|
|
|
|
|
|
|
* will be drawn in the right direction.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return The bottom to where we have written.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
int DrawStringMultiLine(int left, int right, int top, int bottom, StringID str, StringAlignment align)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
char buffer[DRAW_STRING_BUFFER];
|
|
|
|
int maxw = right - left;
|
|
|
|
uint32 tmp;
|
|
|
|
int maxh = bottom - top;
|
|
|
|
int num, mt;
|
|
|
|
|
|
|
|
const char *src;
|
|
|
|
|
|
|
|
WChar c;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GetString(buffer, str, lastof(buffer));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tmp = FormatStringLinebreaks(buffer, maxw);
|
|
|
|
|
|
|
|
num = GB(tmp, 0, 16);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mt = GetCharacterHeight((FontSize)GB(tmp, 16, 16));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
y -= (mt >> 1) * num;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src = buffer;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
|
|
|
|
char buf2[DRAW_STRING_BUFFER];
|
|
|
|
|
|
|
|
strecpy(buf2, src, lastof(buf2));
|
|
|
|
|
|
|
|
HandleBiDiAndArabicShapes(buf2, lastof(buf2));
|
|
|
|
|
|
|
|
int w = GetStringBoundingBox(buf2).width;
|
|
|
|
|
|
|
|
ReallyDoDrawString(buf2, x - (w >> 1), y, TC_FROMSTRING, true);
|
|
|
|
|
|
|
|
_cur_fontsize = _last_fontsize;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
|
|
|
|
c = Utf8Consume(&src);
|
|
|
|
|
|
|
|
if (c == 0) {
|
|
|
|
|
|
|
|
y += mt;
|
|
|
|
|
|
|
|
if (--num < 0) {
|
|
|
|
|
|
|
|
_cur_fontsize = FS_NORMAL;
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
} else if (c == SCC_SETX) {
|
|
|
|
|
|
|
|
src++;
|
|
|
|
|
|
|
|
} else if (c == SCC_SETXY) {
|
|
|
|
|
|
|
|
src += 2;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint DrawStringMultiLine(int x, int y, StringID str, int maxw, int maxh)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
char buffer[DRAW_STRING_BUFFER];
|
|
|
|
char buffer[DRAW_STRING_BUFFER];
|
|
|
|
uint32 tmp;
|
|
|
|
|
|
|
|
int num, mt;
|
|
|
|
|
|
|
|
uint total_height;
|
|
|
|
|
|
|
|
const char *src;
|
|
|
|
|
|
|
|
WChar c;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GetString(buffer, str, lastof(buffer));
|
|
|
|
GetString(buffer, str, lastof(buffer));
|
|
|
|
|
|
|
|
|
|
|
|
tmp = FormatStringLinebreaks(buffer, maxw);
|
|
|
|
uint32 tmp = FormatStringLinebreaks(buffer, maxw);
|
|
|
|
num = GB(tmp, 0, 16);
|
|
|
|
int num = GB(tmp, 0, 16);
|
|
|
|
|
|
|
|
|
|
|
|
mt = GetCharacterHeight((FontSize)GB(tmp, 16, 16));
|
|
|
|
int mt = GetCharacterHeight((FontSize)GB(tmp, 16, 16));
|
|
|
|
total_height = (num + 1) * mt;
|
|
|
|
int total_height = (num + 1) * mt;
|
|
|
|
|
|
|
|
|
|
|
|
if (maxh != -1 && (int)total_height > maxh) {
|
|
|
|
if (maxh != -1 && (int)total_height > maxh) {
|
|
|
|
/* Check there's room enough for at least one line. */
|
|
|
|
/* Check there's room enough for at least one line. */
|
|
|
@ -680,22 +637,22 @@ uint DrawStringMultiLine(int x, int y, StringID str, int maxw, int maxh)
|
|
|
|
total_height = (num + 1) * mt;
|
|
|
|
total_height = (num + 1) * mt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
src = buffer;
|
|
|
|
int y = top;
|
|
|
|
|
|
|
|
const char *src = buffer;
|
|
|
|
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
for (;;) {
|
|
|
|
char buf2[DRAW_STRING_BUFFER];
|
|
|
|
char buf2[DRAW_STRING_BUFFER];
|
|
|
|
strecpy(buf2, src, lastof(buf2));
|
|
|
|
strecpy(buf2, src, lastof(buf2));
|
|
|
|
HandleBiDiAndArabicShapes(buf2, lastof(buf2));
|
|
|
|
DrawString(left, right, y, buf2, lastof(buf2), TC_FROMSTRING, align, false, false);
|
|
|
|
ReallyDoDrawString(buf2, x, y, TC_FROMSTRING, true);
|
|
|
|
|
|
|
|
_cur_fontsize = _last_fontsize;
|
|
|
|
_cur_fontsize = _last_fontsize;
|
|
|
|
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
for (;;) {
|
|
|
|
c = Utf8Consume(&src);
|
|
|
|
WChar c = Utf8Consume(&src);
|
|
|
|
if (c == 0) {
|
|
|
|
if (c == 0) {
|
|
|
|
y += mt;
|
|
|
|
y += mt;
|
|
|
|
if (--num < 0) {
|
|
|
|
if (--num < 0) {
|
|
|
|
_cur_fontsize = FS_NORMAL;
|
|
|
|
_cur_fontsize = FS_NORMAL;
|
|
|
|
return total_height;
|
|
|
|
return top + total_height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
} else if (c == SCC_SETX) {
|
|
|
|
} else if (c == SCC_SETX) {
|
|
|
@ -707,6 +664,21 @@ uint DrawStringMultiLine(int x, int y, StringID str, int maxw, int maxh)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** 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, INT32_MAX, str, SA_CENTER);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint DrawStringMultiLine(int x, int y, StringID str, int maxw, int maxh)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return DrawStringMultiLine(x, x + maxw, y, y + maxh, str, SA_LEFT) - y;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** Return the string dimension in pixels. The height and width are returned
|
|
|
|
/** Return the string dimension in pixels. The height and width are returned
|
|
|
|
* in a single Dimension value. TINYFONT, BIGFONT modifiers are only
|
|
|
|
* in a single Dimension value. TINYFONT, BIGFONT modifiers are only
|
|
|
|
* supported as the first character of the string. The returned dimensions
|
|
|
|
* supported as the first character of the string. The returned dimensions
|
|
|
|