aboutsummaryrefslogtreecommitdiffstats
path: root/pugl
diff options
context:
space:
mode:
Diffstat (limited to 'pugl')
-rw-r--r--pugl/pugl.h7
-rw-r--r--pugl/pugl_internal.h7
-rw-r--r--pugl/pugl_x11.c17
3 files changed, 30 insertions, 1 deletions
diff --git a/pugl/pugl.h b/pugl/pugl.h
index a764620..f173525 100644
--- a/pugl/pugl.h
+++ b/pugl/pugl.h
@@ -55,6 +55,7 @@ typedef void (*PuglMouseFunc)(PuglWindow* handle,
int button, bool down,
int x, int y);
typedef void (*PuglReshapeFunc)(PuglWindow* handle, int width, int height);
+typedef void (*PuglScrollFunc)(PuglWindow* handle, int dx, int dy);
/**
Create a new GL window.
@@ -120,6 +121,12 @@ void
puglSetMouseFunc(PuglWindow* window, PuglMouseFunc mouseFunc);
/**
+ Set the function to call on scroll events.
+*/
+void
+puglSetScrollFunc(PuglWindow* window, PuglScrollFunc scrollFunc);
+
+/**
Set the function to call when the window size changes.
*/
void
diff --git a/pugl/pugl_internal.h b/pugl/pugl_internal.h
index 8a7b217..3685522 100644
--- a/pugl/pugl_internal.h
+++ b/pugl/pugl_internal.h
@@ -35,6 +35,7 @@ struct PuglWindowImpl {
PuglMotionFunc motionFunc;
PuglMouseFunc mouseFunc;
PuglReshapeFunc reshapeFunc;
+ PuglScrollFunc scrollFunc;
PuglPlatformData* impl;
@@ -90,3 +91,9 @@ puglSetReshapeFunc(PuglWindow* window, PuglReshapeFunc reshapeFunc)
{
window->reshapeFunc = reshapeFunc;
}
+
+void
+puglSetScrollFunc(PuglWindow* window, PuglScrollFunc scrollFunc)
+{
+ window->scrollFunc = scrollFunc;
+}
diff --git a/pugl/pugl_x11.c b/pugl/pugl_x11.c
index d8685b2..735cdb1 100644
--- a/pugl/pugl_x11.c
+++ b/pugl/pugl_x11.c
@@ -238,8 +238,23 @@ puglProcessEvents(PuglWindow* win)
}
break;
case ButtonPress:
+ if (event.xbutton.button >= 4 && event.xbutton.button <= 7) {
+ if (win->scrollFunc) {
+ int dx = 0, dy = 0;
+ switch (event.xbutton.button) {
+ case 4: dy = 1; break;
+ case 5: dy = -1; break;
+ case 6: dx = -1; break;
+ case 7: dx = 1; break;
+ }
+ win->scrollFunc(win, dx, dy);
+ }
+ break;
+ }
+ // nobreak
case ButtonRelease:
- if (win->mouseFunc) {
+ if (win->mouseFunc &&
+ (event.xbutton.button < 4 || event.xbutton.button > 7)) {
win->mouseFunc(win,
event.xbutton.button, event.type == ButtonPress,
event.xbutton.x, event.xbutton.y);