fix sdl file dialog list display
authorborg323 <4010067-borg323@users.noreply.gitlab.com>
Fri, 5 Jul 2019 00:19:18 +0000 (03:19 +0300)
committerborg323 <4010067-borg323@users.noreply.gitlab.com>
Fri, 5 Jul 2019 00:19:18 +0000 (03:19 +0300)
src/sdl/sf_osfdlg.c

index e8fc9eda5588f511eb59f5d6ce5eb7ef7acc524d..86a966dccdc0276fe110405ae49beb59e6cd363d 100644 (file)
@@ -641,6 +641,21 @@ STATIC ENTRY * dodir(
   return res;
   }
 
+#ifdef USE_UTF8
+// Convert character count into index in UTF-8 encoded string.
+// Works by skipping over continuation bytes.
+STATIC int utf8_char_pos(char *s, int pos)
+  {
+  int cpos;
+  int idx = 0;
+  for (cpos = 0; s[cpos] && idx < pos; cpos++)
+    {
+    if ((s[cpos+1] & 0xc0) != 0x80)
+      idx++;
+    }
+  return cpos;
+}
+#endif
 
 //////////////////////////////////////////////
 // white,black,gray,yellow
@@ -722,18 +737,31 @@ STATIC void drawit( int x, int y, ENTRY *e, int w, int issub)
   int i, j, n, color;
   unsigned char *bmp;
   char *s = e->value;
+  int width, height;
+  os_font_data(0, &height, &width);
   bmp = (issub ? folderbmp : docbmp);
   for (i=0;i<16;i++) for (j=0;j<16;j++) sf_wpixel(x+j,y+i,bcolors[*bmp++]);
   x += 17;
   w -= 17;
-  n = w/8;
+  n = w/width;
   if (n < 1) return;
   if (strlen(s) > n)
        {
        strcpy(buffer,s);
+#ifndef USE_UTF8
        buffer[n] = 0;
        buffer[n-1] = '>';
        s = buffer;
+#else
+       i = utf8_len(buffer);
+       if (i > n-1)
+         {
+         j = utf8_char_pos(buffer, n-1);
+         buffer[j+1] = 0;
+         buffer[j] = '>';
+         s = buffer;
+         }
+#endif
        }
   if (e == selected)
        {
@@ -903,22 +931,6 @@ STATIC zword yesnoover( int xc, int yc)
   return c;
   }
 
-#ifdef USE_UTF8
-// Convert character count into index in UTF-8 encoded string.
-// Works by skipping over continuation bytes.
-STATIC int utf8_char_pos(char *s, int pos)
-  {
-  int cpos;
-  int idx = 0;
-  for (cpos = 0; s[cpos] && idx < pos; cpos++)
-    {
-    if ((s[cpos+1] & 0xc0) != 0x80)
-      idx++;
-    }
-  return cpos;
-}
-#endif
-
 // this is needed for overlapping source and dest in Zentry
 // (lib does not guarantee correct behaviour in that case)
 static void mystrcpy( char *d, const char *s)