Fix mouse position backward compatibility with new SDL2 versions.

Clamp the mouse coordinates to the window's dimensions.
This commit is contained in:
Sasha Szpakowski
2023-07-01 17:53:29 -03:00
parent 6563aec89d
commit e582677344
5 changed files with 50 additions and 14 deletions
+7
View File
@@ -1124,6 +1124,13 @@ int Window::getPixelHeight() const
return pixelHeight;
}
void Window::clampPositionInWindow(double *wx, double *wy) const
{
if (wx != nullptr)
*wx = std::min(std::max(0.0, *wx), (double) getWidth() - 1);
if (wy != nullptr)
*wy = std::min(std::max(0.0, *wy), (double) getHeight() - 1);
}
void Window::windowToPixelCoords(double *x, double *y) const
{
+2
View File
@@ -104,6 +104,8 @@ public:
int getPixelWidth() const override;
int getPixelHeight() const override;
void clampPositionInWindow(double *wx, double *wy) const override;
void windowToPixelCoords(double *x, double *y) const override;
void pixelToWindowCoords(double *x, double *y) const override;