aboutsummaryrefslogtreecommitdiffstats
path: root/examples/pugl_embed_demo.c
diff options
context:
space:
mode:
Diffstat (limited to 'examples/pugl_embed_demo.c')
-rw-r--r--examples/pugl_embed_demo.c61
1 files changed, 28 insertions, 33 deletions
diff --git a/examples/pugl_embed_demo.c b/examples/pugl_embed_demo.c
index c14afde..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(
@@ -100,32 +89,33 @@ swapFocus(PuglTestApp* app)
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,16 +123,17 @@ 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) {
@@ -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));
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);