Compare commits

...

3 Commits

Author SHA1 Message Date
148dec2d3d Enable drop file events 2024-01-14 19:51:33 +00:00
0f87945e89 Add rectangle drawing utilities 2024-01-14 19:51:18 +00:00
02e4326f4c Update README.md 2024-01-14 19:51:03 +00:00
4 changed files with 23 additions and 4 deletions

View File

@ -1,3 +1,3 @@
# SDL Boilerplate
# Compositor test
Boilerplate for setting up a simple SDL program that creates a window and a renderer and handles the quit event.
Test for building a basic node-based compositing application

View File

@ -10,6 +10,7 @@
typedef struct point point_t;
typedef struct line line_t;
typedef struct triangle triangle_t;
typedef struct rect rect_t;
typedef struct window window_t;
struct point {
@ -28,6 +29,12 @@ struct triangle {
point_t p2;
};
struct rect {
point_t topleft;
i32 w;
i32 h;
};
struct window {
u64 width;
u64 height;
@ -52,5 +59,6 @@ void draw_point(const window_t *wnd, point_t p, colour_t colour);
void draw_line(const window_t *wnd, const line_t *ln, colour_t colour);
void draw_triangle(const window_t *wnd, const triangle_t *triangle,
colour_t colour);
void draw_rect(const window_t *wnd, const rect_t *rect, colour_t colour);
#endif // !WINDOW_H

View File

@ -36,6 +36,8 @@ i32 run_main_loop(void) {
comp.running = true;
SDL_EventState(SDL_DROPFILE, SDL_ENABLE);
colour_t bg_colour = {.abgr = 0xffffffff};
colour_t fg_colour = {.abgr = 0xff000000};

View File

@ -1,7 +1,8 @@
#include "window.h"
#include "SDL_render.h"
#include "SDL_video.h"
#include "aliases/aliases.h"
#include <SDL2/SDL_rect.h>
#include <SDL2/SDL_render.h>
#include <SDL2/SDL_video.h>
#include <stdbool.h>
bool init_window(window_t *wnd, const char *title, u64 width, u64 height) {
@ -72,3 +73,11 @@ void draw_triangle(const window_t *wnd, const triangle_t *triangle,
draw_line(wnd, &ln1, colour);
draw_line(wnd, &ln2, colour);
}
void draw_rect(const window_t *wnd, const rect_t *rect, colour_t colour) {
set_colour(wnd, colour);
SDL_Rect dst = {rect->topleft.x, rect->topleft.y, rect->w, rect->h};
SDL_RenderDrawRect(wnd->renderer, &dst);
}