11
11
#include " shared/graphics/ITexture.hpp"
12
12
#include " shared/graphics/types/TextureProps.hpp"
13
13
#include " shared/graphics/types/TextProps.hpp"
14
+ #include " common/exceptions/WindowException.hpp"
14
15
15
16
namespace arcade ::graphics::sfml::window {
16
17
class Renderer ;
@@ -42,9 +43,6 @@ class arcade::graphics::sfml::window::Renderer {
42
43
sf::Text _text;
43
44
sf::Sprite _sprite;
44
45
45
- template <class From , class To >
46
- static std::shared_ptr<To> _castOrThrow (std::shared_ptr<From> from);
47
-
48
46
/* *
49
47
* @brief Reset the text properties
50
48
* @param text Text to reset
@@ -76,10 +74,10 @@ class arcade::graphics::sfml::window::Renderer {
76
74
);
77
75
78
76
/* *
79
- * @brief Align the text
80
- * @param align Text alignment
81
- * @param entitySize Entity size
82
- */
77
+ * @brief Align the text
78
+ * @param align Text alignment
79
+ * @param entitySize Entity size
80
+ */
83
81
void _textAlign (const shared::graphics::TextAlign &align, const shared::types::Vector2i &entitySize);
84
82
85
83
/* *
@@ -92,4 +90,23 @@ class arcade::graphics::sfml::window::Renderer {
92
90
* @param props Texture properties
93
91
*/
94
92
void _setTextureRectAndScale (const shared::graphics::TextureProps &props);
95
- };
93
+
94
+ /* *
95
+ * @brief Cast a shared pointer from a type to another
96
+ * @tparam From Type from which to cast
97
+ * @tparam To Type to which cast
98
+ * @param from Value to cast
99
+ * @return Casted value
100
+ */
101
+ template <class From , class To >
102
+ static std::shared_ptr<To> _castOrThrow (std::shared_ptr<From> from) {
103
+ std::shared_ptr<To> to = std::dynamic_pointer_cast<To>(from);
104
+ if (!to) {
105
+ throw common::exceptions::WindowException (
106
+ " Failed to cast shared pointer of:" + std::string (typeid (from).name ()) + " to " + typeid (to).name (),
107
+ " SFML Library Renderer::_castOrThrow"
108
+ );
109
+ }
110
+ return to;
111
+ };
112
+ };
0 commit comments