(svn r15794) -Codechange: remove the DoDrawString part of the old text drawing API

This commit is contained in:
rubidium 2009-03-21 22:46:17 +00:00
parent ce513b46b7
commit f11300d1f9
10 changed files with 35 additions and 58 deletions

View File

@ -162,24 +162,25 @@ struct IConsoleWindow : Window
virtual void OnPaint()
{
int max = (this->height / ICON_LINE_HEIGHT) - 1;
const int max = (this->height / ICON_LINE_HEIGHT) - 1;
const int right = this->width - 1;
const IConsoleLine *print = IConsoleLine::Get(IConsoleWindow::scroll);
GfxFillRect(this->left, this->top, this->width, this->height - 1, 0);
for (int i = 0; i < max && print != NULL; i++, print = print->previous) {
DoDrawString(print->buffer, 5,
this->height - (2 + i) * ICON_LINE_HEIGHT, print->colour);
DrawString(5, right, this->height - (2 + i) * ICON_LINE_HEIGHT, print->buffer, print->colour);
}
/* If the text is longer than the window, don't show the starting ']' */
int delta = this->width - 10 - _iconsole_cmdline.width - ICON_RIGHT_BORDERWIDTH;
if (delta > 0) {
DoDrawString("]", 5, this->height - ICON_LINE_HEIGHT, (TextColour)CC_COMMAND);
DrawString(5, right, this->height - ICON_LINE_HEIGHT, "]", (TextColour)CC_COMMAND);
delta = 0;
}
DoDrawString(_iconsole_cmdline.buf, 10 + delta, this->height - ICON_LINE_HEIGHT, (TextColour)CC_COMMAND);
DrawString(10 + delta, right, this->height - ICON_LINE_HEIGHT, _iconsole_cmdline.buf, (TextColour)CC_COMMAND);
if (_focused_window == this && _iconsole_cmdline.caret) {
DoDrawString("_", 10 + delta + _iconsole_cmdline.caretxoffs, this->height - ICON_LINE_HEIGHT, TC_WHITE);
DrawString(10 + delta + _iconsole_cmdline.caretxoffs, right, this->height - ICON_LINE_HEIGHT, "_", TC_WHITE);
}
}

View File

