summaryrefslogtreecommitdiff
path: root/platform/osx
diff options
context:
space:
mode:
Diffstat (limited to 'platform/osx')
-rw-r--r--platform/osx/os_osx.mm62
-rw-r--r--platform/osx/power_osx.cpp26
2 files changed, 51 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);
}
diff --git a/platform/osx/power_osx.cpp b/platform/osx/power_osx.cpp
index 0057fe8acc..2ef1a65ff1 100644
--- a/platform/osx/power_osx.cpp
+++ b/platform/osx/power_osx.cpp
@@ -27,6 +27,32 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
+/*
+Adapted from corresponding SDL 2.0 code.
+*/
+
+/*
+ Simple DirectMedia Layer
+ Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+
#include "power_osx.h"
#include <CoreFoundation/CoreFoundation.h>