Compare commits

..

No commits in common. "d114cfce996abc8b315e76a8ead60fc7d74280b5" and "81fbff96b806398fc0d0929bbd1a05a8359dec97" have entirely different histories.

3 changed files with 9 additions and 48 deletions

View File

@ -37,8 +37,6 @@ struct rect {
struct window { struct window {
u32 id; u32 id;
u64 x;
u64 y;
u64 width; u64 width;
u64 height; u64 height;
const char *title; const char *title;
@ -54,8 +52,7 @@ struct colour {
}; };
}; };
bool init_window(window_t *wnd, const char *title, u32 width, u32 height, i32 x, bool init_window(window_t *wnd, const char *title, u64 width, u64 height);
i32 y);
void cleanup_window(window_t *wnd); void cleanup_window(window_t *wnd);
void clear_window(const window_t *wnd, colour_t colour); void clear_window(const window_t *wnd, colour_t colour);
void swap_buffers(const window_t *wnd); void swap_buffers(const window_t *wnd);

View File

@ -38,19 +38,13 @@ i32 run_main_loop(void) {
comp.nodes = (node_t *)malloc(sizeof(node_t) * MAX_NODES); comp.nodes = (node_t *)malloc(sizeof(node_t) * MAX_NODES);
window_t *main_window = &(comp.windows[0]); window_t *main_window = &(comp.windows[0]);
window_t *toolbox = &(comp.windows[1]);
if (!init_window(main_window, "Compositor", WINDOW_WIDTH, WINDOW_HEIGHT, -1, if (!init_window(main_window, "Compositor", WINDOW_WIDTH, WINDOW_HEIGHT)) {
-1)) {
SDL_Quit(); SDL_Quit();
return EXIT_FAILURE; return EXIT_FAILURE;
} }
u32 toolbox_window_width = WINDOW_WIDTH / 7;
init_window(toolbox, "Toolbox", toolbox_window_width, WINDOW_HEIGHT,
main_window->x - toolbox_window_width, -1);
comp.running = true; comp.running = true;
SDL_EventState(SDL_DROPFILE, SDL_ENABLE); SDL_EventState(SDL_DROPFILE, SDL_ENABLE);
@ -62,14 +56,6 @@ i32 run_main_loop(void) {
switch (comp.event.type) { switch (comp.event.type) {
case SDL_QUIT: case SDL_QUIT:
comp.running = false; comp.running = false;
break;
case SDL_WINDOWEVENT:
switch (comp.event.window.event) {
case SDL_WINDOWEVENT_CLOSE:
comp.running = false;
break;
}
break; break;
case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONDOWN:
if (comp.event.button.windowID == main_window->id) { if (comp.event.button.windowID == main_window->id) {
@ -122,23 +108,16 @@ i32 run_main_loop(void) {
} }
} }
for (u64 i = 0; i < MAX_WINDOWS; ++i) { clear_window(main_window, bg_colour);
clear_window(&(comp.windows[i]), bg_colour);
}
for (u64 i = 0; i < comp.count; ++i) { for (u64 i = 0; i < comp.count; ++i) {
node_t *node = &(comp.nodes[i]); node_t *node = &(comp.nodes[i]);
draw_node(main_window, node); draw_node(main_window, node);
} }
for (u64 i = 0; i < MAX_WINDOWS; ++i) { swap_buffers(main_window);
swap_buffers(&(comp.windows[i]));
}
} }
cleanup_window(toolbox);
cleanup_window(main_window);
SDL_Quit(); SDL_Quit();
return EXIT_SUCCESS; return EXIT_SUCCESS;

View File

@ -5,13 +5,10 @@
#include <SDL2/SDL_video.h> #include <SDL2/SDL_video.h>
#include <stdbool.h> #include <stdbool.h>
bool init_window(window_t *wnd, const char *title, u32 width, u32 height, i32 x, bool init_window(window_t *wnd, const char *title, u64 width, u64 height) {
i32 y) {
i32 pos_x = x >= 0 ? x : SDL_WINDOWPOS_CENTERED;
i32 pos_y = y >= 0 ? y : SDL_WINDOWPOS_CENTERED;
wnd->window = wnd->window =
SDL_CreateWindow(title, pos_x, pos_y, width, height, SDL_WINDOW_SHOWN); SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
width, height, SDL_WINDOW_SHOWN);
if (!(wnd->window)) { if (!(wnd->window)) {
return false; return false;
} }
@ -25,20 +22,8 @@ bool init_window(window_t *wnd, const char *title, u32 width, u32 height, i32 x,
wnd->id = SDL_GetWindowID(wnd->window); wnd->id = SDL_GetWindowID(wnd->window);
wnd->title = title; wnd->title = title;
wnd->width = width;
i32 x_tmp = -1; wnd->height = height;
i32 y_tmp = -1;
SDL_GetWindowPosition(wnd->window, &x_tmp, &y_tmp);
wnd->x = x_tmp;
wnd->y = y_tmp;
i32 w_tmp = -1;
i32 h_tmp = -1;
SDL_GetWindowSize(wnd->window, &w_tmp, &h_tmp);
wnd->width = w_tmp;
wnd->height = h_tmp;
return true; return true;
} }