SDL: Split joystick mouse event generation into two functions

That way it is easier to implement relative mouse movement in
ResidualVM.
This commit is contained in:
Bastien Bouclet 2018-03-18 13:00:21 +01:00
parent 16a1d637b5
commit 2e875a768d
2 changed files with 87 additions and 83 deletions

View file

@ -164,15 +164,11 @@ bool SdlEventSource::processMouseEvent(Common::Event &event, int x, int y) {
return true;
}
bool SdlEventSource::handleKbdMouse(Common::Event &event) {
// returns true if an event is generated
// Skip recording of these events
void SdlEventSource::updateKbdMouse() {
uint32 curTime = g_system->getMillis(true);
if (curTime >= _km.last_time + _km.delay_time) {
int16 oldKmX = _km.x;
int16 oldKmY = _km.y;
if (curTime < _km.last_time + _km.delay_time) {
return;
}
_km.last_time = curTime;
if (_km.x_down_count == 1) {
@ -247,17 +243,24 @@ bool SdlEventSource::handleKbdMouse(Common::Event &event) {
_km.y_vel = 1 * MULTIPLIER;
_km.y_down_count = 1;
}
}
}
bool SdlEventSource::handleKbdMouse(Common::Event &event) {
int16 oldKmX = _km.x;
int16 oldKmY = _km.y;
updateKbdMouse();
if (_km.x != oldKmX || _km.y != oldKmY) {
if (_graphicsManager) {
_graphicsManager->getWindow()->warpMouseInWindow((Uint16)(_km.x / MULTIPLIER), (Uint16)(_km.y / MULTIPLIER));
}
if (_km.x != oldKmX || _km.y != oldKmY) {
event.type = Common::EVENT_MOUSEMOVE;
return processMouseEvent(event, _km.x / MULTIPLIER, _km.y / MULTIPLIER);
}
}
}
return false;
}

View file

@ -135,6 +135,7 @@ protected:
virtual bool handleJoyButtonDown(SDL_Event &ev, Common::Event &event);
virtual bool handleJoyButtonUp(SDL_Event &ev, Common::Event &event);
virtual bool handleJoyAxisMotion(SDL_Event &ev, Common::Event &event);
virtual void updateKbdMouse();
virtual bool handleKbdMouse(Common::Event &event);
#if SDL_VERSION_ATLEAST(2, 0, 0)