diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2017-11-21 13:03:32 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-21 13:03:32 +0100 |
commit | 5a23136d1bdc88589ee7082098dadf74afef53c2 (patch) | |
tree | 70f59ef74795849c2941db99d92ba61e36a5bf8a /core | |
parent | ec4d467b4c5edac86af6aaab0545770377294346 (diff) | |
parent | 80ad8afc85a90e6fda1b136b13c1eb42e35c115e (diff) |
Merge pull request #12573 from poke1024/macostouchpad
Native pan and zoom for macOS + InputEventGesture
Diffstat (limited to 'core')
-rw-r--r-- | core/os/input_event.cpp | 90 | ||||
-rw-r--r-- | core/os/input_event.h | 40 |
2 files changed, 122 insertions, 8 deletions
diff --git a/core/os/input_event.cpp b/core/os/input_event.cpp index 6b43f2c63b..103a8e82c2 100644 --- a/core/os/input_event.cpp +++ b/core/os/input_event.cpp @@ -177,6 +177,14 @@ bool InputEventWithModifiers::get_command() const { return command; } +void InputEventWithModifiers::set_modifiers_from_event(const InputEventWithModifiers *event) { + + set_alt(event->get_alt()); + set_shift(event->get_shift()); + set_control(event->get_control()); + set_metakey(event->get_metakey()); +} + void InputEventWithModifiers::_bind_methods() { ClassDB::bind_method(D_METHOD("set_alt", "enable"), &InputEventWithModifiers::set_alt); @@ -436,10 +444,7 @@ Ref<InputEvent> InputEventMouseButton::xformed_by(const Transform2D &p_xform, co mb->set_id(get_id()); mb->set_device(get_device()); - mb->set_alt(get_alt()); - mb->set_shift(get_shift()); - mb->set_control(get_control()); - mb->set_metakey(get_metakey()); + mb->set_modifiers_from_event(this); mb->set_position(l); mb->set_global_position(g); @@ -555,10 +560,7 @@ Ref<InputEvent> InputEventMouseMotion::xformed_by(const Transform2D &p_xform, co mm->set_id(get_id()); mm->set_device(get_device()); - mm->set_alt(get_alt()); - mm->set_shift(get_shift()); - mm->set_control(get_control()); - mm->set_metakey(get_metakey()); + mm->set_modifiers_from_event(this); mm->set_position(l); mm->set_global_position(g); @@ -930,3 +932,75 @@ void InputEventAction::_bind_methods() { InputEventAction::InputEventAction() { pressed = false; } +///////////////////////////// + +void InputEventGesture::set_position(const Vector2 &p_pos) { + + pos = p_pos; +} + +Vector2 InputEventGesture::get_position() const { + + return pos; +} +///////////////////////////// + +void InputEventMagnifyGesture::set_factor(real_t p_factor) { + + factor = p_factor; +} + +real_t InputEventMagnifyGesture::get_factor() const { + + return factor; +} + +Ref<InputEvent> InputEventMagnifyGesture::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const { + + Ref<InputEventMagnifyGesture> ev; + ev.instance(); + + ev->set_id(get_id()); + ev->set_device(get_device()); + ev->set_modifiers_from_event(this); + + ev->set_position(p_xform.xform(get_position() + p_local_ofs)); + ev->set_factor(get_factor()); + + return ev; +} + +InputEventMagnifyGesture::InputEventMagnifyGesture() { + + factor = 1.0; +} +///////////////////////////// + +void InputEventPanGesture::set_delta(const Vector2 &p_delta) { + + delta = p_delta; +} + +Vector2 InputEventPanGesture::get_delta() const { + return delta; +} + +Ref<InputEvent> InputEventPanGesture::xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs) const { + + Ref<InputEventPanGesture> ev; + ev.instance(); + + ev->set_id(get_id()); + ev->set_device(get_device()); + ev->set_modifiers_from_event(this); + + ev->set_position(p_xform.xform(get_position() + p_local_ofs)); + ev->set_delta(get_delta()); + + return ev; +} + +InputEventPanGesture::InputEventPanGesture() { + + delta = Vector2(0, 0); +} diff --git a/core/os/input_event.h b/core/os/input_event.h index de3c0232ff..2cba60bede 100644 --- a/core/os/input_event.h +++ b/core/os/input_event.h @@ -213,6 +213,8 @@ public: void set_command(bool p_enabled); bool get_command() const; + void set_modifiers_from_event(const InputEventWithModifiers *event); + InputEventWithModifiers(); }; @@ -468,4 +470,42 @@ public: InputEventAction(); }; +class InputEventGesture : public InputEventWithModifiers { + + GDCLASS(InputEventGesture, InputEventWithModifiers) + + Vector2 pos; + +public: + void set_position(const Vector2 &p_pos); + Vector2 get_position() const; +}; + +class InputEventMagnifyGesture : public InputEventGesture { + + GDCLASS(InputEventMagnifyGesture, InputEventGesture) + real_t factor; + +public: + void set_factor(real_t p_factor); + real_t get_factor() const; + + virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const; + + InputEventMagnifyGesture(); +}; + +class InputEventPanGesture : public InputEventGesture { + + GDCLASS(InputEventPanGesture, InputEventGesture) + Vector2 delta; + +public: + void set_delta(const Vector2 &p_delta); + Vector2 get_delta() const; + + virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const; + + InputEventPanGesture(); +}; #endif |