Fix mouse relative calculation to ensure pointer goes from minX to maxX (and Y) included.
Signed-off-by: Andrea Odetti <mariofutire@gmail.com>
This commit is contained in:
parent
db71bb1a4c
commit
d68b503d0d
5 changed files with 23 additions and 9 deletions
|
@ -152,8 +152,11 @@ namespace sa2
|
|||
int width, height;
|
||||
SDL_GetWindowSize(myWindow.get(), &width, &height);
|
||||
|
||||
x = double(motion.x) / double(width);
|
||||
y = double(std::max(motion.y, myDeadTopZone) - myDeadTopZone) / double(std::max(height - myDeadTopZone, 1));
|
||||
const int posY = std::max(motion.y - myDeadTopZone, 0);
|
||||
height = std::max(height - myDeadTopZone, 1); // a real window has a minimum size of 1
|
||||
|
||||
x = GetRelativePosition(motion.x, width);
|
||||
y = GetRelativePosition(posY, height);
|
||||
}
|
||||
|
||||
void SDLImGuiFrame::RenderPresent()
|
||||
|
|
|
@ -39,7 +39,7 @@ namespace sa2
|
|||
size_t myBorderlessWidth;
|
||||
size_t myBorderlessHeight;
|
||||
|
||||
Sint32 myDeadTopZone; // for mouse position
|
||||
int myDeadTopZone; // for mouse position
|
||||
|
||||
SDL_GLContext myGLContext;
|
||||
ImTextureID myTexture;
|
||||
|
|
|
@ -65,8 +65,8 @@ namespace sa2
|
|||
int width, height;
|
||||
SDL_GetWindowSize(myWindow.get(), &width, &height);
|
||||
|
||||
x = double(motion.x) / double(width);
|
||||
y = double(motion.y) / double(height);
|
||||
x = GetRelativePosition(motion.x, width);
|
||||
y = GetRelativePosition(motion.y, height);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -296,6 +296,13 @@ namespace sa2
|
|||
}
|
||||
}
|
||||
|
||||
double SDLFrame::GetRelativePosition(const int value, const int size)
|
||||
{
|
||||
// the minimum size of a window is 1
|
||||
const double result = double(value) / double(std::max(1, size - 1));
|
||||
return result;
|
||||
}
|
||||
|
||||
void SDLFrame::ProcessMouseMotion(const SDL_MouseMotionEvent & motion)
|
||||
{
|
||||
CardManager & cardManager = GetCardMgr();
|
||||
|
@ -339,14 +346,16 @@ namespace sa2
|
|||
}
|
||||
else
|
||||
{
|
||||
const int sizeX = iMaxX - iMinX + 1;
|
||||
const int sizeY = iMaxY - iMinY + 1;
|
||||
const int sizeX = iMaxX - iMinX;
|
||||
const int sizeY = iMaxY - iMinY;
|
||||
|
||||
|
||||
double x, y;
|
||||
GetRelativeMousePosition(motion, x, y);
|
||||
|
||||
const int newX = lround(x * sizeX + iMinX);
|
||||
const int newY = lround(y * sizeY + iMinY);
|
||||
const int newX = lround(x * sizeX) + iMinX;
|
||||
const int newY = lround(y * sizeY) + iMinY;
|
||||
|
||||
dx = newX - iX;
|
||||
dy = newY - iY;
|
||||
}
|
||||
|
|
|
@ -56,6 +56,8 @@ namespace sa2
|
|||
void ExecuteInRunningMode(const size_t msNextFrame);
|
||||
void ExecuteInDebugMode(const size_t msNextFrame);
|
||||
|
||||
static double GetRelativePosition(const int value, const int width);
|
||||
|
||||
std::shared_ptr<SDL_Window> myWindow;
|
||||
|
||||
bool myForceCapsLock;
|
||||
|
|
Loading…
Add table
Reference in a new issue