1
Graphics / Re: origin relative to the Transformable
« on: September 06, 2024, 09:05:26 am »
I cannot speak of SFML team. But you can easily add template that handles that for each Transformable.
Now you can try if it works. It would even work for your graphical entities based on sf::Transformable.
#include <SFML/Graphics/Transformable.hpp>
#include <type_traits>
template <typename T>
concept SfTransformable = std::is_base_of_v<sf::Transformable, T>;
void setOriginToCenter (SfTransformable auto& sfTransformableObject)
{
sfTransformableObject.setOrigin(sfTransformableObject.getLocalBounds().getPosition()
+ (sfTransformableObject.getLocalBounds().getSize() / 2.f));
}
#include <type_traits>
template <typename T>
concept SfTransformable = std::is_base_of_v<sf::Transformable, T>;
void setOriginToCenter (SfTransformable auto& sfTransformableObject)
{
sfTransformableObject.setOrigin(sfTransformableObject.getLocalBounds().getPosition()
+ (sfTransformableObject.getLocalBounds().getSize() / 2.f));
}
Now you can try if it works. It would even work for your graphical entities based on sf::Transformable.
#include <SFML/Graphics.hpp>
int main ()
{
sf::RectangleShape shape;
setOriginToCenter(shape);
sf::Text text;
setOriginToCenter(text);
int a;
//setOriginToCenter(a); // error - do not pass concept SfTransformable
sf::Vector2f vec2f;
//setOriginToCenter(vec2f) // error - do not pass concept SfTransformable
return 0;
}
int main ()
{
sf::RectangleShape shape;
setOriginToCenter(shape);
sf::Text text;
setOriginToCenter(text);
int a;
//setOriginToCenter(a); // error - do not pass concept SfTransformable
sf::Vector2f vec2f;
//setOriginToCenter(vec2f) // error - do not pass concept SfTransformable
return 0;
}