mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r2623) - CodeChange: rework DrawStringCenteredTruncated() a bit. Instead of giving center + width you give the coordinates of the bounding box (left, right) it has to fit in (ludde)
- CodeChange: changed (back) maximum pixel length of truncated strings to a signed integer.
This commit is contained in:
parent
52b42ff508
commit
0550c4a87a
|
@ -556,10 +556,8 @@ static void AircraftViewWndProc(Window *w, WindowEvent *e)
|
|||
}
|
||||
|
||||
/* draw the flag plus orders */
|
||||
{ int w_width = w->widget[5].right - w->widget[5].left;
|
||||
DrawSprite(v->vehstatus & VS_STOPPED ? 0xC12 : 0xC13, 2, w->widget[5].top + 1);
|
||||
DrawStringCenteredTruncated(w_width / 2 + 6, w->widget[5].top + 1, str, 0, w_width - 8);
|
||||
}
|
||||
DrawSprite(v->vehstatus & VS_STOPPED ? 0xC12 : 0xC13, 2, w->widget[5].top + 1);
|
||||
DrawStringCenteredTruncated(w->widget[5].left + 8, w->widget[5].right, w->widget[5].top + 1, str, 0);
|
||||
DrawWindowViewport(w);
|
||||
} break;
|
||||
|
||||
|
|
22
gfx.c
22
gfx.c
|
@ -261,9 +261,9 @@ enum {
|
|||
* @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 uint TruncateString(char *str, uint maxw)
|
||||
static int TruncateString(char *str, int maxw)
|
||||
{
|
||||
uint w = 0;
|
||||
int w = 0;
|
||||
int base = _stringwidth_base;
|
||||
int ddd, ddd_w;
|
||||
|
||||
|
@ -273,7 +273,7 @@ static uint TruncateString(char *str, uint maxw)
|
|||
base = _stringwidth_base;
|
||||
ddd_w = ddd = GetCharacterWidth(base + '.') * 3;
|
||||
|
||||
for (c = *str, ddd_pos = str; *str != '\0'; c = (*++str)) {
|
||||
for (ddd_pos = str; (c = *str++) != '\0'; ) {
|
||||
if (c >= ASCII_LETTERSTART) {
|
||||
w += GetCharacterWidth(base + c);
|
||||
|
||||
|
@ -298,14 +298,14 @@ static uint TruncateString(char *str, uint maxw)
|
|||
// Remember the last position where three dots fit.
|
||||
if (w + ddd < maxw) {
|
||||
ddd_w = w + ddd;
|
||||
ddd_pos = str + 1;
|
||||
ddd_pos = str;
|
||||
}
|
||||
}
|
||||
|
||||
return w;
|
||||
}
|
||||
|
||||
static inline uint TruncateStringID(StringID src, char *dest, uint maxw)
|
||||
static inline int TruncateStringID(StringID src, char *dest, int maxw)
|
||||
{
|
||||
GetString(dest, src);
|
||||
return TruncateString(dest, maxw);
|
||||
|
@ -358,11 +358,11 @@ int DrawStringCentered(int x, int y, StringID str, uint16 color)
|
|||
return w;
|
||||
}
|
||||
|
||||
int DrawStringCenteredTruncated(int x, int y, StringID str, uint16 color, uint maxw)
|
||||
int DrawStringCenteredTruncated(int xl, int xr, int y, StringID str, uint16 color)
|
||||
{
|
||||
char buffer[512];
|
||||
uint w = TruncateStringID(str, buffer, maxw);
|
||||
return DoDrawString(buffer, x - (w / 2), y, color);
|
||||
int w = TruncateStringID(str, buffer, xr - xl);
|
||||
return DoDrawString(buffer, (xl + xr - w) / 2, y, color);
|
||||
}
|
||||
|
||||
void DrawStringCenterUnderline(int x, int y, StringID str, uint16 color)
|
||||
|
@ -371,10 +371,10 @@ void DrawStringCenterUnderline(int x, int y, StringID str, uint16 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)
|
||||
void DrawStringCenterUnderlineTruncated(int xl, int xr, int y, StringID str, uint16 color)
|
||||
{
|
||||
int w = DrawStringCenteredTruncated(x, y, str, color, maxw);
|
||||
GfxFillRect(x - (w >> 1), y + 10, x - (w >> 1) + w, y + 10, _string_colorremap[1]);
|
||||
int w = DrawStringCenteredTruncated(xl, xr, y, str, color);
|
||||
GfxFillRect((xl + xr - w) / 2, y + 10, (xl + xr + w) / 2, y + 10, _string_colorremap[1]);
|
||||
}
|
||||
|
||||
static uint32 FormatStringLinebreaks(char *str, int maxw)
|
||||
|
|
4
gfx.h
4
gfx.h
|
@ -37,7 +37,7 @@ void RedrawScreenRect(int left, int top, int right, int bottom);
|
|||
void GfxScroll(int left, int top, int width, int height, int xo, int yo);
|
||||
|
||||
int DrawStringCentered(int x, int y, StringID str, uint16 color);
|
||||
int DrawStringCenteredTruncated(int x, int y, StringID str, uint16 color, uint maxw);
|
||||
int DrawStringCenteredTruncated(int xl, int xr, int y, StringID str, uint16 color);
|
||||
|
||||
int DrawString(int x, int y, StringID str, uint16 color);
|
||||
int DrawStringTruncated(int x, int y, StringID str, uint16 color, uint maxw);
|
||||
|
@ -46,7 +46,7 @@ int DoDrawString(const char *string, int x, int y, uint16 color);
|
|||
int DoDrawStringTruncated(const char *str, int x, int y, uint16 color, uint maxw);
|
||||
|
||||
void DrawStringCenterUnderline(int x, int y, StringID str, uint16 color);
|
||||
void DrawStringCenterUnderlineTruncated(int x, int y, StringID str, uint16 color, uint maxw);
|
||||
void DrawStringCenterUnderlineTruncated(int xl, int xr, int y, StringID str, uint16 color);
|
||||
|
||||
void DrawStringRightAligned(int x, int y, StringID str, uint16 color);
|
||||
void DrawStringRightAlignedTruncated(int x, int y, StringID str, uint16 color, uint maxw);
|
||||
|
|
|
@ -277,10 +277,8 @@ static void RoadVehViewWndProc(Window *w, WindowEvent *e)
|
|||
}
|
||||
|
||||
/* draw the flag plus orders */
|
||||
{ int w_width = w->widget[5].right - w->widget[5].left;
|
||||
DrawSprite(v->vehstatus & VS_STOPPED ? 0xC12 : 0xC13, 2, w->widget[5].top + 1);
|
||||
DrawStringCenteredTruncated(w_width / 2 + 6, w->widget[5].top + 1, str, 0, w_width - 8);
|
||||
}
|
||||
DrawSprite(v->vehstatus & VS_STOPPED ? 0xC12 : 0xC13, 2, w->widget[5].top + 1);
|
||||
DrawStringCenteredTruncated(w->widget[5].left + 8, w->widget[5].right, w->widget[5].top + 1, str, 0);
|
||||
DrawWindowViewport(w);
|
||||
} break;
|
||||
|
||||
|
|
|
@ -516,10 +516,8 @@ static void ShipViewWndProc(Window *w, WindowEvent *e) {
|
|||
}
|
||||
|
||||
/* draw the flag plus orders */
|
||||
{ int w_width = w->widget[5].right - w->widget[5].left;
|
||||
DrawSprite(v->vehstatus & VS_STOPPED ? 0xC12 : 0xC13, 2, w->widget[5].top + 1);
|
||||
DrawStringCenteredTruncated(w_width / 2 + 6, w->widget[5].top + 1, str, 0, w_width - 8);
|
||||
}
|
||||
DrawSprite(v->vehstatus & VS_STOPPED ? 0xC12 : 0xC13, 2, w->widget[5].top + 1);
|
||||
DrawStringCenteredTruncated(w->widget[5].left + 8, w->widget[5].right, w->widget[5].top + 1, str, 0);
|
||||
DrawWindowViewport(w);
|
||||
} break;
|
||||
|
||||
|
|
15
train_gui.c
15
train_gui.c
|
@ -417,9 +417,9 @@ static void DrawTrainDepotWindow(Window *w)
|
|||
do {
|
||||
i += u->u.rail.cached_veh_length + 1;
|
||||
} while ( (u=u->next) != NULL); //Determine length of train
|
||||
SetDParam(0, (i+8) / 9); //Set the counter
|
||||
i = (w->hscroll.cap * 29) + (x + 26); //Calculate position of text according to window size
|
||||
DrawStringCentered(i, y+5, STR_TINY_BLACK, 0); //Draw the counter
|
||||
|
||||
SetDParam(0, (i + 8) / 9); //Set the counter
|
||||
DrawStringRightAligned(w->widget[6].right - 1, y + 4, STR_TINY_BLACK, 0); //Draw the counter
|
||||
|
||||
/* Draw the pretty flag */
|
||||
DrawSprite(v->vehstatus&VS_STOPPED ? 0xC12 : 0xC13, x+15, y);
|
||||
|
@ -441,8 +441,7 @@ static void DrawTrainDepotWindow(Window *w)
|
|||
u = v;
|
||||
do i++; while ( (u=u->next) != NULL); //Determine length of train
|
||||
SetDParam(0, i); //Set the counter
|
||||
i = (w->hscroll.cap * 29) + (x + 26); //Calculate position of text according to window size
|
||||
DrawStringCentered(i, y+5, STR_TINY_BLACK, 0); //Draw the counter
|
||||
DrawStringRightAligned(w->widget[6].right - 1, y + 4, STR_TINY_BLACK, 0); //Draw the counter
|
||||
y += 14;
|
||||
}
|
||||
}
|
||||
|
@ -883,10 +882,8 @@ static void TrainViewWndProc(Window *w, WindowEvent *e)
|
|||
}
|
||||
|
||||
/* draw the flag plus orders */
|
||||
{ int w_width = w->widget[5].right - w->widget[5].left;
|
||||
DrawSprite(v->vehstatus & VS_STOPPED ? 0xC12 : 0xC13, 2, w->widget[5].top + 1);
|
||||
DrawStringCenteredTruncated(w_width / 2 + 6, w->widget[5].top + 1, str, 0, w_width - 8);
|
||||
}
|
||||
DrawSprite(v->vehstatus & VS_STOPPED ? 0xC12 : 0xC13, 2, w->widget[5].top + 1);
|
||||
DrawStringCenteredTruncated(w->widget[5].left + 8, w->widget[5].right, w->widget[5].top + 1, str, 0);
|
||||
DrawWindowViewport(w);
|
||||
} break;
|
||||
|
||||
|
|
Loading…
Reference in New Issue