diff options
author | David Robillard <d@drobilla.net> | 2021-05-24 18:45:36 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2021-05-24 20:44:16 -0400 |
commit | 7c3aa758300b6dbcdbb7f287e70b071d90620baa (patch) | |
tree | 108ed1ed631b0459d1647fe6ac36a9bb8ca66df6 /bindings/cpp/include/pugl | |
parent | dd0b921970c2024dc1de72b5b522884f0a2e7e52 (diff) | |
download | pugl-7c3aa758300b6dbcdbb7f287e70b071d90620baa.tar.gz pugl-7c3aa758300b6dbcdbb7f287e70b071d90620baa.tar.bz2 pugl-7c3aa758300b6dbcdbb7f287e70b071d90620baa.zip |
Add fancy constructor for C++ events and wrap puglSendEvent()
Diffstat (limited to 'bindings/cpp/include/pugl')
-rw-r--r-- | bindings/cpp/include/pugl/pugl.hpp | 15 |
1 files changed, 15 insertions, 0 deletions
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)); + } + /** @} */ |