summaryrefslogtreecommitdiff
path: root/pugl/pugl_internal.h
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2014-08-27 23:32:26 +0000
committerDavid Robillard <d@drobilla.net>2014-08-27 23:32:26 +0000
commitd0c878fe0e496083a1e892795c23a1ac939714a9 (patch)
tree6a70e0fbd68726357a8b008ecd2bba1d3062e6b1 /pugl/pugl_internal.h
parentb4dbb3616865cd236cda4f2e4ac806b3b4840b29 (diff)
Event-based dispatch.
Diffstat (limited to 'pugl/pugl_internal.h')
-rw-r--r--pugl/pugl_internal.h115
1 files changed, 85 insertions, 30 deletions
diff --git a/pugl/pugl_internal.h b/pugl/pugl_internal.h
index 3db08f7..32d31bf 100644
--- a/pugl/pugl_internal.h
+++ b/pugl/pugl_internal.h
@@ -24,27 +24,18 @@
If you are copying the pugl code into your source tree, the following
symbols can be defined to tweak pugl behaviour:
- PUGL_GRAB_FOCUS: Work around reparent keyboard issues by grabbing focus.
- PUGL_VERBOSE: Print graphics information to console.
PUGL_HAVE_CAIRO: Include Cairo support code.
PUGL_HAVE_GL: Include OpenGL support code.
*/
-#include "pugl.h"
-
-#ifdef PUGL_VERBOSE
-# include <stdio.h>
-# define PUGL_LOG(str) fprintf(stderr, "pugl: " str)
-# define PUGL_LOGF(fmt, ...) fprintf(stderr, "pugl: " fmt, __VA_ARGS__)
-#else
-# define PUGL_LOG(str)
-# define PUGL_LOGF(fmt, ...)
-#endif
+#include "pugl/pugl.h"
+#include "pugl/event.h"
typedef struct PuglInternalsImpl PuglInternals;
struct PuglViewImpl {
PuglHandle handle;
+ PuglEventFunc eventFunc;
PuglCloseFunc closeFunc;
PuglDisplayFunc displayFunc;
PuglKeyboardFunc keyboardFunc;
@@ -71,8 +62,6 @@ struct PuglViewImpl {
PuglInternals* puglInitInternals();
-void puglDefaultReshape(PuglView* view, int width, int height);
-
PuglView*
puglInit(int* pargc, char** argv)
{
@@ -143,27 +132,15 @@ puglGetModifiers(PuglView* view)
}
void
-puglDefaultReshape(PuglView* view, int width, int height)
+puglIgnoreKeyRepeat(PuglView* view, bool ignore)
{
-#ifdef PUGL_HAVE_GL
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(0, width, height, 0, 0, 1);
- glViewport(0, 0, width, height);
-
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
-#endif
- return;
-
- // unused
- (void)view;
+ view->ignoreKeyRepeat = ignore;
}
void
-puglIgnoreKeyRepeat(PuglView* view, bool ignore)
+puglSetEventFunc(PuglView* view, PuglEventFunc eventFunc)
{
- view->ignoreKeyRepeat = ignore;
+ view->eventFunc = eventFunc;
}
void
@@ -213,3 +190,81 @@ puglSetSpecialFunc(PuglView* view, PuglSpecialFunc specialFunc)
{
view->specialFunc = specialFunc;
}
+
+void
+puglEnterContext(PuglView* view);
+
+void
+puglLeaveContext(PuglView* view, bool flush);
+
+static void
+puglDispatchEvent(PuglView* view, const PuglEvent* event)
+{
+ if (view->eventFunc) {
+ view->eventFunc(view, event);
+ }
+
+ 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_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;
+ }
+}