diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/saffron.c | 9 | ||||
| -rw-r--r-- | src/saffron_button.c | 4 | ||||
| -rw-r--r-- | src/saffron_text.c | 10 | ||||
| -rw-r--r-- | src/saffron_widget.c | 17 | ||||
| -rw-r--r-- | src/saffron_window.c | 2 |
5 files changed, 38 insertions, 4 deletions
diff --git a/src/saffron.c b/src/saffron.c index 65816bc..64c7842 100644 --- a/src/saffron.c +++ b/src/saffron.c @@ -4,6 +4,15 @@ #include <SDL3_ttf/SDL_ttf.h> #include <saffron.h> /* meson include directories */ +/* why is this defined in saffron.c, you ask, and not in a separate saffron_theme.c file? because i cant be bothered to make a whole separate .c file for theming which is pretty much mostly headers and some tweaks around the engine */ +const SaffronTheme SAFFRON_DEFAULT_THEME = { + .bg = {30, 30, 46, 255}, + .fg = {205, 214, 244, 255}, + .primary = {137, 180, 250, 255}, + .secondary = {166, 227, 161, 255}, + .tertiary = {203, 166, 247, 255} +}; + bool saffron_init(void) { if (!SDL_Init(SDL_INIT_VIDEO)) { printf("[Saffron] SDL init failed: %s\n", SDL_GetError()); diff --git a/src/saffron_button.c b/src/saffron_button.c index f0cf77e..0fdbd10 100644 --- a/src/saffron_button.c +++ b/src/saffron_button.c @@ -3,7 +3,9 @@ #include <saffron.h> static void saffron_button_draw(SaffronWidget* widget, SDL_Renderer* renderer) { - // do stuff here + SaffronButton* btn = (SaffronButton*)widget; + + // waiting to finish saffrontheme first } SaffronButton* saffron_button_new(bool enabled, void (*callback)(SaffronButton* self), int width, int height) { diff --git a/src/saffron_text.c b/src/saffron_text.c index 6e7accf..3beb219 100644 --- a/src/saffron_text.c +++ b/src/saffron_text.c @@ -13,7 +13,12 @@ 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); + SaffronTheme* theme = ((SaffronWidget*)text)->theme; + if (!theme) return; + + SaffronColor text_color = theme->primary; + SDL_Color color = {text_color.r, text_color.g, text_color.b, text_color.a}; + SDL_Surface* surface = TTF_RenderText_Blended(text->font, text->text, 0, color); if (!surface) return; SDL_Texture* texture = SDL_CreateTextureFromSurface(renderer, surface); @@ -24,7 +29,7 @@ static void saffron_text_draw(SaffronWidget* widget, SDL_Renderer* renderer) { SDL_DestroySurface(surface); } -SaffronText* saffron_text_new(const char* text, TTF_Font* font, SDL_Color color) { +SaffronText* saffron_text_new(const char* text, TTF_Font* font) { SaffronText* text_widget = malloc(sizeof(SaffronText)); if (!text_widget) return NULL; @@ -47,7 +52,6 @@ SaffronText* saffron_text_new(const char* text, TTF_Font* font, SDL_Color color) strcpy(text_widget->text, text); } text_widget->font = font; - text_widget->color = color; return text_widget; } diff --git a/src/saffron_widget.c b/src/saffron_widget.c index 955e265..6cb1664 100644 --- a/src/saffron_widget.c +++ b/src/saffron_widget.c @@ -1,3 +1,5 @@ +#include "saffron_api.h" +#include "saffron_theme.h" #include <SDL3/SDL.h> #include <stdio.h> #include <stdlib.h> @@ -23,6 +25,7 @@ void saffron_widget_init(SaffronWidget* widget) { widget->type = SAFFRON_WIDGET_UNKNOWN; widget->free = NULL; + widget->theme = NULL; } SaffronWidget* saffron_widget_new(void) { @@ -75,6 +78,14 @@ void saffron_widget_add_child(SaffronWidget *parent, SaffronWidget *child) { if (parent->type == SAFFRON_WIDGET_BOX) { saffron_box_layout((SaffronBox*)parent); } + + if (!child->theme) { + if (parent->theme) { + child->theme = parent->theme; /* inherit from parent */ + } else { + child->theme = SF_MACRO_DEFAULT_THEME; + } + } } SaffronWidget* saffron_widget_hit_test(SaffronWidget* widget, int x, int y) { @@ -100,3 +111,9 @@ SaffronWidget* saffron_widget_hit_test(SaffronWidget* widget, int x, int y) { return widget; } + +void saffron_widget_set_theme(SaffronWidget *widget, SaffronTheme *theme) { + if (!theme) return; + if (!widget) return; + widget->theme = theme; +} diff --git a/src/saffron_window.c b/src/saffron_window.c index 5687f16..41bc050 100644 --- a/src/saffron_window.c +++ b/src/saffron_window.c @@ -1,3 +1,4 @@ +#include "saffron_theme.h" #include <SDL3/SDL_render.h> #include <SDL3/SDL_video.h> #include <stdio.h> @@ -17,6 +18,7 @@ SaffronWindow* saffron_window_new(const char* title, int w, int h) { Uint32 flags = SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIGH_PIXEL_DENSITY; window->sdl_window = SDL_CreateWindow(title, w, h, flags); window->renderer = SDL_CreateRenderer(window->sdl_window, NULL); + window->root->theme = SF_MACRO_DEFAULT_THEME; return window; } |
