diff --git a/tests/render/000-static-asserts/drawers.h b/tests/render/000-static-asserts/drawers.h index bd5b8ab54..aabf30cbb 100644 --- a/tests/render/000-static-asserts/drawers.h +++ b/tests/render/000-static-asserts/drawers.h @@ -132,36 +132,20 @@ void drawersStaticAssertsWM() "EventDrawer&& does not satisfy the EventDrawerConcept"); static_assert( - CantBlockEventDrawerConcept>, - "EventDrawer does not satisfy the CantBlockEventDrawerConcept"); + !BlockerEventDrawerConcept>, + "EventDrawer does satisfy the BlockerEventDrawerConcept"); static_assert( - CantBlockEventDrawerConcept>, - "const EventDrawer does not satisfy the CantBlockEventDrawerConcept"); + !BlockerEventDrawerConcept>, + "const EventDrawer does satisfy the BlockerEventDrawerConcept"); static_assert( - CantBlockEventDrawerConcept&>, - "EventDrawer& does not satisfy the CantBlockEventDrawerConcept"); + !BlockerEventDrawerConcept&>, + "EventDrawer& does satisfy the BlockerEventDrawerConcept"); static_assert( - CantBlockEventDrawerConcept&>, - "const EventDrawer& does not satisfy the CantBlockEventDrawerConcept"); + !BlockerEventDrawerConcept&>, + "const EventDrawer& does satisfy the BlockerEventDrawerConcept"); static_assert( - CantBlockEventDrawerConcept&&>, - "EventDrawer&& does not satisfy the CantBlockEventDrawerConcept"); - - static_assert( - !CanBlockEventDrawerConcept>, - "EventDrawer does satisfy the CanBlockEventDrawerConcept"); - static_assert( - !CanBlockEventDrawerConcept>, - "const EventDrawer does satisfy the CanBlockEventDrawerConcept"); - static_assert( - !CanBlockEventDrawerConcept&>, - "EventDrawer& does satisfy the CanBlockEventDrawerConcept"); - static_assert( - !CanBlockEventDrawerConcept&>, - "const EventDrawer& does satisfy the CanBlockEventDrawerConcept"); - static_assert( - !CanBlockEventDrawerConcept&&>, - "EventDrawer&& does satisfy the CanBlockEventDrawerConcept"); + !BlockerEventDrawerConcept&&>, + "EventDrawer&& does satisfy the BlockerEventDrawerConcept"); // BlockerEventDrawer static_assert( @@ -197,36 +181,20 @@ void drawersStaticAssertsWM() "BlockerEventDrawer&& does not satisfy the EventDrawerConcept"); static_assert( - !CantBlockEventDrawerConcept>, - "BlockerEventDrawer does satisfy the CantBlockEventDrawerConcept"); - static_assert( - !CantBlockEventDrawerConcept>, - "const BlockerEventDrawer does satisfy the CantBlockEventDrawerConcept"); - static_assert( - !CantBlockEventDrawerConcept&>, - "BlockerEventDrawer& does satisfy the CantBlockEventDrawerConcept"); - static_assert( - !CantBlockEventDrawerConcept&>, - "const BlockerEventDrawer& does satisfy the CantBlockEventDrawerConcept"); - static_assert( - !CantBlockEventDrawerConcept&&>, - "BlockerEventDrawer&& does satisfy the CantBlockEventDrawerConcept"); - - static_assert( - CanBlockEventDrawerConcept>, - "BlockerEventDrawer does not satisfy the CanBlockEventDrawerConcept"); + BlockerEventDrawerConcept>, + "BlockerEventDrawer does not satisfy the BlockerEventDrawerConcept"); static_assert( - CanBlockEventDrawerConcept>, - "const BlockerEventDrawer does not satisfy the CanBlockEventDrawerConcept"); + BlockerEventDrawerConcept>, + "const BlockerEventDrawer does not satisfy the BlockerEventDrawerConcept"); static_assert( - CanBlockEventDrawerConcept&>, - "BlockerEventDrawer& does not satisfy the CanBlockEventDrawerConcept"); + BlockerEventDrawerConcept&>, + "BlockerEventDrawer& does not satisfy the BlockerEventDrawerConcept"); static_assert( - CanBlockEventDrawerConcept&>, - "const BlockerEventDrawer& does not satisfy the CanBlockEventDrawerConcept"); + BlockerEventDrawerConcept&>, + "const BlockerEventDrawer& does not satisfy the BlockerEventDrawerConcept"); static_assert( - CanBlockEventDrawerConcept&&>, - "BlockerEventDrawer&& does not satisfy the CanBlockEventDrawerConcept"); + BlockerEventDrawerConcept&&>, + "BlockerEventDrawer&& does not satisfy the BlockerEventDrawerConcept"); // ViewerDrawer static_assert( @@ -262,36 +230,20 @@ void drawersStaticAssertsWM() "ViewerDrawer&& does not satisfy the EventDrawerConcept"); static_assert( - CantBlockEventDrawerConcept>, - "ViewerDrawer does not satisfy the CantBlockEventDrawerConcept"); + !BlockerEventDrawerConcept>, + "ViewerDrawer does satisfy the BlockerEventDrawerConcept"); static_assert( - CantBlockEventDrawerConcept>, - "const ViewerDrawer does not satisfy the CantBlockEventDrawerConcept"); + !BlockerEventDrawerConcept>, + "const ViewerDrawer does satisfy the BlockerEventDrawerConcept"); static_assert( - CantBlockEventDrawerConcept&>, - "ViewerDrawer& does not satisfy the CantBlockEventDrawerConcept"); + !BlockerEventDrawerConcept&>, + "ViewerDrawer& does satisfy the BlockerEventDrawerConcept"); static_assert( - CantBlockEventDrawerConcept&>, - "const ViewerDrawer& does not satisfy the CantBlockEventDrawerConcept"); + !BlockerEventDrawerConcept&>, + "const ViewerDrawer& does satisfy the BlockerEventDrawerConcept"); static_assert( - CantBlockEventDrawerConcept&&>, - "ViewerDrawer&& does not satisfy the CantBlockEventDrawerConcept"); - - static_assert( - !CanBlockEventDrawerConcept>, - "ViewerDrawer does satisfy the CanBlockEventDrawerConcept"); - static_assert( - !CanBlockEventDrawerConcept>, - "const ViewerDrawer does satisfy the CanBlockEventDrawerConcept"); - static_assert( - !CanBlockEventDrawerConcept&>, - "ViewerDrawer& does satisfy the CanBlockEventDrawerConcept"); - static_assert( - !CanBlockEventDrawerConcept&>, - "const ViewerDrawer& does satisfy the CanBlockEventDrawerConcept"); - static_assert( - !CanBlockEventDrawerConcept&&>, - "ViewerDrawer&& does satisfy the CanBlockEventDrawerConcept"); + !BlockerEventDrawerConcept&&>, + "ViewerDrawer&& does satisfy the BlockerEventDrawerConcept"); #ifdef VCLIB_RENDER_BACKEND_BGFX using RendererTypeTD = Renderer; @@ -384,36 +336,20 @@ void drawersStaticAsserts() "ImguiDrawer&& does not satisfy the EventDrawerConcept"); static_assert( - CanBlockEventDrawerConcept>, - "ImguiDrawer does not satisfy the CanBlockEventDrawerConcept"); - static_assert( - CanBlockEventDrawerConcept>, - "const ImguiDrawer does not satisfy the CanBlockEventDrawerConcept"); - static_assert( - CanBlockEventDrawerConcept&>, - "ImguiDrawer& does not satisfy the CanBlockEventDrawerConcept"); - static_assert( - CanBlockEventDrawerConcept&>, - "const ImguiDrawer& does not satisfy the CanBlockEventDrawerConcept"); - static_assert( - CanBlockEventDrawerConcept&&>, - "ImguiDrawer&& does not satisfy the CanBlockEventDrawerConcept"); - - static_assert( - !CantBlockEventDrawerConcept>, - "ImguiDrawer does satisfy the CantBlockEventDrawerConcept"); + BlockerEventDrawerConcept>, + "ImguiDrawer does not satisfy the BlockerEventDrawerConcept"); static_assert( - !CantBlockEventDrawerConcept>, - "const ImguiDrawer does satisfy the CantBlockEventDrawerConcept"); + BlockerEventDrawerConcept>, + "const ImguiDrawer does not satisfy the BlockerEventDrawerConcept"); static_assert( - !CantBlockEventDrawerConcept&>, - "ImguiDrawer& does satisfy the CantBlockEventDrawerConcept"); + BlockerEventDrawerConcept&>, + "ImguiDrawer& does not satisfy the BlockerEventDrawerConcept"); static_assert( - !CantBlockEventDrawerConcept&>, - "const ImguiDrawer& does satisfy the CantBlockEventDrawerConcept"); + BlockerEventDrawerConcept&>, + "const ImguiDrawer& does not satisfy the BlockerEventDrawerConcept"); static_assert( - !CantBlockEventDrawerConcept&&>, - "ImguiDrawer&& does satisfy the CantBlockEventDrawerConcept"); + BlockerEventDrawerConcept&&>, + "ImguiDrawer&& does not satisfy the BlockerEventDrawerConcept"); #endif } diff --git a/vclib/render/include/vclib/imgui/imgui_drawer.h b/vclib/render/include/vclib/imgui/imgui_drawer.h index a35d16712..8c4862729 100644 --- a/vclib/render/include/vclib/imgui/imgui_drawer.h +++ b/vclib/render/include/vclib/imgui/imgui_drawer.h @@ -23,7 +23,7 @@ #ifndef IMGUI_DRAWER_H #define IMGUI_DRAWER_H -#include +#include #include // Include the render backand imgui implementation diff --git a/vclib/render/include/vclib/render/concepts/blocker_event_drawer.h b/vclib/render/include/vclib/render/concepts/blocker_event_drawer.h new file mode 100644 index 000000000..5aedb8015 --- /dev/null +++ b/vclib/render/include/vclib/render/concepts/blocker_event_drawer.h @@ -0,0 +1,68 @@ +/***************************************************************************** + * VCLib * + * Visual Computing Library * + * * + * Copyright(C) 2021-2024 * + * Visual Computing Lab * + * ISTI - Italian National Research Council * + * * + * All rights reserved. * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the Mozilla Public License Version 2.0 as published * + * by the Mozilla Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * Mozilla Public License Version 2.0 * + * (https://www.mozilla.org/en-US/MPL/2.0/) for more details. * + ****************************************************************************/ + +#ifndef CONCEPTS_BLOCKER_EVENT_DRAWER_H +#define CONCEPTS_BLOCKER_EVENT_DRAWER_H + +#include "event_drawer.h" + +#include + +namespace vcl { + +template +concept BlockerEventDrawerConcept = + EventDrawerConcept && requires (T&& obj) { + requires RemoveRef::CAN_BLOCK_EVENT_PROPAGATION == true; + + // non const requirements + requires IsConst || requires { + { + obj.onKeyPress(Key::Enum(), KeyModifiers()) + } -> std::same_as; + { + obj.onKeyRelease(Key::Enum(), KeyModifiers()) + } -> std::same_as; + { + obj.onMouseMove(double(), double(), KeyModifiers()) + } -> std::same_as; + { + obj.onMousePress( + MouseButton::Enum(), double(), double(), KeyModifiers()) + } -> std::same_as; + { + obj.onMouseRelease( + MouseButton::Enum(), double(), double(), KeyModifiers()) + } -> std::same_as; + { + obj.onMouseDoubleClick( + MouseButton::Enum(), double(), double(), KeyModifiers()) + } -> std::same_as; + { + obj.onMouseScroll(double(), double(), KeyModifiers()) + } -> std::same_as; + }; + }; + +} // namespace vcl + +#endif // CONCEPTS_BLOCKER_EVENT_DRAWER_H diff --git a/vclib/render/include/vclib/render/concepts/event_drawer.h b/vclib/render/include/vclib/render/concepts/event_drawer.h index c75befb79..58fb83792 100644 --- a/vclib/render/include/vclib/render/concepts/event_drawer.h +++ b/vclib/render/include/vclib/render/concepts/event_drawer.h @@ -30,67 +30,28 @@ namespace vcl { template -concept CantBlockEventDrawerConcept = DrawerConcept && requires (T&& obj) { - requires RemoveRef::CAN_BLOCK_EVENT_PROPAGATION == false; +concept EventDrawerConcept = DrawerConcept && requires (T&& obj) { + RemoveRef::CAN_BLOCK_EVENT_PROPAGATION; // non const requirements requires IsConst || requires { - { obj.onKeyPress(Key::Enum(), KeyModifiers()) } -> std::same_as; - { obj.onKeyRelease(Key::Enum(), KeyModifiers()) } -> std::same_as; - { - obj.onMouseMove(double(), double(), KeyModifiers()) - } -> std::same_as; - { - obj.onMousePress( - MouseButton::Enum(), double(), double(), KeyModifiers()) - } -> std::same_as; - { - obj.onMouseRelease( - MouseButton::Enum(), double(), double(), KeyModifiers()) - } -> std::same_as; - { - obj.onMouseDoubleClick( - MouseButton::Enum(), double(), double(), KeyModifiers()) - } -> std::same_as; - { - obj.onMouseScroll(double(), double(), KeyModifiers()) - } -> std::same_as; + // note: we don't check return type on purpose here + // as BlockerEventDrawers can return a boolean value, while + // most EventDrawers do not return anything + + obj.onKeyPress(Key::Enum(), KeyModifiers()); + obj.onKeyRelease(Key::Enum(), KeyModifiers()); + obj.onMouseMove(double(), double(), KeyModifiers()); + obj.onMousePress( + MouseButton::Enum(), double(), double(), KeyModifiers()); + obj.onMouseRelease( + MouseButton::Enum(), double(), double(), KeyModifiers()); + obj.onMouseDoubleClick( + MouseButton::Enum(), double(), double(), KeyModifiers()); + obj.onMouseScroll(double(), double(), KeyModifiers()); }; }; -template -concept CanBlockEventDrawerConcept = DrawerConcept && requires (T&& obj) { - requires RemoveRef::CAN_BLOCK_EVENT_PROPAGATION == true; - - // non const requirements - requires IsConst || requires { - { obj.onKeyPress(Key::Enum(), KeyModifiers()) } -> std::same_as; - { obj.onKeyRelease(Key::Enum(), KeyModifiers()) } -> std::same_as; - { - obj.onMouseMove(double(), double(), KeyModifiers()) - } -> std::same_as; - { - obj.onMousePress( - MouseButton::Enum(), double(), double(), KeyModifiers()) - } -> std::same_as; - { - obj.onMouseRelease( - MouseButton::Enum(), double(), double(), KeyModifiers()) - } -> std::same_as; - { - obj.onMouseDoubleClick( - MouseButton::Enum(), double(), double(), KeyModifiers()) - } -> std::same_as; - { - obj.onMouseScroll(double(), double(), KeyModifiers()) - } -> std::same_as; - }; -}; - -template -concept EventDrawerConcept = - CanBlockEventDrawerConcept || CantBlockEventDrawerConcept; - } // namespace vcl #endif // CONCEPTS_EVENT_DRAWER_H diff --git a/vclib/render/include/vclib/render/drawers/blocker_event_drawer.h b/vclib/render/include/vclib/render/drawers/blocker_event_drawer.h new file mode 100644 index 000000000..c660e60bc --- /dev/null +++ b/vclib/render/include/vclib/render/drawers/blocker_event_drawer.h @@ -0,0 +1,109 @@ +/***************************************************************************** + * VCLib * + * Visual Computing Library * + * * + * Copyright(C) 2021-2025 * + * Visual Computing Lab * + * ISTI - Italian National Research Council * + * * + * All rights reserved. * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the Mozilla Public License Version 2.0 as published * + * by the Mozilla Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * Mozilla Public License Version 2.0 * + * (https://www.mozilla.org/en-US/MPL/2.0/) for more details. * + ****************************************************************************/ + +#ifndef BLOCKER_EVENT_DRAWER_H +#define BLOCKER_EVENT_DRAWER_H + +#include "plain_drawer.h" + +#include + +namespace vcl { + +/** + * @brief Special EventDrawer class for the case where the drawer can request to + * block the event propagation. + * + * A drawer that inherits from this class can request to block the event + * propagation, and (if requested) the event will not be propagated to the other + * drawer arguments of the Renderer class. + * + * All the event functions of this class return a boolean value. If the function + * returns true, the DerivedRenderer will block event propagation to other + * drawers; otherwise, the event is propagated to the other drawers. + * + * @tparam DerivedRenderer The type of the derived renderer class. + */ +template +class BlockerEventDrawer : public PlainDrawer +{ +public: + static const bool CAN_BLOCK_EVENT_PROPAGATION = true; + + BlockerEventDrawer() = default; + + BlockerEventDrawer(uint, uint) {} + + virtual bool onKeyPress(Key::Enum key, const KeyModifiers& modifiers) + { + return false; + } + + virtual bool onKeyRelease(Key::Enum key, const KeyModifiers& modifiers) + { + return false; + } + + virtual bool onMouseMove(double x, double y, const KeyModifiers& modifiers) + { + return false; + } + + virtual bool onMousePress( + MouseButton::Enum button, + double x, + double y, + const KeyModifiers& modifiers) + { + return false; + } + + virtual bool onMouseRelease( + MouseButton::Enum button, + double x, + double y, + const KeyModifiers& modifiers) + { + return false; + } + + virtual bool onMouseDoubleClick( + MouseButton::Enum button, + double x, + double y, + const KeyModifiers& modifiers) + { + return false; + } + + virtual bool onMouseScroll( + double x, + double y, + const KeyModifiers& modifiers) + { + return false; + } +}; + +} // namespace vcl + +#endif // BLOCKER_EVENT_DRAWER_H diff --git a/vclib/render/include/vclib/render/drawers/event_drawer.h b/vclib/render/include/vclib/render/drawers/event_drawer.h index 87e250021..455db7cd3 100644 --- a/vclib/render/include/vclib/render/drawers/event_drawer.h +++ b/vclib/render/include/vclib/render/drawers/event_drawer.h @@ -29,42 +29,18 @@ namespace vcl { -namespace detail { - /** - * @brief The EventDrawer class is a base class for all drawers that handle + * @brief The EventDrawer class is a base class for drawers that can handle * events. * * The EventDrawer class is a CRTP class that is templated on the derived * renderer class. It provides the interface for handling events produced by the * DerivedRenderer class. * - * The EventDrawer class is specialized for two cases: - * - CAN_BLOCK_EVENT_PROPAGATION = false: The drawer cannot request to block the - * event propagation. All the event functions do not return any value. @see - * EventDrawer. - * - CAN_BLOCK_EVENT_PROPAGATION = true: The drawer can request to block the - * event propagation. All the event functions return a boolean value that - * indicates if the event propagation is blocked. @see - * EventDrawer. - * - * @tparam DerivedRenderer The type of the derived renderer class. - * @tparam CAN_BLOCK_EVENT_PROPAGATION: A boolean flag that indicates if the - * drawer can request to block the event propagation. - */ -template -class EventDrawer -{ -}; - -/** - * @brief Default specialization of the EventDrawer class for the case where the - * drawer cannot request to block the event propagation. - * * @tparam DerivedRenderer The type of the derived renderer class. */ template -class EventDrawer : public PlainDrawer +class EventDrawer : public PlainDrawer { public: static const bool CAN_BLOCK_EVENT_PROPAGATION = false; @@ -113,89 +89,6 @@ class EventDrawer : public PlainDrawer } }; -/** - * @brief Specialization of the EventDrawer class for the case where the drawer - * can request to block the event propagation. - * - * A drawer that inherits from this class can request to block the event - * propagation, and (if requested) the event will not be propagated to the other - * drawer arguments of the Renderer class. - * - * All the event functions of this class return a boolean value. If the function - * returns true, the DerivedRenderer will block event propagation to other - * drawers; otherwise, the event is propagated to the other drawers. - * - * @tparam DerivedRenderer The type of the derived renderer class. - */ -template -class EventDrawer : public PlainDrawer -{ -public: - static const bool CAN_BLOCK_EVENT_PROPAGATION = true; - - EventDrawer() = default; - - EventDrawer(uint, uint) {} - - virtual bool onKeyPress(Key::Enum key, const KeyModifiers& modifiers) - { - return false; - } - - virtual bool onKeyRelease(Key::Enum key, const KeyModifiers& modifiers) - { - return false; - } - - virtual bool onMouseMove(double x, double y, const KeyModifiers& modifiers) - { - return false; - } - - virtual bool onMousePress( - MouseButton::Enum button, - double x, - double y, - const KeyModifiers& modifiers) - { - return false; - } - - virtual bool onMouseRelease( - MouseButton::Enum button, - double x, - double y, - const KeyModifiers& modifiers) - { - return false; - } - - virtual bool onMouseDoubleClick( - MouseButton::Enum button, - double x, - double y, - const KeyModifiers& modifiers) - { - return false; - } - - virtual bool onMouseScroll( - double x, - double y, - const KeyModifiers& modifiers) - { - return false; - } -}; - -} // namespace detail - -template -using EventDrawer = detail::EventDrawer; - -template -using BlockerEventDrawer = detail::EventDrawer; - } // namespace vcl #endif // EVENT_DRAWER_H diff --git a/vclib/render/include/vclib/render/renderer.h b/vclib/render/include/vclib/render/renderer.h index e4d71d618..e1d6a9ef3 100644 --- a/vclib/render/include/vclib/render/renderer.h +++ b/vclib/render/include/vclib/render/renderer.h @@ -23,6 +23,7 @@ #ifndef VCL_RENDER_RENDERER_H #define VCL_RENDER_RENDERER_H +#include "concepts/blocker_event_drawer.h" #include "concepts/canvas.h" #include "concepts/event_drawer.h" #include "concepts/window_manager.h" @@ -152,7 +153,7 @@ class Renderer : { bool block = false; if constexpr(EventDrawerConcept){ - if constexpr (CanBlockEventDrawerConcept) { + if constexpr (BlockerEventDrawerConcept) { block = lambda.template operator()(this); } else { lambda.template operator()(this);