Filter events by window ID
This commit is contained in:
parent
10ff46cfe4
commit
81fbff96b8
@ -26,7 +26,8 @@ struct compositor {
|
|||||||
bool move_node;
|
bool move_node;
|
||||||
};
|
};
|
||||||
|
|
||||||
void add_node(compositor_t *comp, const char *path, i32 x, i32 y);
|
void add_node(compositor_t *comp, node_type_t type, node_data_t data, i32 x,
|
||||||
|
i32 y);
|
||||||
|
|
||||||
i32 run_main_loop(void) {
|
i32 run_main_loop(void) {
|
||||||
if (SDL_Init(SDL_INIT_EVERYTHING) != 0) {
|
if (SDL_Init(SDL_INIT_EVERYTHING) != 0) {
|
||||||
@ -57,44 +58,53 @@ i32 run_main_loop(void) {
|
|||||||
comp.running = false;
|
comp.running = false;
|
||||||
break;
|
break;
|
||||||
case SDL_MOUSEBUTTONDOWN:
|
case SDL_MOUSEBUTTONDOWN:
|
||||||
if (comp.node_hovered != -1) {
|
if (comp.event.button.windowID == main_window->id) {
|
||||||
comp.move_node = true;
|
if (comp.node_hovered != -1) {
|
||||||
}
|
comp.move_node = true;
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case SDL_MOUSEBUTTONUP:
|
case SDL_MOUSEBUTTONUP:
|
||||||
comp.move_node = false;
|
comp.move_node = false;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case SDL_MOUSEMOTION:
|
case SDL_MOUSEMOTION:
|
||||||
comp.mouse_x = comp.event.motion.x;
|
if (comp.event.motion.windowID == main_window->id) {
|
||||||
comp.mouse_y = comp.event.motion.y;
|
comp.mouse_x = comp.event.motion.x;
|
||||||
|
comp.mouse_y = comp.event.motion.y;
|
||||||
|
|
||||||
if (comp.move_node) {
|
if (comp.move_node) {
|
||||||
i32 dx = comp.event.motion.xrel;
|
i32 dx = comp.event.motion.xrel;
|
||||||
i32 dy = comp.event.motion.yrel;
|
i32 dy = comp.event.motion.yrel;
|
||||||
|
|
||||||
node_t *node = &(comp.nodes[comp.node_hovered]);
|
node_t *node = &(comp.nodes[comp.node_hovered]);
|
||||||
|
|
||||||
node->rect.topleft.x += dx;
|
node->rect.topleft.x += dx;
|
||||||
node->rect.topleft.y += dy;
|
node->rect.topleft.y += dy;
|
||||||
} else {
|
} else {
|
||||||
comp.node_hovered = -1;
|
comp.node_hovered = -1;
|
||||||
|
|
||||||
for (u64 i = comp.count - 1; i >= 0; --i) {
|
for (u64 i = comp.count - 1; i >= 0; --i) {
|
||||||
node_t *node = &(comp.nodes[i]);
|
node_t *node = &(comp.nodes[i]);
|
||||||
|
|
||||||
if (aabb(node, comp.mouse_x, comp.mouse_y)) {
|
if (aabb(node, comp.mouse_x, comp.mouse_y)) {
|
||||||
comp.node_hovered = i;
|
comp.node_hovered = i;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case SDL_DROPFILE:
|
case SDL_DROPFILE:
|
||||||
add_node(&comp, comp.event.drop.file, comp.mouse_x, comp.mouse_y);
|
if (comp.event.drop.windowID == main_window->id) {
|
||||||
break;
|
node_data_t data = (node_data_t){.path = comp.event.drop.file};
|
||||||
|
|
||||||
|
add_node(&comp, NODE_TYPE_IO, data, comp.mouse_x, comp.mouse_y);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,7 +123,8 @@ i32 run_main_loop(void) {
|
|||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void add_node(compositor_t *comp, const char *path, i32 x, i32 y) {
|
void add_node(compositor_t *comp, node_type_t type, node_data_t data, i32 x,
|
||||||
|
i32 y) {
|
||||||
if (comp->count + 1 >= MAX_NODES) {
|
if (comp->count + 1 >= MAX_NODES) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -126,6 +137,7 @@ void add_node(compositor_t *comp, const char *path, i32 x, i32 y) {
|
|||||||
.w = NODE_WIDTH,
|
.w = NODE_WIDTH,
|
||||||
.h = NODE_HEIGHT,
|
.h = NODE_HEIGHT,
|
||||||
},
|
},
|
||||||
.path = path,
|
.type = type,
|
||||||
|
.data.path = data.path,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user