Pārlūkot izejas kodu

Better rendering unicode support

Kajetan Johannes Hammerle 1 dienu atpakaļ
vecāks
revīzija
8e5d7aafb7
3 mainītis faili ar 23 papildinājumiem un 32 dzēšanām
  1. 15 28
      examples/window.basic
  2. 6 2
      src/SystemFunctions.c
  3. 2 2
      src/WindowCharacters.c

+ 15 - 28
examples/window.basic

@@ -29,30 +29,17 @@ while !shouldClose()
     if isButtonDown(BT_DOWN)
         y = y + 1
     end
-    if isButtonDown(BT_START)
-        big(100, 80)
-    end
-    if isButtonDown(BT_SELECT)
-        big(100, 90)
-    end
-    if isButtonDown(BT_A)
-        big(100, 100)
-    end
-    if isButtonDown(BT_B)
-        big(100, 110)
-    end
-    if isButtonDown(BT_X)
-        big(100, 120)
-    end
-    if isButtonDown(BT_Y)
-        big(100, 130)
-    end
-    if isButtonDown(BT_L)
-        big(100, 140)
-    end
-    if isButtonDown(BT_R)
-        big(100, 150)
-    end
+
+    white = color(31, 31, 31)
+    render(0, 0, white,  "Start: ", getButtonDownTime(BT_START))
+    render(0, 8, white,  "Select: ", getButtonDownTime(BT_SELECT))
+    render(0, 16, white, "A: ", getButtonDownTime(BT_A))
+    render(0, 24, white, "B: ", getButtonDownTime(BT_B))
+    render(0, 32, white, "X: ", getButtonDownTime(BT_X))
+    render(0, 40, white, "Y: ", getButtonDownTime(BT_Y))
+    render(0, 48, white, "L: ", getButtonDownTime(BT_L))
+    render(0, 56, white, "R: ", getButtonDownTime(BT_R))
+    render(0, 64, white, "äüößÄÜÖ")
 
     if x < 0
         x = 0
@@ -69,10 +56,10 @@ while !shouldClose()
 
     big(x, y)
 
-    render(0, 0, c, "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
-    render(0, 8, c, "abcdefghijklmnopqrstuvwxyz")
-    render(0, 16, c, "0123456789()[]{}<>/\\?")
-    render(0, 24, c, "\"$%^&*-_=+#~.,;:|")
+    #render(0, 0, c, "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
+    #render(0, 8, c, "abcdefghijklmnopqrstuvwxyz")
+    #render(0, 16, c, "0123456789()[]{}<>/\\?")
+    #render(0, 24, c, "\"$%^&*-_=+#~.,;:|")
 end
 
 printLine("stop")

+ 6 - 2
src/SystemFunctions.c

@@ -87,11 +87,15 @@ static bool sfRender(Code* c, Value* r, Value* vs, i32 n) {
     print(c, vs + 3, n - 3, buffer, sizeof(buffer));
     char* s = buffer;
     while(*s != 0) {
-        UTF8 u = {.data = {*s}, .length = 1};
+        UTF8 u = {.data = {*(s++)}, .length = 1};
+        for(int k = 0; k < 3 && isUTF8Remainder(*s); k++) {
+            u.data[u.length] = *s;
+            u.length++;
+            s++;
+        }
         i32 i = convertUTF8toUnicode(u);
         windowSetCharacter(x, y, i, color);
         x += 8;
-        s++;
     }
     RETURN_INT(0);
 }

+ 2 - 2
src/WindowCharacters.c

@@ -251,8 +251,8 @@ const u8 CHARACTERS[256][8] =
          {0b00000000, 0b00000000, 0b00011110, 0b00100000, 0b00011100,
           0b00000010, 0b00111100, 0b00000000},
      ['t'] =
-         {0b00001000, 0b00001000, 0b00111100, 0b00001000, 0b00001000,
-          0b00001000, 0b00001100, 0b00000000},
+         {0b00001000, 0b00001000, 0b00111110, 0b00001000, 0b00001000,
+          0b00001000, 0b00000110, 0b00000000},
      ['u'] =
          {0b00000000, 0b00000000, 0b00100010, 0b00100010, 0b00100010,
           0b00100010, 0b00011100, 0b00000000},