aboutsummaryrefslogtreecommitdiffstats
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
parent8150102ad806632e70f8bd8cd211dbe74bc40be5 (diff)
downloadpugl-69b2d6336b3598957a59a37a6bc95bcb154bab95.tar.gz
pugl-69b2d6336b3598957a59a37a6bc95bcb154bab95.tar.bz2
pugl-69b2d6336b3598957a59a37a6bc95bcb154bab95.zip
Remove GLUT-like event callbacks
-rw-r--r--pugl/pugl.h136
-rw-r--r--pugl/pugl.hpp2
-rw-r--r--pugl/pugl_internal.h143
-rw-r--r--pugl/pugl_x11.c5
-rw-r--r--pugl_cairo_test.c8
-rw-r--r--pugl_test.c116
6 files changed, 73 insertions, 337 deletions
diff --git a/pugl/pugl.h b/pugl/pugl.h
index 91179c0..b4c723b 100644
--- a/pugl/pugl.h
+++ b/pugl/pugl.h
@@ -61,80 +61,6 @@ extern "C" {
typedef void (*PuglEventFunc)(PuglView* view, const PuglEvent* event);
/**
- A function called when the window is closed.
-*/
-typedef void (*PuglCloseFunc)(PuglView* view);
-
-/**
- A function called to draw the view contents with OpenGL.
-*/
-typedef void (*PuglDisplayFunc)(PuglView* view);
-
-/**
- A function called when a key is pressed or released.
- @param view The view the event occured in.
- @param press True if the key was pressed, false if released.
- @param key Unicode point of the key pressed.
-*/
-typedef void (*PuglKeyboardFunc)(PuglView* view, bool press, uint32_t key);
-
-/**
- A function called when the pointer moves.
- @param view The view the event occured in.
- @param x The window-relative x coordinate of the pointer.
- @param y The window-relative y coordinate of the pointer.
-*/
-typedef void (*PuglMotionFunc)(PuglView* view, int x, int y);
-
-/**
- A function called when a mouse button is pressed or released.
- @param view The view the event occured in.
- @param button The button number (1 = left, 2 = middle, 3 = right).
- @param press True if the key was pressed, false if released.
- @param x The window-relative x coordinate of the pointer.
- @param y The window-relative y coordinate of the pointer.
-*/
-typedef void (*PuglMouseFunc)(
- PuglView* view, int button, bool press, int x, int y);
-
-/**
- A function called when the view is resized.
- @param view The view being resized.
- @param width The new view width.
- @param height The new view height.
-*/
-typedef void (*PuglReshapeFunc)(PuglView* view, int width, int height);
-
-/**
- A function called on scrolling (e.g. mouse wheel or track pad).
-
- The distances used here are in "lines", a single tick of a clicking mouse
- wheel. For example, @p dy = 1.0 scrolls 1 line up. Some systems and
- devices support finer resolution and/or higher values for fast scrolls,
- so programs should handle any value gracefully.
-
- @param view The view being scrolled.
- @param dx The scroll x distance.
- @param dx The scroll y distance.
-*/
-typedef void (*PuglScrollFunc)(PuglView* view,
- int x,
- int y,
- float dx,
- float dy);
-
-/**
- A function called when a special key is pressed or released.
-
- This callback allows the use of keys that do not have unicode points.
-
- @param view The view the event occured in.
- @param press True if the key was pressed, false if released.
- @param key The key pressed.
-*/
-typedef void (*PuglSpecialFunc)(PuglView* view, bool press, PuglKey key);
-
-/**
@name Initialization
Configuration functions which must be called before creating a window.
@{
@@ -288,20 +214,6 @@ PUGL_API void
puglGetSize(PuglView* view, int* width, int* height);
/**
- Return the timestamp (if any) of the currently-processing event.
-*/
-PUGL_API uint32_t
-puglGetEventTimestamp(PuglView* view);
-
-/**
- Get the currently active modifiers (PuglMod flags).
-
- This should only be called from an event handler.
-*/
-PUGL_API int
-puglGetModifiers(PuglView* view);
-
-/**
Ignore synthetic repeated key events.
*/
PUGL_API void
@@ -339,54 +251,6 @@ PUGL_API void
puglSetEventFunc(PuglView* view, PuglEventFunc eventFunc);
/**
- Set the function to call when the window is closed.
-*/
-PUGL_API void
-puglSetCloseFunc(PuglView* view, PuglCloseFunc closeFunc);
-
-/**
- Set the display function which should draw the UI using GL.
-*/
-PUGL_API void
-puglSetDisplayFunc(PuglView* view, PuglDisplayFunc displayFunc);
-
-/**
- Set the function to call on keyboard events.
-*/
-PUGL_API void
-puglSetKeyboardFunc(PuglView* view, PuglKeyboardFunc keyboardFunc);
-
-/**
- Set the function to call on mouse motion.
-*/
-PUGL_API void
-puglSetMotionFunc(PuglView* view, PuglMotionFunc motionFunc);
-
-/**
- Set the function to call on mouse button events.
-*/
-PUGL_API void
-puglSetMouseFunc(PuglView* view, PuglMouseFunc mouseFunc);
-
-/**
- Set the function to call on scroll events.
-*/
-PUGL_API void
-puglSetScrollFunc(PuglView* view, PuglScrollFunc scrollFunc);
-
-/**
- Set the function to call on special events.
-*/
-PUGL_API void
-puglSetSpecialFunc(PuglView* view, PuglSpecialFunc specialFunc);
-
-/**
- Set the function to call when the window size changes.
-*/
-PUGL_API void
-puglSetReshapeFunc(PuglView* view, PuglReshapeFunc reshapeFunc);
-
-/**
@}
*/
diff --git a/pugl/pugl.hpp b/pugl/pugl.hpp
index 03816c2..d405759 100644
--- a/pugl/pugl.hpp
+++ b/pugl/pugl.hpp
@@ -87,8 +87,6 @@ public:
virtual void onDisplay() {}
virtual void* getContext() { return puglGetContext(_view); }
- virtual uint32_t getEventTimestamp() { return puglGetEventTimestamp(_view); }
- virtual int getModifiers() { return puglGetModifiers(_view); }
virtual void ignoreKeyRepeat(bool ignore) { puglIgnoreKeyRepeat(_view, ignore); }
virtual void grabFocus() { puglGrabFocus(_view); }
virtual PuglStatus waitForEvent() { return puglWaitForEvent(_view); }
diff --git a/pugl/pugl_internal.h b/pugl/pugl_internal.h
index aa55c6d..aeb580d 100644
--- a/pugl/pugl_internal.h
+++ b/pugl/pugl_internal.h
@@ -39,14 +39,6 @@ typedef struct PuglInternalsImpl PuglInternals;
struct PuglViewImpl {
PuglHandle handle;
PuglEventFunc eventFunc;
- PuglCloseFunc closeFunc;
- PuglDisplayFunc displayFunc;
- PuglKeyboardFunc keyboardFunc;
- PuglMotionFunc motionFunc;
- PuglMouseFunc mouseFunc;
- PuglReshapeFunc reshapeFunc;
- PuglScrollFunc scrollFunc;
- PuglSpecialFunc specialFunc;
PuglInternals* impl;
@@ -63,13 +55,10 @@ struct PuglViewImpl {
int min_aspect_y;
int max_aspect_x;
int max_aspect_y;
- int mods;
- bool mouse_in_view;
bool ignoreKeyRepeat;
bool redisplay;
bool resizable;
bool visible;
- uint32_t event_timestamp_ms;
};
PuglInternals* puglInitInternals(void);
@@ -181,18 +170,6 @@ puglGetSize(PuglView* view, int* width, int* height)
*height = view->height;
}
-uint32_t
-puglGetEventTimestamp(PuglView* view)
-{
- return view->event_timestamp_ms;
-}
-
-int
-puglGetModifiers(PuglView* view)
-{
- return view->mods;
-}
-
void
puglIgnoreKeyRepeat(PuglView* view, bool ignore)
{
@@ -205,54 +182,6 @@ puglSetEventFunc(PuglView* view, PuglEventFunc eventFunc)
view->eventFunc = eventFunc;
}
-void
-puglSetCloseFunc(PuglView* view, PuglCloseFunc closeFunc)
-{
- view->closeFunc = closeFunc;
-}
-
-void
-puglSetDisplayFunc(PuglView* view, PuglDisplayFunc displayFunc)
-{
- view->displayFunc = displayFunc;
-}
-
-void
-puglSetKeyboardFunc(PuglView* view, PuglKeyboardFunc keyboardFunc)
-{
- view->keyboardFunc = keyboardFunc;
-}
-
-void
-puglSetMotionFunc(PuglView* view, PuglMotionFunc motionFunc)
-{
- view->motionFunc = motionFunc;
-}
-
-void
-puglSetMouseFunc(PuglView* view, PuglMouseFunc mouseFunc)
-{
- view->mouseFunc = mouseFunc;
-}
-
-void
-puglSetReshapeFunc(PuglView* view, PuglReshapeFunc reshapeFunc)
-{
- view->reshapeFunc = reshapeFunc;
-}
-
-void
-puglSetScrollFunc(PuglView* view, PuglScrollFunc scrollFunc)
-{
- view->scrollFunc = scrollFunc;
-}
-
-void
-puglSetSpecialFunc(PuglView* view, PuglSpecialFunc specialFunc)
-{
- view->specialFunc = specialFunc;
-}
-
/** Return the code point for buf, or the replacement character on error. */
static uint32_t
puglDecodeUTF8(const uint8_t* buf)
@@ -292,6 +221,8 @@ puglDispatchEvent(PuglView* view, const PuglEvent* event)
{
if (event->type == PUGL_NOTHING) {
return;
+ } else if (event->type == PUGL_EXPOSE && event->expose.count > 0) {
+ return;
} else if (view->eventFunc) {
const bool is_draw = (event->type == PUGL_CONFIGURE ||
event->type == PUGL_EXPOSE);
@@ -303,74 +234,4 @@ puglDispatchEvent(PuglView* view, const PuglEvent* event)
puglLeaveContext(view, event->type == PUGL_EXPOSE);
}
}
-
- switch (event->type) {
- case PUGL_CONFIGURE:
- puglEnterContext(view);
- view->width = event->configure.width;
- view->height = event->configure.height;
- if (view->reshapeFunc) {
- view->reshapeFunc(view, view->width, view->height);
- }
- puglLeaveContext(view, false);
- break;
- case PUGL_EXPOSE:
- if (event->expose.count == 0) {
- puglEnterContext(view);
- if (view->displayFunc) {
- view->displayFunc(view);
- }
- view->redisplay = false;
- puglLeaveContext(view, true);
- }
- break;
- case PUGL_CLOSE:
- if (view->closeFunc) {
- view->closeFunc(view);
- }
- view->redisplay = false;
- break;
- case PUGL_MOTION_NOTIFY:
- view->event_timestamp_ms = event->motion.time;
- view->mods = event->motion.state;
- if (view->motionFunc) {
- view->motionFunc(view, event->motion.x, event->motion.y);
- }
- break;
- case PUGL_SCROLL:
- if (view->scrollFunc) {
- view->scrollFunc(view,
- event->scroll.x, event->scroll.y,
- event->scroll.dx, event->scroll.dy);
- }
- break;
- case PUGL_BUTTON_PRESS:
- case PUGL_BUTTON_RELEASE:
- view->event_timestamp_ms = event->button.time;
- view->mods = event->button.state;
- if (view->mouseFunc) {
- view->mouseFunc(view,
- event->button.button,
- event->type == PUGL_BUTTON_PRESS,
- event->button.x,
- event->button.y);
- }
- break;
- case PUGL_KEY_PRESS:
- case PUGL_KEY_RELEASE:
- view->event_timestamp_ms = event->key.time;
- view->mods = event->key.state;
- if (event->key.special && view->specialFunc) {
- view->specialFunc(view,
- event->type == PUGL_KEY_PRESS,
- event->key.special);
- } else if (event->key.character && view->keyboardFunc) {
- view->keyboardFunc(view,
- event->type == PUGL_KEY_PRESS,
- event->key.character);
- }
- break;
- default:
- break;
- }
}
diff --git a/pugl/pugl_x11.c b/pugl/pugl_x11.c
index 7ceef29..75fedca 100644
--- a/pugl/pugl_x11.c
+++ b/pugl/pugl_x11.c
@@ -61,6 +61,8 @@ static int attrListDbl[] = {
GLX_GREEN_SIZE , 4,
GLX_BLUE_SIZE , 4,
GLX_DEPTH_SIZE , 16,
+ /* GLX_SAMPLE_BUFFERS , 1, */
+ /* GLX_SAMPLES , 4, */
None
};
@@ -72,6 +74,8 @@ static int attrListSgl[] = {
GLX_GREEN_SIZE , 4,
GLX_BLUE_SIZE , 4,
GLX_DEPTH_SIZE , 16,
+ /* GLX_SAMPLE_BUFFERS , 1, */
+ /* GLX_SAMPLES , 4, */
None
};
@@ -684,6 +688,7 @@ puglProcessEvents(PuglView* view)
expose_event.expose.y = 0;
expose_event.expose.width = view->width;
expose_event.expose.height = view->height;
+ view->redisplay = false;
}
if (expose_event.type) {
diff --git a/pugl_cairo_test.c b/pugl_cairo_test.c
index 508a57a..ccffab5 100644
--- a/pugl_cairo_test.c
+++ b/pugl_cairo_test.c
@@ -149,6 +149,12 @@ onEvent(PuglView* view, const PuglEvent* event)
entered = false;
puglPostRedisplay(view);
break;
+ case PUGL_EXPOSE:
+ onDisplay(view);
+ break;
+ case PUGL_CLOSE:
+ onClose(view);
+ break;
default: break;
}
}
@@ -181,8 +187,6 @@ main(int argc, char** argv)
puglIgnoreKeyRepeat(view, ignoreKeyRepeat);
puglSetEventFunc(view, onEvent);
- puglSetDisplayFunc(view, onDisplay);
- puglSetCloseFunc(view, onClose);
puglCreateWindow(view, "Pugl Test");
puglShowWindow(view);
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");