From a016618bde1f4e3fe87579ac430847b0b955058a Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 16 Mar 2020 20:32:36 +0100 Subject: Embed Demo: Add timer to occasionally reverse spin direction --- examples/pugl_embed_demo.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'examples/pugl_embed_demo.c') diff --git a/examples/pugl_embed_demo.c b/examples/pugl_embed_demo.c index 174fd36..a540b67 100644 --- a/examples/pugl_embed_demo.c +++ b/examples/pugl_embed_demo.c @@ -32,7 +32,8 @@ #include #include -static const int borderWidth = 64; +static const int borderWidth = 64; +static const uintptr_t reverseTimerId = 1u; typedef struct { @@ -49,6 +50,7 @@ typedef struct double lastDrawTime; bool mouseEntered; bool verbose; + bool reversing; } PuglTestApp; static const float backgroundVertices[] = { @@ -78,7 +80,8 @@ onDisplay(PuglView* view) const double thisTime = puglGetTime(app->world); if (app->continuous) { - const double dTime = thisTime - app->lastDrawTime; + const double dTime = (thisTime - app->lastDrawTime) * + (app->reversing ? -1.0 : 1.0); app->xAngle = fmod(app->xAngle + dTime * 100.0, 360.0); app->yAngle = fmod(app->yAngle + dTime * 100.0, 360.0); @@ -249,6 +252,9 @@ onEvent(PuglView* view, const PuglEvent* event) case PUGL_LEAVE_NOTIFY: app->mouseEntered = false; break; + case PUGL_TIMER: + app->reversing = !app->reversing; + break; default: break; } @@ -321,6 +327,8 @@ main(int argc, char** argv) puglShowWindow(app.parent); puglShowWindow(app.child); + puglStartTimer(app.child, reverseTimerId, 3.6); + PuglFpsPrinter fpsPrinter = { puglGetTime(app.world) }; unsigned framesDrawn = 0; bool requestedAttention = false; -- cgit v1.2.1