diff options
Diffstat (limited to 'examples/pugl_embed_demo.c')
-rw-r--r-- | examples/pugl_embed_demo.c | 77 |
1 files changed, 36 insertions, 41 deletions
diff --git a/examples/pugl_embed_demo.c b/examples/pugl_embed_demo.c index a66e032..70e00c2 100644 --- a/examples/pugl_embed_demo.c +++ b/examples/pugl_embed_demo.c @@ -3,10 +3,11 @@ #include "cube_view.h" #include "demo_utils.h" -#include "test/test_utils.h" -#include "pugl/gl.h" -#include "pugl/pugl.h" +#include <puglutil/test_utils.h> + +#include <pugl/gl.h> +#include <pugl/pugl.h> #include <math.h> #include <stdbool.h> @@ -50,18 +51,6 @@ static const float backgroundColorVertices[] = { // clang-format on -static PuglRect -getChildFrame(const PuglRect parentFrame) -{ - const PuglRect childFrame = { - borderWidth, - borderWidth, - (PuglSpan)(parentFrame.width - 2 * borderWidth), - (PuglSpan)(parentFrame.height - 2 * borderWidth)}; - - return childFrame; -} - static void onDisplay(PuglView* view) { @@ -72,8 +61,8 @@ onDisplay(PuglView* view) 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); + app->xAngle = fmod(app->xAngle + (dTime * 100.0), 360.0); + app->yAngle = fmod(app->yAngle + (dTime * 100.0), 360.0); } displayCube( @@ -92,40 +81,41 @@ swapFocus(PuglTestApp* app) } if (!app->continuous) { - puglPostRedisplay(app->parent); - puglPostRedisplay(app->child); + puglObscureView(app->parent); + puglObscureView(app->child); } } static void onKeyPress(PuglView* view, const PuglKeyEvent* event) { - PuglTestApp* app = (PuglTestApp*)puglGetHandle(view); - PuglRect frame = puglGetFrame(view); + PuglTestApp* app = (PuglTestApp*)puglGetHandle(view); if (event->key == '\t') { swapFocus(app); } else if (event->key == 'q' || event->key == PUGL_KEY_ESCAPE) { app->quit = 1; } else if (event->state & PUGL_MOD_SHIFT) { + const PuglArea size = puglGetSizeHint(view, PUGL_CURRENT_SIZE); if (event->key == PUGL_KEY_UP) { - puglSetSize(view, frame.width, frame.height - 10U); + puglSetSizeHint(view, PUGL_CURRENT_SIZE, size.width, size.height - 10U); } else if (event->key == PUGL_KEY_DOWN) { - puglSetSize(view, frame.width, frame.height + 10U); + puglSetSizeHint(view, PUGL_CURRENT_SIZE, size.width, size.height + 10U); } else if (event->key == PUGL_KEY_LEFT) { - puglSetSize(view, frame.width - 10U, frame.height); + puglSetSizeHint(view, PUGL_CURRENT_SIZE, size.width - 10U, size.height); } else if (event->key == PUGL_KEY_RIGHT) { - puglSetSize(view, frame.width + 10U, frame.height); + puglSetSizeHint(view, PUGL_CURRENT_SIZE, size.width + 10U, size.height); } } else { + const PuglPoint pos = puglGetPositionHint(view, PUGL_CURRENT_POSITION); if (event->key == PUGL_KEY_UP) { - puglSetPosition(view, frame.x, frame.y - 10); + puglSetPositionHint(view, PUGL_CURRENT_POSITION, pos.x, pos.y - 10); } else if (event->key == PUGL_KEY_DOWN) { - puglSetPosition(view, frame.x, frame.y + 10); + puglSetPositionHint(view, PUGL_CURRENT_POSITION, pos.x, pos.y + 10); } else if (event->key == PUGL_KEY_LEFT) { - puglSetPosition(view, frame.x - 10, frame.y); + puglSetPositionHint(view, PUGL_CURRENT_POSITION, pos.x - 10, pos.y); } else if (event->key == PUGL_KEY_RIGHT) { - puglSetPosition(view, frame.x + 10, frame.y); + puglSetPositionHint(view, PUGL_CURRENT_POSITION, pos.x + 10, pos.y); } } } @@ -133,20 +123,21 @@ onKeyPress(PuglView* view, const PuglKeyEvent* event) static PuglStatus onParentEvent(PuglView* view, const PuglEvent* event) { - PuglTestApp* app = (PuglTestApp*)puglGetHandle(view); - const PuglRect parentFrame = puglGetFrame(view); + PuglTestApp* const app = (PuglTestApp*)puglGetHandle(view); printEvent(event, "Parent: ", app->verbose); switch (event->type) { case PUGL_CONFIGURE: reshapeCube((float)event->configure.width, (float)event->configure.height); - - puglSetFrame(app->child, getChildFrame(parentFrame)); + puglSetSizeHint(app->child, + PUGL_CURRENT_SIZE, + event->configure.width - (2U * borderWidth), + event->configure.height - (2U * borderWidth)); break; case PUGL_UPDATE: if (app->continuous) { - puglPostRedisplay(view); + puglObscureView(view); } break; case PUGL_EXPOSE: @@ -195,7 +186,7 @@ onEvent(PuglView* view, const PuglEvent* event) break; case PUGL_UPDATE: if (app->continuous) { - puglPostRedisplay(view); + puglObscureView(view); } break; case PUGL_EXPOSE: @@ -213,14 +204,14 @@ onEvent(PuglView* view, const PuglEvent* event) app->lastMouseX = event->motion.x; app->lastMouseY = event->motion.y; if (!app->continuous) { - puglPostRedisplay(view); - puglPostRedisplay(app->parent); + puglObscureView(view); + puglObscureView(app->parent); } break; case PUGL_SCROLL: app->dist = fmaxf(10.0f, app->dist + (float)event->scroll.dy); if (!app->continuous) { - puglPostRedisplay(view); + puglObscureView(view); } break; case PUGL_POINTER_IN: @@ -261,7 +252,6 @@ main(int argc, char** argv) puglSetWorldString(app.world, PUGL_CLASS_NAME, "PuglEmbedDemo"); - const PuglRect parentFrame = {0, 0, 512, 512}; puglSetSizeHint(app.parent, PUGL_DEFAULT_SIZE, 512, 512); puglSetSizeHint(app.parent, PUGL_MIN_SIZE, 192, 192); puglSetSizeHint(app.parent, PUGL_MAX_SIZE, 1024, 1024); @@ -288,8 +278,13 @@ main(int argc, char** argv) return logError("Failed to create parent window (%s)\n", puglStrerror(st)); } - puglSetFrame(app.child, getChildFrame(parentFrame)); - puglSetParentWindow(app.child, puglGetNativeView(app.parent)); + puglSetParent(app.child, puglGetNativeView(app.parent)); + puglSetPositionHint( + app.child, PUGL_DEFAULT_POSITION, borderWidth, borderWidth); + puglSetSizeHint(app.child, + PUGL_DEFAULT_SIZE, + 512U - (2U * borderWidth), + 512U - (2U * borderWidth)); puglSetViewHint(app.child, PUGL_CONTEXT_DEBUG, opts.errorChecking); puglSetViewHint(app.child, PUGL_SAMPLES, opts.samples); |