From 57f12a3121522fb1d70228596c0252cc3a903727 Mon Sep 17 00:00:00 2001 From: Timo Korvola Date: Tue, 27 Mar 2018 02:44:50 +0300 Subject: [PATCH] Fix cursor positioning. Input text width was computed incorrectly. --- src/sdl/sf_fonts.c | 10 +++++----- src/sdl/sf_frotz.h | 6 ++++++ src/sdl/sf_video.c | 4 ++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/sdl/sf_fonts.c b/src/sdl/sf_fonts.c index 832819d..cc9a183 100644 --- a/src/sdl/sf_fonts.c +++ b/src/sdl/sf_fonts.c @@ -439,11 +439,11 @@ int os_check_unicode(int font, zword c) return ((current.font->hasglyph(current.font,c,0) != 0) ? 3 : 2); } -static int charwidth( zword c, int *oh) +int sf_charwidth( zword c, int *oh) { SF_glyph *g; int ww = 0; - if (c == ZC_INDENT) return (3*charwidth(' ',oh)); - if (c == ZC_GAP) return (2*charwidth(' ',oh)); + if (c == ZC_INDENT) return (3*sf_charwidth(' ',oh)); + if (c == ZC_GAP) return (2*sf_charwidth(' ',oh)); *oh = 0; g = current.font->getglyph(current.font,c,1); if (g) @@ -464,7 +464,7 @@ static int charwidth( zword c, int *oh) int os_char_width(zchar c) { int w, oh; - w = charwidth( c, &oh); + w = sf_charwidth( c, &oh); return (w+oh); } @@ -583,7 +583,7 @@ int os_string_width(const zchar *s) os_set_font(*s++); } else - width += charwidth(c,&oh); + width += sf_charwidth(c,&oh); } sf_poptextsettings(); diff --git a/src/sdl/sf_frotz.h b/src/sdl/sf_frotz.h index 8e706f6..b6da1d4 100644 --- a/src/sdl/sf_frotz.h +++ b/src/sdl/sf_frotz.h @@ -160,6 +160,12 @@ typedef struct { SF_textsetting * sf_curtextsetting(void); +/** + * Return the advance width of character c. + * Store glyph width minus advance width to oh ("overhang"). + */ +int sf_charwidth( zword c, int *oh); + void sf_writeglyph( SF_glyph *g); void sf_fillrect( unsigned long color, int x, int y, int w, int h); diff --git a/src/sdl/sf_video.c b/src/sdl/sf_video.c index c54ed13..75f358e 100644 --- a/src/sdl/sf_video.c +++ b/src/sdl/sf_video.c @@ -928,8 +928,8 @@ void sf_DrawInput(zchar * buffer, int pos, int ptx, int pty, int width, bool cur if (cursor) { - int wid=0, i=0; - while (i