Fix scrolling behavior by accumulating partial ticks

This commit is contained in:
Cameron Gutman 2016-02-26 14:43:20 -05:00
parent e7b45e5b6c
commit 4f6c547e47
2 changed files with 16 additions and 3 deletions

View File

@ -112,14 +112,25 @@ bool MoonlightInstance::HandleInputEvent(const pp::InputEvent& event) {
}
case PP_INPUTEVENT_TYPE_WHEEL: {
signed char fullTicks;
if (!m_MouseLocked) {
return false;
}
pp::WheelInputEvent wheelEvent(event);
// FIXME: Handle fractional scroll ticks
LiSendScrollEvent((signed char) wheelEvent.GetTicks().y());
// Accumulate the current tick value
m_AccumulatedTicks += wheelEvent.GetTicks().y();
// Compute the number of full ticks
fullTicks = (signed char) m_AccumulatedTicks;
// Send a scroll event if we've completed a full tick
if (fullTicks != 0) {
LiSendScrollEvent(fullTicks);
m_AccumulatedTicks -= fullTicks;
}
return true;
}

View File

@ -44,7 +44,8 @@ class MoonlightInstance : public pp::Instance, public pp::MouseLock {
m_CallbackFactory(this),
m_MouseLocked(false),
m_KeyModifiers(0),
m_WaitingForAllModifiersUp(false) {
m_WaitingForAllModifiersUp(false),
m_AccumulatedTicks(0) {
// This function MUST be used otherwise sockets don't work (nacl_io_init() doesn't work!)
nacl_io_init_ppapi(pp_instance(), pp::Module::Get()->get_browser_interface());
@ -135,6 +136,7 @@ class MoonlightInstance : public pp::Instance, public pp::MouseLock {
bool m_MouseLocked;
char m_KeyModifiers;
bool m_WaitingForAllModifiersUp;
float m_AccumulatedTicks;
};
extern MoonlightInstance* g_Instance;