diff options
author | toger5 <toger5@hotmail.de> | 2017-02-22 00:45:31 +0200 |
---|---|---|
committer | RĂ©mi Verschelde <rverschelde@gmail.com> | 2017-05-07 14:23:56 +0200 |
commit | 304a1f5b5a3ce6975952f5cd22d688a246367790 (patch) | |
tree | 14de7920daa3f90af91c668b3edcccdf439ed6f2 /platform/osx | |
parent | c8aea60324e3e219945a805f871363c10292f38b (diff) |
Implemented scrolling factor for smooth trackpad scrolling
Working platforms platform: OSX, Windows.
Support for almost all ui elements, including project list.
Diffstat (limited to 'platform/osx')
-rw-r--r-- | platform/osx/os_osx.mm | 62 |
1 files changed, 25 insertions, 37 deletions
diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm index c6c2e6dab1..7a914a88fb 100644 --- a/platform/osx/os_osx.mm +++ b/platform/osx/os_osx.mm @@ -788,6 +788,22 @@ static int translateKey(unsigned int key) { */ } +inline void sendScrollEvent(int button, double factor) { + InputEvent ev; + ev.type = InputEvent::MOUSE_BUTTON; + ev.mouse_button.button_index = button; + ev.mouse_button.factor = factor; + ev.mouse_button.pressed = true; + ev.mouse_button.x = mouse_x; + ev.mouse_button.y = mouse_y; + ev.mouse_button.global_x = mouse_x; + ev.mouse_button.global_y = mouse_y; + ev.mouse_button.button_mask = button_mask; + OS_OSX::singleton->push_input(ev); + ev.mouse_button.pressed = false; + OS_OSX::singleton->push_input(ev); +} + - (void)scrollWheel:(NSEvent *)event { double deltaX, deltaY; @@ -797,48 +813,21 @@ static int translateKey(unsigned int key) { deltaY = [event scrollingDeltaY]; if ([event hasPreciseScrollingDeltas]) { - deltaX *= 0.1; - deltaY *= 0.1; + deltaX *= 0.03; + deltaY *= 0.03; } - } else { + } else +#endif // MAC_OS_X_VERSION_MAX_ALLOWED + { deltaX = [event deltaX]; deltaY = [event deltaY]; } -#else - deltaX = [event deltaX]; - deltaY = [event deltaY]; -#endif /*MAC_OS_X_VERSION_MAX_ALLOWED*/ - - if (fabs(deltaY)) { - - InputEvent ev; - ev.type = InputEvent::MOUSE_BUTTON; - ev.mouse_button.button_index = deltaY > 0 ? BUTTON_WHEEL_UP : BUTTON_WHEEL_DOWN; - ev.mouse_button.pressed = true; - ev.mouse_button.x = mouse_x; - ev.mouse_button.y = mouse_y; - ev.mouse_button.global_x = mouse_x; - ev.mouse_button.global_y = mouse_y; - ev.mouse_button.button_mask = button_mask; - OS_OSX::singleton->push_input(ev); - ev.mouse_button.pressed = false; - OS_OSX::singleton->push_input(ev); - } if (fabs(deltaX)) { - - InputEvent ev; - ev.type = InputEvent::MOUSE_BUTTON; - ev.mouse_button.button_index = deltaX < 0 ? BUTTON_WHEEL_RIGHT : BUTTON_WHEEL_LEFT; - ev.mouse_button.pressed = true; - ev.mouse_button.x = mouse_x; - ev.mouse_button.y = mouse_y; - ev.mouse_button.global_x = mouse_x; - ev.mouse_button.global_y = mouse_y; - ev.mouse_button.button_mask = button_mask; - OS_OSX::singleton->push_input(ev); - ev.mouse_button.pressed = false; - OS_OSX::singleton->push_input(ev); + sendScrollEvent(0 > deltaX ? BUTTON_WHEEL_RIGHT : BUTTON_WHEEL_LEFT, fabs(deltaX * 0.3)); + } + if (fabs(deltaY)) { + sendScrollEvent(0 < deltaY ? BUTTON_WHEEL_UP : BUTTON_WHEEL_DOWN, fabs(deltaY * 0.3)); } } @@ -1630,7 +1619,6 @@ void OS_OSX::process_events() { void OS_OSX::push_input(const InputEvent &p_event) { InputEvent ev = p_event; - //print_line("EV: "+String(ev)); input->parse_input_event(ev); } |