diff options
author | David Robillard <d@drobilla.net> | 2025-02-08 16:49:06 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2025-02-08 18:02:30 -0500 |
commit | 1395c97015ac9d5069881a038f4272a426fda9e9 (patch) | |
tree | 9049ba724b9866701f9fd0330038cb6965792663 /examples | |
parent | 23b0774862b79543b93a9b50b4f085c2c396698a (diff) | |
download | pugl-1395c97015ac9d5069881a038f4272a426fda9e9.tar.gz pugl-1395c97015ac9d5069881a038f4272a426fda9e9.tar.bz2 pugl-1395c97015ac9d5069881a038f4272a426fda9e9.zip |
Replace frame with size and position hints
Diffstat (limited to 'examples')
-rw-r--r-- | examples/pugl_cairo_demo.c | 6 | ||||
-rw-r--r-- | examples/pugl_cpp_demo.cpp | 3 | ||||
-rw-r--r-- | examples/pugl_cursor_demo.c | 6 | ||||
-rw-r--r-- | examples/pugl_embed_demo.c | 42 | ||||
-rw-r--r-- | examples/pugl_management_demo.c | 15 | ||||
-rw-r--r-- | examples/pugl_shader_demo.c | 12 | ||||
-rw-r--r-- | examples/pugl_window_demo.c | 26 |
7 files changed, 58 insertions, 52 deletions
diff --git a/examples/pugl_cairo_demo.c b/examples/pugl_cairo_demo.c index 4af0b37..71e13e2 100644 --- a/examples/pugl_cairo_demo.c +++ b/examples/pugl_cairo_demo.c @@ -50,9 +50,9 @@ static const Button buttons[] = {{128, 128, 64, 64, "1"}, static ViewScale getScale(const PuglView* const view) { - const PuglRect frame = puglGetFrame(view); - const ViewScale scale = {(frame.width - (512.0 / frame.width)) / 512.0, - (frame.height - (512.0 / frame.height)) / 512.0}; + const PuglArea size = puglGetSizeHint(view, PUGL_CURRENT_SIZE); + const ViewScale scale = {(size.width - (512.0 / size.width)) / 512.0, + (size.height - (512.0 / size.height)) / 512.0}; return scale; } diff --git a/examples/pugl_cpp_demo.cpp b/examples/pugl_cpp_demo.cpp index e6075ff..2d74213 100644 --- a/examples/pugl_cpp_demo.cpp +++ b/examples/pugl_cpp_demo.cpp @@ -58,8 +58,9 @@ CubeView::onEvent(const pugl::UpdateEvent&) noexcept // return obscure(); // But for testing, use sendEvent() instead: + const auto currentSize = this->size(pugl::SizeHint::currentSize); return sendEvent(pugl::ExposeEvent{ - 0U, PuglCoord{0}, PuglCoord{0}, frame().width, frame().height}); + 0U, PuglCoord{0}, PuglCoord{0}, currentSize.width, currentSize.height}); } pugl::Status diff --git a/examples/pugl_cursor_demo.c b/examples/pugl_cursor_demo.c index 0783b88..8a09a44 100644 --- a/examples/pugl_cursor_demo.c +++ b/examples/pugl_cursor_demo.c @@ -59,9 +59,9 @@ onExpose(void) static void onMotion(PuglView* view, double x, double y) { - const PuglRect frame = puglGetFrame(view); - int row = (int)(y * N_ROWS / frame.height); - int col = (int)(x * N_COLS / frame.width); + const PuglArea size = puglGetSizeHint(view, PUGL_CURRENT_SIZE); + int row = (int)(y * N_ROWS / size.height); + int col = (int)(x * N_COLS / size.width); row = (row < 0) ? 0 : (row >= N_ROWS) ? (N_ROWS - 1) : row; col = (col < 0) ? 0 : (col >= N_COLS) ? (N_COLS - 1) : col; diff --git a/examples/pugl_embed_demo.c b/examples/pugl_embed_demo.c index 9f0028a..4e5fc75 100644 --- a/examples/pugl_embed_demo.c +++ b/examples/pugl_embed_demo.c @@ -89,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); } } } @@ -122,17 +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); - puglSetSize(app->child, - parentFrame.width - (2 * borderWidth), - parentFrame.height - (2 * borderWidth)); + puglSetSizeHint(app->child, + PUGL_CURRENT_SIZE, + event->configure.width - (2U * borderWidth), + event->configure.height - (2U * borderWidth)); break; case PUGL_UPDATE: if (app->continuous) { @@ -251,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); @@ -279,10 +279,12 @@ main(int argc, char** argv) } puglSetParent(app.child, puglGetNativeView(app.parent)); - puglSetPosition(app.child, borderWidth, borderWidth); - puglSetSize(app.child, - parentFrame.width - (2 * borderWidth), - parentFrame.height - (2 * borderWidth)); + 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); diff --git a/examples/pugl_management_demo.c b/examples/pugl_management_demo.c index 6e42efa..61d7a51 100644 --- a/examples/pugl_management_demo.c +++ b/examples/pugl_management_demo.c @@ -37,12 +37,13 @@ onMainEvent(PuglView* view, const PuglEvent* event); static PuglStatus onExpose(PuglView* const view, const PuglExposeEvent* const event) { - PuglWorld* const world = puglGetWorld(view); - DemoApp* const app = (DemoApp*)puglGetWorldHandle(world); - const PuglRect frame = puglGetFrame(view); + PuglWorld* const world = puglGetWorld(view); + DemoApp* const app = (DemoApp*)puglGetWorldHandle(world); + const PuglPoint pos = puglGetPositionHint(view, PUGL_CURRENT_POSITION); + const PuglArea size = puglGetSizeHint(view, PUGL_CURRENT_SIZE); const PuglViewStyleFlags style = puglGetViewStyle(view); - const PuglCoord cx = (PuglCoord)(frame.width / 2U); - const PuglCoord cy = (PuglCoord)(frame.height / 2U); + const PuglCoord cx = (PuglCoord)(size.width / 2U); + const PuglCoord cy = (PuglCoord)(size.height / 2U); cairo_t* const cr = (cairo_t*)puglGetContext(view); // Clip to expose region @@ -61,14 +62,14 @@ onExpose(PuglView* const view, const PuglExposeEvent* const event) cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); // Draw position label - snprintf(buf, sizeof(buf), "Position: %5d, %5d", frame.x, frame.y); + snprintf(buf, sizeof(buf), "Position: %5d, %5d", pos.x, pos.y); cairo_text_extents(cr, buf, &extents); cairo_move_to( cr, cx - (extents.width / 2.0), cy + (extents.height / 2.0) - 192.0); cairo_show_text(cr, buf); // Draw size label - snprintf(buf, sizeof(buf), "Size: %5u, %5u", frame.width, frame.height); + snprintf(buf, sizeof(buf), "Size: %5u, %5u", size.width, size.height); cairo_text_extents(cr, buf, &extents); cairo_move_to( cr, cx - (extents.width / 2.0), cy + (extents.height / 2.0) - 144.0); diff --git a/examples/pugl_shader_demo.c b/examples/pugl_shader_demo.c index d89cd7d..7f2fe6c 100644 --- a/examples/pugl_shader_demo.c +++ b/examples/pugl_shader_demo.c @@ -91,15 +91,15 @@ static void onExpose(PuglView* view) { PuglTestApp* app = (PuglTestApp*)puglGetHandle(view); - const PuglRect frame = puglGetFrame(view); - const float width = (float)frame.width; - const float height = (float)frame.height; + const PuglArea size = puglGetSizeHint(view, PUGL_CURRENT_SIZE); + const float width = (float)size.width; + const float height = (float)size.height; const double time = puglGetTime(puglGetWorld(view)); // Construct projection matrix for 2D window surface (in pixels) mat4 proj; mat4Ortho( - proj, 0.0f, (float)frame.width, 0.0f, (float)frame.height, -1.0f, 1.0f); + proj, 0.0f, (float)size.width, 0.0f, (float)size.height, -1.0f, 1.0f); // Clear and bind everything that is the same for every rect glClear(GL_COLOR_BUFFER_BIT); @@ -109,7 +109,7 @@ onExpose(PuglView* view) // Update horizontal mouse cursor line (last rect) Rect* const mouseH = &app->rects[app->numRects]; mouseH->pos[0] = (float)(app->mouseX - 8.0); - mouseH->pos[1] = (float)(frame.height - app->mouseY - 1.0); + mouseH->pos[1] = (float)(size.height - app->mouseY - 1.0); mouseH->size[0] = 16.0f; mouseH->size[1] = 2.0f; mouseH->fillColor[0] = 1.0f; @@ -120,7 +120,7 @@ onExpose(PuglView* view) // Update vertical mouse cursor line (second last rect) Rect* const mouseV = &app->rects[app->numRects + 1]; mouseV->pos[0] = (float)(app->mouseX - 2.0); - mouseV->pos[1] = (float)(frame.height - app->mouseY - 8.0); + mouseV->pos[1] = (float)(size.height - app->mouseY - 8.0); mouseV->size[0] = 2.0f; mouseV->size[1] = 16.0f; mouseV->fillColor[0] = 1.0f; diff --git a/examples/pugl_window_demo.c b/examples/pugl_window_demo.c index 18755c3..6e87274 100644 --- a/examples/pugl_window_demo.c +++ b/examples/pugl_window_demo.c @@ -65,29 +65,30 @@ onKeyPress(PuglView* view, const PuglKeyEvent* event) { PuglWorld* world = puglGetWorld(view); PuglTestApp* app = (PuglTestApp*)puglGetWorldHandle(world); - PuglRect frame = puglGetFrame(view); 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); } } } @@ -187,9 +188,10 @@ main(int argc, char** argv) cube->dist = 10; puglSetViewString(view, PUGL_WINDOW_TITLE, "Pugl Window Demo"); - puglSetPosition(view, - (PuglCoord)(pad + ((128U + pad) * i)), - (PuglCoord)(pad + ((128U + pad) * i))); + puglSetPositionHint(view, + PUGL_DEFAULT_POSITION, + (PuglCoord)(pad + ((128U + pad) * i)), + (PuglCoord)(pad + ((128U + pad) * i))); puglSetSizeHint(view, PUGL_DEFAULT_SIZE, 512, 512); puglSetSizeHint(view, PUGL_MIN_SIZE, 128, 128); |