aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/.clang-tidy11
-rw-r--r--examples/cube_view.h6
-rw-r--r--examples/demo_utils.h11
-rw-r--r--examples/glad/.clang-format6
-rw-r--r--examples/meson.build40
-rw-r--r--examples/pugl_cairo_demo.app/MacOS/meson.build4
-rw-r--r--examples/pugl_cairo_demo.c66
-rw-r--r--examples/pugl_clipboard_demo.app/MacOS/meson.build4
-rw-r--r--examples/pugl_clipboard_demo.c15
-rw-r--r--examples/pugl_cpp_demo.app/MacOS/meson.build4
-rw-r--r--examples/pugl_cpp_demo.cpp16
-rw-r--r--examples/pugl_cursor_demo.app/MacOS/meson.build4
-rw-r--r--examples/pugl_cursor_demo.c18
-rw-r--r--examples/pugl_embed_demo.app/MacOS/meson.build4
-rw-r--r--examples/pugl_embed_demo.c77
-rw-r--r--examples/pugl_management_demo.app/MacOS/meson.build4
-rw-r--r--examples/pugl_management_demo.c55
-rw-r--r--examples/pugl_print_events.c6
-rw-r--r--examples/pugl_shader_demo.app/MacOS/meson.build4
-rw-r--r--examples/pugl_shader_demo.c49
-rw-r--r--examples/pugl_vulkan_cpp_demo.app/MacOS/meson.build4
-rw-r--r--examples/pugl_vulkan_cpp_demo.cpp32
-rw-r--r--examples/pugl_vulkan_demo.app/MacOS/meson.build4
-rw-r--r--examples/pugl_vulkan_demo.c35
-rw-r--r--examples/pugl_window_demo.app/MacOS/meson.build4
-rw-r--r--examples/pugl_window_demo.c41
-rw-r--r--examples/sybok.hpp8
27 files changed, 293 insertions, 239 deletions
diff --git a/examples/.clang-tidy b/examples/.clang-tidy
index 7dde8bb..bc26cde 100644
--- a/examples/.clang-tidy
+++ b/examples/.clang-tidy
@@ -1,4 +1,4 @@
-# Copyright 2020-2023 David Robillard <d@drobilla.net>
+# Copyright 2020-2025 David Robillard <d@drobilla.net>
# SPDX-License-Identifier: 0BSD OR ISC
Checks: >
@@ -6,11 +6,14 @@ Checks: >
-*-non-private-member-variables-in-classes,
-*avoid-c-arrays,
-android-cloexec-fopen,
+ -boost-*,
-bugprone-easily-swappable-parameters,
-bugprone-macro-parentheses,
+ -bugprone-multi-level-implicit-pointer-conversion,
-bugprone-reserved-identifier,
-bugprone-suspicious-string-compare,
-cert-dcl37-c,
+ -cert-dcl50-cpp,
-cert-dcl51-cpp,
-cert-err33-c,
-cert-err34-c,
@@ -26,6 +29,7 @@ Checks: >
-fuchsia-default-arguments,
-fuchsia-default-arguments-calls,
-fuchsia-overloaded-operator,
+ -google-readability-casting,
-google-runtime-references,
-hicpp-multiway-paths-covered,
-hicpp-no-array-decay,
@@ -33,10 +37,15 @@ Checks: >
-hicpp-vararg,
-llvm-header-guard,
-misc-misplaced-const,
+ -modernize-redundant-void-arg,
-modernize-use-trailing-return-type,
+ -modernize-use-using,
+ -performance-enum-size,
+ -performance-enum-size,
-performance-no-int-to-ptr,
-readability-function-cognitive-complexity,
-readability-implicit-bool-conversion,
+ -readability-redundant-member-init,
CheckOptions:
- key: cppcoreguidelines-avoid-do-while.IgnoreMacros
value: true
diff --git a/examples/cube_view.h b/examples/cube_view.h
index 399f625..a02154f 100644
--- a/examples/cube_view.h
+++ b/examples/cube_view.h
@@ -4,12 +4,12 @@
#ifndef EXAMPLES_CUBE_VIEW_H
#define EXAMPLES_CUBE_VIEW_H
-#define GL_SILENCE_DEPRECATION 1 // NOLINT(modernize-macro-to-enum)
+#define GL_SILENCE_DEPRECATION 1 // NOLINT(*-macro-to-enum)
#include "demo_utils.h"
-#include "pugl/gl.h"
-#include "pugl/pugl.h"
+#include <pugl/gl.h>
+#include <pugl/pugl.h>
#include <stdbool.h>
diff --git a/examples/demo_utils.h b/examples/demo_utils.h
index b43cc2b..db66b21 100644
--- a/examples/demo_utils.h
+++ b/examples/demo_utils.h
@@ -4,7 +4,7 @@
#ifndef EXAMPLES_DEMO_UTILS_H
#define EXAMPLES_DEMO_UTILS_H
-#include "pugl/pugl.h"
+#include <pugl/pugl.h>
#include <math.h>
#include <stdio.h>
@@ -95,13 +95,14 @@ puglPrintFps(const PuglWorld* world,
unsigned* const framesDrawn)
{
const double thisTime = puglGetTime(world);
- if (thisTime > printer->lastReportTime + 5) {
- const double fps = *framesDrawn / (thisTime - printer->lastReportTime);
+ if (thisTime > printer->lastReportTime + 5.0) {
+ const double elapsed = (thisTime - printer->lastReportTime);
+ const double fps = *framesDrawn / elapsed;
fprintf(stderr,
- "FPS: %.2f (%u frames in %.0f seconds)\n",
+ "FPS: %.2f (%u frames / %.2f seconds)\n",
fps,
*framesDrawn,
- thisTime - printer->lastReportTime);
+ elapsed);
printer->lastReportTime = thisTime;
*framesDrawn = 0;
diff --git a/examples/glad/.clang-format b/examples/glad/.clang-format
new file mode 100644
index 0000000..f219d75
--- /dev/null
+++ b/examples/glad/.clang-format
@@ -0,0 +1,6 @@
+# Copyright 2025 David Robillard <d@drobilla.net>
+# SPDX-License-Identifier: 0BSD OR ISC
+
+---
+DisableFormat: true
+...
diff --git a/examples/meson.build b/examples/meson.build
index aa04e80..65daa31 100644
--- a/examples/meson.build
+++ b/examples/meson.build
@@ -1,4 +1,4 @@
-# Copyright 2021-2023 David Robillard <d@drobilla.net>
+# Copyright 2021-2025 David Robillard <d@drobilla.net>
# SPDX-License-Identifier: 0BSD OR ISC
data_dir = get_option('prefix') / get_option('datadir') / 'pugl-0'
@@ -27,12 +27,6 @@ vulkan_examples = [
'pugl_vulkan_demo.c',
]
-includes = include_directories(
- '..',
- '../bindings/cpp/include',
- '../include',
-)
-
# Suppress some additional C warnings in examples
example_c_args = []
if get_option('warning_level') == 'everything'
@@ -61,6 +55,13 @@ if get_option('warning_level') == 'everything' and is_variable('cpp')
'-Wno-old-style-cast',
'-Wno-switch-enum',
]
+ if host_machine.system() == 'windows'
+ example_cpp_args += [
+ '-Wno-deprecated-declarations',
+ '-Wno-format-nonliteral',
+ '-Wno-nonportable-system-include-path',
+ ]
+ endif
elif cpp.get_id() == 'gcc'
example_cpp_args += [
'-Wno-effc++',
@@ -113,7 +114,7 @@ else
foreach example : stub_examples
source = [example]
target = example.split('.')[0]
- dependencies = [pugl_dep, pugl_stub_dep]
+ dependencies = [pugl_dep, pugl_stub_dep, puglutil_dep]
defines = []
executable(
@@ -122,7 +123,7 @@ else
c_args: example_defines + example_c_args + defines,
cpp_args: example_defines + example_cpp_args + defines,
dependencies: dependencies,
- include_directories: includes,
+ implicit_include_directories: false,
)
endforeach
@@ -131,7 +132,7 @@ else
foreach example : gl_examples
source = [example]
target = example.split('.')[0]
- dependencies = [pugl_dep, pugl_gl_dep]
+ dependencies = [pugl_dep, pugl_gl_dep, puglutil_dep]
defines = []
if target == 'pugl_shader_demo'
@@ -141,6 +142,10 @@ else
elif target == 'pugl_print_events'
dependencies += [pugl_stub_dep]
elif target == 'pugl_cpp_demo'
+ if not is_variable('puglpp_dep')
+ continue
+ endif
+
dependencies += [puglpp_dep]
endif
@@ -150,7 +155,7 @@ else
c_args: example_defines + example_c_args + defines,
cpp_args: example_defines + example_cpp_args + defines,
dependencies: dependencies,
- include_directories: includes,
+ implicit_include_directories: false,
)
endforeach
endif
@@ -163,8 +168,8 @@ else
target,
example,
c_args: example_defines + example_c_args + cairo_args,
- dependencies: [pugl_dep, pugl_cairo_dep],
- include_directories: includes,
+ dependencies: [pugl_dep, pugl_cairo_dep, puglutil_dep],
+ implicit_include_directories: false,
)
endforeach
endif
@@ -174,12 +179,17 @@ else
foreach example : vulkan_examples
source = [example]
target = example.split('.')[0]
- dependencies = [dl_dep, pugl_vulkan_dep]
+ dependencies = [dl_dep, pugl_vulkan_dep, puglutil_dep]
defines = []
if target == 'pugl_vulkan_cpp_demo'
+ if not is_variable('puglpp_dep')
+ continue
+ endif
+
source += ['file_utils.c']
defines += ['-D_POSIX_C_SOURCE=200809L']
+ dependencies += [puglpp_dep]
endif
executable(
@@ -188,7 +198,7 @@ else
c_args: example_defines + example_c_args + defines,
cpp_args: example_defines + example_cpp_args + defines,
dependencies: dependencies,
- include_directories: includes,
+ implicit_include_directories: false,
)
endforeach
endif
diff --git a/examples/pugl_cairo_demo.app/MacOS/meson.build b/examples/pugl_cairo_demo.app/MacOS/meson.build
index 18e1fcf..e8a5242 100644
--- a/examples/pugl_cairo_demo.app/MacOS/meson.build
+++ b/examples/pugl_cairo_demo.app/MacOS/meson.build
@@ -6,6 +6,6 @@ executable(
['../../pugl_cairo_demo.c'],
c_args: example_defines + example_c_args + cairo_args,
cpp_args: example_defines + example_cpp_args,
- dependencies: [pugl_dep, pugl_cairo_dep],
- include_directories: include_directories('../../..'),
+ dependencies: [pugl_dep, pugl_cairo_dep, puglutil_dep],
+ implicit_include_directories: false,
)
diff --git a/examples/pugl_cairo_demo.c b/examples/pugl_cairo_demo.c
index 6608bab..109149d 100644
--- a/examples/pugl_cairo_demo.c
+++ b/examples/pugl_cairo_demo.c
@@ -2,10 +2,11 @@
// SPDX-License-Identifier: ISC
#include "demo_utils.h"
-#include "test/test_utils.h"
-#include "pugl/cairo.h"
-#include "pugl/pugl.h"
+#include <puglutil/test_utils.h>
+
+#include <pugl/cairo.h>
+#include <pugl/pugl.h>
#include <cairo.h>
@@ -49,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;
}
@@ -100,8 +101,8 @@ buttonDraw(PuglTestApp* app, cairo_t* cr, const Button* but, const double time)
cairo_set_font_size(cr, 32.0);
cairo_text_extents(cr, but->label, &extents);
cairo_move_to(cr,
- (but->w / 2.0) - extents.width / 2,
- (but->h / 2.0) + extents.height / 2);
+ (but->w / 2.0) - (extents.width / 2),
+ (but->h / 2.0) + (extents.height / 2));
cairo_set_source_rgba(cr, 0, 0, 0, 1);
cairo_show_text(cr, but->label);
@@ -114,13 +115,12 @@ postButtonRedisplay(PuglView* view)
const ViewScale scale = getScale(view);
for (const Button* b = buttons; b->label; ++b) {
- const double span = sqrt(b->w * b->w + b->h * b->h);
- const PuglRect rect = {(PuglCoord)((b->x - span) * scale.x),
- (PuglCoord)((b->y - span) * scale.y),
- (PuglSpan)ceil(span * 2.0 * scale.x),
- (PuglSpan)ceil(span * 2.0 * scale.y)};
-
- puglPostRedisplayRect(view, rect);
+ const double span = sqrt((b->w * b->w) + (b->h * b->h));
+ puglObscureRegion(view,
+ (int)((b->x - span) * scale.x),
+ (int)((b->y - span) * scale.y),
+ (unsigned)ceil(span * 2.0 * scale.x),
+ (unsigned)ceil(span * 2.0 * scale.y));
}
}
@@ -172,18 +172,17 @@ onClose(PuglView* view)
app->quit = 1;
}
-static PuglRect
-mouseCursorViewBounds(const PuglView* const view,
- const double mouseX,
- const double mouseY)
+static PuglStatus
+obscureMouseCursor(PuglView* const view,
+ const ViewScale scale,
+ const double mouseX,
+ const double mouseY)
{
- const ViewScale scale = getScale(view);
- const PuglRect rect = {(PuglCoord)floor(mouseX - (10.0 * scale.x)),
- (PuglCoord)floor(mouseY - (10.0 * scale.y)),
- (PuglSpan)ceil(20.0 * scale.x),
- (PuglSpan)ceil(20.0 * scale.y)};
-
- return rect;
+ return puglObscureRegion(view,
+ (int)floor(mouseX - (10.0 * scale.x)),
+ (int)floor(mouseY - (10.0 * scale.y)),
+ (unsigned)ceil(20.0 * scale.x),
+ (unsigned)ceil(20.0 * scale.y));
}
static PuglStatus
@@ -193,6 +192,7 @@ onEvent(PuglView* view, const PuglEvent* event)
printEvent(event, "Event: ", app->opts.verbose);
+ const ViewScale scale = getScale(view);
switch (event->type) {
case PUGL_KEY_PRESS:
if (event->key.key == 'q' || event->key.key == PUGL_KEY_ESCAPE) {
@@ -209,31 +209,27 @@ onEvent(PuglView* view, const PuglEvent* event)
break;
case PUGL_MOTION:
// Redisplay to clear the old cursor position
- puglPostRedisplayRect(
- view,
- mouseCursorViewBounds(view, app->lastDrawnMouseX, app->lastDrawnMouseY));
+ obscureMouseCursor(view, scale, app->lastDrawnMouseX, app->lastDrawnMouseY);
// Redisplay to show the new cursor position
app->currentMouseX = event->motion.x;
app->currentMouseY = event->motion.y;
- puglPostRedisplayRect(
- view,
- mouseCursorViewBounds(view, app->currentMouseX, app->currentMouseY));
+ obscureMouseCursor(view, scale, app->currentMouseX, app->currentMouseY);
app->lastDrawnMouseX = app->currentMouseX;
app->lastDrawnMouseY = app->currentMouseY;
break;
case PUGL_POINTER_IN:
app->entered = true;
- puglPostRedisplay(view);
+ puglObscureView(view);
break;
case PUGL_POINTER_OUT:
app->entered = false;
- puglPostRedisplay(view);
+ puglObscureView(view);
break;
case PUGL_UPDATE:
if (app->opts.continuous) {
- puglPostRedisplay(view);
+ puglObscureView(view);
}
break;
case PUGL_EXPOSE:
diff --git a/examples/pugl_clipboard_demo.app/MacOS/meson.build b/examples/pugl_clipboard_demo.app/MacOS/meson.build
index 31ad2f0..f56ae59 100644
--- a/examples/pugl_clipboard_demo.app/MacOS/meson.build
+++ b/examples/pugl_clipboard_demo.app/MacOS/meson.build
@@ -5,6 +5,6 @@ executable(
'pugl_clipboard_demo',
'../../pugl_clipboard_demo.c',
c_args: example_defines + example_c_args,
- dependencies: [pugl_dep, pugl_gl_dep],
- include_directories: include_directories('../../..'),
+ dependencies: [pugl_dep, pugl_gl_dep, puglutil_dep],
+ implicit_include_directories: false,
)
diff --git a/examples/pugl_clipboard_demo.c b/examples/pugl_clipboard_demo.c
index efeb1eb..04929ab 100644
--- a/examples/pugl_clipboard_demo.c
+++ b/examples/pugl_clipboard_demo.c
@@ -4,10 +4,11 @@
// A demonstration of using clipboards for copy/paste and drag and drop
#include "cube_view.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>
@@ -44,8 +45,8 @@ onDisplay(PuglView* view)
if (app->continuous) {
const double dTime = thisTime - cube->lastDrawTime;
- cube->xAngle = fmod(cube->xAngle + dTime * 100.0, 360.0);
- cube->yAngle = fmod(cube->yAngle + dTime * 100.0, 360.0);
+ cube->xAngle = fmod(cube->xAngle + (dTime * 100.0), 360.0);
+ cube->yAngle = fmod(cube->yAngle + (dTime * 100.0), 360.0);
}
displayCube(
@@ -116,7 +117,7 @@ static void
redisplayView(PuglTestApp* app, PuglView* view)
{
if (!app->continuous) {
- puglPostRedisplay(view);
+ puglObscureView(view);
}
}
@@ -135,7 +136,7 @@ onEvent(PuglView* view, const PuglEvent* event)
break;
case PUGL_UPDATE:
if (app->continuous) {
- puglPostRedisplay(view);
+ puglObscureView(view);
}
break;
case PUGL_EXPOSE:
diff --git a/examples/pugl_cpp_demo.app/MacOS/meson.build b/examples/pugl_cpp_demo.app/MacOS/meson.build
index f5ddd67..891dcd9 100644
--- a/examples/pugl_cpp_demo.app/MacOS/meson.build
+++ b/examples/pugl_cpp_demo.app/MacOS/meson.build
@@ -6,6 +6,6 @@ executable(
'../../pugl_cpp_demo.cpp',
c_args: example_defines + example_c_args,
cpp_args: example_defines + example_cpp_args,
- dependencies: [puglpp_dep, pugl_gl_dep],
- include_directories: include_directories('../../..'),
+ dependencies: [puglpp_dep, pugl_gl_dep, puglutil_dep],
+ implicit_include_directories: false,
)
diff --git a/examples/pugl_cpp_demo.cpp b/examples/pugl_cpp_demo.cpp
index 2b3c0a1..9ba5723 100644
--- a/examples/pugl_cpp_demo.cpp
+++ b/examples/pugl_cpp_demo.cpp
@@ -3,11 +3,12 @@
#include "cube_view.h"
#include "demo_utils.h"
-#include "test/test_utils.h"
-#include "pugl/gl.hpp"
-#include "pugl/pugl.h"
-#include "pugl/pugl.hpp"
+#include <puglutil/test_utils.h>
+
+#include <pugl/gl.hpp>
+#include <pugl/pugl.h>
+#include <pugl/pugl.hpp>
#include <cmath>
@@ -53,12 +54,13 @@ CubeView::onEvent(const pugl::ConfigureEvent& event) noexcept
pugl::Status
CubeView::onEvent(const pugl::UpdateEvent&) noexcept
{
- // Normally, we would post a redisplay:
- // return postRedisplay();
+ // Normally, we would obscure the view
+ // 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.app/MacOS/meson.build b/examples/pugl_cursor_demo.app/MacOS/meson.build
index 94359cd..0836875 100644
--- a/examples/pugl_cursor_demo.app/MacOS/meson.build
+++ b/examples/pugl_cursor_demo.app/MacOS/meson.build
@@ -6,6 +6,6 @@ executable(
'../../pugl_cursor_demo.c',
c_args: example_defines + example_c_args,
cpp_args: example_defines + example_cpp_args,
- dependencies: [pugl_dep, pugl_gl_dep],
- include_directories: include_directories('../../..'),
+ dependencies: [pugl_dep, pugl_gl_dep, puglutil_dep],
+ implicit_include_directories: false,
)
diff --git a/examples/pugl_cursor_demo.c b/examples/pugl_cursor_demo.c
index ba9c54f..6ddd5ad 100644
--- a/examples/pugl_cursor_demo.c
+++ b/examples/pugl_cursor_demo.c
@@ -1,10 +1,10 @@
// Copyright 2012-2020 David Robillard <d@drobilla.net>
// SPDX-License-Identifier: ISC
-#include "test/test_utils.h"
+#include <puglutil/test_utils.h>
-#include "pugl/gl.h"
-#include "pugl/pugl.h"
+#include <pugl/gl.h>
+#include <pugl/pugl.h>
#include <stdbool.h>
@@ -19,7 +19,7 @@ typedef struct {
} PuglTestApp;
static void
-onConfigure(const double width, const double height)
+onConfigure(const PuglSpan width, const PuglSpan height)
{
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
@@ -40,7 +40,7 @@ onExpose(void)
glColor3f(0.6f, 0.6f, 0.6f);
for (int row = 1; row < N_ROWS; ++row) {
- const float y = (float)row * (2.0f / (float)N_ROWS) - 1.0f;
+ const float y = ((float)row * (2.0f / (float)N_ROWS)) - 1.0f;
glBegin(GL_LINES);
glVertex2f(-1.0f, y);
glVertex2f(1.0f, y);
@@ -48,7 +48,7 @@ onExpose(void)
}
for (int col = 1; col < N_COLS; ++col) {
- const float x = (float)col * (2.0f / (float)N_COLS) - 1.0f;
+ const float x = ((float)col * (2.0f / (float)N_COLS)) - 1.0f;
glBegin(GL_LINES);
glVertex2f(x, -1.0f);
glVertex2f(x, 1.0f);
@@ -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.app/MacOS/meson.build b/examples/pugl_embed_demo.app/MacOS/meson.build
index 9e6dd58..34d4ccb 100644
--- a/examples/pugl_embed_demo.app/MacOS/meson.build
+++ b/examples/pugl_embed_demo.app/MacOS/meson.build
@@ -6,6 +6,6 @@ executable(
'../../pugl_embed_demo.c',
c_args: example_defines + example_c_args,
cpp_args: example_defines + example_cpp_args,
- dependencies: [pugl_dep, pugl_gl_dep],
- include_directories: include_directories('../../..'),
+ dependencies: [pugl_dep, pugl_gl_dep, puglutil_dep],
+ implicit_include_directories: false,
)
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);
diff --git a/examples/pugl_management_demo.app/MacOS/meson.build b/examples/pugl_management_demo.app/MacOS/meson.build
index 69dafc7..308a88c 100644
--- a/examples/pugl_management_demo.app/MacOS/meson.build
+++ b/examples/pugl_management_demo.app/MacOS/meson.build
@@ -6,6 +6,6 @@ executable(
['../../pugl_management_demo.c'],
c_args: example_defines + example_c_args + cairo_args,
cpp_args: example_defines + example_cpp_args,
- dependencies: [pugl_dep, pugl_cairo_dep],
- include_directories: include_directories('../../..'),
+ dependencies: [pugl_dep, pugl_cairo_dep, puglutil_dep],
+ implicit_include_directories: false,
)
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:
diff --git a/examples/pugl_print_events.c b/examples/pugl_print_events.c
index 96a8889..9445e50 100644
--- a/examples/pugl_print_events.c
+++ b/examples/pugl_print_events.c
@@ -1,10 +1,10 @@
// Copyright 2012-2020 David Robillard <d@drobilla.net>
// SPDX-License-Identifier: ISC
-#include "test/test_utils.h"
+#include <puglutil/test_utils.h>
-#include "pugl/pugl.h"
-#include "pugl/stub.h"
+#include <pugl/pugl.h>
+#include <pugl/stub.h>
#include <stdbool.h>
#include <stdio.h>
diff --git a/examples/pugl_shader_demo.app/MacOS/meson.build b/examples/pugl_shader_demo.app/MacOS/meson.build
index d3d0755..afcd532 100644
--- a/examples/pugl_shader_demo.app/MacOS/meson.build
+++ b/examples/pugl_shader_demo.app/MacOS/meson.build
@@ -10,6 +10,6 @@ executable(
],
c_args: example_defines + example_c_args,
cpp_args: example_defines + example_cpp_args,
- dependencies: [pugl_dep, pugl_gl_dep, dl_dep],
- include_directories: include_directories('../../..'),
+ dependencies: [pugl_dep, pugl_gl_dep, dl_dep, puglutil_dep],
+ implicit_include_directories: false,
)
diff --git a/examples/pugl_shader_demo.c b/examples/pugl_shader_demo.c
index 9ba3da0..5bef21e 100644
--- a/examples/pugl_shader_demo.c
+++ b/examples/pugl_shader_demo.c
@@ -21,16 +21,19 @@
about 100000 rectangles.
*/
+#define PUGL_NO_INCLUDE_GL_H
+
#include "demo_utils.h"
#include "file_utils.h"
#include "rects.h"
#include "shader_utils.h"
-#include "test/test_utils.h"
#include "glad/glad.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 <stddef.h>
@@ -75,7 +78,7 @@ static void
teardownGl(PuglTestApp* app);
static void
-onConfigure(PuglView* view, double width, double height)
+onConfigure(PuglView* view, PuglSpan width, PuglSpan height)
{
(void)view;
@@ -90,15 +93,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);
@@ -108,7 +111,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;
@@ -119,7 +122,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;
@@ -168,7 +171,7 @@ onEvent(PuglView* view, const PuglEvent* event)
onConfigure(view, event->configure.width, event->configure.height);
break;
case PUGL_UPDATE:
- puglPostRedisplay(view);
+ puglObscureView(view);
break;
case PUGL_EXPOSE:
onExpose(view);
@@ -195,7 +198,7 @@ onEvent(PuglView* view, const PuglEvent* event)
break;
case PUGL_TIMER:
if (event->timer.id == resizeTimerId) {
- puglPostRedisplay(view);
+ puglObscureView(view);
}
break;
default:
@@ -230,10 +233,15 @@ loadShader(const char* const programPath, const char* const name)
free(path);
fseek(file, 0, SEEK_END);
- const size_t fileSize = (size_t)ftell(file);
+ const long filePos = ftell(file);
+ if (filePos <= 0) {
+ fclose(file);
+ return NULL;
+ }
fseek(file, 0, SEEK_SET);
- char* source = (char*)calloc(1, fileSize + 1U);
+ const size_t fileSize = (size_t)filePos;
+ char* source = (char*)calloc(1, fileSize + 1U);
if (fread(source, 1, fileSize, file) != fileSize) {
free(source);
@@ -351,17 +359,16 @@ setupGl(PuglTestApp* app)
char* const fragmentSource =
loadShader(app->programPath, SHADER_DIR "rect.frag");
- if (!vertexSource || !fragmentSource) {
- logError("Failed to load shader sources\n");
- return PUGL_FAILURE;
+ // Compile rectangle shaders and program
+ if (headerSource && vertexSource && fragmentSource) {
+ app->drawRect = compileProgram(headerSource, vertexSource, fragmentSource);
}
- // Compile rectangle shaders and program
- app->drawRect = compileProgram(headerSource, vertexSource, fragmentSource);
free(fragmentSource);
free(vertexSource);
free(headerSource);
if (!app->drawRect.program) {
+ logError("Failed to compile shader program\n");
return PUGL_FAILURE;
}
@@ -470,7 +477,7 @@ updateTimeout(const PuglTestApp* const app)
const double nextExposeTime = nextFrameEndTime - neededTime;
const double timeUntilNext = nextExposeTime - now;
- return timeUntilNext;
+ return fmax(0.0, (timeUntilNext * 0.9) - 0.001);
}
int
@@ -505,7 +512,7 @@ main(int argc, char** argv)
const double startTime = puglGetTime(app.world);
PuglFpsPrinter fpsPrinter = {startTime};
while (!app.quit) {
- puglUpdate(app.world, fmax(0.0, updateTimeout(&app)));
+ puglUpdate(app.world, updateTimeout(&app));
puglPrintFps(app.world, &fpsPrinter, &app.framesDrawn);
}
diff --git a/examples/pugl_vulkan_cpp_demo.app/MacOS/meson.build b/examples/pugl_vulkan_cpp_demo.app/MacOS/meson.build
index d75c75d..7e7556b 100644
--- a/examples/pugl_vulkan_cpp_demo.app/MacOS/meson.build
+++ b/examples/pugl_vulkan_cpp_demo.app/MacOS/meson.build
@@ -9,6 +9,6 @@ executable(
],
c_args: example_defines + example_c_args,
cpp_args: example_defines + example_cpp_args,
- dependencies: [puglpp_dep, pugl_vulkan_dep],
- include_directories: include_directories('../../..'),
+ dependencies: [puglpp_dep, pugl_vulkan_dep, puglutil_dep],
+ implicit_include_directories: false,
)
diff --git a/examples/pugl_vulkan_cpp_demo.cpp b/examples/pugl_vulkan_cpp_demo.cpp
index 5e30b88..4a73157 100644
--- a/examples/pugl_vulkan_cpp_demo.cpp
+++ b/examples/pugl_vulkan_cpp_demo.cpp
@@ -17,13 +17,14 @@
#include "demo_utils.h"
#include "file_utils.h"
#include "rects.h"
-#include "test/test_utils.h"
#include "sybok.hpp"
-#include "pugl/pugl.h"
-#include "pugl/pugl.hpp"
-#include "pugl/vulkan.hpp"
+#include <puglutil/test_utils.h>
+
+#include <pugl/pugl.h>
+#include <pugl/pugl.hpp>
+#include <pugl/vulkan.hpp>
#include <vulkan/vk_platform.h>
@@ -559,7 +560,7 @@ Swapchain::init(const sk::VulkanApi& vk,
const auto minNumImages =
(!capabilities.maxImageCount || capabilities.maxImageCount >= 3U)
- ? 3U
+ ? std::max(capabilities.minImageCount, 3U)
: capabilities.maxImageCount;
const VkSwapchainCreateInfoKHR swapchainCreateInfo{
@@ -576,7 +577,7 @@ Swapchain::init(const sk::VulkanApi& vk,
VK_SHARING_MODE_EXCLUSIVE,
SK_COUNTED(0, nullptr),
capabilities.currentTransform,
- VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR,
+ VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR,
mode == RenderMode::resizing ? gpu.resizePresentMode : gpu.presentMode,
VK_TRUE,
oldSwapchain};
@@ -715,7 +716,12 @@ readFile(const char* const programPath, const std::string& filename)
}
fseek(file.get(), 0, SEEK_END);
- const auto fileSize = static_cast<size_t>(ftell(file.get()));
+ const auto filePos = ftell(file.get());
+ if (filePos <= 0) {
+ return {};
+ }
+
+ const auto fileSize = static_cast<size_t>(filePos);
fseek(file.get(), 0, SEEK_SET);
const auto numWords = fileSize / sizeof(uint32_t);
@@ -1512,11 +1518,9 @@ pugl::Status
View::onEvent(const pugl::ConfigureEvent& event)
{
// We just record the size here and lazily resize the surface when exposed
- _app.extent = {static_cast<uint32_t>(event.width),
- static_cast<uint32_t>(event.height)};
-
- _app.mode = (event.style & PUGL_VIEW_STYLE_RESIZING) ? RenderMode::resizing
- : RenderMode::normal;
+ _app.extent = {event.width, event.height};
+ _app.mode = (event.style & PUGL_VIEW_STYLE_RESIZING) ? RenderMode::resizing
+ : RenderMode::normal;
return pugl::Status::success;
}
@@ -1524,7 +1528,7 @@ View::onEvent(const pugl::ConfigureEvent& event)
pugl::Status
View::onEvent(const pugl::UpdateEvent&)
{
- return postRedisplay();
+ return obscure();
}
VkResult
@@ -1710,7 +1714,7 @@ View::onEvent(const pugl::LoopEnterEvent&)
pugl::Status
View::onEvent(const pugl::TimerEvent&)
{
- return postRedisplay();
+ return obscure();
}
pugl::Status
diff --git a/examples/pugl_vulkan_demo.app/MacOS/meson.build b/examples/pugl_vulkan_demo.app/MacOS/meson.build
index 0d07171..0f7f4bf 100644
--- a/examples/pugl_vulkan_demo.app/MacOS/meson.build
+++ b/examples/pugl_vulkan_demo.app/MacOS/meson.build
@@ -8,6 +8,6 @@ executable(
'../../file_utils.c',
],
c_args: example_defines + example_c_args,
- dependencies: [pugl_dep, pugl_vulkan_dep],
- include_directories: include_directories('../../..'),
+ dependencies: [pugl_dep, pugl_vulkan_dep, puglutil_dep],
+ implicit_include_directories: false,
)
diff --git a/examples/pugl_vulkan_demo.c b/examples/pugl_vulkan_demo.c
index 2f9eaff..75083c4 100644
--- a/examples/pugl_vulkan_demo.c
+++ b/examples/pugl_vulkan_demo.c
@@ -10,10 +10,11 @@
*/
#include "demo_utils.h"
-#include "test/test_utils.h"
-#include "pugl/pugl.h"
-#include "pugl/vulkan.h"
+#include <puglutil/test_utils.h>
+
+#include <pugl/pugl.h>
+#include <pugl/vulkan.h>
#include <vulkan/vk_platform.h>
#include <vulkan/vulkan_core.h>
@@ -83,8 +84,8 @@ typedef struct {
PuglView* view;
VulkanState vk;
uint32_t framesDrawn;
- uint32_t width;
- uint32_t height;
+ PuglSpan width;
+ PuglSpan height;
bool quit;
} VulkanApp;
@@ -569,8 +570,8 @@ configureSurface(VulkanState* const vk)
static VkResult
createRawSwapchain(VulkanState* const vk,
- const uint32_t width,
- const uint32_t height)
+ const PuglSpan width,
+ const PuglSpan height)
{
VkSurfaceCapabilitiesKHR surfaceCapabilities;
VkResult vr = VK_SUCCESS;
@@ -583,12 +584,12 @@ createRawSwapchain(VulkanState* const vk,
/* There is a known race condition with window/surface sizes, so we clamp
to what Vulkan reports and hope for the best. */
- vk->swapchain->extent.width = CLAMP(width,
+ vk->swapchain->extent.width = CLAMP((uint32_t)width,
surfaceCapabilities.minImageExtent.width,
surfaceCapabilities.maxImageExtent.width);
vk->swapchain->extent.height =
- CLAMP(height,
+ CLAMP((uint32_t)height,
surfaceCapabilities.minImageExtent.height,
surfaceCapabilities.maxImageExtent.height);
@@ -707,8 +708,8 @@ recordCommandBuffers(VulkanState* const vk)
static VkResult
createSwapchain(VulkanState* const vk,
- const uint32_t width,
- const uint32_t height)
+ const PuglSpan width,
+ const PuglSpan height)
{
VkResult vr = VK_SUCCESS;
@@ -895,21 +896,21 @@ destroyWorld(VulkanApp* const app)
}
static PuglStatus
-onConfigure(PuglView* const view, const double width, const double height)
+onConfigure(PuglView* const view, const PuglSpan width, const PuglSpan height)
{
VulkanApp* const app = (VulkanApp*)puglGetHandle(view);
// We just record the size here and lazily resize the surface when exposed
- app->width = (uint32_t)width;
- app->height = (uint32_t)height;
+ app->width = width;
+ app->height = height;
return PUGL_SUCCESS;
}
static PuglStatus
recreateSwapchain(VulkanState* const vk,
- const uint32_t width,
- const uint32_t height)
+ const PuglSpan width,
+ const PuglSpan height)
{
vkDeviceWaitIdle(vk->device);
destroySwapchain(vk, vk->swapchain);
@@ -1009,7 +1010,7 @@ onEvent(PuglView* const view, const PuglEvent* const e)
switch (e->type) {
case PUGL_UPDATE:
- return app->opts.continuous ? puglPostRedisplay(view) : PUGL_SUCCESS;
+ return app->opts.continuous ? puglObscureView(view) : PUGL_SUCCESS;
case PUGL_EXPOSE:
return onExpose(view);
case PUGL_CONFIGURE:
diff --git a/examples/pugl_window_demo.app/MacOS/meson.build b/examples/pugl_window_demo.app/MacOS/meson.build
index 7bfc219..f2623f2 100644
--- a/examples/pugl_window_demo.app/MacOS/meson.build
+++ b/examples/pugl_window_demo.app/MacOS/meson.build
@@ -6,6 +6,6 @@ executable(
'../../pugl_window_demo.c',
c_args: example_defines + example_c_args,
cpp_args: example_defines + example_cpp_args,
- dependencies: [pugl_dep, pugl_gl_dep],
- include_directories: include_directories('../../..'),
+ dependencies: [pugl_dep, pugl_gl_dep, puglutil_dep],
+ implicit_include_directories: false,
)
diff --git a/examples/pugl_window_demo.c b/examples/pugl_window_demo.c
index 67086bb..867f856 100644
--- a/examples/pugl_window_demo.c
+++ b/examples/pugl_window_demo.c
@@ -7,10 +7,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>
@@ -49,8 +50,8 @@ onDisplay(PuglView* view)
if (app->continuous) {
const double dTime = thisTime - cube->lastDrawTime;
- cube->xAngle = fmod(cube->xAngle + dTime * 100.0, 360.0);
- cube->yAngle = fmod(cube->yAngle + dTime * 100.0, 360.0);
+ cube->xAngle = fmod(cube->xAngle + (dTime * 100.0), 360.0);
+ cube->yAngle = fmod(cube->yAngle + (dTime * 100.0), 360.0);
}
displayCube(
@@ -64,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);
}
}
}
@@ -95,7 +97,7 @@ static void
redisplayView(PuglTestApp* app, PuglView* view)
{
if (!app->continuous) {
- puglPostRedisplay(view);
+ puglObscureView(view);
}
}
@@ -115,7 +117,7 @@ onEvent(PuglView* view, const PuglEvent* event)
break;
case PUGL_UPDATE:
if (app->continuous) {
- puglPostRedisplay(view);
+ puglObscureView(view);
}
break;
case PUGL_EXPOSE:
@@ -186,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);
diff --git a/examples/sybok.hpp b/examples/sybok.hpp
index 49abdf0..db0cdd5 100644
--- a/examples/sybok.hpp
+++ b/examples/sybok.hpp
@@ -1751,10 +1751,10 @@ public:
private:
template<class T>
- static inline VkResult wrapResult(const VkResult r,
- const typename T::Handle handle,
- typename T::Deleter&& deleter,
- T& result) noexcept
+ static VkResult wrapResult(const VkResult r,
+ const typename T::Handle handle,
+ typename T::Deleter&& deleter,
+ T& result) noexcept
{
if (r) {
return r;