diff --git a/game/src/ui/uiman.c b/game/src/ui/uiman.c index e629cf7..f559bab 100644 --- a/game/src/ui/uiman.c +++ b/game/src/ui/uiman.c @@ -195,7 +195,7 @@ gboolean uiman_cb_mouse_motion (SDL_Event *event, void *data) { UNUSED (event, data); - vec2 pos = { event->motion.x, event->motion.y }; + ivec2 pos = { event->motion.x, event->motion.y }; Widget *new_hover = Widget_find_xy_cond (ui_root, pos, wcond_any, NULL); @@ -235,9 +235,10 @@ gboolean uiman_cb_button_down (SDL_Event *event, void *data) { UNUSED (data); + ivec2 pos = { event->button.x, event->button.y }; WidgetEvent e = event->button.button == SDL_BUTTON_LEFT ? EVENT_LEFT_DOWN : EVENT_RIGHT_DOWN; - Widget *widget = Widget_find_xy_cond (ui_root, (vec2) { event->button.x, event->button.y }, wcond_any, NULL); + Widget *widget = Widget_find_xy_cond (ui_root, pos, wcond_any, NULL); _uiman_set_clicked (widget, TRUE); clicked_widget = widget; @@ -270,9 +271,10 @@ gboolean uiman_cb_mouse_wheel (SDL_Event *event, void *data) { UNUSED (event, data); + ivec2 pos = { event->button.x, event->button.y }; WidgetEvent e = event->wheel.y > 0 ? EVENT_SCROLL_UP : EVENT_SCROLL_DOWN; - Widget *widget = Widget_find_xy_cond (ui_root, (vec2) { event->wheel.mouse_x, event->wheel.mouse_y }, wcond_event, GINT_TO_POINTER (e)); + Widget *widget = Widget_find_xy_cond (ui_root, pos, wcond_event, GINT_TO_POINTER (e)); return _uiman_call_on_event (widget, event, e); } diff --git a/game/src/ui/widget_core.c b/game/src/ui/widget_core.c index e7472b8..0f133b3 100644 --- a/game/src/ui/widget_core.c +++ b/game/src/ui/widget_core.c @@ -278,10 +278,14 @@ Widget_entry_input_text (Widget *widget, const char *text) } void -Widget_scrollable_scroll (Widget *widget, vec2 direction) +Widget_scrollable_scroll (Widget *widget, ivec2 direction) { widget->layout_dirty = TRUE; - glm_vec2_muladds (direction, widget->scrollable.scroll_amount, widget->scrollable.scroll_position); + + ivec2 v; + glm_ivec2_scale (direction, widget->scrollable.scroll_amount, v); + glm_ivec2_add (v, widget->scrollable.scroll_position, widget->scrollable.scroll_position); + widget->scrollable.scroll_position[0] = glm_clamp (widget->scrollable.scroll_position[0], 0.0f, glm_max (0.0f, widget->scrollable.content_size[0] - widget->size[0])); @@ -291,15 +295,15 @@ Widget_scrollable_scroll (Widget *widget, vec2 direction) } gboolean -Widget_hit_test (Widget *widget, vec2 point) +Widget_hit_test (Widget *widget, ivec2 point) { - float x = point[0]; - float y = point[1]; + int x = point[0]; + int y = point[1]; - float left = widget->position[0]; - float top = widget->position[1]; - float right = left + widget->size[0]; - float bottom = top + widget->size[1]; + int left = widget->position[0]; + int top = widget->position[1]; + int right = left + widget->size[0]; + int bottom = top + widget->size[1]; return (x >= left && x <= right && y >= top && y <= bottom); @@ -327,7 +331,7 @@ wcond_any (Widget *widget, void *userdata) } Widget * -Widget_find_xy_cond (Widget *widget, vec2 pos, gboolean (*cond_func) (Widget *, void *), void *userdata) +Widget_find_xy_cond (Widget *widget, ivec2 pos, gboolean (*cond_func) (Widget *, void *), void *userdata) { if (!widget->visible) { @@ -339,12 +343,12 @@ Widget_find_xy_cond (Widget *widget, vec2 pos, gboolean (*cond_func) (Widget *, return NULL; } - vec2 pos_scrolled; - glm_vec2_copy (pos, pos_scrolled); + ivec2 pos_scrolled; + glm_ivec2_copy (pos, pos_scrolled); if (widget->kind == WIDGET_SCROLLABLE) { - glm_vec2_add (pos_scrolled, widget->scrollable.scroll_position, pos_scrolled); + glm_ivec2_add (pos_scrolled, widget->scrollable.scroll_position, pos_scrolled); } for (int i = widget->children->len - 1; i >= 0; --i) diff --git a/game/src/ui/widget_core.h b/game/src/ui/widget_core.h index b9bb486..19a40fa 100644 --- a/game/src/ui/widget_core.h +++ b/game/src/ui/widget_core.h @@ -87,7 +87,7 @@ typedef struct ScrollbarWidget gboolean horizontal; /* Used for input. */ gboolean dragging; - float drag_offset; + int drag_offset; } ScrollbarWidget; typedef struct ProgressWidget @@ -108,7 +108,7 @@ typedef struct MultilineTextWidget { GString *text; GArray *lines; - float line_height; + int line_height; TextAlignment text_alignment; } MultilineTextWidget; @@ -122,9 +122,9 @@ typedef struct ScrollableWidget gboolean layout_horizontal; gboolean layout_vertical; - float scroll_amount; - vec2 scroll_position; - vec2 content_size; + int scroll_amount; + ivec2 scroll_position; + ivec2 content_size; } ScrollableWidget; typedef struct FlowBoxWidget @@ -135,9 +135,9 @@ typedef struct FlowBoxWidget typedef struct WindowWidget { GString *title; - float titlebar_height; + int titlebar_height; gboolean moving, resizing; - vec2 drag_offset; + ivec2 drag_offset; gboolean resizable_h, resizable_v; } WindowWidget; @@ -216,12 +216,12 @@ void Widget_multiline_text_set_text (Widget *widget, const char *text); void Widget_entry_input_text (Widget *widget, const char *text); -void Widget_scrollable_scroll (Widget *widget, vec2 direction); +void Widget_scrollable_scroll (Widget *widget, ivec2 direction); gboolean wcond_tooltip (Widget *widget, void *userdata); gboolean wcond_event (Widget *widget, void *event); gboolean wcond_any (Widget *widget, void *userdata); -Widget *Widget_find_xy_cond (Widget *widget, vec2 point, gboolean (*cond_func) (Widget *, void *), void *userdata); +Widget *Widget_find_xy_cond (Widget *widget, ivec2 point, gboolean (*cond_func) (Widget *, void *), void *userdata); void Widget_tick (Widget *widget); void Widget_render (Widget *widget, mat4 projection, int window_height); diff --git a/game/src/ui/widget_layout.c b/game/src/ui/widget_layout.c index 38ef0a9..44f560e 100644 --- a/game/src/ui/widget_layout.c +++ b/game/src/ui/widget_layout.c @@ -78,7 +78,7 @@ Widget_layout_container (Widget *self) void Widget_layout_scrollable (Widget *self) { - vec2 content_size = { 0.0 }; + ivec2 content_size = { 0.0 }; Widget *child; WIDGET_FOREACH_CHILD (self, i, child) @@ -106,7 +106,7 @@ Widget_layout_scrollable (Widget *self) } } - glm_vec2_copy (content_size, self->scrollable.content_size); + glm_ivec2_copy (content_size, self->scrollable.content_size); } void diff --git a/game/src/ui/widget_ops.c b/game/src/ui/widget_ops.c index 20c3b1f..1835414 100644 --- a/game/src/ui/widget_ops.c +++ b/game/src/ui/widget_ops.c @@ -22,7 +22,7 @@ WidgetOpData_new (WidgetOp op, void *ptr, ...) data->delta = (float) va_arg (ap, double); break; case OP_SCROLLABLE_SCROLL: - glm_vec2_copy (va_arg (ap, float *), data->scroll_dir); + glm_ivec2_copy (va_arg (ap, int *), data->scroll_dir); break; default: break; diff --git a/game/src/ui/widget_ops.h b/game/src/ui/widget_ops.h index e6d26d7..a0ac4b7 100644 --- a/game/src/ui/widget_ops.h +++ b/game/src/ui/widget_ops.h @@ -34,7 +34,7 @@ typedef struct WidgetOpData /* These are used dependant on what you wanna do. */ const char *fmt; float delta; - vec2 scroll_dir; + ivec2 scroll_dir; } WidgetOpData; WidgetOpData *WidgetOpData_new (WidgetOp op, void *ptr, ...);