mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-31 19:51:45 +02:00
Fix initial mouse position and unsafe SDL_Event union access
This commit is contained in:
@@ -406,11 +406,11 @@ void EventProcess(SDL_Event event)
|
|||||||
// if mouse hasn't moved yet, sdl will send 0,0. We don't want that
|
// if mouse hasn't moved yet, sdl will send 0,0. We don't want that
|
||||||
if (hasMouseMoved)
|
if (hasMouseMoved)
|
||||||
{
|
{
|
||||||
mousex = event.motion.x;
|
mousex = event.button.x;
|
||||||
mousey = event.motion.y;
|
mousey = event.button.y;
|
||||||
}
|
}
|
||||||
mouseButton = event.button.button;
|
mouseButton = event.button.button;
|
||||||
engine->onMouseClick(event.motion.x, event.motion.y, mouseButton);
|
engine->onMouseClick(mousex, mousey, mouseButton);
|
||||||
|
|
||||||
mouseDown = true;
|
mouseDown = true;
|
||||||
#if !defined(NDEBUG) && !defined(DEBUG)
|
#if !defined(NDEBUG) && !defined(DEBUG)
|
||||||
@@ -421,8 +421,8 @@ void EventProcess(SDL_Event event)
|
|||||||
// if mouse hasn't moved yet, sdl will send 0,0. We don't want that
|
// if mouse hasn't moved yet, sdl will send 0,0. We don't want that
|
||||||
if (hasMouseMoved)
|
if (hasMouseMoved)
|
||||||
{
|
{
|
||||||
mousex = event.motion.x;
|
mousex = event.button.x;
|
||||||
mousey = event.motion.y;
|
mousey = event.button.y;
|
||||||
}
|
}
|
||||||
mouseButton = event.button.button;
|
mouseButton = event.button.button;
|
||||||
engine->onMouseUnclick(mousex, mousey, mouseButton);
|
engine->onMouseUnclick(mousex, mousey, mouseButton);
|
||||||
@@ -441,6 +441,7 @@ void EventProcess(SDL_Event event)
|
|||||||
{
|
{
|
||||||
//initial mouse coords, sdl won't tell us this if mouse hasn't moved
|
//initial mouse coords, sdl won't tell us this if mouse hasn't moved
|
||||||
CalculateMousePosition(&mousex, &mousey);
|
CalculateMousePosition(&mousex, &mousey);
|
||||||
|
engine->initialMouse(mousex, mousey);
|
||||||
engine->onMouseMove(mousex, mousey);
|
engine->onMouseMove(mousex, mousey);
|
||||||
calculatedInitialMouse = true;
|
calculatedInitialMouse = true;
|
||||||
}
|
}
|
||||||
|
@@ -276,6 +276,12 @@ void Engine::onMouseUnclick(int x, int y, unsigned button)
|
|||||||
state_->DoMouseUp(x, y, button);
|
state_->DoMouseUp(x, y, button);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Engine::initialMouse(int x, int y)
|
||||||
|
{
|
||||||
|
mousexp_ = x;
|
||||||
|
mouseyp_ = y;
|
||||||
|
}
|
||||||
|
|
||||||
void Engine::onMouseMove(int x, int y)
|
void Engine::onMouseMove(int x, int y)
|
||||||
{
|
{
|
||||||
mousex_ = x;
|
mousex_ = x;
|
||||||
|
@@ -25,6 +25,7 @@ namespace ui
|
|||||||
void ShowWindow(Window * window);
|
void ShowWindow(Window * window);
|
||||||
int CloseWindow();
|
int CloseWindow();
|
||||||
|
|
||||||
|
void initialMouse(int x, int y);
|
||||||
void onMouseMove(int x, int y);
|
void onMouseMove(int x, int y);
|
||||||
void onMouseClick(int x, int y, unsigned button);
|
void onMouseClick(int x, int y, unsigned button);
|
||||||
void onMouseUnclick(int x, int y, unsigned button);
|
void onMouseUnclick(int x, int y, unsigned button);
|
||||||
|
Reference in New Issue
Block a user