Skip to content

Commit

Permalink
[render] EventDrawer and BlockerEventDrawer are separate classes
Browse files Browse the repository at this point in the history
  • Loading branch information
alemuntoni committed Jan 9, 2025
1 parent 49a5784 commit 8d49e2a
Show file tree
Hide file tree
Showing 7 changed files with 238 additions and 270 deletions.
144 changes: 40 additions & 104 deletions tests/render/000-static-asserts/drawers.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,36 +132,20 @@ void drawersStaticAssertsWM()
"EventDrawer&& does not satisfy the EventDrawerConcept");

static_assert(
CantBlockEventDrawerConcept<EventDrawer<RendererTypeED>>,
"EventDrawer does not satisfy the CantBlockEventDrawerConcept");
!BlockerEventDrawerConcept<EventDrawer<RendererTypeED>>,
"EventDrawer does satisfy the BlockerEventDrawerConcept");
static_assert(
CantBlockEventDrawerConcept<const EventDrawer<RendererTypeED>>,
"const EventDrawer does not satisfy the CantBlockEventDrawerConcept");
!BlockerEventDrawerConcept<const EventDrawer<RendererTypeED>>,
"const EventDrawer does satisfy the BlockerEventDrawerConcept");
static_assert(
CantBlockEventDrawerConcept<EventDrawer<RendererTypeED>&>,
"EventDrawer& does not satisfy the CantBlockEventDrawerConcept");
!BlockerEventDrawerConcept<EventDrawer<RendererTypeED>&>,
"EventDrawer& does satisfy the BlockerEventDrawerConcept");
static_assert(
CantBlockEventDrawerConcept<const EventDrawer<RendererTypeED>&>,
"const EventDrawer& does not satisfy the CantBlockEventDrawerConcept");
!BlockerEventDrawerConcept<const EventDrawer<RendererTypeED>&>,
"const EventDrawer& does satisfy the BlockerEventDrawerConcept");
static_assert(
CantBlockEventDrawerConcept<EventDrawer<RendererTypeED>&&>,
"EventDrawer&& does not satisfy the CantBlockEventDrawerConcept");

static_assert(
!CanBlockEventDrawerConcept<EventDrawer<RendererTypeED>>,
"EventDrawer does satisfy the CanBlockEventDrawerConcept");
static_assert(
!CanBlockEventDrawerConcept<const EventDrawer<RendererTypeED>>,
"const EventDrawer does satisfy the CanBlockEventDrawerConcept");
static_assert(
!CanBlockEventDrawerConcept<EventDrawer<RendererTypeED>&>,
"EventDrawer& does satisfy the CanBlockEventDrawerConcept");
static_assert(
!CanBlockEventDrawerConcept<const EventDrawer<RendererTypeED>&>,
"const EventDrawer& does satisfy the CanBlockEventDrawerConcept");
static_assert(
!CanBlockEventDrawerConcept<EventDrawer<RendererTypeED>&&>,
"EventDrawer&& does satisfy the CanBlockEventDrawerConcept");
!BlockerEventDrawerConcept<EventDrawer<RendererTypeED>&&>,
"EventDrawer&& does satisfy the BlockerEventDrawerConcept");

// BlockerEventDrawer
static_assert(
Expand Down Expand Up @@ -197,36 +181,20 @@ void drawersStaticAssertsWM()
"BlockerEventDrawer&& does not satisfy the EventDrawerConcept");

static_assert(
!CantBlockEventDrawerConcept<BlockerEventDrawer<RendererTypeBED>>,
"BlockerEventDrawer does satisfy the CantBlockEventDrawerConcept");
static_assert(
!CantBlockEventDrawerConcept<const BlockerEventDrawer<RendererTypeBED>>,
"const BlockerEventDrawer does satisfy the CantBlockEventDrawerConcept");
static_assert(
!CantBlockEventDrawerConcept<BlockerEventDrawer<RendererTypeBED>&>,
"BlockerEventDrawer& does satisfy the CantBlockEventDrawerConcept");
static_assert(
!CantBlockEventDrawerConcept<const BlockerEventDrawer<RendererTypeBED>&>,
"const BlockerEventDrawer& does satisfy the CantBlockEventDrawerConcept");
static_assert(
!CantBlockEventDrawerConcept<BlockerEventDrawer<RendererTypeBED>&&>,
"BlockerEventDrawer&& does satisfy the CantBlockEventDrawerConcept");

