summaryrefslogtreecommitdiff
path: root/src/static-ui.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/static-ui.cpp')
-rw-r--r--src/static-ui.cpp34
1 files changed, 33 insertions, 1 deletions
diff --git a/src/static-ui.cpp b/src/static-ui.cpp
index 1abd6b2..da5ab2b 100644
--- a/src/static-ui.cpp
+++ b/src/static-ui.cpp
@@ -5,6 +5,7 @@
#include "font.hpp"
#include "game-settings.hpp"
#include "pk.h"
+#include "player-input.hpp"
#include "static-plane.hpp"
#include "vendor-glm-include.hpp"
#include "window.hpp"
@@ -16,6 +17,7 @@
TypeSafeInt_B(PKE_UI_BOX_TYPE);
TypeSafeInt_B(PKE_UI_BOX_FLAG);
+TypeSafeInt_B(PKE_UI_BOX_STATE_FLAG);
struct pke_ui_box_instance_buffer_item {
glm::mat4 pos_scale;
@@ -250,6 +252,32 @@ void pke_ui_calc_px(pk_arr_t<pke_ui_box_instance_buffer_item> &buffer, pke_ui_fl
pk_arr_append_t(&buffer, tmp);
}
+void pke_ui_update_state_recursive(pke_ui_box *box, uint8_t depth = 0) {
+ (void)depth;
+ double mouse_x, mouse_y;
+
+ // update state
+ PKE_UI_BOX_STATE_FLAG old_state = box->state_flags;
+ box->state_flags = PKE_UI_BOX_STATE_FLAG_NONE;
+
+ pke_input_query_mouse_pos(mouse_x, mouse_y);
+ if (mouse_x >= box->internal.px_corner.x + box->internal.px_padding_l
+ && mouse_y >= box->internal.px_corner.y + box->internal.px_padding_t
+ && mouse_x <= box->internal.px_corner.x + box->internal.px_size.x - box->internal.px_padding_r
+ && mouse_y <= box->internal.px_corner.y + box->internal.px_size.y - box->internal.px_padding_b) {
+ box->state_flags |= PKE_UI_BOX_STATE_FLAG_MOUSE_HOVER;
+ if (!PK_HAS_FLAG(old_state, PKE_UI_BOX_STATE_FLAG_MOUSE_HOVER)) {
+ box->state_flags |= PKE_UI_BOX_STATE_FLAG_MOUSE_ENTERED;
+ }
+ } else if (PK_HAS_FLAG(old_state, PKE_UI_BOX_STATE_FLAG_MOUSE_HOVER)) {
+ box->state_flags |= PKE_UI_BOX_STATE_FLAG_MOUSE_EXITED;
+ }
+
+ for (pke_ui_box_count_T i = 0; i < box->internal.h_children; ++i) {
+ pke_ui_update_state_recursive(box->internal.children[i], depth + 1);
+ }
+}
+
void pke_ui_recalc_sizes_recursive(pk_arr_t<pke_ui_box_instance_buffer_item> &arr, pke_ui_box *box, uint8_t depth = 0) {
PKE_UI_BOX_FLAG_T flags_masked;
uint8_t flex_count = 0;
@@ -377,6 +405,7 @@ void pke_ui_update_instance_buffer(pk_arr_t<pke_ui_box_instance_buffer_item> &ar
void pke_ui_tick(double delta) {
(void)delta;
+ pke_ui_box_count_T i;
if (pke_ui_master.h_root_boxes == 0) return;
if (pke_ui_master.should_recalc_ui == true || pkeSettings.rt.was_framebuffer_resized == true) {
pk_arr_t<pke_ui_box_instance_buffer_item> arr;
@@ -385,13 +414,16 @@ void pke_ui_tick(double delta) {
2.0 / (float)Extent.width,
2.0 / (float)Extent.height
);
- for (pke_ui_box_count_T i = 0; i < pke_ui_master.h_root_boxes; ++i) {
+ for (i = 0; i < pke_ui_master.h_root_boxes; ++i) {
pke_ui_box *box = pke_ui_master.root_boxes[i];
pke_ui_calc_px(arr, nullptr, box);
pke_ui_recalc_sizes_recursive(arr, box, 0);
}
pke_ui_update_instance_buffer(arr);
}
+ for (i = 0; i < pke_ui_master.h_root_boxes; ++i) {
+ pke_ui_update_state_recursive(pke_ui_master.root_boxes[i], 0);
+ }
}
void pke_ui_teardown_box_recursive(pke_ui_box *box) {