aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Bouclet2018-03-18 13:00:21 +0100
committerBastien Bouclet2018-03-18 13:09:00 +0100
commit2e875a768d7419788ec518d41674fc4e91df64df (patch)
tree83144e54d269d34a87d71a46002133de30ec3f49
parent16a1d637b511f2c9e0029f274e6b81fc14a64bca (diff)
downloadscummvm-rg350-2e875a768d7419788ec518d41674fc4e91df64df.tar.gz
scummvm-rg350-2e875a768d7419788ec518d41674fc4e91df64df.tar.bz2
scummvm-rg350-2e875a768d7419788ec518d41674fc4e91df64df.zip
SDL: Split joystick mouse event generation into two functions
That way it is easier to implement relative mouse movement in ResidualVM.
-rw-r--r--backends/events/sdl/sdl-events.cpp165
-rw-r--r--backends/events/sdl/sdl-events.h1
2 files changed, 85 insertions, 81 deletions
diff --git a/backends/events/sdl/sdl-events.cpp b/backends/events/sdl/sdl-events.cpp
index a3c0087b94..1ea97a6350 100644
--- a/backends/events/sdl/sdl-events.cpp
+++ b/backends/events/sdl/sdl-events.cpp
@@ -164,100 +164,103 @@ 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) {
+ return;
+ }
- if (curTime >= _km.last_time + _km.delay_time) {
-
- int16 oldKmX = _km.x;
- int16 oldKmY = _km.y;
+ _km.last_time = curTime;
+ if (_km.x_down_count == 1) {
+ _km.x_down_time = curTime;
+ _km.x_down_count = 2;
+ }
+ if (_km.y_down_count == 1) {
+ _km.y_down_time = curTime;
+ _km.y_down_count = 2;
+ }
- _km.last_time = curTime;
- if (_km.x_down_count == 1) {
- _km.x_down_time = curTime;
- _km.x_down_count = 2;
+ if (_km.x_vel || _km.y_vel) {
+ if (_km.x_down_count) {
+ if (curTime > _km.x_down_time + 300) {
+ if (_km.x_vel > 0)
+ _km.x_vel += MULTIPLIER;
+ else
+ _km.x_vel -= MULTIPLIER;
+ } else if (curTime > _km.x_down_time + 200) {
+ if (_km.x_vel > 0)
+ _km.x_vel = 5 * MULTIPLIER;
+ else
+ _km.x_vel = -5 * MULTIPLIER;
+ }
}
- if (_km.y_down_count == 1) {
- _km.y_down_time = curTime;
- _km.y_down_count = 2;
+ if (_km.y_down_count) {
+ if (curTime > _km.y_down_time + 300) {
+ if (_km.y_vel > 0)
+ _km.y_vel += MULTIPLIER;
+ else
+ _km.y_vel -= MULTIPLIER;
+ } else if (curTime > _km.y_down_time + 200) {
+ if (_km.y_vel > 0)
+ _km.y_vel = 5 * MULTIPLIER;
+ else
+ _km.y_vel = -5 * MULTIPLIER;
+ }
}
- if (_km.x_vel || _km.y_vel) {
- if (_km.x_down_count) {
- if (curTime > _km.x_down_time + 300) {
- if (_km.x_vel > 0)
- _km.x_vel += MULTIPLIER;
- else
- _km.x_vel -= MULTIPLIER;
- } else if (curTime > _km.x_down_time + 200) {
- if (_km.x_vel > 0)
- _km.x_vel = 5 * MULTIPLIER;
- else
- _km.x_vel = -5 * MULTIPLIER;
- }
- }
- if (_km.y_down_count) {
- if (curTime > _km.y_down_time + 300) {
- if (_km.y_vel > 0)
- _km.y_vel += MULTIPLIER;
- else
- _km.y_vel -= MULTIPLIER;
- } else if (curTime > _km.y_down_time + 200) {
- if (_km.y_vel > 0)
- _km.y_vel = 5 * MULTIPLIER;
- else
- _km.y_vel = -5 * MULTIPLIER;
- }
- }
+ int16 speedFactor = computeJoystickMouseSpeedFactor();
+
+ // - The modifier key makes the mouse movement slower
+ // - The extra factor "delay/speedFactor" ensures velocities
+ // are independent of the kbdMouse update rate
+ // - all velocities were originally chosen
+ // at a delay of 25, so that is the reference used here
+ // - note: operator order is important to avoid overflow
+ if (_km.modifier) {
+ _km.x += ((_km.x_vel / 10) * ((int16)_km.delay_time)) / speedFactor;
+ _km.y += ((_km.y_vel / 10) * ((int16)_km.delay_time)) / speedFactor;
+ } else {
+ _km.x += (_km.x_vel * ((int16)_km.delay_time)) / speedFactor;
+ _km.y += (_km.y_vel * ((int16)_km.delay_time)) / speedFactor;
+ }
- int16 speedFactor = computeJoystickMouseSpeedFactor();
-
- // - The modifier key makes the mouse movement slower
- // - The extra factor "delay/speedFactor" ensures velocities
- // are independent of the kbdMouse update rate
- // - all velocities were originally chosen
- // at a delay of 25, so that is the reference used here
- // - note: operator order is important to avoid overflow
- if (_km.modifier) {
- _km.x += ((_km.x_vel / 10) * ((int16)_km.delay_time)) / speedFactor;
- _km.y += ((_km.y_vel / 10) * ((int16)_km.delay_time)) / speedFactor;
- } else {
- _km.x += (_km.x_vel * ((int16)_km.delay_time)) / speedFactor;
- _km.y += (_km.y_vel * ((int16)_km.delay_time)) / speedFactor;
- }
+ if (_km.x < 0) {
+ _km.x = 0;
+ _km.x_vel = -1 * MULTIPLIER;
+ _km.x_down_count = 1;
+ } else if (_km.x > _km.x_max * MULTIPLIER) {
+ _km.x = _km.x_max * MULTIPLIER;
+ _km.x_vel = 1 * MULTIPLIER;
+ _km.x_down_count = 1;
+ }
- if (_km.x < 0) {
- _km.x = 0;
- _km.x_vel = -1 * MULTIPLIER;
- _km.x_down_count = 1;
- } else if (_km.x > _km.x_max * MULTIPLIER) {
- _km.x = _km.x_max * MULTIPLIER;
- _km.x_vel = 1 * MULTIPLIER;
- _km.x_down_count = 1;
- }
+ if (_km.y < 0) {
+ _km.y = 0;
+ _km.y_vel = -1 * MULTIPLIER;
+ _km.y_down_count = 1;
+ } else if (_km.y > _km.y_max * MULTIPLIER) {
+ _km.y = _km.y_max * MULTIPLIER;
+ _km.y_vel = 1 * MULTIPLIER;
+ _km.y_down_count = 1;
+ }
+ }
+}
- if (_km.y < 0) {
- _km.y = 0;
- _km.y_vel = -1 * MULTIPLIER;
- _km.y_down_count = 1;
- } else if (_km.y > _km.y_max * MULTIPLIER) {
- _km.y = _km.y_max * MULTIPLIER;
- _km.y_vel = 1 * MULTIPLIER;
- _km.y_down_count = 1;
- }
+bool SdlEventSource::handleKbdMouse(Common::Event &event) {
+ int16 oldKmX = _km.x;
+ int16 oldKmY = _km.y;
- if (_graphicsManager) {
- _graphicsManager->getWindow()->warpMouseInWindow((Uint16)(_km.x / MULTIPLIER), (Uint16)(_km.y / MULTIPLIER));
- }
+ updateKbdMouse();
- if (_km.x != oldKmX || _km.y != oldKmY) {
- event.type = Common::EVENT_MOUSEMOVE;
- return processMouseEvent(event, _km.x / MULTIPLIER, _km.y / MULTIPLIER);
- }
+ if (_km.x != oldKmX || _km.y != oldKmY) {
+ if (_graphicsManager) {
+ _graphicsManager->getWindow()->warpMouseInWindow((Uint16)(_km.x / MULTIPLIER), (Uint16)(_km.y / MULTIPLIER));
}
+
+ event.type = Common::EVENT_MOUSEMOVE;
+ return processMouseEvent(event, _km.x / MULTIPLIER, _km.y / MULTIPLIER);
}
+
return false;
}
diff --git a/backends/events/sdl/sdl-events.h b/backends/events/sdl/sdl-events.h
index c4c2ab406d..2899b584af 100644
--- a/backends/events/sdl/sdl-events.h
+++ b/backends/events/sdl/sdl-events.h
@@ -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)