static_assert(
CanBlockEventDrawerConcept<BlockerEventDrawer<RendererTypeBED>>,
"BlockerEventDrawer does not satisfy the CanBlockEventDrawerConcept");
BlockerEventDrawerConcept<BlockerEventDrawer<RendererTypeBED>>,
"BlockerEventDrawer does not satisfy the BlockerEventDrawerConcept");
static_assert(
CanBlockEventDrawerConcept<const BlockerEventDrawer<RendererTypeBED>>,
"const BlockerEventDrawer does not satisfy the CanBlockEventDrawerConcept");
BlockerEventDrawerConcept<const BlockerEventDrawer<RendererTypeBED>>,
"const BlockerEventDrawer does not satisfy the BlockerEventDrawerConcept");
static_assert(
CanBlockEventDrawerConcept<BlockerEventDrawer<RendererTypeBED>&>,
"BlockerEventDrawer& does not satisfy the CanBlockEventDrawerConcept");
BlockerEventDrawerConcept<BlockerEventDrawer<RendererTypeBED>&>,
"BlockerEventDrawer& does not satisfy the BlockerEventDrawerConcept");
static_assert(
CanBlockEventDrawerConcept<const BlockerEventDrawer<RendererTypeBED>&>,
"const BlockerEventDrawer& does not satisfy the CanBlockEventDrawerConcept");
BlockerEventDrawerConcept<const BlockerEventDrawer<RendererTypeBED>&>,
"const BlockerEventDrawer& does not satisfy the BlockerEventDrawerConcept");
static_assert(
CanBlockEventDrawerConcept<BlockerEventDrawer<RendererTypeBED>&&>,
"BlockerEventDrawer&& does not satisfy the CanBlockEventDrawerConcept");
BlockerEventDrawerConcept<BlockerEventDrawer<RendererTypeBED>&&>,
"BlockerEventDrawer&& does not satisfy the BlockerEventDrawerConcept");

// ViewerDrawer
static_assert(
Expand Down Expand Up @@ -262,36 +230,20 @@ void drawersStaticAssertsWM()
"ViewerDrawer&& does not satisfy the EventDrawerConcept");

static_assert(
CantBlockEventDrawerConcept<ViewerDrawer<RendererTypeVD>>,
"ViewerDrawer does not satisfy the CantBlockEventDrawerConcept");
!BlockerEventDrawerConcept<ViewerDrawer<RendererTypeVD>>,
"ViewerDrawer does satisfy the BlockerEventDrawerConcept");
static_assert(
CantBlockEventDrawerConcept<const ViewerDrawer<RendererTypeVD>>,
"const ViewerDrawer does not satisfy the CantBlockEventDrawerConcept");
!BlockerEventDrawerConcept<const ViewerDrawer<RendererTypeVD>>,
"const ViewerDrawer does satisfy the BlockerEventDrawerConcept");
static_assert(
CantBlockEventDrawerConcept<ViewerDrawer<RendererTypeVD>&>,
"ViewerDrawer& does not satisfy the CantBlockEventDrawerConcept");
!BlockerEventDrawerConcept<ViewerDrawer<RendererTypeVD>&>,
"ViewerDrawer& does satisfy the BlockerEventDrawerConcept");
static_assert(
CantBlockEventDrawerConcept<const ViewerDrawer<RendererTypeVD>&>,
"const ViewerDrawer& does not satisfy the CantBlockEventDrawerConcept");
!BlockerEventDrawerConcept<const ViewerDrawer<RendererTypeVD>&>,
"const ViewerDrawer& does satisfy the BlockerEventDrawerConcept");
static_assert(
CantBlockEventDrawerConcept<ViewerDrawer<RendererTypeVD>&&>,
"ViewerDrawer&& does not satisfy the CantBlockEventDrawerConcept");

