Browse Source

Add custom font with Cyryllic support

Evgeniy Parfenyuk 3 tuần trước cách đây
mục cha
commit
807fe45e8c
3 tập tin đã thay đổi với 7 bổ sung5 xóa
  1. BIN
      assets/fonts/NotoSans-Regular.ttf
  2. 1 1
      src/main.c
  3. 6 4
      src/ui/text_box.c

BIN
assets/fonts/NotoSans-Regular.ttf


+ 1 - 1
src/main.c

@@ -32,7 +32,7 @@ int main(void)
     TextBox dialogueBox;
     TextBoxInit(&dialogueBox, screenWidth, screenHeight);
 
-    TextBoxSetText(&dialogueBox, "Alice",
+    TextBoxSetText(&dialogueBox, "\xD0\x90\xD0\xBB\xD0\xB8\xD1\x81\xD0\xB0",
                    "Hello from Vinora Engine textbox!\n\n"
                    "D-d-do you like it or something? :3");
 

+ 6 - 4
src/ui/text_box.c

@@ -25,11 +25,12 @@ void TextBoxInit(TextBox *tb, int screenWidth, int screenHeight)
     tb->bg_color = (Color){0, 0, 0, 220};
     tb->border_color = (Color){255, 255, 255, 180};
     tb->border_thickness = 3;
-
-    tb->font = GetFontDefault();
+    // TODO: remake to use charset instead of 0-2048 range
+    tb->font = LoadFontEx("assets/fonts/NotoSans-Regular.ttf", 32, NULL, 2048);
+    SetTextureFilter(tb->font.texture, TEXTURE_FILTER_BILINEAR);
     tb->font_size = 24;
     tb->text_color = WHITE;
-    tb->name_color = YELLOW;
+    tb->name_color = RED;
 
     memset(tb->name, 0, sizeof(tb->name));
     tb->text = NULL;
@@ -67,7 +68,7 @@ void TextBoxDraw(TextBox *tb)
         DrawRectangleLinesEx(nameRect, 3, tb->border_color);
 
         DrawTextEx(tb->font, tb->name,
-                   (Vector2){nameRect.x + 12, nameRect.y + 6},
+                   (Vector2){nameRect.x + 12, nameRect.y + 3},
                    tb->font_size + 2, 1, tb->name_color);
     }
 
@@ -81,6 +82,7 @@ void TextBoxDraw(TextBox *tb)
 
 void TextBoxCleanup(TextBox *tb)
 {
+    UnloadFont(tb->font);
     if (tb->text)
     {
         free(tb->text);