From 380126452078c69862d2037886679bcade662c17 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 12 Sep 2016 23:23:35 +0800 Subject: Demonstrate enter and leave events --- pugl_cairo_test.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) 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; } } -- cgit v1.2.1