static_assert(
!CanBlockEventDrawerConcept<ViewerDrawer<RendererTypeVD>>,
"ViewerDrawer does satisfy the CanBlockEventDrawerConcept");
static_assert(
!CanBlockEventDrawerConcept<const ViewerDrawer<RendererTypeVD>>,
"const ViewerDrawer does satisfy the CanBlockEventDrawerConcept");
static_assert(
!CanBlockEventDrawerConcept<ViewerDrawer<RendererTypeVD>&>,
"ViewerDrawer& does satisfy the CanBlockEventDrawerConcept");
static_assert(
!CanBlockEventDrawerConcept<const ViewerDrawer<RendererTypeVD>&>,
"const ViewerDrawer& does satisfy the CanBlockEventDrawerConcept");
static_assert(
!CanBlockEventDrawerConcept<ViewerDrawer<RendererTypeVD>&&>,
"ViewerDrawer&& does satisfy the CanBlockEventDrawerConcept");
!BlockerEventDrawerConcept<ViewerDrawer<RendererTypeVD>&&>,
"ViewerDrawer&& does satisfy the BlockerEventDrawerConcept");

#ifdef VCLIB_RENDER_BACKEND_BGFX
using RendererTypeTD = Renderer<WMQ, Canvas, TextDrawer>;
Expand Down Expand Up @@ -384,36 +336,20 @@ void drawersStaticAsserts()
"ImguiDrawer&& does not satisfy the EventDrawerConcept");

static_assert(
CanBlockEventDrawerConcept<ImGuiDrawer<RendererTypeID>>,
"ImguiDrawer does not satisfy the CanBlockEventDrawerConcept");
static_assert(
CanBlockEventDrawerConcept<const ImGuiDrawer<RendererTypeID>>,
"const ImguiDrawer does not satisfy the CanBlockEventDrawerConcept");
static_assert(
CanBlockEventDrawerConcept<ImGuiDrawer<RendererTypeID>&>,
"ImguiDrawer& does not satisfy the CanBlockEventDrawerConcept");
static_assert(
CanBlockEventDrawerConcept<const ImGuiDrawer<RendererTypeID>&>,
"const ImguiDrawer& does not satisfy the CanBlockEventDrawerConcept");
static_assert(
CanBlockEventDrawerConcept<ImGuiDrawer<RendererTypeID>&&>,
"ImguiDrawer&& does not satisfy the CanBlockEventDrawerConcept");

static_assert(
!CantBlockEventDrawerConcept<ImGuiDrawer<RendererTypeID>>,
"ImguiDrawer does satisfy the CantBlockEventDrawerConcept");
BlockerEventDrawerConcept<ImGuiDrawer<RendererTypeID>>,
"ImguiDrawer does not satisfy the BlockerEventDrawerConcept");
static_assert(
!CantBlockEventDrawerConcept<const ImGuiDrawer<RendererTypeID>>,
"const ImguiDrawer does satisfy the CantBlockEventDrawerConcept");
BlockerEventDrawerConcept<const ImGuiDrawer<RendererTypeID>>,
"const ImguiDrawer does not satisfy the BlockerEventDrawerConcept");
static_assert(
!CantBlockEventDrawerConcept<ImGuiDrawer<RendererTypeID>&>,
"ImguiDrawer& does satisfy the CantBlockEventDrawerConcept");
BlockerEventDrawerConcept<ImGuiDrawer<RendererTypeID>&>,
"ImguiDrawer& does not satisfy the BlockerEventDrawerConcept");
static_assert(
!CantBlockEventDrawerConcept<const ImGuiDrawer<RendererTypeID>&>,
"const ImguiDrawer& does satisfy the CantBlockEventDrawerConcept");
BlockerEventDrawerConcept<const ImGuiDrawer<RendererTypeID>&>,
"const ImguiDrawer& does not satisfy the BlockerEventDrawerConcept");
static_assert(
!CantBlockEventDrawerConcept<ImGuiDrawer<RendererTypeID>&&>,
"ImguiDrawer&& does satisfy the CantBlockEventDrawerConcept");
BlockerEventDrawerConcept<ImGuiDrawer<RendererTypeID>&&>,
"ImguiDrawer&& does not satisfy the BlockerEventDrawerConcept");
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion vclib/render/include/vclib/imgui/imgui_drawer.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#ifndef IMGUI_DRAWER_H
#define IMGUI_DRAWER_H

#include <vclib/render/drawers/event_drawer.h>
#include <vclib/render/drawers/blocker_event_drawer.h>
#include <vclib/render/window_managers.h>

