forked from mirror/OpenTTD
(svn r1894) - Codechange: cleaned up the console a bit, wholly unified handling of text with that of editboxes
- Codechange: Introduction of Textbuf struct which not only holds physical data as length but also pixel-constrains (width) and information about the caret - Codechange: Move Clipboard function to OS specific file. Currently only Windows has clipboard actions - Feature: Editboxes, console and exit screen also accept the numeric-enter as a yes - Feature: Navigation through text with cursor keys is possible, as well as arbitrary insertion (also paste) and deletion; both backspace and del keys. Functions DeleteTextBufferChar, InsertTextBufferChar and InsertTextBufferClipboard handle input and deletion. Navigation is done through MoveTextBufferPos. - Fix: OTTD crash when opening 'add server' editbox - CodeChange: fix up some stringwidth calculations in gfx.c. You can get the width in pixels of a character by calling GetCharacterWidth().
This commit is contained in:
19
gfx.c
19
gfx.c
@@ -244,8 +244,6 @@ void GfxDrawLine(int x, int y, int x2, int y2, int color)
|
||||
|
||||
|
||||
enum {
|
||||
ASCII_LETTERSTART = 32,
|
||||
|
||||
ASCII_SETX = 1,
|
||||
ASCII_SETXY = 2,
|
||||
|
||||
@@ -309,10 +307,10 @@ static uint32 FormatStringLinebreaks(char *str, int maxw)
|
||||
|
||||
for(;;) {
|
||||
c = *str++;
|
||||
if (c == ' ') last_space = str;
|
||||
if (c == ASCII_LETTERSTART) last_space = str;
|
||||
|
||||
if (c >= ASCII_LETTERSTART) {
|
||||
w += _stringwidth_table[base + ((byte)c) - 0x20];
|
||||
w += GetCharacterWidth(base + (byte)c);
|
||||
if (w > maxw) {
|
||||
str = last_space;
|
||||
if (str == NULL)
|
||||
@@ -428,16 +426,12 @@ void DrawStringMultiLine(int x, int y, uint16 str, int maxw) {
|
||||
|
||||
int GetStringWidth(const char *str)
|
||||
{
|
||||
int w = -1;
|
||||
int w = 0;
|
||||
byte c;
|
||||
int base = _stringwidth_base;
|
||||
|
||||
for(;;) {
|
||||
c = *str++;
|
||||
if (c == 0)
|
||||
return w;
|
||||
for (c = *str; c != '\0'; c = *(++str)) {
|
||||
if (c >= ASCII_LETTERSTART) {
|
||||
w += _stringwidth_table[base + c - ASCII_LETTERSTART];
|
||||
w += GetCharacterWidth(base + c);
|
||||
} else {
|
||||
if (c == ASCII_SETX) str++;
|
||||
else if (c == ASCII_SETXY) str += 2;
|
||||
@@ -445,6 +439,7 @@ int GetStringWidth(const char *str)
|
||||
else if (c == ASCII_BIGFONT) base = 448;
|
||||
}
|
||||
}
|
||||
return w;
|
||||
}
|
||||
|
||||
void DrawFrameRect(int left, int top, int right, int bottom, int ctab, int flags) {
|
||||
@@ -531,7 +526,7 @@ skip_cont:;
|
||||
if (x + 26 >= dpi->left) {
|
||||
GfxMainBlitter(GetSprite(base + 2 + c - ASCII_LETTERSTART), x, y, 1);
|
||||
}
|
||||
x += _stringwidth_table[base + c - ' '];
|
||||
x += GetCharacterWidth(base + c);
|
||||
} else if (c == ASCII_NL) { // newline = {}
|
||||
x = xo;
|
||||
y += 10;
|
||||
|
Reference in New Issue
Block a user