SDL2.0 (Windows)
I believe I’ve found a bug with mouse events which I’ve been able to re-produce in my app and other apps that captures MOUSEBUTTONDOWN and MOUSEMOTION events.
The Basics:
Code:
// For Simplicity
SDL_Event event;
while(SDL_PollEvent(&event) != 0)
{
switch (event.type)
{
case SDL_MOUSEBUTTONUP:
// If the left mouse button release, reset flag to false!
if( event.button.button == SDL_BUTTON_LEFT )
{
isMouseSelection = false;
//Debuggin: Get the mouse offsets
std::cout << "Mouse released at: " << event.button.x << "," << event.button.y << std::endl;
}
break;
case SDL_MOUSEBUTTONDOWN:
// We want mouse down on left button only.
if( event.button.button == SDL_BUTTON_LEFT )
{
// Mark extra flag that the mouse down has executed.
isMouseSelection = true;
//Debuggin: Get the mouse offsets
std::cout << "Mouse pressed at: " << event.button.x << "," << event.button.y << std::endl;
}
break;
case SDL_MOUSEMOTION:
// We only want Motion when the Left button is down!
// And isMouseSelection is TRUE
if( event.button.button == SDL_BUTTON_LEFT
&& isMouseSelection)
{
std::cout << "Mouse moved by: "
<< event.motion.xrel << ", " << event.motion.yrel
<< " : "
<< event.motion.x << "," << event.motion.y
<< std::endl;
}
break;
}
}
Pretty simple, On left button down, we set isMouseSelection = true. On release we set isMouseSelection = false.
Only when isMouseSelection == true & LEFT mouse is down, should the MOUSEMOTION be captured.
The problem:
If your in a window (not full screen) and change focus to the DESKTOP or another window
- Left Click outside of the SDL window to change the focus to the desktop or another program.
- Left Click back on your programs windows (But click the Window Title So your not clicking on the actual canvas, your clicking on the window border itself at the TOP).
When moving your mouse around the canvas this appears to register the active MOUSEMOTION event for the LEFT button. (meaning SDL thinks the left mouse button is still being held down).
As I move the mouse around the following is somehow showing true and displaying the MOTION output over the entire canvas until i reset it by clicking and releasing the LEFT Mouse button again.
Both the Left Mouse Button, and the Variable only set in the MouseDown event is active!
Code:
event.button.button == SDL_BUTTON_LEFT
&& isMouseSelection
I can see that clicking the window title might execute a MOUSEBUTTONDOWN event, but it should also register a MOUSEBUTTONUP on the release which it doesn’t doing.
It should also not be showing event.button.button == SDL_BUTTON_LEFT in the MOUSEMOTION event becasue the button is not being held down, only the program title was clicked and released for focus.
This is leaving the mouse event active the entire time which i believe should be looked into and corrected.
I hope I’ve explained this clearly.