feature (kernel): graphics buffer string draw function returns now the updated position

This commit is contained in:
antifallobst 2023-02-22 13:28:09 +01:00
parent 08c7f32349
commit 7b467b1cd5
2 changed files with 13 additions and 11 deletions

View File

@ -18,6 +18,7 @@
#include "utils/stdtypes.h" #include "utils/stdtypes.h"
#include "utils/string.h" #include "utils/string.h"
#include "utils/math.h"
#include "drivers/graphics/color.h" #include "drivers/graphics/color.h"
#include "drivers/graphics/font.h" #include "drivers/graphics/font.h"
#include "drivers/graphics/framebuffer.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); 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); 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_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_init (boot_info_T* boot_info);
void graphics_renderer_update (); void graphics_renderer_update ();

View File

@ -15,7 +15,6 @@
#include "drivers/graphics/renderer.h" #include "drivers/graphics/renderer.h"
#include "utils/memory.h" #include "utils/memory.h"
#include "utils/math.h"
#include "utils/core.h" #include "utils/core.h"
graphics_renderer_T g_renderer; 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) CORE_HALT_WHILE(graphics_buffer->blocked)
graphics_buffer->blocked = true; graphics_buffer->blocked = true;
position_T pos = (position_T){x, y};
uint64_t strlen = string_length(string); uint64_t strlen = string_length(string);
for (int i = 0; i < strlen; i++) { for (int i = 0; i < strlen; i++) {
switch (string[i]) { switch (string[i]) {
case '\n': { case '\n': {
x = 0; pos.x = 0;
y += g_renderer.font.height; pos.y += g_renderer.font.height;
break; break;
} }
case '\r': { case '\r': {
x = 0; pos.x = 0;
break; break;
} }
default: { default: {
if (x + g_renderer.font.width >= graphics_buffer->width) { if (pos.x + g_renderer.font.width >= graphics_buffer->width) {
x = 0; pos.x = 0;
y += g_renderer.font.height; pos.y += g_renderer.font.height;
} }
graphics_buffer_draw_char(graphics_buffer, x, y, color, string[i]); graphics_buffer_draw_char(graphics_buffer, pos.x, pos.y, color, string[i]);
x += g_renderer.font.width; pos.x += g_renderer.font.width;
break; break;
} }
} }
} }
graphics_buffer->blocked = false; graphics_buffer->blocked = false;
return pos;
} }
void graphics_renderer_init(boot_info_T* boot_info_T) { void graphics_renderer_init(boot_info_T* boot_info_T) {