From db65f8d5bf8b1ee2536889b996741c044c9deb63 Mon Sep 17 00:00:00 2001 From: jacekpoz Date: Tue, 13 Aug 2024 15:14:13 +0200 Subject: [PATCH] use children[0] for the hitbox in PtkClickable --- include/ptk.h | 1 - src/ptk.c | 3 ++- src/ptk_vk/components.c | 8 +------- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/include/ptk.h b/include/ptk.h index b069194..dc4bec6 100644 --- a/include/ptk.h +++ b/include/ptk.h @@ -59,7 +59,6 @@ PTK_COMPONENT_DEFINE(PtkEllipse, typedef void (*MouseButtonCallback)(const int button, const int action, const int mods); PTK_COMPONENT_DEFINE(PtkClickable, - PtkHandle hitbox; MouseButtonCallback on_press; ); diff --git a/src/ptk.c b/src/ptk.c index a6cd946..3385463 100644 --- a/src/ptk.c +++ b/src/ptk.c @@ -190,9 +190,10 @@ PtkHandle ptk_clickable(PtkHandle hitbox, const MouseButtonCallback on_press) { PtkClickable *ret = malloc(sizeof(PtkClickable)); *ret = (PtkClickable){ .type = PTK_COMPONENT_TYPE_CLICKABLE, - .hitbox = hitbox, + .children = PTK_LIST_NEW(PtkHandle, 1), .on_press = on_press, }; + PTK_LIST_ADD(PtkHandle, ret->children, hitbox); return (PtkHandle)ret; } diff --git a/src/ptk_vk/components.c b/src/ptk_vk/components.c index 0eb08a9..9b56bf0 100644 --- a/src/ptk_vk/components.c +++ b/src/ptk_vk/components.c @@ -90,12 +90,6 @@ void vk_component(PtkHandle component) { PTK_LIST_ADD(PtkHandle, m_components, component); - if (component->type == PTK_COMPONENT_TYPE_CLICKABLE) { - PtkClickable *c = (PtkClickable *)component; - vk_component(c->hitbox); - return; - } - switch (component->type) { case PTK_COMPONENT_TYPE_TRIANGLE: { triangle((PtkTriangle *)component, 0); @@ -162,7 +156,7 @@ bool intersects(const PtkHandle component, const PtkPos point) { case PTK_COMPONENT_TYPE_ELLIPSE: return ellipse_intersects(*(PtkEllipse *)component, point); case PTK_COMPONENT_TYPE_CLICKABLE: - return intersects(((PtkClickable *)component)->hitbox, point); + return intersects(component->children.data[0], point); } }