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;
|
int width, height;
|
||||||
SDL_GetWindowSize(myWindow.get(), &width, &height);
|
SDL_GetWindowSize(myWindow.get(), &width, &height);
|
||||||
|
|
||||||
x = double(motion.x) / double(width);
|
const int posY = std::max(motion.y - myDeadTopZone, 0);
|
||||||
y = double(std::max(motion.y, myDeadTopZone) - myDeadTopZone) / double(std::max(height - myDeadTopZone, 1));
|
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()
|
void SDLImGuiFrame::RenderPresent()
|
||||||
|
|
|
@ -39,7 +39,7 @@ namespace sa2
|
||||||
size_t myBorderlessWidth;
|
size_t myBorderlessWidth;
|
||||||
size_t myBorderlessHeight;
|
size_t myBorderlessHeight;
|
||||||
|
|
||||||
Sint32 myDeadTopZone; // for mouse position
|
int myDeadTopZone; // for mouse position
|
||||||
|
|
||||||
SDL_GLContext myGLContext;
|
SDL_GLContext myGLContext;
|
||||||
ImTextureID myTexture;
|
ImTextureID myTexture;
|
||||||
|
|
|
@ -65,8 +65,8 @@ namespace sa2
|
||||||
int width, height;
|
int width, height;
|
||||||
SDL_GetWindowSize(myWindow.get(), &width, &height);
|
SDL_GetWindowSize(myWindow.get(), &width, &height);
|
||||||
|
|
||||||
x = double(motion.x) / double(width);
|
x = GetRelativePosition(motion.x, width);
|
||||||
y = double(motion.y) / double(height);
|
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)
|
void SDLFrame::ProcessMouseMotion(const SDL_MouseMotionEvent & motion)
|
||||||
{
|
{
|
||||||
CardManager & cardManager = GetCardMgr();
|
CardManager & cardManager = GetCardMgr();
|
||||||
|
@ -339,14 +346,16 @@ namespace sa2
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const int sizeX = iMaxX - iMinX + 1;
|
const int sizeX = iMaxX - iMinX;
|
||||||
const int sizeY = iMaxY - iMinY + 1;
|
const int sizeY = iMaxY - iMinY;
|
||||||
|
|
||||||
|
|
||||||
double x, y;
|
double x, y;
|
||||||
GetRelativeMousePosition(motion, x, y);
|
GetRelativeMousePosition(motion, x, y);
|
||||||
|
|
||||||
const int newX = lround(x * sizeX + iMinX);
|
const int newX = lround(x * sizeX) + iMinX;
|
||||||
const int newY = lround(y * sizeY + iMinY);
|
const int newY = lround(y * sizeY) + iMinY;
|
||||||
|
|
||||||
dx = newX - iX;
|
dx = newX - iX;
|
||||||
dy = newY - iY;
|
dy = newY - iY;
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,6 +56,8 @@ namespace sa2
|
||||||
void ExecuteInRunningMode(const size_t msNextFrame);
|
void ExecuteInRunningMode(const size_t msNextFrame);
|
||||||
void ExecuteInDebugMode(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;
|
std::shared_ptr<SDL_Window> myWindow;
|
||||||
|
|
||||||
bool myForceCapsLock;
|
bool myForceCapsLock;
|
||||||
|
|
Loading…
Add table
Reference in a new issue