aboutsummaryrefslogtreecommitdiff
path: root/src/saffron_text.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/saffron_text.c')
-rw-r--r--src/saffron_text.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/saffron_text.c b/src/saffron_text.c
new file mode 100644
index 0000000..8a093ea
--- /dev/null
+++ b/src/saffron_text.c
@@ -0,0 +1,31 @@
+#include <SDL3/SDL_render.h>
+#include <saffron.h>
+#include <SDL3/SDL.h>
+#include <SDL3_ttf/SDL_ttf.h>
+#include <stdlib.h>
+
+static void saffron_text_draw(SaffronWidget* widget, SDL_Renderer* renderer) {
+ SaffronText* text = (SaffronText*)widget;
+ if (!text->text || !text->font) return;
+
+ SDL_Surface* surface = TTF_RenderText_Blended(text->font, text->text, 0, text->color);
+ if (!surface) return;
+
+ SDL_Texture* texture = SDL_CreateTextureFromSurface(renderer, surface);
+ SDL_FRect dest = {widget->x, widget->y, (float)surface->w, (float)surface->h};
+ SDL_RenderTexture(renderer, texture, NULL, &dest);
+
+ SDL_DestroyTexture(texture);
+ SDL_DestroySurface(surface);
+}
+
+SaffronText* saffron_text_new(const char* text, int font_size, SDL_Color color) {
+ SaffronText* text_widget = malloc(sizeof(SaffronText));
+ if (!text_widget) return NULL;
+
+ saffron_widget_init((SaffronWidget*)text_widget);
+
+ // todo actually do stuff
+ // and return something
+ // im tired ill do this later
+}