Browse Source

Updated mobile/interop backends

pull/2829/head
Nikita Tsukanov 7 years ago
parent
commit
b7f971d87d
  1. 8
      src/Android/Avalonia.Android/Platform/Specific/Helpers/AndroidKeyboardEventsHelper.cs
  2. 6
      src/Android/Avalonia.Android/Platform/Specific/Helpers/AndroidTouchEventsHelper.cs
  3. 32
      src/Windows/Avalonia.Win32.Interop/Wpf/WpfTopLevelImpl.cs
  4. 2
      src/iOS/Avalonia.iOS/Specific/KeyboardEventsHelper.cs
  5. 10
      src/iOS/Avalonia.iOS/TopLevelImpl.cs

8
src/Android/Avalonia.Android/Platform/Specific/Helpers/AndroidKeyboardEventsHelper.cs

@ -72,12 +72,12 @@ namespace Avalonia.Android.Platform.Specific.Helpers
return false;
}
private static InputModifiers GetModifierKeys(KeyEvent e)
private static RawInputModifiers GetModifierKeys(KeyEvent e)
{
var rv = InputModifiers.None;
var rv = RawInputModifiers.None;
if (e.IsCtrlPressed) rv |= InputModifiers.Control;
if (e.IsShiftPressed) rv |= InputModifiers.Shift;
if (e.IsCtrlPressed) rv |= RawInputModifiers.Control;
if (e.IsShiftPressed) rv |= RawInputModifiers.Shift;
return rv;
}

6
src/Android/Avalonia.Android/Platform/Specific/Helpers/AndroidTouchEventsHelper.cs

@ -78,12 +78,12 @@ namespace Avalonia.Android.Platform.Specific.Helpers
if (mouseEventType == RawPointerEventType.LeftButtonDown)
{
var me = new RawPointerEventArgs(mouseDevice, (uint)eventTime.Ticks, inputRoot,
RawPointerEventType.Move, _point, InputModifiers.None);
RawPointerEventType.Move, _point, RawInputModifiers.None);
_view.Input(me);
}
var mouseEvent = new RawPointerEventArgs(mouseDevice, (uint)eventTime.Ticks, inputRoot,
mouseEventType.Value, _point, InputModifiers.LeftMouseButton);
mouseEventType.Value, _point, RawInputModifiers.LeftMouseButton);
_view.Input(mouseEvent);
if (e.Action == MotionEventActions.Move && mouseDevice.Captured == null)
@ -102,7 +102,7 @@ namespace Avalonia.Android.Platform.Specific.Helpers
(uint)eventTime.Ticks,
inputRoot,
_point,
new Vector(vectorX * correction / ps, vectorY * correction / ps), InputModifiers.LeftMouseButton);
new Vector(vectorX * correction / ps, vectorY * correction / ps), RawInputModifiers.LeftMouseButton);
_view.Input(mouseWheelEvent);
}
_lastTouchMovePoint = _point;

32
src/Windows/Avalonia.Win32.Interop/Wpf/WpfTopLevelImpl.cs

