aboutsummaryrefslogtreecommitdiffstats
path: root/examples/pugl_management_demo.c
diff options
context:
space:
mode:
Diffstat (limited to 'examples/pugl_management_demo.c')
-rw-r--r--examples/pugl_management_demo.c55
1 files changed, 37 insertions, 18 deletions
diff --git a/examples/pugl_management_demo.c b/examples/pugl_management_demo.c
index 50109a4..c9b3f4a 100644
--- a/examples/pugl_management_demo.c
+++ b/examples/pugl_management_demo.c
@@ -1,14 +1,12 @@
// Copyright 2012-2023 David Robillard <d@drobilla.net>
// SPDX-License-Identifier: ISC
-/*
- A demonstration of window types, states, and management.
-*/
+// A demonstration of window types, states, and management
-#include "test/test_utils.h"
+#include <puglutil/test_utils.h>
-#include "pugl/cairo.h"
-#include "pugl/pugl.h"
+#include <pugl/cairo.h>
+#include <pugl/pugl.h>
#include <cairo.h>
@@ -37,12 +35,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
@@ -58,12 +57,34 @@ onExpose(PuglView* const view, const PuglExposeEvent* const event)
char buf[128] = {0};
cairo_text_extents_t extents = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
cairo_set_font_size(cr, 30.0);
+ cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
+
+ // Draw position label
+ 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", 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);
+ cairo_show_text(cr, buf);
+
+ // Draw scale label
+ snprintf(buf, sizeof(buf), "Scale: %g", puglGetScaleFactor(view));
+ cairo_text_extents(cr, buf, &extents);
+ cairo_move_to(
+ cr, cx - (extents.width / 2.0), cy + (extents.height / 2.0) - 96.0);
+ cairo_show_text(cr, buf);
// Draw time label
snprintf(buf, sizeof(buf), "Draw time: %g", puglGetTime(world));
cairo_text_extents(cr, buf, &extents);
- cairo_move_to(cr, cx - extents.width / 2.0, cy + extents.height / 2.0 - 48.0);
- cairo_set_source_rgb(cr, 0.9, 0.9, 0.9);
+ cairo_move_to(
+ cr, cx - (extents.width / 2.0), cy + (extents.height / 2.0) - 48.0);
cairo_show_text(cr, buf);
// Draw style label
@@ -80,8 +101,7 @@ onExpose(PuglView* const view, const PuglExposeEvent* const event)
style & PUGL_VIEW_STYLE_DEMANDING ? " demanding" : "",
style & PUGL_VIEW_STYLE_RESIZING ? " resizing" : "");
cairo_text_extents(cr, buf, &extents);
- cairo_move_to(cr, cx - extents.width / 2.0, cy + extents.height / 2.0);
- cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
+ cairo_move_to(cr, cx - (extents.width / 2.0), cy + (extents.height / 2.0));
cairo_show_text(cr, buf);
if (view == app->mainView.view) {
@@ -89,8 +109,7 @@ onExpose(PuglView* const view, const PuglExposeEvent* const event)
snprintf(buf, sizeof(buf), "Keys: Space T W H M F A B D Q");
cairo_text_extents(cr, buf, &extents);
cairo_move_to(
- cr, cx - extents.width / 2.0, cy + extents.height / 2.0 + 48.0);
- cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
+ cr, cx - (extents.width / 2.0), cy + (extents.height / 2.0) + 48.0);
cairo_show_text(cr, buf);
}
@@ -185,7 +204,7 @@ onCommonEvent(PuglView* view, const PuglEvent* const event)
}
break;
case PUGL_CONFIGURE:
- return puglPostRedisplay(view);
+ return puglObscureView(view);
case PUGL_EXPOSE:
return onExpose(view, &event->expose);
case PUGL_KEY_PRESS: