]> git.lizzy.rs Git - nothing.git/commitdiff
(#1201) Support newline character for text rendering
authorMetin Ozyildirim <metinozyildirim@trakya.edu.tr>
Sat, 14 Dec 2019 22:31:30 +0000 (22:31 +0000)
committerMetin Ozyildirim <metinozyildirim@trakya.edu.tr>
Mon, 16 Dec 2019 00:20:47 +0000 (00:20 +0000)
src/game/sprite_font.c

index ec7764d87699b48e2e33d9afdd16ef6bd4a8881c..dd4893e50cd1ecd4ce6bc79d999f28718f8c29b4 100644 (file)
@@ -98,14 +98,20 @@ void sprite_font_render_text(const Sprite_font *sprite_font,
                                sdl_color.a));
 
     const size_t text_size = strlen(text);
-    for (size_t i = 0; i < text_size; ++i) {
+    for (size_t i = 0, col = 0, row = 0; i < text_size; ++i) {
+        if (text[i] == '\n'){
+            col = 0;
+            row++;
+            continue;
+        }
         const SDL_Rect char_rect = sprite_font_char_rect(sprite_font, text[i]);
         const SDL_Rect dest_rect = rect_for_sdl(
             rect(
-                position.x + (float) FONT_CHAR_WIDTH * (float) i * size.x,
-                position.y,
+                position.x + (float) FONT_CHAR_WIDTH * (float) col * size.x,
+                position.y + (float) FONT_CHAR_HEIGHT * (float) row * size.y,
                 (float) char_rect.w * size.x,
                 (float) char_rect.h * size.y));
         scc(SDL_RenderCopy(renderer, sprite_font->texture, &char_rect, &dest_rect));
+        col++;
     }
 }