hello there, i'am new to this forums and ofcourse SFML and i like it so far.
i'am following an old tutorial (2010) about how to use SFML (v1.6 i think) -am now using v2.3.2 with vs2015- to make a simple game.
in the tutorial there is a point where i need to determine the mouse coordinates in an image menu to act accordingly. when i used the "Contains" function it always select the first option even tho i click on the other one, it only chooses the second options when i click Significantly lower than its position on the screen.
then i tried the normal (x >= left) && (x < width) && (y >= top) && (y < height) test and it worked correctly.
i will post the Project code here so you can check it yourself.
i managed to fix the "Contains" function by checking (if any of its parts is less than 0) so i process your code, else it makes a normal detection...
template <typename T>
bool Rect<T>::contains(T x, T y) const
{
// Rectangles with negative dimensions are allowed, so we must handle them correctly
if (left < 0 || top < 0 || width < 0 || height < 0 )
{
// Compute the real min and max of the rectangle on both axes
T minX = std::min( left, static_cast<T>( left + width ) );
T maxX = std::max( left, static_cast<T>( left + width ) );
T minY = std::min( top, static_cast<T>( top + height ) );
T maxY = std::max( top, static_cast<T>( top + height ) );
return ( x >= minX ) && ( x < maxX ) && ( y >= minY ) && ( y < maxY );
}
else
return (x >= left) && (x < width) && (y >= top) && (y < height);
}
the function to check is found in MainMenu.cpp -> HandleClick(int x, int y) ------ line57