aboutsummaryrefslogtreecommitdiffstats
path: root/pugl_test.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2016-09-18 22:28:30 -0400
committerDavid Robillard <d@drobilla.net>2016-09-18 22:28:30 -0400
commit69b2d6336b3598957a59a37a6bc95bcb154bab95 (patch)
treec3bdd423f0f795993e96c093f4ecdba09a6cc78b /pugl_test.c
parent8150102ad806632e70f8bd8cd211dbe74bc40be5 (diff)
downloadpugl-69b2d6336b3598957a59a37a6bc95bcb154bab95.tar.gz
pugl-69b2d6336b3598957a59a37a6bc95bcb154bab95.tar.bz2
pugl-69b2d6336b3598957a59a37a6bc95bcb154bab95.zip
Remove GLUT-like event callbacks
Diffstat (limited to 'pugl_test.c')
-rw-r--r--pugl_test.c116
1 files changed, 60 insertions, 56 deletions
diff --git a/pugl_test.c b/pugl_test.c
index 698299b..5c4ab9c 100644
--- a/pugl_test.c
+++ b/pugl_test.c
@@ -131,9 +131,8 @@ onDisplay(PuglView* view)
}
static void
-printModifiers(PuglView* view)
+printModifiers(PuglView* view, unsigned mods)
{
- int mods = puglGetModifiers(view);
fprintf(stderr, "Modifiers:%s%s%s%s\n",
(mods & PUGL_MOD_SHIFT) ? " Shift" : "",
(mods & PUGL_MOD_CTRL) ? " Ctrl" : "",
@@ -144,59 +143,71 @@ printModifiers(PuglView* view)
static void
onEvent(PuglView* view, const PuglEvent* event)
{
- if (event->type == PUGL_KEY_PRESS) {
- const uint32_t ucode = event->key.character;
- fprintf(stderr, "Key %u (char %u) down (%s)%s\n",
- event->key.keycode, ucode, event->key.utf8,
+ switch (event->type) {
+ case PUGL_NOTHING:
+ break;
+ case PUGL_CONFIGURE:
+ onReshape(view, event->configure.width, event->configure.height);
+ break;
+ case PUGL_EXPOSE:
+ onDisplay(view);
+ break;
+ case PUGL_CLOSE:
+ quit = 1;
+ break;
+ case PUGL_KEY_PRESS:
+ fprintf(stderr, "Key %u (char %u) press (%s)%s\n",
+ event->key.keycode, event->key.character, event->key.utf8,
event->key.filter ? " (filtered)" : "");
-
- if (ucode == 'q' || ucode == 'Q' || ucode == PUGL_CHAR_ESCAPE) {
+ if (event->key.character == 'q' ||
+ event->key.character == 'Q' ||
+ event->key.character == PUGL_CHAR_ESCAPE) {
quit = 1;
}
+ break;
+ case PUGL_KEY_RELEASE:
+ fprintf(stderr, "Key %u (char %u) release (%s)%s\n",
+ event->key.keycode, event->key.character, event->key.utf8,
+ event->key.filter ? " (filtered)" : "");
+ break;
+ case PUGL_MOTION_NOTIFY:
+ xAngle = -(int)event->motion.x % 360;
+ yAngle = (int)event->motion.y % 360;
+ puglPostRedisplay(view);
+ break;
+ case PUGL_BUTTON_PRESS:
+ case PUGL_BUTTON_RELEASE:
+ fprintf(stderr, "Mouse %d %s at %f,%f ",
+ event->button.button,
+ (event->type == PUGL_BUTTON_PRESS) ? "down" : "up",
+ event->button.x,
+ event->button.y);
+ break;
+ case PUGL_SCROLL:
+ fprintf(stderr, "Scroll %f %f %f %f ",
+ event->scroll.x, event->scroll.y, event->scroll.dx, event->scroll.dy);
+ printModifiers(view, event->scroll.state);
+ dist += event->scroll.dy;
+ if (dist < 10.0f) {
+ dist = 10.0f;
+ }
+ puglPostRedisplay(view);
+ break;
+ case PUGL_ENTER_NOTIFY:
+ fprintf(stderr, "Entered\n");
+ break;
+ case PUGL_LEAVE_NOTIFY:
+ fprintf(stderr, "Exited\n");
+ break;
+ case PUGL_FOCUS_IN:
+ fprintf(stderr, "Focus in\n");
+ break;
+ case PUGL_FOCUS_OUT:
+ fprintf(stderr, "Focus out\n");
+ break;
}
}
-static void
-onSpecial(PuglView* view, bool press, PuglKey key)
-{
- fprintf(stderr, "Special key %d %s ", key, press ? "down" : "up");
- printModifiers(view);
-}
-
-static void
-onMotion(PuglView* view, int x, int y)
-{
- xAngle = x % 360;
- yAngle = y % 360;
- puglPostRedisplay(view);
-}
-
-static void
-onMouse(PuglView* view, int button, bool press, int x, int y)
-{
- fprintf(stderr, "Mouse %d %s at %d,%d ",
- button, press ? "down" : "up", x, y);
- printModifiers(view);
-}
-
-static void
-onScroll(PuglView* view, int x, int y, float dx, float dy)
-{
- fprintf(stderr, "Scroll %d %d %f %f ", x, y, dx, dy);
- printModifiers(view);
- dist += dy / 4.0f;
- if (dist < 10.0f) {
- dist = 10.0f;
- }
- puglPostRedisplay(view);
-}
-
-static void
-onClose(PuglView* view)
-{
- quit = 1;
-}
-
int
main(int argc, char** argv)
{
@@ -228,13 +239,6 @@ main(int argc, char** argv)
puglIgnoreKeyRepeat(view, ignoreKeyRepeat);
puglSetEventFunc(view, onEvent);
- puglSetMotionFunc(view, onMotion);
- puglSetMouseFunc(view, onMouse);
- puglSetScrollFunc(view, onScroll);
- puglSetSpecialFunc(view, onSpecial);
- puglSetDisplayFunc(view, onDisplay);
- puglSetReshapeFunc(view, onReshape);
- puglSetCloseFunc(view, onClose);
puglCreateWindow(view, "Pugl Test");