Add rectangle drawing utilities
This commit is contained in:
parent
02e4326f4c
commit
0f87945e89
@ -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
|
||||
|
13
src/window.c
13
src/window.c
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user