Changeset - r11431:95d135f68fee
[Not reviewed]
master
0 10 0
rubidium - 16 years ago 2009-03-21 22:46:17
rubidium@openttd.org
(svn r15794) -Codechange: remove the DoDrawString part of the old text drawing API
10 files changed with 35 insertions and 58 deletions:
0 comments (0 inline, 0 general)
src/console_gui.cpp
Show inline comments
 
@@ -159,30 +159,31 @@ struct IConsoleWindow : Window
 
	{
 
		_iconsole_mode = ICONSOLE_CLOSED;
 
	}
 

	
 
	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);
 
		}
 
	}
 

	
 
	virtual void OnHundredthTick()
 
	{
 
		if (IConsoleLine::Truncate() &&
src/gfx.cpp
Show inline comments
 
@@ -763,38 +763,12 @@ void DrawCharCentered(WChar c, int x, in
 
	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.
 
 * @param string              The string to draw. This is already 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
src/gfx_func.h
Show inline comments
 
@@ -93,13 +93,12 @@ enum StringAlignment {
 
};
 

	
 
int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align = SA_LEFT, bool underline = false);
 
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);
 

	
 
void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode = FILLRECT_OPAQUE);
 
void GfxDrawLine(int left, int top, int right, int bottom, int colour);
 
void DrawBox(int x, int y, int dx1, int dy1, int dx2, int dy2, int dx3, int dy3);
src/highscore_gui.cpp
Show inline comments
 
@@ -137,28 +137,30 @@ struct HighScoreWindow : EndGameHighScor
 
	{
 
		const HighScore *hs = _highscore_table[this->window_number];
 
		uint x, y;
 

	
 
		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);
 

	
 
		/* 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);
 
			}
 
		}
 
	}
 
};
 

	
 
static const Widget _highscore_widgets[] = {
src/misc_gui.cpp
Show inline comments
 
@@ -1061,14 +1061,14 @@ void QueryString::DrawEditBox(Window *w,
 

	
 
	delta = (wi->right - wi->left) - tb->width - 10;
 
	if (delta > 0) delta = 0;
 

	
 
	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;
 
}
 

	
 
HandleEditBoxResult QueryStringBaseWindow::HandleEditBoxKey(int wid, uint16 key, uint16 keycode, EventState &state)
 
{
src/network/network_chat_gui.cpp
Show inline comments
 
@@ -234,13 +234,13 @@ void NetworkDrawChatMessage()
 
			_screen.height - _chatmsg_box.y - 2,
 
			PALETTE_TO_TRANSPARENT, FILLRECT_RECOLOUR // black, but with some alpha for background
 
		);
 

	
 
	/* 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 */
 
	_video_driver->MakeDirty(x, y, width, height);
 

	
 
	_chatmessage_visible = true;
src/network/network_gui.cpp
Show inline comments
 
@@ -903,26 +903,26 @@ struct NetworkStartServerWindow : public
 
		this->DrawWidgets();
 

	
 
		/* editbox to set game name */
 
		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
 

	
 
		for (uint pos = this->vscroll.pos; pos < _fios_items.Length() + 1; pos++) {
 
			item = _fios_items.Get(pos - 1);
 
			if (item == this->map || (pos == 0 && this->map == NULL))
 
				GfxFillRect(11, y - 1, 258, y + 10, 155); // show highlighted item with a different colour
 

	
 
			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;
 

	
 
			if (y >= this->vscroll.cap * NSSWND_ROWSIZE + NSSWND_START) break;
 
		}
 
	}
 
@@ -1606,13 +1606,13 @@ struct NetworkClientListPopupWindow : Wi
 
				GfxFillRect(1, y, 150 - 2, y + CLNWND_ROWSIZE - 1, 0);
 
				colour = TC_WHITE;
 
			} else {
 
				colour = TC_BLACK;
 
			}
 

	
 
			DoDrawString(this->action[i], 4, y, colour);
 
			DrawString(4, this->width - 4, y, this->action[i], colour);
 
		}
 
	}
 

	
 
	virtual void OnMouseLoop()
 
	{
 
		/* We selected an action */
 
@@ -1715,13 +1715,13 @@ struct NetworkClientListWindow : Window
 
				DrawString(4, y, STR_NETWORK_CLIENT, colour);
 
			}
 

	
 
			/* 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;
 
		}
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget)
src/settings_gui.cpp
Show inline comments
 
@@ -1492,51 +1492,52 @@ struct CustomCurrencyWindow : Window {
 
		this->separator[1] = '\0';
 
		this->FindWindowPlacementAndResize(desc);
 
	}
 

	
 
	virtual void OnPaint()
 
	{
 
		int const right = this->width - 1;
 
		int x;
 
		int y = 20;
 
		this->DrawWidgets();
 

	
 
		/* exchange rate */
 
		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)
 
	{
 
		int line = (pt.y - 20) / 12;
 
		int len = 0;
src/statusbar_gui.cpp
Show inline comments
 
@@ -54,13 +54,13 @@ static bool DrawScrollingStatusText(cons
 
	DrawPixelInfo tmp_dpi;
 
	if (!FillDrawPixelInfo(&tmp_dpi, 141, 1, width, 11)) return true;
 

	
 
	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;
 
}
 

	
 
struct StatusBarWindow : Window {
src/widget.cpp
Show inline comments
 
@@ -314,17 +314,17 @@ void Window::DrawWidgets() const
 
			assert(wi->data == 0);
 
			assert(r.right - r.left == 11); // To ensure the same sizes are used everywhere!
 

	
 
			/* 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];
 

	
 
			/* draw "shaded" background */
 
			GfxFillRect(r.left, r.top + 10, r.right, r.bottom - 10, c2);
 
@@ -345,17 +345,17 @@ void Window::DrawWidgets() const
 
			assert(wi->data == 0);
 
			assert(r.right - r.left == 11); // To ensure the same sizes are used everywhere!
 

	
 
			/* 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];
 

	
 
			/* draw "shaded" background */
 
			GfxFillRect(r.left, r.top + 10, r.right, r.bottom - 10, c2);
 
@@ -622,8 +622,8 @@ void ResizeWindowForWidget(Window *w, ui
 
 */
 
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);
 
}
0 comments (0 inline, 0 general)