From 0cb37f5596493bb7214b5c6e75358c6dbd09c77b Mon Sep 17 00:00:00 2001 From: Patrick Jakobsen Date: Thu, 28 Sep 2023 09:58:25 +0200 Subject: [PATCH] Got some input working again --- gui/gui.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/gui/gui.c b/gui/gui.c index 5318e14..7f64fa1 100644 --- a/gui/gui.c +++ b/gui/gui.c @@ -345,6 +345,53 @@ void gui_apply_input( (void)context; (void)mouse_x; (void)mouse_y; + // --- Mouse Input --- + // NOTE(Zelaven): First hit test against layers. + GUI_Layer *hit_layer = &context->background_layer; + GUI_Subtree *hit_root_subtree = (GUI_Subtree*)hit_layer->subtree_rdic.root; + { + GUI_Layer *top_layer = &context->top_layer; + GUI_Subtree *root_subtree = (GUI_Subtree*)top_layer->subtree_rdic.root; + if(root_subtree != NULL) + { + GUI_Node *top_layer_root = + (GUI_Node*)root_subtree->rdic.root; + if(top_layer_root != NULL) + if(point_in_rect(mouse_x, mouse_y, top_layer_root->rect)) + { + hit_layer = &context->top_layer; + hit_root_subtree = root_subtree; + } + } + } + (void)hit_layer; + + assert(hit_root_subtree != NULL); + + GUI_Node *top_node_under_cursor = (GUI_Node*)hit_root_subtree->rdic.root; + GUI_Node *current_node = (GUI_Node*)top_node_under_cursor->rdic_node.first_child; + int mouse_over_node = 0; + while(current_node != NULL) + { + mouse_over_node = point_in_rect(mouse_x, mouse_y, current_node->rect); + if(mouse_over_node) + { + top_node_under_cursor = current_node; + current_node = (GUI_Node*)current_node->rdic_node.first_child; + } + else + { + current_node = (GUI_Node*)current_node->rdic_node.sibling; + } + } + + context->top_node_under_cursor.node = top_node_under_cursor; + context->top_node_under_cursor.generation = + top_node_under_cursor->rdic_node.generation; + DEBUG("Top node under cursor: %.*s\n", + top_node_under_cursor->debug_string.length, + top_node_under_cursor->debug_string.cstring); + return; } #if 0