Fix cursor positioning.
authorTimo Korvola <tkorvola@iki.fi>
Mon, 26 Mar 2018 23:44:50 +0000 (02:44 +0300)
committerTimo Korvola <tkorvola@iki.fi>
Mon, 26 Mar 2018 23:47:55 +0000 (02:47 +0300)
Input text width was computed incorrectly.

src/sdl/sf_fonts.c
src/sdl/sf_frotz.h
src/sdl/sf_video.c

index 832819d9ada751333f61a02b4b6037af96c82607..cc9a183befec74f0d10c9f485386196dcfd3b071 100644 (file)
@@ -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();
 
index 8e706f64aaca91ce9cb79e743e7fe6186b8c2198..b6da1d4d5efd9ef9b071edb0c28e743bfabd50b1 100644 (file)
@@ -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);
index c54ed1307b891b122a3adf50cfcf844b2d49ab80..75f358e09223cc4795d570e15aee0da283db5192 100644 (file)
@@ -928,8 +928,8 @@ void sf_DrawInput(zchar * buffer, int pos, int ptx, int pty, int width, bool cur
 \r
   if (cursor)\r
        {\r
-       int wid=0, i=0;\r
-       while (i<pos) wid += os_char_width(buffer[i++]);\r
+       int wid=0, i=0, oh;\r
+       while (i<pos) wid += sf_charwidth(buffer[i++], &oh);\r
        drawthecursor(ptx+wid,pty,1);\r
        }\r
 \r