@ -763,32 +763,6 @@ void DrawCharCentered(WChar c, int x, int y, TextColour colour)
GfxMainBlitter(GetGlyph(FS_NORMAL, c), x - GetCharacterWidth(FS_NORMAL, c) / 2, y, BM_COLOUR_REMAP);
}
/** Draw a string at the given coordinates with the given colour.
* While drawing the string, parse it in case some formatting is specified,
* like new colour, new size or even positionning.
* @param string The string to draw. This is not yet bidi reordered.
* @param x Offset from left side of the screen
* @param y Offset from top side of the screen
* @param colour Colour of the string, see _string_colourmap in
* table/palettes.h or docs/ottd-colourtext-palette.png or the enum TextColour in gfx_type.h
* @param parse_string_also_when_clipped
* By default, always test the available space where to draw the string.
* When in multipline drawing, it would already be done,
* so no need to re-perform the same kind (more or less) of verifications.
* It's not only an optimisation, it's also a way to ensures the string will be parsed
* (as there are certain side effects on global variables, which are important for the next line)
* @return the x-coordinates where the drawing has finished.
* If nothing is drawn, the originally passed x-coordinate is returned
*/
int DoDrawString(const char *string, int x, int y, TextColour colour, bool parse_string_also_when_clipped)
{
char buffer[DRAW_STRING_BUFFER];
strecpy(buffer, string, lastof(buffer));
HandleBiDiAndArabicShapes(buffer, lastof(buffer));
return ReallyDoDrawString(buffer, x, y, colour, parse_string_also_when_clipped);
}
/** Draw a string at the given coordinates with the given colour.
* While drawing the string, parse it in case some formatting is specified,
* like new colour, new size or even positionning.

View File

@ -96,7 +96,6 @@ int DrawString(int left, int right, int top, const char *str, TextColour colour,
int DrawString(int left, int right, int top, StringID str, TextColour colour, StringAlignment align = SA_LEFT, bool underline = false);
int DrawString(int x, int y, StringID str, TextColour colour);
int DoDrawString(const char *string, int x, int y, TextColour colour, bool parse_string_also_when_clipped = false);
void DrawCharCentered(uint32 c, int x, int y, TextColour colour);

View File

@ -140,6 +140,8 @@ struct HighScoreWindow : EndGameHighScoreBaseWindow {
this->SetupHighScoreEndWindow(&x, &y);
const int right = this->left + this->width - 1;
SetDParam(0, ORIGINAL_END_YEAR);
SetDParam(1, this->window_number + STR_6801_EASY);
DrawStringMultiCenter(x + (640 / 2), y + 62, !_networking ? STR_0211_TOP_COMPANIES_WHO_REACHED : STR_TOP_COMPANIES_NETWORK_GAME, 500);
@ -147,15 +149,15 @@ struct HighScoreWindow : EndGameHighScoreBaseWindow {
/* Draw Highscore peepz */
for (uint8 i = 0; i < lengthof(_highscore_table[0]); i++) {
SetDParam(0, i + 1);
DrawString(x + 40, y + 140 + (i * 55), STR_0212, TC_BLACK);
DrawString(x + 40, right, y + 140 + (i * 55), STR_0212, TC_BLACK);
if (hs[i].company[0] != '\0') {
TextColour colour = (this->rank == i) ? TC_RED : TC_BLACK; // draw new highscore in red
DoDrawString(hs[i].company, x + 71, y + 140 + (i * 55), colour);
DrawString(x + 71, right, y + 140 + (i * 55), hs[i].company, colour);
SetDParam(0, hs[i].title);
SetDParam(1, hs[i].score);
DrawString(x + 71, y + 160 + (i * 55), STR_HIGHSCORE_STATS, colour);
DrawString(x + 71, right, y + 160 + (i * 55), STR_HIGHSCORE_STATS, colour);
}
}
}

View File

@ -1064,8 +1064,8 @@ void QueryString::DrawEditBox(Window *w, int wid)
if (tb->caretxoffs + delta < 0) delta = -tb->caretxoffs;
DoDrawString(tb->buf, delta, 0, TC_YELLOW);
if (HasEditBoxFocus(w, wid) && tb->caret) DoDrawString("_", tb->caretxoffs + delta, 0, TC_WHITE);
DrawString(delta, tb->width, 0, tb->buf, TC_YELLOW);
if (HasEditBoxFocus(w, wid) && tb->caret) DrawString(tb->caretxoffs + delta, tb->width + 10, 0, "_", TC_WHITE);
_cur_dpi = old_dpi;
}

View File

@ -237,7 +237,7 @@ void NetworkDrawChatMessage()
/* Paint the chat messages starting with the lowest at the bottom */
for (uint y = NETWORK_CHAT_LINE_HEIGHT; count-- != 0; y += NETWORK_CHAT_LINE_HEIGHT) {
DoDrawString(_chatmsg_list[count].message, _chatmsg_box.x + 3, _screen.height - _chatmsg_box.y - y + 1, _chatmsg_list[count].colour);
DrawString(_chatmsg_box.x + 3, _chatmsg_box.x + _chatmsg_box.width - 1, _screen.height - _chatmsg_box.y - y + 1, _chatmsg_list[count].message, _chatmsg_list[count].colour);
}
/* Make sure the data is updated next flush */

View File

