diff options
| author | Arslaan Pathan <[email protected]> | 2026-04-07 11:13:23 +1200 |
|---|---|---|
| committer | Arslaan Pathan <[email protected]> | 2026-04-07 11:13:23 +1200 |
| commit | 04ff8c0a6acc2cc9204492690b7f99f892ed439a (patch) | |
| tree | f1e2eb213c95f51ba0b97089aa04b60b7d19330d /src | |
| parent | 7fba8447b9ce0c74808b943d9fe7f56b9663c4cf (diff) | |
| download | saffron-04ff8c0a6acc2cc9204492690b7f99f892ed439a.tar.xz saffron-04ff8c0a6acc2cc9204492690b7f99f892ed439a.zip | |
Refactor things, and start implementing API widgets
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.c | 48 | ||||
| -rw-r--r-- | src/saffron.c | 13 |
2 files changed, 13 insertions, 48 deletions
diff --git a/src/main.c b/src/main.c deleted file mode 100644 index f286a0a..0000000 --- a/src/main.c +++ /dev/null @@ -1,48 +0,0 @@ -#include <SDL3/SDL.h> -#include <SDL3/SDL_main.h> -#include <SDL3_ttf/SDL_ttf.h> - -int main(int argc, char *argv[]) { - SDL_Init(SDL_INIT_VIDEO); - TTF_Init(); - - SDL_Window *window = SDL_CreateWindow("Saffron", 800, 600, 0); - SDL_Renderer *renderer = SDL_CreateRenderer(window, NULL); - - TTF_Font *font = TTF_OpenFont("/usr/share/fonts/maple-mono/MapleMonoNL-Regular.ttf", 20); // "works on my machine" - Arslaan, 2026 - - bool running = true; - SDL_Event event; - SDL_FRect rect; - rect.x = rect.y = 100; - rect.w = rect.h = 100; - - SDL_FRect text_rect = {200, 200, 0, 0}; - SDL_Color white = {255, 255, 255, 255}; - SDL_Surface *surface = TTF_RenderText_Blended(font, "Hello Saffron!", 0, white); - SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, surface); - SDL_DestroySurface(surface); - SDL_GetTextureSize(texture, &text_rect.w, &text_rect.h); - - while (running) { - while (SDL_PollEvent(&event)) { - if (event.type == SDL_EVENT_QUIT) { - running = false; - } - } - - SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE); - SDL_RenderClear(renderer); - SDL_SetRenderDrawColor(renderer, 255, 0, 0, SDL_ALPHA_OPAQUE); - SDL_RenderFillRect(renderer, &rect); - SDL_RenderTexture(renderer, texture, NULL, &text_rect); - SDL_RenderPresent(renderer); - } - - TTF_CloseFont(font); - TTF_Quit(); - SDL_DestroyRenderer(renderer); - SDL_DestroyWindow(window); - SDL_Quit(); - return 0; -} diff --git a/src/saffron.c b/src/saffron.c new file mode 100644 index 0000000..dc6e470 --- /dev/null +++ b/src/saffron.c @@ -0,0 +1,13 @@ +#include <stdio.h> +#include <SDL3/SDL.h> +#include <SDL3_ttf/SDL_ttf.h> +#include <SDL3/SDL_main.h> + +typedef struct SaffronWidget { + int x, y, w, h; + void (*draw)(struct SaffronWidget *self, SDL_Renderer *renderer); + void (*on_click)(struct SaffronWidget *self); + struct SaffronWidget *parent; + struct SaffronWidget **children; + int child_count; +} SaffronWidget; |