// Include the render backand imgui implementation
Expand Down
68 changes: 68 additions & 0 deletions vclib/render/include/vclib/render/concepts/blocker_event_drawer.h
Original file line number Diff line number Diff line change
@@ -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 <vclib/render/input.h>

namespace vcl {

template<typename T>
concept BlockerEventDrawerConcept =
EventDrawerConcept<T> && requires (T&& obj) {
requires RemoveRef<T>::CAN_BLOCK_EVENT_PROPAGATION == true;

// non const requirements
requires IsConst<T> || requires {
{
obj.onKeyPress(Key::Enum(), KeyModifiers())
} -> std::same_as<bool>;
{
obj.onKeyRelease(Key::Enum(), KeyModifiers())
} -> std::same_as<bool>;
{
obj.onMouseMove(double(), double(), KeyModifiers())
} -> std::same_as<bool>;
{
obj.onMousePress(
MouseButton::Enum(), double(), double(), KeyModifiers())
} -> std::same_as<bool>;
{
obj.onMouseRelease(
MouseButton::Enum(), double(), double(), KeyModifiers())
} -> std::same_as<bool>;
{
obj.onMouseDoubleClick(
MouseButton::Enum(), double(), double(), KeyModifiers())
} -> std::same_as<bool>;
{
obj.onMouseScroll(double(), double(), KeyModifiers())
} -> std::same_as<bool>;
};
};

} // namespace vcl

#endif // CONCEPTS_BLOCKER_EVENT_DRAWER_H
71 changes: 16 additions & 55 deletions vclib/render/include/vclib/render/concepts/event_drawer.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,67 +30,28 @@
namespace vcl {

template<typename T>
concept CantBlockEventDrawerConcept = DrawerConcept<T> && requires (T&& obj) {
requires RemoveRef<T>::CAN_BLOCK_EVENT_PROPAGATION == false;
concept EventDrawerConcept = DrawerConcept<T> && requires (T&& obj) {
RemoveRef<T>::CAN_BLOCK_EVENT_PROPAGATION;

// non const requirements
requires IsConst<T> || requires {
{ obj.onKeyPress(Key::Enum(), KeyModifiers()) } -> std::same_as<void>;
{ obj.onKeyRelease(Key::Enum(), KeyModifiers()) } -> std::same_as<void>;
{
obj.onMouseMove(double(), double(), KeyModifiers())
} -> std::same_as<void>;
{
obj.onMousePress(
MouseButton::Enum(), double(), double(), KeyModifiers())
} -> std::same_as<void>;
{
obj.onMouseRelease(
MouseButton::Enum(), double(), double(), KeyModifiers())
} -> std::same_as<void>;
{
obj.onMouseDoubleClick(
MouseButton::Enum(), double(), double(), KeyModifiers())
} -> std::same_as<void>;
{
obj.onMouseScroll(double(), double(), KeyModifiers())
} -> std::same_as<void>;
// 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<typename T>
concept CanBlockEventDrawerConcept = DrawerConcept<T> && requires (T&& obj) {
requires RemoveRef<T>::CAN_BLOCK_EVENT_PROPAGATION == true;

// non const requirements
requires IsConst<T> || requires {
{ obj.onKeyPress(Key::Enum(), KeyModifiers()) } -> std::same_as<bool>;
{ obj.onKeyRelease(Key::Enum(), KeyModifiers()) } -> std::same_as<bool>;
{
obj.onMouseMove(double(), double(), KeyModifiers())
} -> std::same_as<bool>;
{
obj.onMousePress(
MouseButton::Enum(), double(), double(), KeyModifiers())
} -> std::same_as<bool>;
{
obj.onMouseRelease(
MouseButton::Enum(), double(), double(), KeyModifiers())
} -> std::same_as<bool>;
{
obj.onMouseDoubleClick(
MouseButton::Enum(), double(), double(), KeyModifiers())
} -> std::same_as<bool>;
{
obj.onMouseScroll(double(), double(), KeyModifiers())
} -> std::same_as<bool>;
};
};

template<typename T>
concept EventDrawerConcept =
CanBlockEventDrawerConcept<T> || CantBlockEventDrawerConcept<T>;

} // namespace vcl

#endif // CONCEPTS_EVENT_DRAWER_H
Loading

0 comments on commit 8d49e2a

Please sign in to comment.