aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/pugl_cxx_demo.cpp33
-rw-r--r--examples/pugl_vulkan_cxx_demo.cpp43
2 files changed, 35 insertions, 41 deletions
diff --git a/examples/pugl_cxx_demo.cpp b/examples/pugl_cxx_demo.cpp
index ed2d21a..4dab35c 100644
--- a/examples/pugl_cxx_demo.cpp
+++ b/examples/pugl_cxx_demo.cpp
@@ -26,30 +26,23 @@
#include "pugl/gl.hpp"
#include "pugl/pugl.h"
#include "pugl/pugl.hpp"
-#include "pugl/pugl.ipp" // IWYU pragma: keep
#include <cmath>
-class CubeView : public pugl::View
+class CubeView : public pugl::View<CubeView>
{
public:
explicit CubeView(pugl::World& world)
- : pugl::View{world}
+ : pugl::View<CubeView>{world}
{}
- CubeView(const CubeView&) = delete;
- CubeView& operator=(const CubeView&) = delete;
+ using pugl::View<CubeView>::onEvent;
- CubeView(CubeView&&) = delete;
- CubeView& operator=(CubeView&&) = delete;
-
- ~CubeView() override = default;
-
- pugl::Status onConfigure(const pugl::ConfigureEvent& event) override;
- pugl::Status onUpdate(const pugl::UpdateEvent& event) override;
- pugl::Status onExpose(const pugl::ExposeEvent& event) override;
- pugl::Status onKeyPress(const pugl::KeyPressEvent& event) override;
- pugl::Status onClose(const pugl::CloseEvent& event) override;
+ static pugl::Status onEvent(const pugl::ConfigureEvent& event) noexcept;
+ pugl::Status onEvent(const pugl::UpdateEvent& event) noexcept;
+ pugl::Status onEvent(const pugl::ExposeEvent& event) noexcept;
+ pugl::Status onEvent(const pugl::KeyPressEvent& event) noexcept;
+ pugl::Status onEvent(const pugl::CloseEvent& event) noexcept;
bool quit() const { return _quit; }
@@ -61,7 +54,7 @@ private:
};
pugl::Status
-CubeView::onConfigure(const pugl::ConfigureEvent& event)
+CubeView::onEvent(const pugl::ConfigureEvent& event) noexcept
{
reshapeCube(static_cast<float>(event.width),
static_cast<float>(event.height));
@@ -70,13 +63,13 @@ CubeView::onConfigure(const pugl::ConfigureEvent& event)
}
pugl::Status
-CubeView::onUpdate(const pugl::UpdateEvent&)
+CubeView::onEvent(const pugl::UpdateEvent&) noexcept
{
return postRedisplay();
}
pugl::Status
-CubeView::onExpose(const pugl::ExposeEvent&)
+CubeView::onEvent(const pugl::ExposeEvent&) noexcept
{
const double thisTime = world().time();
const double dTime = thisTime - _lastDrawTime;
@@ -96,7 +89,7 @@ CubeView::onExpose(const pugl::ExposeEvent&)
}
pugl::Status
-CubeView::onKeyPress(const pugl::KeyPressEvent& event)
+CubeView::onEvent(const pugl::KeyPressEvent& event) noexcept
{
if (event.key == PUGL_KEY_ESCAPE || event.key == 'q') {
_quit = true;
@@ -106,7 +99,7 @@ CubeView::onKeyPress(const pugl::KeyPressEvent& event)
}
pugl::Status
-CubeView::onClose(const pugl::CloseEvent&)
+CubeView::onEvent(const pugl::CloseEvent&) noexcept
{
_quit = true;
diff --git a/examples/pugl_vulkan_cxx_demo.cpp b/examples/pugl_vulkan_cxx_demo.cpp
index 12b2626..a4634ee 100644
--- a/examples/pugl_vulkan_cxx_demo.cpp
+++ b/examples/pugl_vulkan_cxx_demo.cpp
@@ -36,7 +36,6 @@
#include "pugl/pugl.h"
#include "pugl/pugl.hpp"
-#include "pugl/pugl.ipp" // IWYU pragma: keep
#include "pugl/vulkan.hpp"
#include <vulkan/vk_platform.h>
@@ -79,7 +78,7 @@ struct VulkanContext {
struct GraphicsDevice {
VkResult init(const pugl::VulkanLoader& loader,
const VulkanContext& context,
- pugl::View& view,
+ pugl::ViewBase& view,
const PuglTestOptions& opts);
sk::SurfaceKHR surface;
@@ -410,7 +409,7 @@ selectPhysicalDevice(const sk::VulkanApi& vk,
VkResult
GraphicsDevice::init(const pugl::VulkanLoader& loader,
const VulkanContext& context,
- pugl::View& view,
+ pugl::ViewBase& view,
const PuglTestOptions& opts)
{
const auto& vk = context.vk;
@@ -1373,22 +1372,24 @@ recordCommandBuffers(const sk::VulkanApi& vk,
class PuglVulkanDemo;
-class View : public pugl::View
+class View : public pugl::View<View>
{
public:
View(pugl::World& world, PuglVulkanDemo& app)
- : pugl::View{world}
+ : pugl::View<View>{world}
, _app{app}
{}
- pugl::Status onConfigure(const pugl::ConfigureEvent& event) override;
- pugl::Status onUpdate(const pugl::UpdateEvent& event) override;
- pugl::Status onExpose(const pugl::ExposeEvent& event) override;
- pugl::Status onLoopEnter(const pugl::LoopEnterEvent& event) override;
- pugl::Status onTimer(const pugl::TimerEvent& event) override;
- pugl::Status onLoopLeave(const pugl::LoopLeaveEvent& event) override;
- pugl::Status onKeyPress(const pugl::KeyPressEvent& event) override;
- pugl::Status onClose(const pugl::CloseEvent& event) override;
+ using pugl::View<View>::onEvent;
+
+ pugl::Status onEvent(const pugl::ConfigureEvent& event);
+ pugl::Status onEvent(const pugl::UpdateEvent& event);
+ pugl::Status onEvent(const pugl::ExposeEvent& event);
+ pugl::Status onEvent(const pugl::LoopEnterEvent& event);
+ pugl::Status onEvent(const pugl::TimerEvent& event);
+ pugl::Status onEvent(const pugl::LoopLeaveEvent& event);
+ pugl::Status onEvent(const pugl::KeyPressEvent& event);
+ pugl::Status onEvent(const pugl::CloseEvent& event);
private:
PuglVulkanDemo& _app;
@@ -1482,7 +1483,7 @@ recreateRenderer(PuglVulkanDemo& app,
}
pugl::Status
-View::onConfigure(const pugl::ConfigureEvent& event)
+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),
@@ -1492,7 +1493,7 @@ View::onConfigure(const pugl::ConfigureEvent& event)
}
pugl::Status
-View::onUpdate(const pugl::UpdateEvent&)
+View::onEvent(const pugl::UpdateEvent&)
{
return postRedisplay();
}
@@ -1633,7 +1634,7 @@ endFrame(const sk::VulkanApi& vk,
}
pugl::Status
-View::onExpose(const pugl::ExposeEvent&)
+View::onEvent(const pugl::ExposeEvent&)
{
const auto& vk = _app.vulkan.vk;
const auto& gpu = _app.gpu;
@@ -1658,7 +1659,7 @@ View::onExpose(const pugl::ExposeEvent&)
}
pugl::Status
-View::onLoopEnter(const pugl::LoopEnterEvent&)
+View::onEvent(const pugl::LoopEnterEvent&)
{
_app.resizing = true;
startTimer(resizeTimerId,
@@ -1668,13 +1669,13 @@ View::onLoopEnter(const pugl::LoopEnterEvent&)
}
pugl::Status
-View::onTimer(const pugl::TimerEvent&)
+View::onEvent(const pugl::TimerEvent&)
{
return postRedisplay();
}
pugl::Status
-View::onLoopLeave(const pugl::LoopLeaveEvent&)
+View::onEvent(const pugl::LoopLeaveEvent&)
{
stopTimer(resizeTimerId);
@@ -1686,7 +1687,7 @@ View::onLoopLeave(const pugl::LoopLeaveEvent&)
}
pugl::Status
-View::onKeyPress(const pugl::KeyPressEvent& event)
+View::onEvent(const pugl::KeyPressEvent& event)
{
if (event.key == PUGL_KEY_ESCAPE || event.key == 'q') {
_app.quit = true;
@@ -1696,7 +1697,7 @@ View::onKeyPress(const pugl::KeyPressEvent& event)
}
pugl::Status
-View::onClose(const pugl::CloseEvent&)
+View::onEvent(const pugl::CloseEvent&)
{
_app.quit = true;