aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHarry Jeffery <harry@exec64.co.uk>2019-07-13 00:35:19 +0100
committerHarry Jeffery <harry@exec64.co.uk>2019-07-13 00:35:19 +0100
commit4473f6d8b7bda3ecb6acaf16e8609a219f7ef6fc (patch)
treebeec9492b8a013ca7ad815ed1ea8a7691e5c7a2b /src
parent5a1571d00dd1e73f906b1c83b7abe13aa0908e9a (diff)
downloadimv-4473f6d8b7bda3ecb6acaf16e8609a219f7ef6fc.tar.gz
Implement scroll input
Diffstat (limited to 'src')
-rw-r--r--src/imv.c17
-rw-r--r--src/window.c39
-rw-r--r--src/window.h6
3 files changed, 50 insertions, 12 deletions
diff --git a/src/imv.c b/src/imv.c
index c6fe9f6..aa99a72 100644
--- a/src/imv.c
+++ b/src/imv.c
@@ -455,6 +455,14 @@ static void event_handler(void *data, const struct imv_event *e)
e->data.mouse_motion.dy, imv->current_image);
}
break;
+ case IMV_EVENT_MOUSE_SCROLL:
+ {
+ double x, y;
+ imv_window_get_mouse_position(imv->window, &x, &y);
+ imv_viewport_zoom(imv->view, imv->current_image, IMV_ZOOM_MOUSE,
+ x, y, -e->data.mouse_scroll.dy);
+ }
+ break;
case IMV_EVENT_CUSTOM:
consume_internal_event(imv, e->data.custom);
break;
@@ -464,15 +472,6 @@ static void event_handler(void *data, const struct imv_event *e)
}
-/* static void scroll_callback(GLFWwindow *window, double x, double y)*/
-/* {*/
-/* (void)x;*/
-/* struct imv *imv = glfwGetWindowUserPointer(window);*/
-/* imv_viewport_zoom(imv->view, imv->current_image, IMV_ZOOM_MOUSE,*/
-/* imv->last_cursor_position.x,*/
-/* imv->last_cursor_position.y, -y);*/
-/* }*/
-
static void log_to_stderr(enum imv_log_level level, const char *text, void *data)
{
(void)data;
diff --git a/src/window.c b/src/window.c
index fd1986f..de188c0 100644
--- a/src/window.c
+++ b/src/window.c
@@ -52,6 +52,10 @@ struct imv_window {
bool last;
bool current;
} mouse1;
+ struct {
+ double dx;
+ double dy;
+ } scroll;
} pointer;
struct {
@@ -205,11 +209,15 @@ static void pointer_button(void *data, struct wl_pointer *pointer,
static void pointer_axis(void *data, struct wl_pointer *pointer,
uint32_t time, uint32_t axis, wl_fixed_t value)
{
- (void)data;
(void)pointer;
(void)time;
- (void)axis;
- (void)value;
+
+ struct imv_window *window = data;
+ if (axis == WL_POINTER_AXIS_VERTICAL_SCROLL) {
+ window->pointer.scroll.dy += wl_fixed_to_double(value);
+ } else if (axis == WL_POINTER_AXIS_HORIZONTAL_SCROLL) {
+ window->pointer.scroll.dx += wl_fixed_to_double(value);
+ }
}
static void pointer_frame(void *data, struct wl_pointer *pointer)
@@ -251,6 +259,21 @@ static void pointer_frame(void *data, struct wl_pointer *pointer)
imv_window_push_event(window, &e);
}
+ if (window->pointer.scroll.dx || window->pointer.scroll.dy) {
+ struct imv_event e = {
+ .type = IMV_EVENT_MOUSE_SCROLL,
+ .data = {
+ .mouse_scroll = {
+ .dx = window->pointer.scroll.dx,
+ .dy = window->pointer.scroll.dy
+ }
+ }
+ };
+ imv_window_push_event(window, &e);
+ window->pointer.scroll.dx = 0;
+ window->pointer.scroll.dy = 0;
+ }
+
}
static void pointer_axis_source(void *data, struct wl_pointer *pointer,
@@ -565,6 +588,16 @@ bool imv_window_get_mouse_button(struct imv_window *window, int button)
return false;
}
+void imv_window_get_mouse_position(struct imv_window *window, double *x, double *y)
+{
+ if (x) {
+ *x = window->pointer.x.last;
+ }
+ if (y) {
+ *y = window->pointer.y.last;
+ }
+}
+
void imv_window_present(struct imv_window *window)
{
eglSwapBuffers(window->egl_display, window->egl_surface);
diff --git a/src/window.h b/src/window.h
index d6e317e..3e61043 100644
--- a/src/window.h
+++ b/src/window.h
@@ -11,6 +11,7 @@ enum imv_event_type {
IMV_EVENT_KEYBOARD,
IMV_EVENT_MOUSE_MOTION,
IMV_EVENT_MOUSE_BUTTON,
+ IMV_EVENT_MOUSE_SCROLL,
IMV_EVENT_CUSTOM
};
@@ -34,6 +35,9 @@ struct imv_event {
int button;
bool pressed;
} mouse_button;
+ struct {
+ double dx, dy;
+ } mouse_scroll;
void *custom;
} data;
};
@@ -54,6 +58,8 @@ void imv_window_set_fullscreen(struct imv_window *window, bool fullscreen);
bool imv_window_get_mouse_button(struct imv_window *window, int button);
+void imv_window_get_mouse_position(struct imv_window *window, double *x, double *y);
+
void imv_window_present(struct imv_window *window);
void imv_window_wait_for_event(struct imv_window *window, double timeout);