General => Feature requests => Topic started by: Phanoo on October 30, 2014, 02:09:31 pm
Title: Set an object's color without creating a color object
Post by: Phanoo on October 30, 2014, 02:09:31 pm
A small wish for me:
Allow to set color to sprites/shapes without having to create a Color object.
example: Sprite s; s.setColor(200,200,200,100);
instead of s.setColor(Color(200,200,200,100));
same with the RectangleShape constructor. Set directly its size, without having to create a vector2f object: RectangleShape rect(10,10) instead of RectangleShape rect(Vector2f(10,10))
The small things that makes life easier :)
I like SFML's Oriented Object style , but sometimes it's a bit too heavy
Title: Re: Set an object's color without creating a color object
Post by: Laurent on October 30, 2014, 02:36:58 pm
Really? Is it going to change your life? Does it deserve that we create tons of overloads and make the API bigger than it should be?
Anyway... with C++11 support you'll be able to write something close to what you want:
s.setColor({200,200,200,100});
Title: Re: Set an object's color without creating a color object
Post by: Phanoo on October 30, 2014, 03:52:02 pm
It just makes the code looks clearer, i think we need to have both like it's already the case for some methods (setPosition ? i'm not sure i can't verify now, but for some class i can pass either a Vector2f or two floats x and y)
Title: Re: Set an object's color without creating a color object
Post by: Ixrec on October 30, 2014, 04:28:53 pm
Though I agree it's not worth adding these overloads solely for convenience (after all, there's a reason we're supposed to write out std:: and sf:: every single time), I think there might be a legitimate concern about consistency. Looking just at sf::RectangleShape, we have:
It does seem at least a little inconsistent that the constructor and the setSize methods don't have a two-floats overload when all the other methods taking a Vector2f do.
Maybe it's only worth changing this stuff for SFML 3 when sweeping changes to the APIs are possible, but we should probably aim to have a consistent rule about when "piecewise overloads" are available and when you have to go through a vocabulary type (even if C++11 makes it as simple as an extra pair of curly braces).
My first idea for such a rule: If the type has only one constructor taking scalars (like sf::Vector2f or sf::Color) and the method takes nothing but that type (so no risk of confusion) then provide a piecewise overload. Alternatively, I'd probably accept the other extreme of removing all such overloads and instead requiring the extra {} every single time, assuming SFML 3 will in fact be C++11-only.
Title: Re: Set an object's color without creating a color object
Post by: binary1248 on October 30, 2014, 04:39:43 pm
Come SFML 3, we might drop the single component overloads for consistency, since as Laurent already showed, it becomes trivial to pass in the values using braces instead.
Title: Re: Set an object's color without creating a color object
Post by: Nexus on October 30, 2014, 10:09:38 pm
The reason why this is not provided is combinatorial explosion: instead of having a constructor for a type once, you need to provide a separate overload everywhere the type is used as a parameter.
I'm also in favor of removing the component-wise overloads in SFML 3. It has the nice side effect of motivating people to use the classes as intended; for example I could imagine that it helps people understand the concept of vectors as an abstraction of separate X/Y coordinates.
Title: Re: Set an object's color without creating a color object
Post by: Jesper Juhl on October 30, 2014, 11:39:30 pm
Given that it's trivial to just call the relevant functions with {x, y, z} in modern C++, I think the overloads should just go away. Just my opinion.
Title: Re: Set an object's color without creating a color object
Post by: minirop on November 07, 2014, 11:54:04 pm