diff options
-rw-r--r-- | bindings/cpp/include/.clang-tidy | 1 | ||||
-rw-r--r-- | bindings/cpp/include/pugl/pugl.hpp | 15 | ||||
-rw-r--r-- | examples/pugl_cpp_demo.cpp | 7 |
3 files changed, 22 insertions, 1 deletions
diff --git a/bindings/cpp/include/.clang-tidy b/bindings/cpp/include/.clang-tidy index 816223d..1c986fe 100644 --- a/bindings/cpp/include/.clang-tidy +++ b/bindings/cpp/include/.clang-tidy @@ -3,6 +3,7 @@ Checks: > -*-uppercase-literal-suffix, -clang-diagnostic-unused-macros, -cppcoreguidelines-pro-bounds-pointer-arithmetic, + -cppcoreguidelines-pro-type-reinterpret-cast, -cppcoreguidelines-pro-type-static-cast-downcast, -google-runtime-references, -hicpp-named-parameter, diff --git a/bindings/cpp/include/pugl/pugl.hpp b/bindings/cpp/include/pugl/pugl.hpp index 51cfdb8..4eebdac 100644 --- a/bindings/cpp/include/pugl/pugl.hpp +++ b/bindings/cpp/include/pugl/pugl.hpp @@ -102,6 +102,11 @@ struct Event final : Base { /// The `type` field of the corresponding C event structure static constexpr const PuglEventType type = t; + + template<class... Args> + explicit Event(const PuglEventFlags f, Args... args) + : Base{t, f, args...} + {} }; using Mod = PuglMod; ///< @copydoc PuglMod @@ -622,6 +627,16 @@ public: return static_cast<Status>(puglStopTimer(cobj(), id)); } + template<PuglEventType t, class Base> + Status sendEvent(const Event<t, Base>& event) noexcept + { + PuglEvent cEvent{{t, 0}}; + + *reinterpret_cast<Base*>(&cEvent) = event; + + return static_cast<Status>(puglSendEvent(cobj(), &cEvent)); + } + /** @} */ diff --git a/examples/pugl_cpp_demo.cpp b/examples/pugl_cpp_demo.cpp index e49c416..552094f 100644 --- a/examples/pugl_cpp_demo.cpp +++ b/examples/pugl_cpp_demo.cpp @@ -66,7 +66,12 @@ CubeView::onEvent(const pugl::ConfigureEvent& event) noexcept pugl::Status CubeView::onEvent(const pugl::UpdateEvent&) noexcept { - return postRedisplay(); + // Normally, we would post a redisplay: + // return postRedisplay(); + + // But for testing, use sendEvent() instead: + return sendEvent( + pugl::ExposeEvent{0u, 0.0, 0.0, frame().width, frame().height}); } pugl::Status |