From 7c3aa758300b6dbcdbb7f287e70b071d90620baa Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 24 May 2021 18:45:36 -0400 Subject: Add fancy constructor for C++ events and wrap puglSendEvent() --- bindings/cpp/include/pugl/pugl.hpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'bindings/cpp/include/pugl') 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 + explicit Event(const PuglEventFlags f, Args... args) + : Base{t, f, args...} + {} }; using Mod = PuglMod; ///< @copydoc PuglMod @@ -622,6 +627,16 @@ public: return static_cast(puglStopTimer(cobj(), id)); } + template + Status sendEvent(const Event& event) noexcept + { + PuglEvent cEvent{{t, 0}}; + + *reinterpret_cast(&cEvent) = event; + + return static_cast(puglSendEvent(cobj(), &cEvent)); + } + /** @} */ -- cgit v1.2.1