diff --git a/kernel/inc/drivers/graphics/renderer.h b/kernel/inc/drivers/graphics/renderer.h index 0a5ebb0..1217ce9 100644 --- a/kernel/inc/drivers/graphics/renderer.h +++ b/kernel/inc/drivers/graphics/renderer.h @@ -18,6 +18,7 @@ #include "utils/stdtypes.h" #include "utils/string.h" +#include "utils/math.h" #include "drivers/graphics/color.h" #include "drivers/graphics/font.h" #include "drivers/graphics/framebuffer.h" @@ -57,7 +58,7 @@ void graphics_buffer_destruct (graphics_buffer_T* grap void graphics_buffer_set_pixel (graphics_buffer_T* graphics_buffer, uint32_t x, uint32_t y, color_argb_T color); color_argb_T graphics_buffer_get_pixel (graphics_buffer_T* graphics_buffer, uint32_t x, uint32_t y); void graphics_buffer_draw_char (graphics_buffer_T* graphics_buffer, uint32_t x, uint32_t y, color_argb_T color, char chr); -void graphics_buffer_draw_string (graphics_buffer_T* graphics_buffer, uint32_t x, uint32_t y, color_argb_T color, string_t string); +position_T graphics_buffer_draw_string (graphics_buffer_T* graphics_buffer, uint32_t x, uint32_t y, color_argb_T color, string_t string); void graphics_renderer_init (boot_info_T* boot_info); void graphics_renderer_update (); diff --git a/kernel/src/drivers/graphics/renderer.c b/kernel/src/drivers/graphics/renderer.c index 665c98f..cb75dc4 100644 --- a/kernel/src/drivers/graphics/renderer.c +++ b/kernel/src/drivers/graphics/renderer.c @@ -15,7 +15,6 @@ #include "drivers/graphics/renderer.h" #include "utils/memory.h" -#include "utils/math.h" #include "utils/core.h" graphics_renderer_T g_renderer; @@ -82,36 +81,38 @@ void graphics_buffer_draw_char(graphics_buffer_T* graphics_buffer, uint32_t x, u } } -void graphics_buffer_draw_string(graphics_buffer_T* graphics_buffer, uint32_t x, uint32_t y, color_argb_T color, string_t string) { +position_T graphics_buffer_draw_string(graphics_buffer_T* graphics_buffer, uint32_t x, uint32_t y, color_argb_T color, string_t string) { CORE_HALT_WHILE(graphics_buffer->blocked) graphics_buffer->blocked = true; + position_T pos = (position_T){x, y}; uint64_t strlen = string_length(string); for (int i = 0; i < strlen; i++) { switch (string[i]) { case '\n': { - x = 0; - y += g_renderer.font.height; + pos.x = 0; + pos.y += g_renderer.font.height; break; } case '\r': { - x = 0; + pos.x = 0; break; } default: { - if (x + g_renderer.font.width >= graphics_buffer->width) { - x = 0; - y += g_renderer.font.height; + if (pos.x + g_renderer.font.width >= graphics_buffer->width) { + pos.x = 0; + pos.y += g_renderer.font.height; } - graphics_buffer_draw_char(graphics_buffer, x, y, color, string[i]); - x += g_renderer.font.width; + graphics_buffer_draw_char(graphics_buffer, pos.x, pos.y, color, string[i]); + pos.x += g_renderer.font.width; break; } } } graphics_buffer->blocked = false; + return pos; } void graphics_renderer_init(boot_info_T* boot_info_T) {