diff options
author | David Robillard <d@drobilla.net> | 2020-03-16 20:32:36 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2020-03-16 21:21:15 +0100 |
commit | a016618bde1f4e3fe87579ac430847b0b955058a (patch) | |
tree | ac391fa26746ea41f7e73e2b9a14d5f56f7c8bcc /examples/pugl_embed_demo.c | |
parent | fc32174ab3902a5221767a3ce04e065209d9975c (diff) | |
download | pugl-a016618bde1f4e3fe87579ac430847b0b955058a.tar.gz pugl-a016618bde1f4e3fe87579ac430847b0b955058a.tar.bz2 pugl-a016618bde1f4e3fe87579ac430847b0b955058a.zip |
Embed Demo: Add timer to occasionally reverse spin direction
Diffstat (limited to 'examples/pugl_embed_demo.c')
-rw-r--r-- | examples/pugl_embed_demo.c | 12 |
1 files changed, 10 insertions, 2 deletions
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 <stdio.h> #include <string.h> -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; |