From c0ec2caac178680b1c81ba626a9e5433e23cb860 Mon Sep 17 00:00:00 2001 From: MysterD Date: Thu, 15 Jul 2021 18:47:19 -0700 Subject: [PATCH] DJUI: Made cursor hover location control-configurable --- src/pc/djui/djui_base.c | 6 ++++++ src/pc/djui/djui_base.h | 1 + src/pc/djui/djui_checkbox.c | 9 +++++++++ src/pc/djui/djui_cursor.c | 3 +-- src/pc/djui/djui_selectionbox.c | 9 +++++++++ src/pc/djui/djui_slider.c | 9 +++++++++ 6 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/pc/djui/djui_base.c b/src/pc/djui/djui_base.c index cb6413ee..8e491b5a 100644 --- a/src/pc/djui/djui_base.c +++ b/src/pc/djui/djui_base.c @@ -81,6 +81,11 @@ void djui_base_set_alignment(struct DjuiBase* base, enum DjuiHAlign hAlign, enum // utility // ///////////// +static void djui_base_get_cursor_hover_location(struct DjuiBase* base, f32* x, f32* y) { + *x = (base->elem.x + base->elem.width * 3.0f / 4.0f); + *y = (base->elem.y + base->elem.height * 3.0f / 4.0f); +} + static void djui_base_clip(struct DjuiBase* base) { struct DjuiBase* parent = base->parent; struct DjuiBaseRect* comp = &base->comp; @@ -363,6 +368,7 @@ void djui_base_init(struct DjuiBase* parent, struct DjuiBase* base, void(*render djui_base_set_enabled(base, true); djui_base_set_size(base, 64, 64); djui_base_set_color(base, 255, 255, 255, 255); + base->get_cursor_hover_location = djui_base_get_cursor_hover_location; base->render = render; base->destroy = destroy; djui_base_add_child(parent, base); diff --git a/src/pc/djui/djui_base.h b/src/pc/djui/djui_base.h index faca43dc..bfc8aeda 100644 --- a/src/pc/djui/djui_base.h +++ b/src/pc/djui/djui_base.h @@ -44,6 +44,7 @@ struct DjuiBase { struct DjuiBaseRect clip; struct DjuiInteractable* interactable; s32 tag; + void (*get_cursor_hover_location)(struct DjuiBase*, f32* x, f32* y); void (*on_child_render)(struct DjuiBase*, struct DjuiBase*); void (*on_render_pre)(struct DjuiBase*, bool*); void (*render)(struct DjuiBase*); diff --git a/src/pc/djui/djui_checkbox.c b/src/pc/djui/djui_checkbox.c index 9ec8a94c..bcdce16a 100644 --- a/src/pc/djui/djui_checkbox.c +++ b/src/pc/djui/djui_checkbox.c @@ -15,6 +15,13 @@ static void djui_checkbox_on_hover(struct DjuiBase* base) { djui_base_set_color(&checkbox->rectValue->base, 229, 241, 251, 255); } +static void djui_checkbox_get_cursor_hover_location(struct DjuiBase* base, f32* x, f32* y) { + struct DjuiCheckbox* checkbox = (struct DjuiCheckbox*)base; + struct DjuiBase* rectBase = &checkbox->rect->base; + *x = (rectBase->elem.x + rectBase->elem.width * 3.0f / 4.0f); + *y = (rectBase->elem.y + rectBase->elem.height * 3.0f / 4.0f); +} + static void djui_checkbox_on_hover_end(struct DjuiBase* base) { djui_checkbox_set_default_style(base); } @@ -78,5 +85,7 @@ struct DjuiCheckbox* djui_checkbox_create(struct DjuiBase* parent, const char* m djui_checkbox_set_default_style(base); + base->get_cursor_hover_location = djui_checkbox_get_cursor_hover_location; + return checkbox; } diff --git a/src/pc/djui/djui_cursor.c b/src/pc/djui/djui_cursor.c index 842d161d..a483bb11 100644 --- a/src/pc/djui/djui_cursor.c +++ b/src/pc/djui/djui_cursor.c @@ -33,8 +33,7 @@ bool djui_cursor_inside_base(struct DjuiBase* base) { } static void djui_cursor_base_hover_location(struct DjuiBase* base, f32* x, f32* y) { - *x = (base->elem.x + base->elem.width * 3.0f / 4.0f); - *y = (base->elem.y + base->elem.height * 3.0f / 4.0f); + base->get_cursor_hover_location(base, x, y); } void djui_cursor_input_controlled_center(struct DjuiBase* base) { diff --git a/src/pc/djui/djui_selectionbox.c b/src/pc/djui/djui_selectionbox.c index c0d7b5c8..3d6bb851 100644 --- a/src/pc/djui/djui_selectionbox.c +++ b/src/pc/djui/djui_selectionbox.c @@ -16,6 +16,13 @@ static void djui_selectionbox_set_default_style(struct DjuiBase* base) { djui_base_set_color(&selectionbox->text->base, 200, 200, 200, 255); } +static void djui_selectionbox_get_cursor_hover_location(struct DjuiBase* base, f32* x, f32* y) { + struct DjuiSelectionbox* selectionbox = (struct DjuiSelectionbox*)base; + struct DjuiBase* rectBase = &selectionbox->rect->base; + *x = (rectBase->elem.x + rectBase->elem.width * 3.0f / 4.0f); + *y = (rectBase->elem.y + rectBase->elem.height * 3.0f / 4.0f); +} + static void djui_selectionbox_on_hover(struct DjuiBase* base) { struct DjuiSelectionbox* selectionbox = (struct DjuiSelectionbox*)base; f32 x = selectionbox->rect->base.elem.x; @@ -119,5 +126,7 @@ struct DjuiSelectionbox* djui_selectionbox_create(struct DjuiBase* parent, const djui_selectionbox_set_default_style(base); + base->get_cursor_hover_location = djui_selectionbox_get_cursor_hover_location; + return selectionbox; } diff --git a/src/pc/djui/djui_slider.c b/src/pc/djui/djui_slider.c index 5cd8b01b..425599d6 100644 --- a/src/pc/djui/djui_slider.c +++ b/src/pc/djui/djui_slider.c @@ -16,6 +16,13 @@ static void djui_slider_set_default_style(struct DjuiBase* base) { djui_base_set_color(&slider->rectValue->base, 200, 200, 200, 255); } +static void djui_slider_get_cursor_hover_location(struct DjuiBase* base, f32* x, f32* y) { + struct DjuiSlider* slider = (struct DjuiSlider*)base; + struct DjuiBase* rectBase = &slider->rect->base; + *x = (rectBase->elem.x + rectBase->elem.width * 3.0f / 4.0f); + *y = (rectBase->elem.y + rectBase->elem.height * 3.0f / 4.0f); +} + static void djui_slider_on_hover(struct DjuiBase* base) { struct DjuiSlider* slider = (struct DjuiSlider*)base; f32 x = slider->rect->base.elem.x; @@ -143,5 +150,7 @@ struct DjuiSlider* djui_slider_create(struct DjuiBase* parent, const char* messa djui_slider_update_value(base); djui_slider_set_default_style(base); + base->get_cursor_hover_location = djui_slider_get_cursor_hover_location; + return slider; }