@ -906,7 +906,7 @@ struct NetworkStartServerWindow : public QueryStringBaseWindow {
this->DrawEditBox(NSSW_GAMENAME);
/* if password is set, draw red '*' next to 'Set password' button */
if (!StrEmpty(_settings_client.network.server_password)) DoDrawString("*", 408, 23, TC_RED);
if (!StrEmpty(_settings_client.network.server_password)) DrawString(408, this->width - 2, 23, "*", TC_RED);
/* draw list of maps */
GfxFillRect(11, 63, 258, 215, 0xD7); // black background of maps list
@ -919,7 +919,7 @@ struct NetworkStartServerWindow : public QueryStringBaseWindow {
if (pos == 0) {
DrawString(14, y, STR_4010_GENERATE_RANDOM_NEW_GAME, TC_DARK_GREEN);
} else {
DoDrawString(item->title, 14, y, _fios_colours[item->type] );
DrawString(14, this->width - 1, y, item->title, _fios_colours[item->type] );
}
y += NSSWND_ROWSIZE;
@ -1609,7 +1609,7 @@ struct NetworkClientListPopupWindow : Window {
colour = TC_BLACK;
}
DoDrawString(this->action[i], 4, y, colour);
DrawString(4, this->width - 4, y, this->action[i], colour);
}
}
@ -1718,7 +1718,7 @@ struct NetworkClientListWindow : Window
/* Filter out spectators */
if (IsValidCompanyID(ci->client_playas)) DrawCompanyIcon(ci->client_playas, 64, y + 1);
DoDrawString(ci->client_name, 81, y, colour);
DrawString(81, this->width - 2, y, ci->client_name, colour);
y += CLNWND_ROWSIZE;
}

View File

