mirror of https://github.com/OpenTTD/OpenTTD
(svn r15844) -Codechange: allow text alignment to be forced so the console and ai debug output don't get swapped (those are untranslateable anyways)
parent
4a500bbcdb
commit
3e93f8adda
|
@ -655,7 +655,7 @@ struct AIDebugWindow : public Window {
|
||||||
assert(info != NULL);
|
assert(info != NULL);
|
||||||
char name[1024];
|
char name[1024];
|
||||||
snprintf(name, sizeof(name), "%s (v%d)", info->GetName(), info->GetVersion());
|
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;
|
CompanyID old_company = _current_company;
|
||||||
_current_company = ai_debug_company;
|
_current_company = ai_debug_company;
|
||||||
|
@ -681,7 +681,7 @@ struct AIDebugWindow : public Window {
|
||||||
default: colour = TC_BLACK; break;
|
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;
|
y += 12;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -163,24 +163,24 @@ struct IConsoleWindow : Window
|
||||||
virtual void OnPaint()
|
virtual void OnPaint()
|
||||||
{
|
{
|
||||||
const int max = (this->height / ICON_LINE_HEIGHT) - 1;
|
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);
|
const IConsoleLine *print = IConsoleLine::Get(IConsoleWindow::scroll);
|
||||||
GfxFillRect(this->left, this->top, this->width, this->height - 1, 0);
|
GfxFillRect(this->left, this->top, this->width, this->height - 1, 0);
|
||||||
for (int i = 0; i < max && print != NULL; i++, print = print->previous) {
|
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 ']' */
|
/* If the text is longer than the window, don't show the starting ']' */
|
||||||
int delta = this->width - 10 - _iconsole_cmdline.width - ICON_RIGHT_BORDERWIDTH;
|
int delta = this->width - 10 - _iconsole_cmdline.width - ICON_RIGHT_BORDERWIDTH;
|
||||||
if (delta > 0) {
|
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;
|
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) {
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -426,7 +426,7 @@ static int DrawString(int left, int right, int top, char *str, const char *last,
|
||||||
continue;
|
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...");
|
DEBUG(grf, 1, "Using SETX and/or SETXY when not aligned to the left. Fixing alignment...");
|
||||||
align = SA_LEFT;
|
align = SA_LEFT;
|
||||||
}
|
}
|
||||||
|
@ -443,7 +443,7 @@ static int DrawString(int left, int right, int top, char *str, const char *last,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* In case we have a RTL language we swap the alignment. */
|
/* 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
|
/* 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
|
* BiDi algorithm the room to replace characters. It also simplifies
|
||||||
|
@ -470,7 +470,7 @@ static int DrawString(int left, int right, int top, char *str, const char *last,
|
||||||
* seen as lastof(todraw) and width as lengthof(todraw). They differ by 1.
|
* 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'.
|
* So most +1/-1 additions are to move from lengthof to 'indices'.
|
||||||
*/
|
*/
|
||||||
switch (align) {
|
switch (align & SA_MASK) {
|
||||||
case SA_LEFT:
|
case SA_LEFT:
|
||||||
/* right + 1 = left + w */
|
/* right + 1 = left + w */
|
||||||
left = initial_left + offset;
|
left = initial_left + offset;
|
||||||
|
|
|
@ -87,10 +87,13 @@ void DrawSprite(SpriteID img, SpriteID pal, int x, int y, const SubSprite *sub =
|
||||||
|
|
||||||
/** How to align the to-be drawn text. */
|
/** How to align the to-be drawn text. */
|
||||||
enum StringAlignment {
|
enum StringAlignment {
|
||||||
SA_LEFT, ///< Left align the text
|
SA_LEFT, ///< Left align the text
|
||||||
SA_CENTER, ///< Center the text
|
SA_CENTER, ///< Center the text
|
||||||
SA_RIGHT, ///< Right align 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, 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 left, int right, int top, StringID str, TextColour colour, StringAlignment align = SA_LEFT, bool underline = false);
|
||||||
|
|
Loading…
Reference in New Issue