summaryrefslogtreecommitdiff
path: root/gfx.c
diff options
context:
space:
mode:
authorDarkvater <darkvater@openttd.org>2005-02-21 18:59:54 +0000
committerDarkvater <darkvater@openttd.org>2005-02-21 18:59:54 +0000
commitd865c55007321366d49b9b3d49eb0d61715dfc98 (patch)
treeac473756965e88790f53e13ff4589035499ce9c1 /gfx.c
parent0d8dcacee2dbd1ae639f8851a2847b3806c7da16 (diff)
downloadopenttd-d865c55007321366d49b9b3d49eb0d61715dfc98.tar.xz
(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().
Diffstat (limited to 'gfx.c')
-rw-r--r--gfx.c19
1 files changed, 7 insertions, 12 deletions
diff --git a/gfx.c b/gfx.c
index b4bf72894..4bdf40441 100644
--- a/gfx.c
+++ b/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;