@ -1495,6 +1495,7 @@ struct CustomCurrencyWindow : Window {
virtual void OnPaint()
{
int const right = this->width - 1;
int x;
int y = 20;
this->DrawWidgets();
@ -1503,37 +1504,37 @@ struct CustomCurrencyWindow : Window {
DrawArrowButtons(10, y, COLOUR_YELLOW, GB(this->click, 0, 2), true, true);
SetDParam(0, 1);
SetDParam(1, 1);
DrawString(35, y + 1, STR_CURRENCY_EXCHANGE_RATE, TC_FROMSTRING);
DrawString(35, right, y + 1, STR_CURRENCY_EXCHANGE_RATE, TC_FROMSTRING);
y += 12;
/* separator */
DrawFrameRect(10, y + 1, 29, y + 9, COLOUR_DARK_BLUE, GB(this->click, 2, 2) ? FR_LOWERED : FR_NONE);
x = DrawString(35, y + 1, STR_CURRENCY_SEPARATOR, TC_FROMSTRING);
DoDrawString(this->separator, x + 4, y + 1, TC_ORANGE);
x = DrawString(35, right, y + 1, STR_CURRENCY_SEPARATOR, TC_FROMSTRING);
DrawString(x + 4, right, y + 1, this->separator, TC_ORANGE);
y += 12;
/* prefix */
DrawFrameRect(10, y + 1, 29, y + 9, COLOUR_DARK_BLUE, GB(this->click, 4, 2) ? FR_LOWERED : FR_NONE);
x = DrawString(35, y + 1, STR_CURRENCY_PREFIX, TC_FROMSTRING);
DoDrawString(_custom_currency.prefix, x + 4, y + 1, TC_ORANGE);
x = DrawString(35, right, y + 1, STR_CURRENCY_PREFIX, TC_FROMSTRING);
DrawString(right, x + 4, y + 1, _custom_currency.prefix, TC_ORANGE);
y += 12;
/* suffix */
DrawFrameRect(10, y + 1, 29, y + 9, COLOUR_DARK_BLUE, GB(this->click, 6, 2) ? FR_LOWERED : FR_NONE);
x = DrawString(35, y + 1, STR_CURRENCY_SUFFIX, TC_FROMSTRING);
DoDrawString(_custom_currency.suffix, x + 4, y + 1, TC_ORANGE);
x = DrawString(35, right, y + 1, STR_CURRENCY_SUFFIX, TC_FROMSTRING);
DrawString(x + 4, right, y + 1, _custom_currency.suffix, TC_ORANGE);
y += 12;
/* switch to euro */
DrawArrowButtons(10, y, COLOUR_YELLOW, GB(this->click, 8, 2), true, true);
SetDParam(0, _custom_currency.to_euro);
DrawString(35, y + 1, (_custom_currency.to_euro != CF_NOEURO) ? STR_CURRENCY_SWITCH_TO_EURO : STR_CURRENCY_SWITCH_TO_EURO_NEVER, TC_FROMSTRING);
DrawString(35, right, y + 1, (_custom_currency.to_euro != CF_NOEURO) ? STR_CURRENCY_SWITCH_TO_EURO : STR_CURRENCY_SWITCH_TO_EURO_NEVER, TC_FROMSTRING);
y += 12;
/* Preview */
y += 12;
SetDParam(0, 10000);
DrawString(35, y + 1, STR_CURRENCY_PREVIEW, TC_FROMSTRING);
DrawString(35, right, y + 1, STR_CURRENCY_PREVIEW, TC_FROMSTRING);
}
virtual void OnClick(Point pt, int widget)

View File

@ -57,7 +57,7 @@ static bool DrawScrollingStatusText(const NewsItem *ni, int pos, int width)
DrawPixelInfo *old_dpi = _cur_dpi;
_cur_dpi = &tmp_dpi;
int x = DoDrawString(buffer, pos, 0, TC_LIGHT_BLUE);
int x = DrawString(pos, pos + width, 0, buffer, TC_LIGHT_BLUE);
_cur_dpi = old_dpi;
return x > 0;

View File

@ -317,11 +317,11 @@ void Window::DrawWidgets() const
/* draw up/down buttons */
clicked = ((this->flags4 & (WF_SCROLL_UP | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_UP);
DrawFrameRect(r.left, r.top, r.right, r.top + 9, wi->colour, (clicked) ? FR_LOWERED : FR_NONE);
DoDrawString(UPARROW, r.left + 2 + clicked, r.top + clicked, TC_BLACK);
DrawString(r.left + 2 + clicked, r.right, r.top + clicked, UPARROW, TC_BLACK);
clicked = (((this->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_DOWN));
DrawFrameRect(r.left, r.bottom - 9, r.right, r.bottom, wi->colour, (clicked) ? FR_LOWERED : FR_NONE);
DoDrawString(DOWNARROW, r.left + 2 + clicked, r.bottom - 9 + clicked, TC_BLACK);
DrawString(r.left + 2 + clicked, r.right, r.bottom - 9 + clicked, DOWNARROW, TC_BLACK);
int c1 = _colour_gradient[wi->colour & 0xF][3];
int c2 = _colour_gradient[wi->colour & 0xF][7];
@ -348,11 +348,11 @@ void Window::DrawWidgets() const
/* draw up/down buttons */
clicked = ((this->flags4 & (WF_SCROLL_UP | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_UP | WF_SCROLL2));
DrawFrameRect(r.left, r.top, r.right, r.top + 9, wi->colour, (clicked) ? FR_LOWERED : FR_NONE);
DoDrawString(UPARROW, r.left + 2 + clicked, r.top + clicked, TC_BLACK);
DrawString(r.left + 2 + clicked, r.right, r.top + clicked, UPARROW, TC_BLACK);
clicked = ((this->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_DOWN | WF_SCROLL2));
DrawFrameRect(r.left, r.bottom - 9, r.right, r.bottom, wi->colour, (clicked) ? FR_LOWERED : FR_NONE);
DoDrawString(DOWNARROW, r.left + 2 + clicked, r.bottom - 9 + clicked, TC_BLACK);
DrawString(r.left + 2 + clicked, r.right, r.bottom - 9 + clicked, DOWNARROW, TC_BLACK);
int c1 = _colour_gradient[wi->colour & 0xF][3];
int c2 = _colour_gradient[wi->colour & 0xF][7];
@ -625,5 +625,5 @@ void Window::DrawSortButtonState(int widget, SortButtonState state) const
if (state == SBS_OFF) return;
int offset = this->IsWidgetLowered(widget) ? 1 : 0;
DoDrawString(state == SBS_DOWN ? DOWNARROW : UPARROW, this->widget[widget].right - 11 + offset, this->widget[widget].top + 1 + offset, TC_BLACK);
DrawString(this->widget[widget].right - 11 + offset, this->widget[widget].right, this->widget[widget].top + 1 + offset, state == SBS_DOWN ? DOWNARROW : UPARROW, TC_BLACK);
}