Changeset - r11478:e8623893607d
[Not reviewed]
master
0 4 0
rubidium - 15 years ago 2009-03-25 01:10:24
rubidium@openttd.org
(svn r15844) -Codechange: allow text alignment to be forced so the console and ai debug output don't get swapped (those are untranslateable anyways)
4 files changed with 16 insertions and 13 deletions:
0 comments (0 inline, 0 general)
src/ai/ai_gui.cpp
Show inline comments
 
@@ -655,7 +655,7 @@ struct AIDebugWindow : public Window {
 
		assert(info != NULL);
 
		char name[1024];
 
		snprintf(name, sizeof(name), "%s (v%d)", info->GetName(), info->GetVersion());
 
		DrawString(7, this->widget[AID_WIDGET_VIEW].right, 47, name, TC_BLACK);
 
		DrawString(this->widget[AID_WIDGET_NAME_TEXT].left + 7, this->widget[AID_WIDGET_NAME_TEXT].right - 7, 47, name, TC_BLACK, SA_CENTER);
 

	
 
		CompanyID old_company = _current_company;
 
		_current_company = ai_debug_company;
 
@@ -681,7 +681,7 @@ struct AIDebugWindow : public Window {
 
				default:                  colour = TC_BLACK;  break;
 
			}
 

	
 
			DrawString(this->widget[AID_WIDGET_LOG_PANEL].left + 7, this->widget[AID_WIDGET_LOG_PANEL].right - 7, this->widget[AID_WIDGET_LOG_PANEL].top + y, log->lines[pos], colour);
 
			DrawString(this->widget[AID_WIDGET_LOG_PANEL].left + 7, this->widget[AID_WIDGET_LOG_PANEL].right - 7, this->widget[AID_WIDGET_LOG_PANEL].top + y, log->lines[pos], colour, SA_LEFT | SA_FORCE);
 
			y += 12;
 
		}
 
	}
src/console_gui.cpp
Show inline comments
 
@@ -163,24 +163,24 @@ struct IConsoleWindow : Window
 
	virtual void OnPaint()
 
	{
 
		const int max = (this->height / ICON_LINE_HEIGHT) - 1;
 
		const int right = this->width - 1;
 
		const int right = this->width - 5;
 

	
 
		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) {
 
			DrawString(5, right, this->height - (2 + i) * ICON_LINE_HEIGHT, print->buffer, print->colour);
 
			DrawString(5, right, this->height - (2 + i) * ICON_LINE_HEIGHT, print->buffer, print->colour, SA_LEFT | SA_FORCE);
 
		}
 
		/* 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) {
 
			DrawString(5, right, this->height - ICON_LINE_HEIGHT, "]", (TextColour)CC_COMMAND);
 
			DrawString(5, right, this->height - ICON_LINE_HEIGHT, "]", (TextColour)CC_COMMAND, SA_LEFT | SA_FORCE);
 
			delta = 0;
 
		}
 

	
 
		DrawString(10 + delta, right, this->height - ICON_LINE_HEIGHT, _iconsole_cmdline.buf, (TextColour)CC_COMMAND);
 
		DrawString(10 + delta, right, this->height - ICON_LINE_HEIGHT, _iconsole_cmdline.buf, (TextColour)CC_COMMAND, SA_LEFT | SA_FORCE);
 

	
 
		if (_focused_window == this && _iconsole_cmdline.caret) {
 
			DrawString(10 + delta + _iconsole_cmdline.caretxoffs, right, this->height - ICON_LINE_HEIGHT, "_", TC_WHITE);
 
			DrawString(10 + delta + _iconsole_cmdline.caretxoffs, right, this->height - ICON_LINE_HEIGHT, "_", TC_WHITE, SA_LEFT | SA_FORCE);
 
		}
 
	}
 

	
src/gfx.cpp
Show inline comments
 
@@ -426,7 +426,7 @@ static int DrawString(int left, int righ
 
			continue;
 
		}
 

	
 
		if (align != SA_LEFT) {
 
		if ((align & SA_MASK) != SA_LEFT) {
 
			DEBUG(grf, 1, "Using SETX and/or SETXY when not aligned to the left. Fixing alignment...");
 
			align = SA_LEFT;
 
		}
 
@@ -443,7 +443,7 @@ static int DrawString(int left, int righ
 
	}
 

	
 
	/* In case we have a RTL language we swap the alignment. */
 
	if (_dynlang.text_dir == TD_RTL && align != SA_CENTER) align = (StringAlignment)(align ^ 2);
 
	if (!(align & SA_FORCE) && _dynlang.text_dir == TD_RTL && align != SA_CENTER) align ^= SA_RIGHT;
 

	
 
	/* Now draw the parts. This is done in the reverse order so we can give the
 
	 * BiDi algorithm the room to replace characters. It also simplifies
 
@@ -470,7 +470,7 @@ static int DrawString(int left, int righ
 
		 * seen as lastof(todraw) and width as lengthof(todraw). They differ by 1.
 
		 * So most +1/-1 additions are to move from lengthof to 'indices'.
 
		 */
 
		switch (align) {
 
		switch (align & SA_MASK) {
 
			case SA_LEFT:
 
				/* right + 1 = left + w */
 
				left = initial_left + offset;
src/gfx_func.h
Show inline comments
 
@@ -87,10 +87,13 @@ void DrawSprite(SpriteID img, SpriteID p
 

	
 
/** How to align the to-be drawn text. */
 
enum StringAlignment {
 
	SA_LEFT,   ///< Left align the text
 
	SA_CENTER, ///< Center the text
 
	SA_RIGHT,  ///< Right align the text
 
	SA_LEFT,      ///< Left align the text
 
	SA_CENTER,    ///< Center the text
 
	SA_RIGHT,     ///< Right align the text
 
	SA_MASK  = 3, ///< Mask for base alignment
 
	SA_FORCE = 4, ///< Force the alignment, i.e. don't swap for RTL languages.
 
};
 
DECLARE_ENUM_AS_BIT_SET(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);
0 comments (0 inline, 0 general)