Loading...
Searching...
No Matches
DrawableWrapper.h
Go to the documentation of this file.
1// Copyright (c) 2025 Dave R. Smith. All rights reserved.
2// Malena Framework — Proprietary Software. See LICENSE for terms.
3
4//
5// Created by Dave Smith on 3/14/26.
6//
7
8#ifndef MALENA_DRAWABLEWRAPPER_H
9#define MALENA_DRAWABLEWRAPPER_H
10
12
13namespace ml
14{
15 // ── Detection traits ─────────────────────────────────────────────────────
16
18
20 template<typename T, typename = void>
21 struct HasSetPosition : std::false_type {};
22 template<typename T>
23 struct HasSetPosition<T, std::void_t<
24 decltype(std::declval<T>().setPosition(std::declval<sf::Vector2f>()))
25 >> : std::true_type {};
26
28 template<typename T, typename = void>
29 struct HasGetPosition : std::false_type {};
30 template<typename T>
31 struct HasGetPosition<T, std::void_t<
32 decltype(std::declval<T>().getPosition())
33 >> : std::true_type {};
34
36 template<typename T, typename = void>
37 struct HasGetGlobalBounds : std::false_type {};
38 template<typename T>
39 struct HasGetGlobalBounds<T, std::void_t<
40 decltype(std::declval<T>().getGlobalBounds())
41 >> : std::true_type {};
42
44
45 // ── DrawableWrapper ───────────────────────────────────────────────────────
46
69 template<typename ENTITY>
70 class DrawableWrapper : public ENTITY, public ml::Core
71 {
72 public:
73 using ENTITY::ENTITY;
74
83 void setPosition(const sf::Vector2f& pos) override
84 {
85 if constexpr (HasSetPosition<ENTITY>::value)
86 ENTITY::setPosition(pos);
87 }
88
96 sf::Vector2f getPosition() const override
97 {
98 if constexpr (HasGetPosition<ENTITY>::value)
99 return ENTITY::getPosition();
100 return {};
101 }
102
114 {
115 if constexpr (HasGetGlobalBounds<ENTITY>::value)
116 return ENTITY::getGlobalBounds();
118 return sf::FloatRect({0.f, 0.f}, sf::Vector2f(size));
119 }
120 };
121
122} // namespace ml
123
124#endif // MALENA_DRAWABLEWRAPPER_H
Virtual base class for all Malena framework objects.
Definition Core.h:69
Adapts any sf::Drawable into a first-class ml::Core object.
void setPosition(const sf::Vector2f &pos) override
Set the world-space position, delegating to ENTITY if supported.
sf::Vector2f getPosition() const override
Return the world-space position, delegating to ENTITY if supported.
sf::FloatRect getGlobalBounds() const override
Return the axis-aligned bounding box, delegating to ENTITY if supported.
Vector2u getSize() const override
sf::RenderWindow & getWindow()
Return the framework's shared sf::RenderWindow.
Definition Component.h:22
Rect< float > FloatRect
Vector2< float > Vector2f