Switch to using if statements instead of switch in event handling code
This commit is contained in:
parent
29bcfabda9
commit
547764764c
@ -88,16 +88,16 @@ i32 run_main_loop(void) {
|
||||
handle_ui_events(&(comp.windows[comp.active_window - 1]), &(comp.ctx),
|
||||
&(comp.event));
|
||||
|
||||
switch (comp.event.type) {
|
||||
case SDL_QUIT:
|
||||
if (comp.event.type == SDL_QUIT) {
|
||||
comp.running = false;
|
||||
break;
|
||||
case SDL_WINDOWEVENT:
|
||||
switch (comp.event.window.event) {
|
||||
case SDL_WINDOWEVENT_CLOSE:
|
||||
}
|
||||
|
||||
if (comp.event.type == SDL_WINDOWEVENT) {
|
||||
if (comp.event.window.event == SDL_WINDOWEVENT_CLOSE) {
|
||||
comp.running = false;
|
||||
break;
|
||||
case SDL_WINDOWEVENT_ENTER: {
|
||||
}
|
||||
|
||||
if (comp.event.window.event == SDL_WINDOWEVENT_ENTER) {
|
||||
u32 id = comp.event.window.windowID;
|
||||
window *wnd = NULL;
|
||||
|
||||
@ -111,25 +111,18 @@ i32 run_main_loop(void) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!wnd) {
|
||||
break;
|
||||
if (wnd) {
|
||||
SDL_RaiseWindow(wnd->window);
|
||||
}
|
||||
|
||||
SDL_RaiseWindow(wnd->window);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case SDL_DROPFILE:
|
||||
if (comp.event.type == SDL_DROPFILE) {
|
||||
if (comp.event.drop.windowID == main_window->id) {
|
||||
node_data data = (node_data){.path = comp.event.drop.file};
|
||||
|
||||
add_node(&comp, NODE_TYPE_IO, data, IO_INPUT_COUNT, comp.ctx.mouse_x,
|
||||
comp.ctx.mouse_y, io_node_colours);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
17
src/ui.c
17
src/ui.c
@ -26,34 +26,31 @@ void reset_ui_ctx(ui_ctx *ctx) {
|
||||
}
|
||||
|
||||
void handle_ui_events(const window *wnd, ui_ctx *ctx, const SDL_Event *event) {
|
||||
switch (event->type) {
|
||||
case SDL_MOUSEMOTION:
|
||||
if (event->type == SDL_MOUSEMOTION) {
|
||||
if (wnd->id == event->motion.windowID) {
|
||||
ctx->mouse_x = event->motion.x;
|
||||
ctx->mouse_y = event->motion.y;
|
||||
ctx->rel_x += event->motion.xrel;
|
||||
ctx->rel_y += event->motion.yrel;
|
||||
ctx->wnd = wnd;
|
||||
|
||||
break;
|
||||
}
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
}
|
||||
|
||||
if (event->type == SDL_MOUSEBUTTONDOWN) {
|
||||
if (wnd->id == event->button.windowID) {
|
||||
ctx->mouse_x = event->button.x;
|
||||
ctx->mouse_y = event->button.y;
|
||||
ctx->mouse_down = true;
|
||||
ctx->wnd = wnd;
|
||||
|
||||
break;
|
||||
}
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
}
|
||||
|
||||
if (event->type == SDL_MOUSEBUTTONUP) {
|
||||
if (wnd->id == event->button.windowID) {
|
||||
ctx->mouse_x = event->button.x;
|
||||
ctx->mouse_y = event->button.y;
|
||||
ctx->mouse_up = true;
|
||||
ctx->wnd = wnd;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user