SFML community forums
General => Feature requests => Topic started by: jstasiak on April 12, 2010, 01:29:48 pm
-
In my code I pretty often use rects and calculate their corners, this is why I use a subclass of Rect<T> class to get following behaviour:
template <typename T>
sf::Vector2<T> Rect<T>::GetP1() const
{
return Vector2<T>(Left, Top);
}
template <typename T>
sf::Vector2<T> Rect<T>::GetP2() const
{
return Vector2<T>(Right, Bottom);
}
I believe it could be useful to add it to SFML. It makes code like
Rectangle(rect.left, rect.top, rect.right, rect.bottom, ...);
// or
Rectangle(Vector2f(rect.left, rect.top), Vector2f(rect.right, rect.bottom), ...);
a little shorter:
Rectangle(rect.GetP1(), rect.GetP2(), ...);
-
Hi
Why should it be in SFML? You can easily write functions on top of the sf::Rect structure (without creating your own subclass, which is a bad solution by the way).
template <typename T>
sf::Vector2<T> TopLeft(const sf::Rect<T>& rect) const
{
return Vector2<T>(rect.Left, rect.Top);
}
template <typename T>
sf::Vector2<T> BottomRight(const sf::Rect<T>& rect) const
{
return Vector2<T>(rect.Right, rect.Bottom);
}
The point is that a lot of people will need a lot of different shortcuts/features for sf::Rect. I don't want to end up with a bloated class so I just define the minimal stuff and let you do whatever you want with it.
-
Solution is as good as it fit my needs - ergo it is good solution dispite your opinion. :)
My point is - if a lot of people need a lot (different) of shortcuts - maybe one should take most wanted and put into SFML? Libraries are to make life easier and to programmers code less as far as I remember - but it's only my $0.03.
-
I understand your point of view. However this feature is not part of the "most wanted" ones so far ;)
-
I thought rects in 2.0 were going to be w,h,x,y?
If so I think I will switch to 2.0 because I don't have to convert all my rect code.
-
I thought rects in 2.0 were going to be w,h,x,y?
They are.
-
I thought rects in 2.0 were going to be w,h,x,y?
They are.
Awesome man, good job.
Yeah, forget this corner stuff. I'm building a rect, not a rhombus.