@ -142,27 +142,33 @@ namespace Avalonia.Win32.Interop.Wpf
protected override void OnLostFocus(RoutedEventArgs e) => LostFocus?.Invoke();
InputModifiers GetModifiers()
RawInputModifiers GetModifiers(MouseEventArgs e)
{
var state = Keyboard.Modifiers;
var rv = default(InputModifiers);
var rv = default(RawInputModifiers);
if (state.HasFlag(ModifierKeys.Windows))
rv |= InputModifiers.Windows;
rv |= RawInputModifiers.Meta;
if (state.HasFlag(ModifierKeys.Alt))
rv |= InputModifiers.Alt;
rv |= RawInputModifiers.Alt;
if (state.HasFlag(ModifierKeys.Control))
rv |= InputModifiers.Control;
rv |= RawInputModifiers.Control;
if (state.HasFlag(ModifierKeys.Shift))
rv |= InputModifiers.Shift;
//TODO: mouse modifiers
rv |= RawInputModifiers.Shift;
if (e != null)
{
if (e.LeftButton == MouseButtonState.Pressed)
rv |= RawInputModifiers.LeftMouseButton;
if (e.RightButton == MouseButtonState.Pressed)
rv |= RawInputModifiers.RightMouseButton;
if (e.MiddleButton == MouseButtonState.Pressed)
rv |= RawInputModifiers.MiddleMouseButton;
}
return rv;
}
void MouseEvent(RawPointerEventType type, MouseEventArgs e)
=> _ttl.Input?.Invoke(new RawPointerEventArgs(_mouse, (uint)e.Timestamp, _inputRoot, type,
e.GetPosition(this).ToAvaloniaPoint(), GetModifiers()));
e.GetPosition(this).ToAvaloniaPoint(), GetModifiers(e)));
protected override void OnMouseDown(MouseButtonEventArgs e)
{
@ -201,19 +207,19 @@ namespace Avalonia.Win32.Interop.Wpf
protected override void OnMouseWheel(MouseWheelEventArgs e) =>
_ttl.Input?.Invoke(new RawMouseWheelEventArgs(_mouse, (uint) e.Timestamp, _inputRoot,
e.GetPosition(this).ToAvaloniaPoint(), new Vector(0, e.Delta), GetModifiers()));
e.GetPosition(this).ToAvaloniaPoint(), new Vector(0, e.Delta), GetModifiers(e)));
protected override void OnMouseLeave(MouseEventArgs e) => MouseEvent(RawPointerEventType.LeaveWindow, e);
protected override void OnKeyDown(KeyEventArgs e)
=> _ttl.Input?.Invoke(new RawKeyEventArgs(_keyboard, (uint) e.Timestamp, RawKeyEventType.KeyDown,
(Key) e.Key,
GetModifiers()));
GetModifiers(null)));
protected override void OnKeyUp(KeyEventArgs e)
=> _ttl.Input?.Invoke(new RawKeyEventArgs(_keyboard, (uint)e.Timestamp, RawKeyEventType.KeyUp,
(Key)e.Key,
GetModifiers()));
GetModifiers(null)));
protected override void OnTextInput(TextCompositionEventArgs e)
=> _ttl.Input?.Invoke(new RawTextInputEventArgs(_keyboard, (uint) e.Timestamp, e.Text));

2
src/iOS/Avalonia.iOS/Specific/KeyboardEventsHelper.cs

@ -76,7 +76,7 @@ namespace Avalonia.iOS.Specific
private void HandleKey(Key key, RawKeyEventType type)
{
var rawKeyEvent = new RawKeyEventArgs(KeyboardDevice.Instance, (uint)DateTime.Now.Ticks, type, key, InputModifiers.None);
var rawKeyEvent = new RawKeyEventArgs(KeyboardDevice.Instance, (uint)DateTime.Now.Ticks, type, key, RawInputModifiers.None);
_view.Input(rawKeyEvent);
}

10
src/iOS/Avalonia.iOS/TopLevelImpl.cs

@ -92,7 +92,7 @@ namespace Avalonia.iOS
_inputRoot,
RawPointerEventType.LeftButtonUp,
location,
InputModifiers.None));
RawInputModifiers.None));
}
}
@ -105,10 +105,10 @@ namespace Avalonia.iOS
var location = touch.LocationInView(this).ToAvalonia();
_touchLastPoint = location;
Input?.Invoke(new RawPointerEventArgs(iOSPlatform.MouseDevice, (uint)touch.Timestamp, _inputRoot,
RawPointerEventType.Move, location, InputModifiers.None));
RawPointerEventType.Move, location, RawInputModifiers.None));
Input?.Invoke(new RawPointerEventArgs(iOSPlatform.MouseDevice, (uint)touch.Timestamp, _inputRoot,
RawPointerEventType.LeftButtonDown, location, InputModifiers.None));
RawPointerEventType.LeftButtonDown, location, RawInputModifiers.None));
}
}
@ -120,14 +120,14 @@ namespace Avalonia.iOS
var location = touch.LocationInView(this).ToAvalonia();
if (iOSPlatform.MouseDevice.Captured != null)
Input?.Invoke(new RawPointerEventArgs(iOSPlatform.MouseDevice, (uint)touch.Timestamp, _inputRoot,
RawPointerEventType.Move, location, InputModifiers.LeftMouseButton));
RawPointerEventType.Move, location, RawInputModifiers.LeftMouseButton));
else
{
//magic number based on test - correction of 0.02 is working perfect
double correction = 0.02;
Input?.Invoke(new RawMouseWheelEventArgs(iOSPlatform.MouseDevice, (uint)touch.Timestamp,
_inputRoot, location, (location - _touchLastPoint) * correction, InputModifiers.LeftMouseButton));
_inputRoot, location, (location - _touchLastPoint) * correction, RawInputModifiers.LeftMouseButton));
}
_touchLastPoint = location;
}

Loading…
Cancel
Save