diff options
author | David Robillard <d@drobilla.net> | 2016-09-12 23:23:35 +0800 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2016-09-12 23:23:35 +0800 |
commit | 380126452078c69862d2037886679bcade662c17 (patch) | |
tree | 09c3db60a7a93474b908ef4cb07af9afe332fb41 | |
parent | 93242ef59b807419cf9ebe81c90829e90f1b518c (diff) | |
download | pugl-380126452078c69862d2037886679bcade662c17.tar.gz pugl-380126452078c69862d2037886679bcade662c17.tar.bz2 pugl-380126452078c69862d2037886679bcade662c17.zip |
Demonstrate enter and leave events
-rw-r--r-- | pugl_cairo_test.c | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/pugl_cairo_test.c b/pugl_cairo_test.c index 9c1bef8..508a57a 100644 --- a/pugl_cairo_test.c +++ b/pugl_cairo_test.c @@ -26,7 +26,8 @@ #include "pugl/pugl.h" -static int quit = 0; +static int quit = 0; +static bool entered = false; typedef struct { int x; @@ -102,6 +103,18 @@ onDisplay(PuglView* view) { cairo_t* cr = puglGetContext(view); + // Draw background + int width, height; + puglGetSize(view, &width, &height); + if (entered) { + cairo_set_source_rgb(cr, 0.1, 0.1, 0.1); + } else { + cairo_set_source_rgb(cr, 0, 0, 0); + } + cairo_rectangle(cr, 0, 0, width, height); + cairo_fill(cr); + + // Draw button buttonDraw(cr, &toggle_button); } @@ -127,6 +140,15 @@ onEvent(PuglView* view, const PuglEvent* event) toggle_button.pressed = !toggle_button.pressed; puglPostRedisplay(view); } + break; + case PUGL_ENTER_NOTIFY: + entered = true; + puglPostRedisplay(view); + break; + case PUGL_LEAVE_NOTIFY: + entered = false; + puglPostRedisplay(view); + break; default: break; } } |