From a022e984920258d0f4473ce24e2eb8156c2b3d51 Mon Sep 17 00:00:00 2001 From: Ramez Ragaa Date: Tue, 19 Nov 2024 15:30:46 +0200 Subject: [PATCH 1/9] chore: remove GestureRecognizer from Uno.UWP --- .../Uno_UI_Xaml_Core/Given_InputManager.cs | 2 +- .../UI/Input/GestureRecognizer.Gesture.cs | 400 ---------- ...ecognizer.Manipulation.InertiaProcessor.cs | 218 ------ .../Input/GestureRecognizer.Manipulation.cs | 712 ------------------ src/Uno.UWP/UI/Input/GestureRecognizer.cs | 280 ------- src/Uno.UWP/UI/Input/ManipulationDelta.cs | 82 -- .../ManipulationInertiaStartingEventArgs.cs | 50 -- .../UI/Input/ManipulationVelocities.cs | 66 -- 8 files changed, 1 insertion(+), 1809 deletions(-) delete mode 100644 src/Uno.UWP/UI/Input/GestureRecognizer.Gesture.cs delete mode 100644 src/Uno.UWP/UI/Input/GestureRecognizer.Manipulation.InertiaProcessor.cs delete mode 100644 src/Uno.UWP/UI/Input/GestureRecognizer.Manipulation.cs delete mode 100644 src/Uno.UWP/UI/Input/GestureRecognizer.cs delete mode 100644 src/Uno.UWP/UI/Input/ManipulationDelta.cs delete mode 100644 src/Uno.UWP/UI/Input/ManipulationInertiaStartingEventArgs.cs delete mode 100644 src/Uno.UWP/UI/Input/ManipulationVelocities.cs diff --git a/src/Uno.UI.RuntimeTests/Tests/Uno_UI_Xaml_Core/Given_InputManager.cs b/src/Uno.UI.RuntimeTests/Tests/Uno_UI_Xaml_Core/Given_InputManager.cs index 77972928366f..57746e4dcbcf 100644 --- a/src/Uno.UI.RuntimeTests/Tests/Uno_UI_Xaml_Core/Given_InputManager.cs +++ b/src/Uno.UI.RuntimeTests/Tests/Uno_UI_Xaml_Core/Given_InputManager.cs @@ -87,7 +87,7 @@ public async Task When_LeaveElementWhileManipulating_Then_CaptureNotLost() HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, Width = 16, - Height = Windows.UI.Input.GestureRecognizer.Manipulation.StartTouch.TranslateY * 3, + Height = GestureRecognizer.Manipulation.StartTouch.TranslateY * 3, Background = new SolidColorBrush(Colors.DeepPink), ManipulationMode = ManipulationModes.TranslateY, RenderTransform = (transform = new TranslateTransform()) diff --git a/src/Uno.UWP/UI/Input/GestureRecognizer.Gesture.cs b/src/Uno.UWP/UI/Input/GestureRecognizer.Gesture.cs deleted file mode 100644 index cbcba5dce0d4..000000000000 --- a/src/Uno.UWP/UI/Input/GestureRecognizer.Gesture.cs +++ /dev/null @@ -1,400 +0,0 @@ -#nullable enable - -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Reflection; -using Windows.Devices.Input; -using Windows.Foundation; -using Windows.System; - -using Uno; -using Uno.Foundation.Logging; - -#if HAS_UNO_WINUI && IS_UNO_UI_PROJECT -namespace Microsoft.UI.Input -#else -namespace Windows.UI.Input -#endif -{ - public partial class GestureRecognizer - { - /// - /// This is the state machine which handles the gesture ([Double|Right]Tapped and Holding gestures) - /// - internal class Gesture - { - private readonly GestureRecognizer _recognizer; - private DispatcherQueueTimer? _holdingTimer; - private HoldingState? _holdingState; - - public ulong PointerIdentifier { get; } - - public PointerDeviceType PointerType { get; } - - public PointerPoint Down { get; } - - public PointerPoint? Up { get; private set; } - - public bool IsCompleted { get; private set; } - - public bool HasMovedOutOfTapRange { get; private set; } - - public bool HasChangedPointerIdentifier { get; private set; } - - public bool HasExceedMinHoldPressure { get; private set; } - - internal GestureSettings Settings - { - get; - private set; - } - - public Gesture(GestureRecognizer recognizer, PointerPoint down) - { - _recognizer = recognizer; - Settings = recognizer._gestureSettings & GestureSettingsHelper.SupportedGestures; // Keep only flags of supported gestures, so we can more quickly disable us if possible - Settings |= GestureSettings.Tap; // On WinUI, Tap is always raised no matter the flag set on the recognizer - - Down = down; - PointerIdentifier = GetPointerIdentifier(down); - PointerType = (PointerDeviceType)down.PointerDevice.PointerDeviceType; - - // This is how WinUI behaves: it will fire the double tap - // on Down for a double tap instead of the Up. - if (TryRecognizeMultiTap()) - { - IsCompleted = true; - } - else if (SupportsHolding()) - { - StartHoldingTimer(); - } - } - - public void ProcessMove(PointerPoint point) - { - if (IsCompleted) - { - return; - } - - // Update internal state - HasMovedOutOfTapRange |= IsOutOfTapRange(Down.Position, point.Position); - HasChangedPointerIdentifier |= PointerIdentifier != GetPointerIdentifier(point); - HasExceedMinHoldPressure |= point.Properties.Pressure >= HoldMinPressure; - - // Process the pointer - TryUpdateHolding(point); - } - - public void ProcessUp(PointerPoint up) - { - if (IsCompleted) - { - return; - } - - // Update internal state - IsCompleted = true; - Up = up; - - // Process the pointer - TryEndHolding(HoldingState.Completed); - TryRecognize(); - } - - public void ProcessComplete() - { - if (IsCompleted) - { - return; - } - - // Update internal state - IsCompleted = true; - - // Process the pointer - TryEndHolding(HoldingState.Canceled); - TryRecognize(); - } - - public void PreventGestures(GestureSettings gestures) - { - if ((gestures & GestureSettings.Hold) != 0) - { - StopHoldingTimer(); - } - - Settings &= ~gestures; - if ((Settings & GestureSettingsHelper.SupportedGestures) == GestureSettings.None) - { - IsCompleted = true; - } - } - - private void TryRecognize() - { - var recognized = TryRecognizeRightTap() // We check right tap first as for touch a right tap is a press and hold of the finger :) - || TryRecognizeTap(); - - if (!recognized && _recognizer._log.IsEnabled(LogLevel.Debug)) - { - _recognizer._log.Debug("No gesture recognized"); - } - } - - private bool TryRecognizeTap() - { - var isTapGesture = IsTapGesture(LeftButton, this); - if (isTapGesture) - { - // Note: Up cannot be 'null' here! - _recognizer._lastSingleTap = (PointerIdentifier, Up!.Timestamp, Up.Position); - - if (Settings.HasFlag(GestureSettings.Tap)) - { - _recognizer.Tapped?.Invoke(_recognizer, new TappedEventArgs(Down.PointerId, PointerType, Down.Position, tapCount: 1)); - return true; - } - } - - return false; - } - - private bool TryRecognizeMultiTap() - { - if (Settings.HasFlag(GestureSettings.DoubleTap) && IsMultiTapGesture(_recognizer._lastSingleTap, Down)) - { - _recognizer._lastSingleTap = default; // The Recognizer supports only double tap, even on UWP - _recognizer.Tapped?.Invoke(_recognizer, new TappedEventArgs(Down.PointerId, PointerType, Down.Position, tapCount: 2)); - - return true; - } - else - { - return false; - } - } - - private bool TryRecognizeRightTap() - { - if (Settings.HasFlag(GestureSettings.RightTap) && IsRightTapGesture(this, out var isLongPress)) - { - _recognizer.RightTapped?.Invoke(_recognizer, new RightTappedEventArgs(Down.PointerId, PointerType, Down.Position)); - - return true; - } - else - { - return false; - } - } - - private void TryUpdateHolding(PointerPoint? current = null, bool timeElapsed = false) - { - Debug.Assert(timeElapsed || current != null); - - if (HasMovedOutOfTapRange) - { - StopHoldingTimer(); - - var currentState = _holdingState; - _holdingState = HoldingState.Canceled; - - if (currentState == HoldingState.Started) - { - _recognizer.Holding?.Invoke(_recognizer, new HoldingEventArgs(Down.PointerId, PointerType, Down.Position, HoldingState.Canceled)); - } - } - else if (SupportsHolding() - && _holdingState is null - && (timeElapsed || IsLongPress(Down, current!)) - && IsBeginningOfTapGesture(LeftButton, this)) - { - StopHoldingTimer(); - - _holdingState = HoldingState.Started; - _recognizer.Holding?.Invoke(_recognizer, new HoldingEventArgs(Down.PointerId, PointerType, Down.Position, HoldingState.Started)); - } - } - - private void TryEndHolding(HoldingState state) - { - Debug.Assert(state != HoldingState.Started); - - StopHoldingTimer(); - - if (_holdingState == HoldingState.Started) - { - _holdingState = state; - _recognizer.Holding?.Invoke(_recognizer, new HoldingEventArgs(Down.PointerId, PointerType, Down.Position, state)); - } - } - - #region Holding timer - private bool SupportsHolding() - => PointerType switch - { - PointerDeviceType.Mouse => Settings.HasFlag(GestureSettings.HoldWithMouse), - _ => Settings.HasFlag(GestureSettings.Hold) - }; - - private void StartHoldingTimer() - { - _holdingTimer = DispatcherQueue.GetForCurrentThread().CreateTimer(); - _holdingTimer.Interval = TimeSpan.FromTicks(HoldMinDelayTicks); - _holdingTimer.State = this; - _holdingTimer.Tick += OnHoldingTimerTick; - _holdingTimer.Start(); - } - - private void StopHoldingTimer() - { - _holdingTimer?.Stop(); - _holdingTimer = null; - } - - private static void OnHoldingTimerTick(DispatcherQueueTimer timer, object _) - { - timer.Stop(); - ((Gesture)timer.State).TryUpdateHolding(timeElapsed: true); - } - #endregion - - #region Gestures recognition (static helpers that defines the actual gestures behavior) - - // The beginning of a Tap gesture is: 1 down -> * moves close to the down with same buttons pressed - private static bool IsBeginningOfTapGesture(CheckButton isExpectedButton, Gesture points) - { - if (!isExpectedButton(points.Down)) // We validate only the start as for other points we validate the full pointer identifier - { - return false; - } - - // Validate tap gesture - // Note: There is no limit for the duration of the tap! - if (points.HasMovedOutOfTapRange || points.HasChangedPointerIdentifier) - { - return false; - } - - return true; - } - - // A Tap gesture is: 1 down -> * moves close to the down with same buttons pressed -> 1 up - private static bool IsTapGesture(CheckButton isExpectedButton, Gesture points) - { - if (points.Up == null) // no tap if no up! - { - return false; - } - - // Validate that all the intermediates points are valid - if (!IsBeginningOfTapGesture(isExpectedButton, points)) - { - return false; - } - - // For the pointer up, we check only the distance, as it's expected that the pressed button changed! - if (IsOutOfTapRange(points.Down.Position, points.Up.Position)) - { - return false; - } - - return true; - } - - public static bool IsMultiTapGesture((ulong id, ulong ts, Point position) previousTap, PointerPoint down) - { - if (previousTap.ts == 0) // i.s. no previous tap to compare with - { - return false; - } - - var currentId = GetPointerIdentifier(down); - var currentTs = down.Timestamp; - var currentPosition = down.Position; - - return previousTap.id == currentId - && currentTs - previousTap.ts <= MultiTapMaxDelayTicks - && !IsOutOfTapRange(previousTap.position, currentPosition); - } - - private static bool IsRightTapGesture(Gesture points, out bool isLongPress) - { - switch (points.PointerType) - { - case PointerDeviceType.Touch: - var isLeftTap = IsTapGesture(LeftButton, points); - if (isLeftTap && IsLongPress(points.Down, points.Up!)) - { - isLongPress = true; - return true; - } -#if __IOS__ - if (Uno.WinRTFeatureConfiguration.GestureRecognizer.InterpretForceTouchAsRightTap - && isLeftTap - && points.HasExceedMinHoldPressure) - { - isLongPress = true; // We handle the pressure exactly like a long press - return true; - } -#endif - isLongPress = false; - return false; - - case PointerDeviceType.Pen: - if (IsTapGesture(BarrelButton, points)) - { - isLongPress = false; - return true; - } - - // Some pens does not have a barrel button, so we also allow long press (and anyway it's the UWP behavior) - if (IsTapGesture(LeftButton, points) && IsLongPress(points.Down, points.Up!)) - { - isLongPress = true; - return true; - } - - isLongPress = false; - return false; - - case PointerDeviceType.Mouse: - if (IsTapGesture(RightButton, points)) - { - isLongPress = false; - return true; - } -#if __ANDROID__ - // On Android, usually the right button is mapped to back navigation. So, unlike UWP, - // we also allow a long press with the left button to be more user friendly. - if (Uno.WinRTFeatureConfiguration.GestureRecognizer.InterpretMouseLeftLongPressAsRightTap - && IsTapGesture(LeftButton, points) - && IsLongPress(points.Down, points.Up!)) - { - isLongPress = true; - return true; - } -#endif - isLongPress = false; - return false; - - default: - isLongPress = false; - return false; - } - } - - private static bool IsLongPress(PointerPoint down, PointerPoint current) - => current.Timestamp - down.Timestamp > HoldMinDelayTicks; - - public static bool IsOutOfTapRange(Point p1, Point p2) - => Math.Abs(p1.X - p2.X) > TapMaxXDelta - || Math.Abs(p1.Y - p2.Y) > TapMaxYDelta; - #endregion - } - } -} diff --git a/src/Uno.UWP/UI/Input/GestureRecognizer.Manipulation.InertiaProcessor.cs b/src/Uno.UWP/UI/Input/GestureRecognizer.Manipulation.InertiaProcessor.cs deleted file mode 100644 index 36678009b1bb..000000000000 --- a/src/Uno.UWP/UI/Input/GestureRecognizer.Manipulation.InertiaProcessor.cs +++ /dev/null @@ -1,218 +0,0 @@ -#nullable enable - -using System; -using System.Linq; -using Windows.Foundation; -using Windows.System; -using Uno.Extensions; -using static System.Math; -using static System.Double; - -#if HAS_UNO_WINUI && IS_UNO_UI_PROJECT -namespace Microsoft.UI.Input -#else -namespace Windows.UI.Input -#endif -{ - public partial class GestureRecognizer - { - internal partial class Manipulation - { - internal class InertiaProcessor : IDisposable - { - // TODO: We should somehow sync tick with frame rendering - private const double _framesPerSecond = 25; - private const double _defaultDurationMs = 1000; - - private readonly DispatcherQueueTimer _timer; - private readonly Manipulation _owner; - private readonly Point _position0; - private readonly ManipulationDelta _cumulative0; // Cumulative of the whole manipulation at t=0 - private readonly ManipulationVelocities _velocities0; - - private ManipulationDelta _inertiaCumulative; // Cumulative of the inertia only at last tick - - private readonly bool _isTranslateInertiaXEnabled; - private readonly bool _isTranslateInertiaYEnabled; - private readonly bool _isRotateInertiaEnabled; - private readonly bool _isScaleInertiaEnabled; - - // Those values can be customized by the application through the ManipInertiaStartingArgs.InertiaBehavior - public double DesiredDisplacement = NaN; - public double DesiredDisplacementDeceleration = NaN; - public double DesiredRotation = NaN; - public double DesiredRotationDeceleration = NaN; - public double DesiredExpansion = NaN; - public double DesiredExpansionDeceleration = NaN; - - public InertiaProcessor(Manipulation owner, Point position, ManipulationDelta cumulative, ManipulationVelocities velocities) - { - _owner = owner; - _position0 = position; - _cumulative0 = cumulative; - _velocities0 = velocities; - - _isTranslateInertiaXEnabled = _owner._isTranslateXEnabled - && _owner._settings.HasFlag(Input.GestureSettings.ManipulationTranslateInertia) - && Math.Abs(velocities.Linear.X) > _owner._inertiaThresholds.TranslateX; - _isTranslateInertiaYEnabled = _owner._isTranslateYEnabled - && _owner._settings.HasFlag(Input.GestureSettings.ManipulationTranslateInertia) - && Math.Abs(velocities.Linear.Y) > _owner._inertiaThresholds.TranslateY; - _isRotateInertiaEnabled = _owner._isRotateEnabled - && _owner._settings.HasFlag(Input.GestureSettings.ManipulationRotateInertia) - && Abs(velocities.Angular) > _owner._inertiaThresholds.Rotate; - _isScaleInertiaEnabled = _owner._isScaleEnabled - && _owner._settings.HasFlag(Input.GestureSettings.ManipulationScaleInertia) - && Abs(velocities.Expansion) > _owner._inertiaThresholds.Expansion; - - global::System.Diagnostics.Debug.Assert(_isTranslateInertiaXEnabled || _isTranslateInertiaYEnabled || _isRotateInertiaEnabled || _isScaleInertiaEnabled); - - // For better experience, as soon inertia kicked-in on an axis, we bypass threshold on the second axis. - _isTranslateInertiaXEnabled |= _isTranslateInertiaYEnabled && _owner._isTranslateXEnabled; - _isTranslateInertiaYEnabled |= _isTranslateInertiaXEnabled && _owner._isTranslateYEnabled; - - _timer = DispatcherQueue.GetForCurrentThread().CreateTimer(); - _timer.Interval = TimeSpan.FromMilliseconds(1000d / _framesPerSecond); - _timer.IsRepeating = true; - _timer.Tick += (snd, e) => Process(snd.LastTickElapsed.TotalMilliseconds); - } - - public bool IsRunning => _timer.IsRunning; - - /// - /// Gets the elapsed time of the inertia (cf. Remarks) - /// - /// - /// Depending of the platform, the timestamp provided by pointer events might not be absolute, - /// so it's preferable to not compare timestamp between pointers and inertia processor. - /// - public long Elapsed => _timer.LastTickElapsed.Ticks; - - public void Start() - { - // As of 2021-07-21, according to test, Displacement takes over Deceleration. - if (!IsNaN(DesiredDisplacement)) - { - var v0 = (Math.Abs(_velocities0.Linear.X) + Math.Abs(_velocities0.Linear.Y)) / 2; - DesiredDisplacementDeceleration = GetDecelerationFromDesiredDisplacement(v0, DesiredDisplacement); - } - if (!IsNaN(DesiredRotation)) - { - DesiredRotationDeceleration = GetDecelerationFromDesiredDisplacement(_velocities0.Angular, DesiredRotation); - } - if (!IsNaN(DesiredExpansion)) - { - DesiredExpansionDeceleration = GetDecelerationFromDesiredDisplacement(_velocities0.Expansion, DesiredExpansion); - } - - // Default values are **inspired** by https://docs.microsoft.com/en-us/windows/win32/wintouch/inertia-mechanics#smooth-object-animation-using-the-velocity-and-deceleration-properties - if (IsNaN(DesiredDisplacementDeceleration)) - { - DesiredDisplacementDeceleration = .001; - } - if (IsNaN(DesiredRotationDeceleration)) - { - DesiredRotationDeceleration = .0001; - } - if (IsNaN(DesiredExpansionDeceleration)) - { - DesiredExpansionDeceleration = .001; - } - - _timer.Start(); - } - - private void Process(double t) - { - // First we update the internal state (i.e. the current cumulative manip delta for the current time) - var previous = _inertiaCumulative; - var current = GetInertiaCumulative(t, previous); - - _inertiaCumulative = current; - - // Then we request to the owner to raise its events (will cause the GetCumulative()) - // We notify in any cases in order to make sure to raise at least one ManipDelta (even if Delta.IsEmpty ^^) before stop the processor - _owner.NotifyUpdate(); - - if (previous.Translation.X == current.Translation.X - && previous.Translation.Y == current.Translation.Y - && previous.Rotation == current.Rotation - && previous.Expansion == current.Expansion) // Note: we DO NOT compare the scaling, expansion is enough here! - { - _timer.Stop(); - _owner.NotifyUpdate(); - } - } - - public Point GetPosition() - => _position0 + _inertiaCumulative.Translation; - - /// - /// Gets the cumulative delta, including the manipulation cumulative when this processor was started - /// - public ManipulationDelta GetCumulative() - => _cumulative0.Add(_inertiaCumulative); - - private ManipulationDelta GetInertiaCumulative(double t, ManipulationDelta previousCumulative) - { - var linearX = GetValue(_isTranslateInertiaXEnabled, _velocities0.Linear.X, DesiredDisplacementDeceleration, t, (float)previousCumulative.Translation.X); - var linearY = GetValue(_isTranslateInertiaYEnabled, _velocities0.Linear.Y, DesiredDisplacementDeceleration, t, (float)previousCumulative.Translation.Y); - var angular = GetValue(_isRotateInertiaEnabled, _velocities0.Angular, DesiredRotationDeceleration, t, previousCumulative.Rotation); - var expansion = GetValue(_isScaleInertiaEnabled, _velocities0.Expansion, DesiredExpansionDeceleration, t, previousCumulative.Expansion); - - var scale = _isScaleInertiaEnabled ? (_owner._origins.Distance + expansion) / _owner._origins.Distance : 1; - - var delta = new ManipulationDelta - { - Translation = new Point(linearX, linearY), - Rotation = angular, - Expansion = expansion, - Scale = scale - }; - - return delta; - } - - private float GetValue(bool enabled, double v0, double d, double t, float lastValue) - => (enabled, IsCompleted(v0, d, t)) switch - { - (false, _) => 0, - (_, true) => lastValue, // Avoid bounce effect by replaying the last value - (true, false) => GetValue(v0, d, t) - }; - - // https://docs.microsoft.com/en-us/windows/win32/wintouch/inertia-mechanics#inertia-physics-overview - private float GetValue(double v0, double d, double t) - => v0 >= 0 - ? (float)(v0 * t - d * Math.Pow(t, 2)) - : -(float)(-v0 * t - d * Math.Pow(t, 2)); - - private bool IsCompleted(double v0, double d, double t) - => Math.Abs(v0) - d * 2 * t <= 0; // The derivative of the GetValue function - - private double GetDecelerationFromDesiredDisplacement(double v0, double displacement, double durationMs = _defaultDurationMs) - => (v0 * durationMs - displacement) / Math.Pow(_defaultDurationMs, 2); - - /// - public void Dispose() - => _timer.Stop(); - -#if IS_UNIT_TESTS - /// - /// For test purposes only! - /// - public void RunSync() - { - var frameDuration = 1000 / _framesPerSecond; - var time = frameDuration; - while (IsRunning) - { - Process(time); - time += frameDuration; - } - } -#endif - } - } - } -} diff --git a/src/Uno.UWP/UI/Input/GestureRecognizer.Manipulation.cs b/src/Uno.UWP/UI/Input/GestureRecognizer.Manipulation.cs deleted file mode 100644 index 1a3b807c09cd..000000000000 --- a/src/Uno.UWP/UI/Input/GestureRecognizer.Manipulation.cs +++ /dev/null @@ -1,712 +0,0 @@ -#nullable enable - -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using System.Numerics; -using Windows.Devices.Input; -using Windows.Foundation; -using Windows.System; -using Uno; -using Uno.Disposables; -using Uno.Foundation.Logging; - -#if HAS_UNO_WINUI && IS_UNO_UI_PROJECT -namespace Microsoft.UI.Input -#else -namespace Windows.UI.Input -#endif -{ - public partial class GestureRecognizer - { - // Note: this is also responsible to handle "Drag manipulations" - internal partial class Manipulation - { - internal static readonly Thresholds StartTouch = new Thresholds { TranslateX = 15, TranslateY = 15, Rotate = 5, Expansion = 15 }; - internal static readonly Thresholds StartPen = new Thresholds { TranslateX = 15, TranslateY = 15, Rotate = 5, Expansion = 15 }; - internal static readonly Thresholds StartMouse = new Thresholds { TranslateX = 1, TranslateY = 1, Rotate = .1, Expansion = 1 }; - - internal static readonly Thresholds DeltaTouch = new Thresholds { TranslateX = 2, TranslateY = 2, Rotate = .1, Expansion = 1 }; - internal static readonly Thresholds DeltaPen = new Thresholds { TranslateX = 2, TranslateY = 2, Rotate = .1, Expansion = 1 }; - internal static readonly Thresholds DeltaMouse = new Thresholds { TranslateX = 1, TranslateY = 1, Rotate = .1, Expansion = 1 }; - - // Inertia thresholds are expressed in 'unit / millisecond' (unit being either 'logical px' or 'degree') - internal static readonly Thresholds InertiaTouch = new Thresholds { TranslateX = 15d / 1000, TranslateY = 15d / 1000, Rotate = 5d / 1000, Expansion = 15d / 1000 }; - internal static readonly Thresholds InertiaPen = new Thresholds { TranslateX = 15d / 1000, TranslateY = 15d / 1000, Rotate = 5d / 1000, Expansion = 15d / 1000 }; - internal static readonly Thresholds InertiaMouse = new Thresholds { TranslateX = 15d / 1000, TranslateY = 15d / 1000, Rotate = 5d / 1000, Expansion = 15d / 1000 }; - - private enum ManipulationState - { - Starting = 1, - Started = 2, - Inertia = 3, - Completed = 4, - } - - private readonly GestureRecognizer _recognizer; - private readonly PointerDeviceType _deviceType; - private readonly GestureSettings _settings; - private bool _isDraggingEnable; // Note: This might get disabled if user moves out of range while initial hold delay with finger - private readonly bool _isTranslateXEnabled; - private readonly bool _isTranslateYEnabled; - private readonly bool _isRotateEnabled; - private readonly bool _isScaleEnabled; - - private readonly Thresholds _startThresholds; - private readonly Thresholds _deltaThresholds; - private readonly Thresholds _inertiaThresholds; - - private DispatcherQueueTimer? _dragHoldTimer; - - private ManipulationState _state = ManipulationState.Starting; - private Points _origins; - private Points _currents; - private (ushort onStart, ushort current) _contacts; - private (ManipulationDelta sumOfDelta, ulong timestamp, ushort contacts) _lastPublishedState = (ManipulationDelta.Empty, 0, 1); // Note: not maintained for dragging manipulation - private ManipulationVelocities _lastRelevantVelocities; - private InertiaProcessor? _inertia; - - /// - /// Indicates that this manipulation **has started** and is for drag-and-drop. - /// (i.e. raises Drag event instead of Manipulation<Started Delta Completed> events). - /// - public bool IsDragManipulation { get; private set; } - - public GestureSettings Settings => _settings; - public bool IsTranslateXEnabled => _isTranslateXEnabled; - public bool IsTranslateYEnabled => _isTranslateYEnabled; - public bool IsRotateEnabled => _isRotateEnabled; - public bool IsScaleEnabled => _isScaleEnabled; - - internal static void AddPointer(GestureRecognizer recognizer, PointerPoint pointer) - { - var current = recognizer._manipulation; - if (current != null) - { - if (current.TryAdd(pointer)) - { - // The pending manipulation which can either handle the pointer, either is still active with another pointer, - // just ignore the new pointer. - return; - } - - // The current manipulation should be discarded - current.Complete(); // Will removed 'current' from the 'recognizer._manipulation' field. - } - - var manipulation = new Manipulation(recognizer, pointer); - if (manipulation._state == ManipulationState.Completed) - { - // The new manipulation has been cancelled in the ManipStarting handler, throw it away. - manipulation.Complete(); // Should not do anything, safety only - } - else - { - recognizer._manipulation = manipulation; - } - } - - private Manipulation(GestureRecognizer recognizer, PointerPoint pointer1) - { - _recognizer = recognizer; - _deviceType = (PointerDeviceType)pointer1.PointerDevice.PointerDeviceType; - - _origins = _currents = pointer1; - _contacts = (0, 1); - - switch (_deviceType) - { - case PointerDeviceType.Mouse: - _startThresholds = StartMouse; - _deltaThresholds = DeltaMouse; - _inertiaThresholds = InertiaMouse; - break; - - case PointerDeviceType.Pen: - _startThresholds = StartPen; - _deltaThresholds = DeltaPen; - _inertiaThresholds = InertiaPen; - break; - - default: - case PointerDeviceType.Touch: - _startThresholds = StartTouch; - _deltaThresholds = DeltaTouch; - _inertiaThresholds = InertiaTouch; - break; - } - - UpdatePublishedState(ManipulationDelta.Empty); - var args = new ManipulationStartingEventArgs(pointer1.Pointer, _recognizer._gestureSettings); - _recognizer.ManipulationStarting?.Invoke(_recognizer, args); - _settings = args.Settings; - - if ((_settings & (GestureSettingsHelper.Manipulations | GestureSettingsHelper.DragAndDrop)) == 0) - { - // The manipulation has been cancelled (all possible manip has been removed) - // WARNING: The _gestureRecognizer._manipulation has not been set yet! We cannot invoke the Complete right now (cf. AddPointer) - - _state = ManipulationState.Completed; - return; - } - - _isDraggingEnable = (_settings & GestureSettings.Drag) != 0; - _isTranslateXEnabled = (_settings & (GestureSettings.ManipulationTranslateX | GestureSettings.ManipulationTranslateRailsX)) != 0; - _isTranslateYEnabled = (_settings & (GestureSettings.ManipulationTranslateY | GestureSettings.ManipulationTranslateRailsY)) != 0; - _isRotateEnabled = (_settings & GestureSettings.ManipulationRotate) != 0; - _isScaleEnabled = (_settings & GestureSettings.ManipulationScale) != 0; - - _recognizer.ManipulationConfigured?.Invoke(_recognizer, this); - StartDragTimer(); - } - - public bool IsActive(PointerIdentifier pointer) - => _state != ManipulationState.Completed - && _deviceType == (PointerDeviceType)pointer.Type - && _origins.ContainsPointer(pointer.Id); - - private bool TryAdd(PointerPoint point) - { - if (point.Pointer == _origins.Pointer1.Pointer) - { - this.Log().Error( - "Invalid manipulation state: We are receiving a down for the second time for the same pointer!" - + "This is however common when using iOS emulator with VNC where we might miss some pointer events " - + "due to focus being stole by debugger, in that case you can safely ignore this message."); - return false; // Request to create a new manipulation - } - else if (_state >= ManipulationState.Inertia) - { - // A new manipulation has to be started - return false; - } - else if ((PointerDeviceType)point.PointerDevice.PointerDeviceType != _deviceType - || _currents.HasPointer2) - { - // A manipulation is already active, but cannot handle this new pointer. - // We don't support multiple active manipulation on a single element / gesture recognizer, - // so even if we don't effectively add the given pointer to the active manipulation, - // we return true to make sure that the current manipulation is not Completed. - return true; - } - - _origins.SetPointer2(point); - _currents.SetPointer2(point); - _contacts.current++; - - // We force to start the manipulation (or update it) as soon as a second pointer is pressed - NotifyUpdate(); - - return true; - } - - public void Update(IList updated) - { - if (_state >= ManipulationState.Inertia) - { - // We no longer track pointers (even pointer2) once inertia has started - return; - } - - var hasUpdate = false; - foreach (var point in updated) - { - hasUpdate |= TryUpdate(point); - } - - if (hasUpdate) - { - NotifyUpdate(); - } - } - - public void Remove(PointerPoint removed) - { - if (_state >= ManipulationState.Inertia) - { - // We no longer track pointers (even pointer2) once inertia has started - return; - } - - if (TryUpdate(removed)) - { - _contacts.current--; - - NotifyUpdate(); - } - } - - public void Complete() - { - StopDragTimer(); - - // If the manipulation was not started, we just abort the manipulation without any event - switch (_state) - { - case ManipulationState.Started when IsDragManipulation: - _inertia?.Dispose(); // Safety, inertia should never been started when IsDragManipulation, especially if _state is ManipulationState.Started ^^ - _state = ManipulationState.Completed; - - _recognizer.Dragging?.Invoke( - _recognizer, - new DraggingEventArgs(_currents.Pointer1, DraggingState.Completed, _contacts.onStart)); - break; - - case ManipulationState.Started: - case ManipulationState.Inertia: - _inertia?.Dispose(); - _state = ManipulationState.Completed; - - var position = GetPosition(); - var cumulative = GetCumulative(); - var delta = GetDelta(cumulative); - var velocities = GetVelocities(delta); - - _recognizer.ManipulationCompleted?.Invoke( - _recognizer, - new ManipulationCompletedEventArgs(_currents.Identifiers, position, cumulative, velocities, _state == ManipulationState.Inertia, _contacts.onStart, _contacts.current)); - break; - - case ManipulationState.Starting: - _inertia?.Dispose(); - _state = ManipulationState.Completed; - - _recognizer.ManipulationAborted?.Invoke(_recognizer, this); - break; - - default: // Safety only - _inertia?.Dispose(); - _state = ManipulationState.Completed; - break; - } - - // Self scavenge our self from the _recognizer ... yes it's a bit strange, - // but it's the safest and easiest way to avoid invalid state. - if (_recognizer._manipulation == this) - { - _recognizer._manipulation = null; - } - } - -#if IS_UNIT_TESTS - public void RunInertiaSync() - => _inertia?.RunSync(); -#endif - - private bool TryUpdate(PointerPoint point) - { - if (_deviceType != (PointerDeviceType)point.PointerDevice.PointerDeviceType) - { - return false; - } - - return _currents.TryUpdate(point); - } - - private void NotifyUpdate() - { - // Note: Make sure to update the _sumOfPublishedDelta before raising the event, so if an exception is raised - // or if the manipulation is Completed, the Complete event args can use the updated _sumOfPublishedDelta. - - var position = GetPosition(); - var cumulative = GetCumulative(); - var delta = GetDelta(cumulative); - var velocities = GetVelocities(delta); - var pointerAdded = _contacts.current > _lastPublishedState.contacts; - var pointerRemoved = _contacts.current < _lastPublishedState.contacts; - - switch (_state) - { - case ManipulationState.Starting when IsBeginningOfDragManipulation(): - // On UWP if the element was configured to allow both Drag and Manipulations, - // both events are going to be raised (... until the drag "content" is being render an captures all pointers). - // This results as a manipulation started which is never completed. - // If user uses double touch the manipulation will however start and complete when user adds / remove the 2nd finger. - // On Uno, as allowing both Manipulations and drop on the same element is really a stretch case (and is bugish on UWP), - // we accept as a known limitation that once dragging started no manipulation event would be fired. - _state = ManipulationState.Started; - _contacts.onStart = _contacts.current; - IsDragManipulation = true; - - _recognizer.Dragging?.Invoke( - _recognizer, - new DraggingEventArgs(_currents.Pointer1, DraggingState.Started, _contacts.onStart)); - break; - - case ManipulationState.Starting when pointerAdded: - _state = ManipulationState.Started; - _contacts.onStart = _contacts.current; - - UpdatePublishedState(cumulative); - _recognizer.ManipulationStarted?.Invoke( - _recognizer, - new ManipulationStartedEventArgs(_currents.Identifiers, _origins.Center, cumulative, _contacts.onStart)); - // No needs to publish an update when we start the manipulation due to an additional pointer as cumulative will be empty. - break; - - case ManipulationState.Starting when cumulative.IsSignificant(_startThresholds): - _state = ManipulationState.Started; - _contacts.onStart = _contacts.current; - - // Note: We first start with an empty delta, then invoke Update. - // This is required to patch a common issue in applications that are using only the - // ManipulationUpdated.Delta property to track the pointer (like the WCT GridSplitter). - // UWP seems to do that only for Touch and Pen (i.e. the Delta is not empty on start with a mouse), - // but there is no side effect to use the same behavior for all pointer types. - - UpdatePublishedState(cumulative); - _recognizer.ManipulationStarted?.Invoke( - _recognizer, - new ManipulationStartedEventArgs(_currents.Identifiers, _origins.Center, ManipulationDelta.Empty, _contacts.onStart)); - _recognizer.ManipulationUpdated?.Invoke( - _recognizer, - new ManipulationUpdatedEventArgs(_currents.Identifiers, position, cumulative, cumulative, ManipulationVelocities.Empty, isInertial: false, _contacts.onStart, _contacts.current)); - break; - - case ManipulationState.Started when pointerRemoved && ShouldStartInertia(velocities): - _state = ManipulationState.Inertia; - _inertia = new InertiaProcessor(this, position, cumulative, velocities); - - UpdatePublishedState(delta); - _recognizer.ManipulationInertiaStarting?.Invoke( - _recognizer, - new ManipulationInertiaStartingEventArgs(_currents.Identifiers, position, delta, cumulative, velocities, _contacts.onStart, _inertia)); - - _inertia.Start(); - break; - - case ManipulationState.Starting when pointerRemoved: - case ManipulationState.Started when pointerRemoved: - // For now we complete the Manipulation as soon as a pointer was removed. - // This is not the UWP behavior where for instance you can scale multiple times by releasing only one finger. - // It's however the right behavior in case of drag conflicting with manipulation (which is not supported by Uno). - case ManipulationState.Inertia when !_inertia!.IsRunning: - Complete(); - break; - - case ManipulationState.Started when IsDragManipulation: - _recognizer.Dragging?.Invoke( - _recognizer, - new DraggingEventArgs(_currents.Pointer1, DraggingState.Continuing, _contacts.onStart)); - break; - - case ManipulationState.Started when pointerAdded: - case ManipulationState.Started when delta.IsSignificant(_deltaThresholds): - case ManipulationState.Inertia: // No significant check for inertia, we prefer smooth animations! - UpdatePublishedState(delta); - _recognizer.ManipulationUpdated?.Invoke( - _recognizer, - new ManipulationUpdatedEventArgs(_currents.Identifiers, position, delta, cumulative, velocities, _state == ManipulationState.Inertia, _contacts.onStart, _contacts.current)); - break; - } - } - - private Point GetPosition() - { - return _inertia?.GetPosition() ?? _currents.Center; - } - - private ManipulationDelta GetCumulative() - { - if (_inertia is { } inertia) - { - return inertia.GetCumulative(); - } - - var translateX = _isTranslateXEnabled ? _currents.Center.X - _origins.Center.X : 0; - var translateY = _isTranslateYEnabled ? _currents.Center.Y - _origins.Center.Y : 0; -#if __MACOS__ - // correction for translateY being inverted (#4700) - translateY *= -1; -#endif - - double rotation; - float scale, expansion; - if (_currents.HasPointer2) - { - rotation = _isRotateEnabled ? Uno.Extensions.MathEx.ToDegree(_currents.Angle - _origins.Angle) : 0; - scale = _isScaleEnabled ? _currents.Distance / _origins.Distance : 1; - expansion = _isScaleEnabled ? _currents.Distance - _origins.Distance : 0; - - // The 'rotation' only contains the current angle compared to the 'origins'. - // But user might have broke his wrist and made a 360° (2π) rotation, the cumulative must reflect it. - // Also, the Math.ATan2 method used to compute that angle is not linear when changing to/from second from/to third quadrant, - // which means that we might have a delta close to 2π while user actually moved only few degrees. - // (https://docs.microsoft.com/en-us/dotnet/api/system.math.atan2?view=net-5.0) - // So here, as long as possible, we try: - // 1. to minimize the angle compared to the last known rotation; - // 2. append that normalized rotation to that last known value in order to have a linear result which also includes the possible "more than 2π rotation". - // Note: That correction is fairly important to properly compute the velocities (and then inertia)! - var previousRotation = _lastPublishedState.sumOfDelta.Rotation; - var rotationNormalizedDelta = (rotation - previousRotation) % 360; // Note: the '% 2π' is for safety only here - if (rotationNormalizedDelta > 180) // π - { - // The angle gone from quadrant 3 to quadrant 2, i.e. the computed angle gone from -(π + α) to (π + β), - // which means that the 'rotationDelta' is (2π + α + β) and we have to limit it to (α + β). - rotationNormalizedDelta -= 360; - } - else if (rotationNormalizedDelta < -180) // -π - { - // The angle gone from quadrant 2 to quadrant 3, i.e. the computed angle gone from (π + α) to -(π + β), - // which means that the 'rotationDelta' is (-2π + α + β) ane we have to limit it to (α + β). - rotationNormalizedDelta += 360; - } - - rotation = previousRotation + rotationNormalizedDelta; - } - else - { - rotation = 0; - scale = 1; - expansion = 0; - } - - return new ManipulationDelta - { - Translation = new Point(translateX, translateY), - Rotation = (float)rotation, - Scale = scale, - Expansion = expansion - }; - } - - private ManipulationDelta GetDelta(ManipulationDelta cumulative) - { - var deltaSum = _lastPublishedState.sumOfDelta; - - var translateX = _isTranslateXEnabled ? cumulative.Translation.X - deltaSum.Translation.X : 0; - var translateY = _isTranslateYEnabled ? cumulative.Translation.Y - deltaSum.Translation.Y : 0; - var rotation = _isRotateEnabled ? cumulative.Rotation - deltaSum.Rotation : 0; - var scale = _isScaleEnabled ? cumulative.Scale / deltaSum.Scale : 1; - var expansion = _isScaleEnabled ? cumulative.Expansion - deltaSum.Expansion : 0; - - return new ManipulationDelta - { - Translation = new Point(translateX, translateY), - Rotation = rotation, - Scale = scale, - Expansion = expansion - }; - } - - private ManipulationVelocities GetVelocities(ManipulationDelta delta) - { - // The _currents.Timestamp is not updated once inertia as started, we must get the elapsed duration from the inertia processor - // (and not compare it to PointerPoint.Timestamp in any way, cf. remarks on InertiaProcessor.Elapsed) - var elapsedTicks = _inertia?.Elapsed ?? (double)_currents.Timestamp - _lastPublishedState.timestamp; - var elapsedMs = elapsedTicks / TimeSpan.TicksPerMillisecond; - - // With uno a single native event might produce multiple managed pointer events. - // In that case we would get an empty velocities ... which is often not relevant! - // When we detect that case, we prefer to replay the last known velocities. - if (delta.IsEmpty || elapsedMs == 0) - { - return _lastRelevantVelocities; - } - - var linearX = delta.Translation.X / elapsedMs; - var linearY = delta.Translation.Y / elapsedMs; - var angular = delta.Rotation / elapsedMs; - var expansion = delta.Expansion / elapsedMs; - - var velocities = new ManipulationVelocities - { - Linear = new Point(linearX, linearY), - Angular = (float)angular, - Expansion = (float)expansion - }; - - if (velocities.IsAnyAbove(default)) - { - _lastRelevantVelocities = velocities; - } - - return _lastRelevantVelocities; - } - - // This has to be invoked before any event being raised, it will update the internal that is used to compute delta and velocities. - private void UpdatePublishedState(ManipulationDelta delta) - { - _lastPublishedState = (_lastPublishedState.sumOfDelta.Add(delta), _currents.Timestamp, _contacts.current); - } - - private void StartDragTimer() - { - if (_isDraggingEnable && _deviceType == PointerDeviceType.Touch) - { - _dragHoldTimer = DispatcherQueue.GetForCurrentThread().CreateTimer(); - _dragHoldTimer.Interval = new TimeSpan(DragWithTouchMinDelayTicks); - _dragHoldTimer.IsRepeating = false; - _dragHoldTimer.Tick += TouchDragMightStart; - _dragHoldTimer.Start(); - - void TouchDragMightStart(DispatcherQueueTimer sender, object o) - { - sender.Tick -= TouchDragMightStart; - sender.Stop(); - - if (_isDraggingEnable) // Sanity only, the timer should have been stopped by the IsBeginningOfDragManipulation() - { - _recognizer.DragReady?.Invoke(_recognizer, this); - } - } - } - } - - private void StopDragTimer() - { - _dragHoldTimer?.Stop(); - } - - // For pen and mouse this only means down -> * moves out of tap range; - // For touch it means down -> * moves close to origin for DragUsingFingerMinDelayTicks -> * moves far from the origin - private bool IsBeginningOfDragManipulation() - { - if (!_isDraggingEnable) - { - return false; - } - - // Note: We use the TapRange and not the manipulation's start threshold as, for mouse and pen, - // those thresholds are lower than a Tap (and actually only 1px), which does not math the UWP behavior. - var down = _origins.Pointer1; - var current = _currents.Pointer1; - var isOutOfRange = Gesture.IsOutOfTapRange(down.Position, current.Position); - - switch (_deviceType) - { - case PointerDeviceType.Mouse: - case PointerDeviceType.Pen: - return isOutOfRange; - - default: - case PointerDeviceType.Touch: - // As for holding, here we rely on the fact that we get a lot of small moves due to the lack of precision - // of the touch device (cf. Gesture.NeedsHoldingTimer). - // This means that this method is expected to be invoked on each move (until manipulation starts) - // in order to update the _isDraggingEnable state. - - var isInHoldPhase = current.Timestamp - down.Timestamp < DragWithTouchMinDelayTicks; - if (isInHoldPhase && isOutOfRange) - { - // The pointer moved out of range while in the hold phase, so we completely disable the drag manipulation - _isDraggingEnable = false; - StopDragTimer(); - return false; - } - else - { - // The drag should start only after the hold delay and if the pointer moved out of the range - return !isInHoldPhase && isOutOfRange; - } - } - } - - private bool ShouldStartInertia(ManipulationVelocities velocities) - => _inertia is null - && !IsDragManipulation - && (_settings & GestureSettingsHelper.Inertia) != 0 - && velocities.IsAnyAbove(_inertiaThresholds); - - internal struct Thresholds - { - public double TranslateX; - public double TranslateY; - public double Rotate; // Degrees - public double Expansion; - } - - // WARNING: This struct is ** MUTABLE ** - private struct Points - { - public PointerPoint Pointer1; - private PointerPoint? _pointer2; - - public ulong Timestamp; - public Point Center; // This is the center in ** absolute ** coordinates spaces (i.e. relative to the screen) - public float Distance; - public double Angle; - - public bool HasPointer2 => _pointer2 != null; - - public PointerIdentifier[] Identifiers; - - public Points(PointerPoint point) - { - Pointer1 = point; - _pointer2 = default; - - Identifiers = new[] { point.Pointer }; - Timestamp = point.Timestamp; - Center = point.RawPosition; // RawPosition => cf. Note in UpdateComputedValues(). - Distance = 0; - Angle = 0; - } - - public bool ContainsPointer(uint pointerId) - => Pointer1.PointerId == pointerId - || (HasPointer2 && _pointer2!.PointerId == pointerId); - - public void SetPointer2(PointerPoint point) - { - _pointer2 = point; - Identifiers = new[] { Pointer1.Pointer, _pointer2.Pointer }; - UpdateComputedValues(); - } - - public bool TryUpdate(PointerPoint point) - { - if (Pointer1.PointerId == point.PointerId) - { - Pointer1 = point; - Timestamp = point.Timestamp; - - UpdateComputedValues(); - - return true; - } - else if (_pointer2 != null && _pointer2.PointerId == point.PointerId) - { - _pointer2 = point; - Timestamp = point.Timestamp; - - UpdateComputedValues(); - - return true; - } - else - { - return false; - } - } - - private void UpdateComputedValues() - { - // Note: Here we use the RawPosition in order to work in the ** absolute ** screen coordinates system - // This is required to avoid to be impacted the any transform applied on the element, - // and it's sufficient as values of the manipulation events are only values relative to the original touch point. - - if (_pointer2 == null) - { - Center = Pointer1.RawPosition; - Distance = 0; - Angle = 0; - } - else - { - var p1 = Pointer1.RawPosition; - var p2 = _pointer2.RawPosition; - - Center = new Point((p1.X + p2.X) / 2, (p1.Y + p2.Y) / 2); - Distance = Vector2.Distance(p1.ToVector2(), p2.ToVector2()); - Angle = Math.Atan2(p1.Y - p2.Y, p1.X - p2.X); - } - } - - public static implicit operator Points(PointerPoint pointer1) - => new Points(pointer1); - } - } - } -} diff --git a/src/Uno.UWP/UI/Input/GestureRecognizer.cs b/src/Uno.UWP/UI/Input/GestureRecognizer.cs deleted file mode 100644 index 28e7ea82d78e..000000000000 --- a/src/Uno.UWP/UI/Input/GestureRecognizer.cs +++ /dev/null @@ -1,280 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Windows.Devices.Input; -using Windows.Foundation; -using Windows.UI.Core; - -using Uno.Disposables; -using Uno.Extensions; -using Uno.Foundation.Logging; -using Uno; -using Windows.Devices.Haptics; - -#if HAS_UNO_WINUI && IS_UNO_UI_PROJECT -namespace Microsoft.UI.Input -#else -namespace Windows.UI.Input -#endif -{ - public partial class GestureRecognizer - { - private const int _defaultGesturesSize = 2; // Number of pointers before we have to resize the gestures dictionary - - internal const int TapMaxXDelta = 10; - internal const int TapMaxYDelta = 10; - - internal const ulong MultiTapMaxDelayTicks = TimeSpan.TicksPerMillisecond * 500; - - internal const long HoldMinDelayTicks = TimeSpan.TicksPerMillisecond * 800; - internal const float HoldMinPressure = .75f; - - internal const long DragWithTouchMinDelayTicks = TimeSpan.TicksPerMillisecond * 300; // https://docs.microsoft.com/en-us/windows/uwp/design/input/drag-and-drop#open-a-context-menu-on-an-item-you-can-drag-with-touch - - private readonly Logger _log; - private IDictionary _gestures = new Dictionary(_defaultGesturesSize); - private Manipulation _manipulation; - private GestureSettings _gestureSettings; - private bool _isManipulationOrDragEnabled; - - public GestureSettings GestureSettings - { - get => _gestureSettings; - set - { - _gestureSettings = value; - _isManipulationOrDragEnabled = (value & (GestureSettingsHelper.Manipulations | GestureSettingsHelper.DragAndDrop)) != 0; - } - } - - public bool IsActive => _gestures.Count > 0 || _manipulation != null; - - internal bool IsDragging => _manipulation?.IsDragManipulation ?? false; - - /// - /// This is the owner provided in the ctor. It might be `null` if none provided. - /// It's purpose it to allow usage of static event handlers. - /// - internal object Owner { get; } - - public GestureRecognizer() - { - _log = this.Log(); - } - - internal GestureRecognizer(object owner) - : this() - { - Owner = owner; - } - - public void ProcessDownEvent(PointerPoint value) - { - // Sanity validation. This is pretty important as the Gesture now has an internal state for the Holding state. - if (_gestures.TryGetValue(value.PointerId, out var previousGesture)) - { - if (_log.IsEnabled(LogLevel.Error)) - { - this.Log().Error($"{Owner} Inconsistent state, we already have a pending gesture for a pointer that is going down. Abort the previous gesture."); - } - previousGesture.ProcessComplete(); - } - - // Create a Gesture responsible to recognize single-pointer gestures - var gesture = new Gesture(this, value); - if (gesture.IsCompleted) - { - // This usually means that the gesture already detected a double tap - if (previousGesture != null) - { - _gestures.Remove(value.PointerId); - } - - return; - } - _gestures[value.PointerId] = gesture; - - // Create or update a Manipulation responsible to recognize multi-pointer and drag gestures - if (_isManipulationOrDragEnabled) - { - Manipulation.AddPointer(this, value); - } - } - - public void ProcessMoveEvents(IList value) => ProcessMoveEvents(value, true); - - internal void ProcessMoveEvents(IList value, bool isRelevant) - { - // Even if the pointer was considered as irrelevant, we still buffer it as it is part of the user interaction - // and we should considered it for the gesture recognition when processing the up. - foreach (var point in value) - { - if (_gestures.TryGetValue(point.PointerId, out var gesture)) - { - gesture.ProcessMove(point); - } - else if (_log.IsEnabled(LogLevel.Debug)) - { - // debug: We might get some PointerMove for mouse even if not pressed, - // or if gesture was completed by user / other gesture recognizers. - _log.Debug($"{Owner} Received a 'Move' for a pointer which was not considered as down. Ignoring event."); - } - } - - _manipulation?.Update(value); - } - - // Manipulation has to be raised BEFORE the pointer up - // The allows users to update the manipulation before anything else. - internal void ProcessBeforeUpEvent(PointerPoint value, bool isRelevant) - { - _manipulation?.Remove(value); - } - - public void ProcessUpEvent(PointerPoint value) => ProcessUpEvent(value, true); - - internal void ProcessUpEvent(PointerPoint value, bool isRelevant) - { - if (_gestures.Remove(value.PointerId, out var gesture)) - { - // Note: At this point we MAY be IsActive == false, which is the expected behavior (same as UWP) - // even if we will fire some events now. - - gesture.ProcessUp(value); - } - else if (_log.IsEnabled(LogLevel.Debug)) - { - // debug: We might get some PointerMove for mouse even if not pressed, - // or if gesture was completed by user / other gesture recognizers. - _log.Debug($"{Owner} Received a 'Up' for a pointer which was not considered as down. Ignoring event."); - } - - _manipulation?.Remove(value); - } - -#if IS_UNIT_TESTS - /// - /// For test purposes only! - /// - internal void RunInertiaSync() - => _manipulation?.RunInertiaSync(); -#endif - - public void CompleteGesture() - { - // Capture the list in order to avoid alteration while enumerating - var gestures = _gestures; - _gestures = new Dictionary(_defaultGesturesSize); - - // Note: At this point we are IsActive == false, which is the expected behavior (same as UWP) - // even if we will fire some events now. - - // Complete all pointers - foreach (var gesture in gestures.Values) - { - gesture.ProcessComplete(); - } - - _manipulation?.Complete(); - } - - /// The set of events that can be raised by this recognizer for this pointer ID - internal GestureSettings PreventEvents(uint pointerId, GestureSettings events) - { - if (_gestures.TryGetValue(pointerId, out var gesture)) - { - gesture.PreventGestures(events & GestureSettingsHelper.SupportedGestures); - - return gesture.Settings; - } - - return GestureSettings.None; - } - - #region Manipulations - internal event TypedEventHandler ManipulationStarting; // This is not on the public API! - internal event TypedEventHandler ManipulationConfigured; // Right after the ManipulationStarting, once application has configured settings ** ONLY if not cancelled in starting ** - internal event TypedEventHandler ManipulationAborted; // The manipulation has been aborted while in starting state ** ONLY if received a ManipulationConfigured ** - public event TypedEventHandler ManipulationCompleted; - public event TypedEventHandler ManipulationInertiaStarting; - public event TypedEventHandler ManipulationStarted; - public event TypedEventHandler ManipulationUpdated; - - internal Manipulation PendingManipulation => _manipulation; - #endregion - - #region Tap (includes DoubleTap and RightTap) - private (ulong id, ulong ts, Point position) _lastSingleTap; - - public event TypedEventHandler Tapped; - public event TypedEventHandler RightTapped; - public event TypedEventHandler Holding; - - public bool CanBeDoubleTap(PointerPoint value) - => _gestureSettings.HasFlag(GestureSettings.DoubleTap) && Gesture.IsMultiTapGesture(_lastSingleTap, value); - #endregion - - #region Dragging - /// - /// This is being raised for touch only, when the pointer remained long enough at the same location so the drag can start. - /// - internal event TypedEventHandler DragReady; - public event TypedEventHandler Dragging; - #endregion - - private delegate bool CheckButton(PointerPoint point); - - private static readonly CheckButton LeftButton = (PointerPoint point) => point.Properties.IsLeftButtonPressed; - private static readonly CheckButton RightButton = (PointerPoint point) => point.Properties.IsRightButtonPressed; - private static readonly CheckButton BarrelButton = (PointerPoint point) => point.Properties.IsBarrelButtonPressed; - - private static ulong GetPointerIdentifier(PointerPoint point) - { - // For mouse, the PointerId is the same, no matter the button pressed. - // The only thing that changes are flags in the properties. - // Here we build a "PointerIdentifier" that fully identifies the pointer used - - // Note: We don't take in consideration props.IsHorizontalMouseWheel as it would require to also check - // the (non existing) props.IsVerticalMouseWheel, and it's actually not something that should - // be considered as a pointer changed. - - var props = point.Properties; - - ulong identifier = point.PointerId; - - // Mouse - if (props.IsLeftButtonPressed) - { - identifier |= 1L << 32; - } - if (props.IsMiddleButtonPressed) - { - identifier |= 1L << 33; - } - if (props.IsRightButtonPressed) - { - identifier |= 1L << 34; - } - if (props.IsXButton1Pressed) - { - identifier |= 1L << 35; - } - if (props.IsXButton2Pressed) - { - identifier |= 1L << 36; - } - - // Pen - if (props.IsBarrelButtonPressed) - { - identifier |= 1L << 37; - } - if (props.IsEraser) - { - identifier |= 1L << 38; - } - - return identifier; - } - } -} diff --git a/src/Uno.UWP/UI/Input/ManipulationDelta.cs b/src/Uno.UWP/UI/Input/ManipulationDelta.cs deleted file mode 100644 index ea485bcd5eda..000000000000 --- a/src/Uno.UWP/UI/Input/ManipulationDelta.cs +++ /dev/null @@ -1,82 +0,0 @@ -using System; -using System.Collections.Generic; -using Windows.Foundation; - -#if HAS_UNO_WINUI && IS_UNO_UI_PROJECT -namespace Microsoft.UI.Input -#else -namespace Windows.UI.Input -#endif -{ - public partial struct ManipulationDelta : IEquatable - { - /// - /// A manipulation that does nothing. - /// This differs to 'default' by having a 'Scale' of 1. - /// - internal static ManipulationDelta Empty { get; } = new ManipulationDelta - { - Translation = Point.Zero, - Rotation = 0, - Scale = 1, - Expansion = 0 - }; - - public Point Translation; - public float Scale; - public float Rotation; - public float Expansion; - - // NOTE: Equality implementation should be modified if a new field/property is added. - - // IsEmpty is intentionally not included in equality since it's calculated from the other fields. - internal bool IsEmpty => Translation == Point.Zero && Rotation == 0 && Scale == 1 && Expansion == 0; - - internal ManipulationDelta Add(ManipulationDelta right) => Add(this, right); - internal static ManipulationDelta Add(ManipulationDelta left, ManipulationDelta right) - => new ManipulationDelta - { - Translation = new Point( - left.Translation.X + right.Translation.X, - left.Translation.Y + right.Translation.Y), - Rotation = left.Rotation + right.Rotation, - Scale = left.Scale * right.Scale, - Expansion = left.Expansion + right.Expansion - }; - - // Note: We should apply a velocity factor to thresholds to determine if isSignificant - internal bool IsSignificant(GestureRecognizer.Manipulation.Thresholds thresholds) - => Math.Abs(Translation.X) >= thresholds.TranslateX - || Math.Abs(Translation.Y) >= thresholds.TranslateY - || Math.Abs(Rotation) >= thresholds.Rotate - || Math.Abs(Expansion) >= thresholds.Expansion; - - /// - public override string ToString() - => $"x:{Translation.X:N0};y:{Translation.Y:N0};θ:{Rotation:F2};s:{Scale:F2};e:{Expansion:F2}"; - - #region Equality Members - public override bool Equals(object obj) => obj is ManipulationDelta delta && Equals(delta); - - public bool Equals(ManipulationDelta other) - { - return EqualityComparer.Default.Equals(Translation, other.Translation) && - Scale == other.Scale && Rotation == other.Rotation && - Expansion == other.Expansion; - } - - public override int GetHashCode() - { - var hashCode = 626270564; - hashCode = hashCode * -1521134295 + Translation.GetHashCode(); - hashCode = hashCode * -1521134295 + Scale.GetHashCode(); - hashCode = hashCode * -1521134295 + Rotation.GetHashCode(); - hashCode = hashCode * -1521134295 + Expansion.GetHashCode(); - return hashCode; - } - - public static bool operator ==(ManipulationDelta left, ManipulationDelta right) => left.Equals(right); - public static bool operator !=(ManipulationDelta left, ManipulationDelta right) => !left.Equals(right); - #endregion - } -} diff --git a/src/Uno.UWP/UI/Input/ManipulationInertiaStartingEventArgs.cs b/src/Uno.UWP/UI/Input/ManipulationInertiaStartingEventArgs.cs deleted file mode 100644 index c758f69cce2a..000000000000 --- a/src/Uno.UWP/UI/Input/ManipulationInertiaStartingEventArgs.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System.Linq; -using Windows.Devices.Input; -using Windows.Foundation; - -#if HAS_UNO_WINUI && IS_UNO_UI_PROJECT -namespace Microsoft.UI.Input -#else -namespace Windows.UI.Input -#endif -{ - public partial class ManipulationInertiaStartingEventArgs - { - internal ManipulationInertiaStartingEventArgs( - PointerIdentifier[] pointers, - Point position, - ManipulationDelta delta, - ManipulationDelta cumulative, - ManipulationVelocities velocities, - uint contactCount, - GestureRecognizer.Manipulation.InertiaProcessor processor) - { - global::System.Diagnostics.Debug.Assert(pointers.Length > 0 && pointers.All(p => p.Type == pointers[0].Type)); - - Pointers = pointers; - PointerDeviceType = (PointerDeviceType)pointers[0].Type; - Position = position; - Delta = delta; - Cumulative = cumulative; - Velocities = velocities; - ContactCount = contactCount; - Processor = processor; - } - - /// - /// Gets identifiers of all pointer that has been involved in that manipulation (cf. Remarks). - /// - /// This collection might contains pointers that has been released. gives the actual number of active pointers. - /// All pointers are expected to have the same . - internal PointerIdentifier[] Pointers { get; } - - public PointerDeviceType PointerDeviceType { get; } - public Point Position { get; } - public ManipulationDelta Delta { get; } - public ManipulationDelta Cumulative { get; } - public ManipulationVelocities Velocities { get; } - public uint ContactCount { get; } - - internal GestureRecognizer.Manipulation.InertiaProcessor Processor { get; } - } -} diff --git a/src/Uno.UWP/UI/Input/ManipulationVelocities.cs b/src/Uno.UWP/UI/Input/ManipulationVelocities.cs deleted file mode 100644 index 6734774488f8..000000000000 --- a/src/Uno.UWP/UI/Input/ManipulationVelocities.cs +++ /dev/null @@ -1,66 +0,0 @@ -using System; -using System.Collections.Generic; -using Windows.Foundation; - -#if HAS_UNO_WINUI && IS_UNO_UI_PROJECT -namespace Microsoft.UI.Input -#else -namespace Windows.UI.Input -#endif -{ - public partial struct ManipulationVelocities : IEquatable - { - internal static ManipulationVelocities Empty { get; } - - /// - /// The expansion, or scaling, velocity in device-independent pixel (DIP) per millisecond. - /// - public Point Linear; - - /// - /// The rotational velocity in degrees per millisecond. - /// - public float Angular; - - /// - /// The expansion, or scaling, velocity in device-independent pixel (DIP) per millisecond. - /// - public float Expansion; - - // NOTE: Equality implementation should be modified if a new field/property is added. - - // Note: We should apply a velocity factor to thresholds to determine if isSignificant - internal bool IsAnyAbove(GestureRecognizer.Manipulation.Thresholds thresholds) - => Math.Abs(Linear.X) > thresholds.TranslateX - || Math.Abs(Linear.Y) > thresholds.TranslateY - || Math.Abs(Angular) > thresholds.Rotate - || Math.Abs(Expansion) > thresholds.Expansion; - - /// - public override string ToString() - => $"x:{Linear.X:N0};y:{Linear.Y:N0};θ:{Angular};e:{Expansion:F2}"; - - #region Equality Members - public override bool Equals(object obj) => obj is ManipulationVelocities velocities && Equals(velocities); - - public bool Equals(ManipulationVelocities other) - { - return EqualityComparer.Default.Equals(Linear, other.Linear) && - Angular == other.Angular && - Expansion == other.Expansion; - } - - public override int GetHashCode() - { - var hashCode = 560214819; - hashCode = hashCode * -1521134295 + Linear.GetHashCode(); - hashCode = hashCode * -1521134295 + Angular.GetHashCode(); - hashCode = hashCode * -1521134295 + Expansion.GetHashCode(); - return hashCode; - } - - public static bool operator ==(ManipulationVelocities left, ManipulationVelocities right) => left.Equals(right); - public static bool operator !=(ManipulationVelocities left, ManipulationVelocities right) => !left.Equals(right); - #endregion - } -} From fa9142e4f0836e501ea2ead7a5862579c3e3f79c Mon Sep 17 00:00:00 2001 From: Ramez Ragaa Date: Tue, 19 Nov 2024 15:35:34 +0200 Subject: [PATCH 2/9] chore: remove GestureRecognizer from Uno.UWP pt 2 --- src/Uno.UWP/UI/Input/DraggingEventArgs.cs | 29 ----- src/Uno.UWP/UI/Input/DraggingState.cs | 13 -- src/Uno.UWP/UI/Input/GestureSettings.cs | 112 ------------------ src/Uno.UWP/UI/Input/HoldingEventArgs.cs | 35 ------ src/Uno.UWP/UI/Input/HoldingState.cs | 13 -- .../Input/ManipulationCompletedEventArgs.cs | 51 -------- .../UI/Input/ManipulationStartedEventArgs.cs | 40 ------- .../UI/Input/ManipulationStartingEventArgs.cs | 28 ----- .../UI/Input/ManipulationUpdatedEventArgs.cs | 54 --------- src/Uno.UWP/UI/Input/RightTappedEventArgs.cs | 35 ------ src/Uno.UWP/UI/Input/TappedEventArgs.cs | 38 ------ 11 files changed, 448 deletions(-) delete mode 100644 src/Uno.UWP/UI/Input/DraggingEventArgs.cs delete mode 100644 src/Uno.UWP/UI/Input/DraggingState.cs delete mode 100644 src/Uno.UWP/UI/Input/GestureSettings.cs delete mode 100644 src/Uno.UWP/UI/Input/HoldingEventArgs.cs delete mode 100644 src/Uno.UWP/UI/Input/HoldingState.cs delete mode 100644 src/Uno.UWP/UI/Input/ManipulationCompletedEventArgs.cs delete mode 100644 src/Uno.UWP/UI/Input/ManipulationStartedEventArgs.cs delete mode 100644 src/Uno.UWP/UI/Input/ManipulationStartingEventArgs.cs delete mode 100644 src/Uno.UWP/UI/Input/ManipulationUpdatedEventArgs.cs delete mode 100644 src/Uno.UWP/UI/Input/RightTappedEventArgs.cs delete mode 100644 src/Uno.UWP/UI/Input/TappedEventArgs.cs diff --git a/src/Uno.UWP/UI/Input/DraggingEventArgs.cs b/src/Uno.UWP/UI/Input/DraggingEventArgs.cs deleted file mode 100644 index 8c42b8e819b7..000000000000 --- a/src/Uno.UWP/UI/Input/DraggingEventArgs.cs +++ /dev/null @@ -1,29 +0,0 @@ -using Windows.Devices.Input; -using Windows.Foundation; - -#if HAS_UNO_WINUI && IS_UNO_UI_PROJECT -namespace Microsoft.UI.Input -#else -namespace Windows.UI.Input -#endif -{ - public partial class DraggingEventArgs - { - internal DraggingEventArgs(PointerPoint point, DraggingState state, uint contactCount) - { - Pointer = point; - DraggingState = state; - ContactCount = contactCount; - } - - internal PointerPoint Pointer { get; } - - public DraggingState DraggingState { get; } - - public PointerDeviceType PointerDeviceType => (PointerDeviceType)Pointer.PointerDevice.PointerDeviceType; - - public Point Position => Pointer.Position; - - public uint ContactCount { get; } - } -} diff --git a/src/Uno.UWP/UI/Input/DraggingState.cs b/src/Uno.UWP/UI/Input/DraggingState.cs deleted file mode 100644 index 5be560f3a80e..000000000000 --- a/src/Uno.UWP/UI/Input/DraggingState.cs +++ /dev/null @@ -1,13 +0,0 @@ -#if HAS_UNO_WINUI && IS_UNO_UI_PROJECT -namespace Microsoft.UI.Input -#else -namespace Windows.UI.Input -#endif -{ - public enum DraggingState - { - Started, - Continuing, - Completed, - } -} diff --git a/src/Uno.UWP/UI/Input/GestureSettings.cs b/src/Uno.UWP/UI/Input/GestureSettings.cs deleted file mode 100644 index e770fd370d1e..000000000000 --- a/src/Uno.UWP/UI/Input/GestureSettings.cs +++ /dev/null @@ -1,112 +0,0 @@ -using System; -using Windows.Foundation; -using Windows.Foundation.Metadata; - -#pragma warning disable 108 // new keyword hiding -#pragma warning disable 114 // new keyword hiding - -#if HAS_UNO_WINUI && IS_UNO_UI_PROJECT -namespace Microsoft.UI.Input -#else -namespace Windows.UI.Input -#endif -{ - [ContractVersion(typeof(UniversalApiContract), 65536U)] - [Flags] - public enum GestureSettings : uint - { - /// Disable support for gestures and manipulations. - None = 0U, - /// Enable support for the tap gesture. - Tap = 1U, - /// Enable support for the double-tap gesture. - DoubleTap = 2U, - /// Enable support for the press and hold gesture (from a single touch or pen/stylus contact). The Holding event is raised if a time threshold is crossed before the contact is lifted, an additional contact is detected, or a gesture is started. - Hold = 4U, - /// Enable support for the press and hold gesture through the left button on a mouse. The Holding event is raised if a time threshold is crossed before the left button is released or a gesture is started.This gesture can be used to display a context menu. - HoldWithMouse = 8U, - /// Enable support for a right-tap interaction. The RightTapped event is raised when the contact is lifted or the mouse button released. - RightTap = 16U, - /// Enable support for the slide or swipe gesture with a mouse or pen/stylus (single contact). The Dragging event is raised when either gesture is detected.This gesture can be used for text selection, selecting or rearranging objects, or scrolling and panning. - Drag = 32U, - /// Enable support for the slide gesture through pointer input, on the horizontal axis. The ManipulationStarted, ManipulationUpdated, and ManipulationCompleted events are all raised during the course of this interaction.This gesture can be used for rearranging objects. - ManipulationTranslateX = 64U, - /// Enable support for the slide gesture through pointer input, on the vertical axis. The ManipulationStarted, ManipulationUpdated, and ManipulationCompleted events are all raised during the course of this interaction.This gesture can be used for rearranging objects. - ManipulationTranslateY = 128U, - /// Enable support for the slide gesture through pointer input, on the horizontal axis using rails (guides). The ManipulationStarted, ManipulationUpdated, and ManipulationCompleted events are all raised during the course of this interaction.This gesture can be used for rearranging objects. - [global::Uno.NotImplemented] // The GestureRecognizer won't raise this event - ManipulationTranslateRailsX = 256U, - /// Enable support for the slide gesture through pointer input, on the vertical axis using rails (guides). The ManipulationStarted, ManipulationUpdated, and ManipulationCompleted events are all raised during the course of this interaction.This gesture can be used for rearranging objects. - [global::Uno.NotImplemented] // The GestureRecognizer won't raise this event - ManipulationTranslateRailsY = 512U, - /// Enable support for the rotation gesture through pointer input. The ManipulationStarted, ManipulationUpdated, and ManipulationCompleted events are all raised during the course of this interaction. - ManipulationRotate = 1024U, - /// Enable support for the pinch or stretch gesture through pointer input.These gestures can be used for optical or semantic zoom and resizing an object. The ManipulationStarted, ManipulationUpdated, and ManipulationCompleted events are all raised during the course of this interaction. - ManipulationScale = 2048U, - /// Enable support for translation inertia after the slide gesture (through pointer input) is complete. The ManipulationInertiaStarting event is raised if inertia is enabled. - ManipulationTranslateInertia = 4096U, - /// Enable support for rotation inertia after the rotate gesture (through pointer input) is complete. The ManipulationInertiaStarting event is raised if inertia is enabled. - ManipulationRotateInertia = 8192U, - /// Enable support for scaling inertia after the pinch or stretch gesture (through pointer input) is complete. The ManipulationInertiaStarting event is raised if inertia is enabled. - ManipulationScaleInertia = 16384U, - /// Enable support for the CrossSliding interaction when using the slide or swipe gesture through a single touch contact.This gesture can be used for selecting or rearranging objects. - [global::Uno.NotImplemented] // The GestureRecognizer won't raise this event - CrossSlide = 32768U, - /// Enable panning and disable zoom when two or more touch contacts are detected.Prevents unintentional zoom interactions when panning with multiple fingers. - [global::Uno.NotImplemented] // The GestureRecognizer won't raise this event - [ContractVersion("Windows.Foundation.UniversalApiContract", 65536U)] - ManipulationMultipleFingerPanning = 65536U, - } - - internal static class GestureSettingsHelper - { - /// - /// A combination of all "manipulation" flags - /// - public const GestureSettings Manipulations = - GestureSettings.ManipulationTranslateX - | GestureSettings.ManipulationTranslateY - | GestureSettings.ManipulationTranslateRailsX - | GestureSettings.ManipulationTranslateRailsY - | GestureSettings.ManipulationTranslateInertia - | GestureSettings.ManipulationRotate - | GestureSettings.ManipulationRotateInertia - | GestureSettings.ManipulationScale - | GestureSettings.ManipulationScaleInertia - | GestureSettings.ManipulationMultipleFingerPanning; // Not supported by ManipulationMode - - /// - /// A combination of all "gesture" flags - /// - public const GestureSettings Gestures = - GestureSettings.Tap - | GestureSettings.DoubleTap - | GestureSettings.Hold - | GestureSettings.HoldWithMouse - | GestureSettings.RightTap - | GestureSettings.CrossSlide; - - /// - /// A combination of all "gesture" flags that can be raised by the GestureRecognizer - /// - public const GestureSettings SupportedGestures = - GestureSettings.Tap - | GestureSettings.DoubleTap - | GestureSettings.Hold - | GestureSettings.HoldWithMouse - | GestureSettings.RightTap; - - /// - /// A combination of all "drag and drop" flags - /// - public const GestureSettings DragAndDrop = GestureSettings.Drag; - - /// - /// A combination of all "inertia" flags - /// - public const GestureSettings Inertia = - GestureSettings.ManipulationTranslateInertia - | GestureSettings.ManipulationScaleInertia - | GestureSettings.ManipulationRotateInertia; - } -} diff --git a/src/Uno.UWP/UI/Input/HoldingEventArgs.cs b/src/Uno.UWP/UI/Input/HoldingEventArgs.cs deleted file mode 100644 index 77530bd2d6ca..000000000000 --- a/src/Uno.UWP/UI/Input/HoldingEventArgs.cs +++ /dev/null @@ -1,35 +0,0 @@ -using Windows.Devices.Input; -using Windows.Foundation; -using Uno; - -#if HAS_UNO_WINUI && IS_UNO_UI_PROJECT -namespace Microsoft.UI.Input -#else -namespace Windows.UI.Input -#endif -{ - public partial class HoldingEventArgs - { - internal HoldingEventArgs(uint pointerId, PointerDeviceType type, Point position, HoldingState state) - { - PointerId = pointerId; - PointerDeviceType = type; - Position = position; - HoldingState = state; - } - - internal uint PointerId { get; } - - public PointerDeviceType PointerDeviceType { get; } - - public Point Position { get; } - - public HoldingState HoldingState { get; } - - [NotImplemented] - public uint ContactCount { get; } = 1; - - [NotImplemented] - public uint CurrentContactCount => HoldingState == HoldingState.Started ? 1u : 0u; - } -} diff --git a/src/Uno.UWP/UI/Input/HoldingState.cs b/src/Uno.UWP/UI/Input/HoldingState.cs deleted file mode 100644 index ace2b5fca268..000000000000 --- a/src/Uno.UWP/UI/Input/HoldingState.cs +++ /dev/null @@ -1,13 +0,0 @@ -#if HAS_UNO_WINUI && IS_UNO_UI_PROJECT -namespace Microsoft.UI.Input -#else -namespace Windows.UI.Input -#endif -{ - public enum HoldingState - { - Started, - Completed, - Canceled, - } -} diff --git a/src/Uno.UWP/UI/Input/ManipulationCompletedEventArgs.cs b/src/Uno.UWP/UI/Input/ManipulationCompletedEventArgs.cs deleted file mode 100644 index a35b0f379ba0..000000000000 --- a/src/Uno.UWP/UI/Input/ManipulationCompletedEventArgs.cs +++ /dev/null @@ -1,51 +0,0 @@ -using System.Linq; -using Windows.Devices.Input; -using Windows.Foundation; - -#pragma warning disable 108 // new keyword hiding -#pragma warning disable 114 // new keyword hiding - -#if HAS_UNO_WINUI && IS_UNO_UI_PROJECT -namespace Microsoft.UI.Input -#else -namespace Windows.UI.Input -#endif -{ - public partial class ManipulationCompletedEventArgs - { - internal ManipulationCompletedEventArgs( - PointerIdentifier[] pointers, - Point position, - ManipulationDelta cumulative, - ManipulationVelocities velocities, - bool isInertial, - uint contactCount, - uint currentContactCount) - { - global::System.Diagnostics.Debug.Assert(pointers.Length > 0 && pointers.All(p => p.Type == pointers[0].Type)); - - Pointers = pointers; - Position = position; - Cumulative = cumulative; - Velocities = velocities; - IsInertial = isInertial; - ContactCount = contactCount; - CurrentContactCount = currentContactCount; - } - - /// - /// Gets identifiers of all pointer that has been involved in that manipulation (cf. Remarks). - /// - /// This collection might contains pointers that has been released. gives the actual number of active pointers. - /// All pointers are expected to have the same . - internal PointerIdentifier[] Pointers { get; } - - public PointerDeviceType PointerDeviceType => (PointerDeviceType)Pointers[0].Type; - public Point Position { get; } - public ManipulationDelta Cumulative { get; } - public ManipulationVelocities Velocities { get; } - public uint ContactCount { get; } - public uint CurrentContactCount { get; } - internal bool IsInertial { get; } - } -} diff --git a/src/Uno.UWP/UI/Input/ManipulationStartedEventArgs.cs b/src/Uno.UWP/UI/Input/ManipulationStartedEventArgs.cs deleted file mode 100644 index dcefc8a274e9..000000000000 --- a/src/Uno.UWP/UI/Input/ManipulationStartedEventArgs.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System.Linq; -using Windows.Devices.Input; -using Windows.Foundation; - -#if HAS_UNO_WINUI && IS_UNO_UI_PROJECT -namespace Microsoft.UI.Input -#else -namespace Windows.UI.Input -#endif -{ - public partial class ManipulationStartedEventArgs - { - internal ManipulationStartedEventArgs( - PointerIdentifier[] pointers, - Point position, - ManipulationDelta cumulative, - uint contactCount) - { - global::System.Diagnostics.Debug.Assert(contactCount == pointers.Length, "We should have the same number of pointers for the manip start."); - global::System.Diagnostics.Debug.Assert(pointers.Length > 0 && pointers.All(p => p.Type == pointers[0].Type)); - - Pointers = pointers; - PointerDeviceType = (PointerDeviceType)pointers[0].Type; - Position = position; - Cumulative = cumulative; - ContactCount = contactCount; - } - - /// - /// Gets identifiers of all pointer that has been involved in that manipulation. - /// - /// All pointers are expected to have the same . - internal PointerIdentifier[] Pointers { get; } - - public PointerDeviceType PointerDeviceType { get; } - public Point Position { get; } - public ManipulationDelta Cumulative { get; } - public uint ContactCount { get; } - } -} diff --git a/src/Uno.UWP/UI/Input/ManipulationStartingEventArgs.cs b/src/Uno.UWP/UI/Input/ManipulationStartingEventArgs.cs deleted file mode 100644 index c22e6eeecb06..000000000000 --- a/src/Uno.UWP/UI/Input/ManipulationStartingEventArgs.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.Linq; -using Windows.Devices.Input; - -#if HAS_UNO_WINUI && IS_UNO_UI_PROJECT -namespace Microsoft.UI.Input -#else -namespace Windows.UI.Input -#endif -{ - internal partial class ManipulationStartingEventArgs - { - // Be aware that this class is not part of the UWP contract - - internal ManipulationStartingEventArgs(PointerIdentifier pointer, GestureSettings settings) - { - Pointer = pointer; - Settings = settings; - } - - /// - /// Gets identifier of the first pointer for which a manipulation is considered - /// - internal PointerIdentifier Pointer { get; } - - public GestureSettings Settings { get; set; } - } -} diff --git a/src/Uno.UWP/UI/Input/ManipulationUpdatedEventArgs.cs b/src/Uno.UWP/UI/Input/ManipulationUpdatedEventArgs.cs deleted file mode 100644 index 5ec5a2685e9c..000000000000 --- a/src/Uno.UWP/UI/Input/ManipulationUpdatedEventArgs.cs +++ /dev/null @@ -1,54 +0,0 @@ -using System.Linq; -using System.Reflection; -using Windows.Devices.Input; -using Windows.Foundation; - -#if HAS_UNO_WINUI && IS_UNO_UI_PROJECT -namespace Microsoft.UI.Input -#else -namespace Windows.UI.Input -#endif -{ - public partial class ManipulationUpdatedEventArgs - { - internal ManipulationUpdatedEventArgs( - PointerIdentifier[] pointers, - Point position, - ManipulationDelta delta, - ManipulationDelta cumulative, - ManipulationVelocities velocities, - bool isInertial, - uint contactCount, - uint currentContactCount) - { - global::System.Diagnostics.Debug.Assert(pointers.Length > 0 && pointers.All(p => p.Type == pointers[0].Type)); - - Pointers = pointers; - PointerDeviceType = (PointerDeviceType)pointers[0].Type; - Position = position; - Delta = delta; - Cumulative = cumulative; - Velocities = velocities; - IsInertial = isInertial; - ContactCount = contactCount; - CurrentContactCount = currentContactCount; - } - - /// - /// Gets identifiers of all pointer that has been involved in that manipulation (cf. Remarks). - /// - /// This collection might contains pointers that has been released. gives the actual number of active pointers. - /// All pointers are expected to have the same . - internal PointerIdentifier[] Pointers { get; } - - public PointerDeviceType PointerDeviceType { get; } - public Point Position { get; } - public ManipulationDelta Delta { get; } - public ManipulationDelta Cumulative { get; } - public ManipulationVelocities Velocities { get; } - public uint ContactCount { get; } - public uint CurrentContactCount { get; } - - internal bool IsInertial { get; } - } -} diff --git a/src/Uno.UWP/UI/Input/RightTappedEventArgs.cs b/src/Uno.UWP/UI/Input/RightTappedEventArgs.cs deleted file mode 100644 index 015866eec9fe..000000000000 --- a/src/Uno.UWP/UI/Input/RightTappedEventArgs.cs +++ /dev/null @@ -1,35 +0,0 @@ -using Windows.Devices.Input; -using Windows.Foundation; - -#if HAS_UNO_WINUI && IS_UNO_UI_PROJECT -namespace Microsoft.UI.Input -#else -namespace Windows.UI.Input -#endif -{ - public partial class RightTappedEventArgs - { - internal RightTappedEventArgs(uint pointerId, PointerDeviceType type, Point position) - { - PointerId = pointerId; - PointerDeviceType = type; - Position = position; - } - - public PointerDeviceType PointerDeviceType { get; } - - public Point Position { get; } - - internal uint PointerId { get; } - - [global::Uno.NotImplemented] - public uint ContactCount - { - get - { - global::Windows.Foundation.Metadata.ApiInformation.TryRaiseNotImplemented("Windows.UI.Input.RightTappedEventArgs", "uint RightTappedEventArgs.ContactCount"); - return 0; - } - } - } -} diff --git a/src/Uno.UWP/UI/Input/TappedEventArgs.cs b/src/Uno.UWP/UI/Input/TappedEventArgs.cs deleted file mode 100644 index 8ad7f75d598c..000000000000 --- a/src/Uno.UWP/UI/Input/TappedEventArgs.cs +++ /dev/null @@ -1,38 +0,0 @@ -using Windows.Devices.Input; -using Windows.Foundation; - -#if HAS_UNO_WINUI && IS_UNO_UI_PROJECT -namespace Microsoft.UI.Input -#else -namespace Windows.UI.Input -#endif -{ - public partial class TappedEventArgs - { - internal TappedEventArgs(uint pointerId, PointerDeviceType type, Point position, uint tapCount) - { - PointerId = pointerId; - PointerDeviceType = type; - Position = position; - TapCount = tapCount; - } - - public PointerDeviceType PointerDeviceType { get; } - - public Point Position { get; } - - internal uint PointerId { get; } - - public uint TapCount { get; } - - [global::Uno.NotImplemented] - public uint ContactCount - { - get - { - global::Windows.Foundation.Metadata.ApiInformation.TryRaiseNotImplemented("Windows.UI.Input.TappedEventArgs", "uint TappedEventArgs.ContactCount"); - return 0; - } - } - } -} From 3389d6a86e86126ccfdbc0c6d7e8f8027acd606f Mon Sep 17 00:00:00 2001 From: Ramez Ragaa Date: Tue, 19 Nov 2024 16:16:52 +0200 Subject: [PATCH 3/9] chore: remove GestureRecognizer from Uno.UWP pt 3 --- src/Uno.UI/UI/Input/PointerPointProperties.cs | 6 + src/Uno.UWP/UI/Input/PointerPoint.cs | 101 ----------- .../UI/Input/PointerPointProperties.cs | 168 ------------------ .../Input/PointerPointPropertiesExtensions.cs | 52 ------ src/Uno.UWP/UI/Input/PointerUpdateKind.cs | 58 ------ src/Uno.UWP/Uno.Reference.csproj | 6 + src/Uno.UWP/Uno.Skia.csproj | 7 + src/Uno.UWP/Uno.Tests.csproj | 6 + src/Uno.UWP/Uno.Wasm.csproj | 6 + src/Uno.UWP/Uno.netcoremobile.csproj | 6 + 10 files changed, 37 insertions(+), 379 deletions(-) delete mode 100644 src/Uno.UWP/UI/Input/PointerPoint.cs delete mode 100644 src/Uno.UWP/UI/Input/PointerPointProperties.cs delete mode 100644 src/Uno.UWP/UI/Input/PointerPointPropertiesExtensions.cs delete mode 100644 src/Uno.UWP/UI/Input/PointerUpdateKind.cs diff --git a/src/Uno.UI/UI/Input/PointerPointProperties.cs b/src/Uno.UI/UI/Input/PointerPointProperties.cs index 815992413ba6..27e01bb92a86 100644 --- a/src/Uno.UI/UI/Input/PointerPointProperties.cs +++ b/src/Uno.UI/UI/Input/PointerPointProperties.cs @@ -80,6 +80,11 @@ internal PointerPointProperties(global::Windows.UI.Input.PointerPointProperties public bool IsInRange { get; internal set; } + /// + /// This is necessary for InteractionTracker, which behaves differently on mouse, touch and trackpad inputs. + /// + internal bool IsTouchPad { get; set; } + public bool IsLeftButtonPressed { get; internal set; } public bool IsMiddleButtonPressed { get; internal set; } @@ -150,6 +155,7 @@ public override string ToString() // Pen if (IsBarrelButtonPressed) builder.Append("barrel "); if (IsEraser) builder.Append("eraser "); + if (IsTouchPad) builder.Append("touchpad "); // Misc builder.Append('('); diff --git a/src/Uno.UWP/UI/Input/PointerPoint.cs b/src/Uno.UWP/UI/Input/PointerPoint.cs deleted file mode 100644 index 88ee6822bf14..000000000000 --- a/src/Uno.UWP/UI/Input/PointerPoint.cs +++ /dev/null @@ -1,101 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Threading; -using Windows.Devices.Input; -using Windows.Foundation; - -#if HAS_UNO_WINUI && IS_UNO_UI_PROJECT -namespace Microsoft.UI.Input -#else -namespace Windows.UI.Input -#endif -{ - public partial class PointerPoint - { - internal PointerPoint( - uint frameId, - ulong timestamp, - PointerDevice device, - uint pointerId, - Point rawPosition, - Point position, - bool isInContact, - PointerPointProperties properties) - { - FrameId = frameId; - Timestamp = timestamp; - PointerDevice = device; - PointerDeviceType = (PointerDeviceType)PointerDevice.PointerDeviceType; - PointerId = pointerId; - RawPosition = rawPosition; - Position = position; - IsInContact = isInContact; - Properties = properties; - } - -#if HAS_UNO_WINUI && IS_UNO_UI_PROJECT - public PointerPoint(Windows.UI.Input.PointerPoint point) - { - FrameId = point.FrameId; - Timestamp = point.Timestamp; - PointerDevice = point.PointerDevice; - PointerId = point.PointerId; - RawPosition = point.RawPosition; - Position = point.Position; - IsInContact = point.IsInContact; - PointerDeviceType = (PointerDeviceType)point.PointerDevice.PointerDeviceType; - - Properties = new PointerPointProperties(point.Properties); - } - - public static explicit operator Windows.UI.Input.PointerPoint(Microsoft.UI.Input.PointerPoint muxPointerPoint) - { - return new Windows.UI.Input.PointerPoint( - muxPointerPoint.FrameId, - muxPointerPoint.Timestamp, - muxPointerPoint.PointerDevice, - muxPointerPoint.PointerId, - muxPointerPoint.RawPosition, - muxPointerPoint.Position, - muxPointerPoint.IsInContact, - (Windows.UI.Input.PointerPointProperties)muxPointerPoint.Properties); - } -#endif - - internal PointerPoint At(Point position) - => new PointerPoint( - FrameId, - Timestamp, - PointerDevice, - PointerId, - RawPosition, - position: position, - IsInContact, - Properties); - - internal PointerIdentifier Pointer => new PointerIdentifier(PointerDevice.PointerDeviceType, PointerId); - - public uint FrameId { get; } - - public ulong Timestamp { get; } - - public PointerDevice PointerDevice { get; } - - public PointerDeviceType PointerDeviceType { get; } - - public uint PointerId { get; } - - public Point RawPosition { get; } - - public Point Position { get; } - - public bool IsInContact { get; } - - public PointerPointProperties Properties { get; } - - /// - public override string ToString() - => $"[{PointerDevice.PointerDeviceType}-{PointerId}] @{Position.ToDebugString()} (raw: {RawPosition.ToDebugString()} | ts: {Timestamp} | props: {Properties} | inContact: {IsInContact})"; - } -} diff --git a/src/Uno.UWP/UI/Input/PointerPointProperties.cs b/src/Uno.UWP/UI/Input/PointerPointProperties.cs deleted file mode 100644 index dbfa81514bfa..000000000000 --- a/src/Uno.UWP/UI/Input/PointerPointProperties.cs +++ /dev/null @@ -1,168 +0,0 @@ -using System.Text; -using Windows.Foundation; -using Uno; - -#if HAS_UNO_WINUI && IS_UNO_UI_PROJECT -namespace Microsoft.UI.Input -#else -namespace Windows.UI.Input -#endif -{ - public partial class PointerPointProperties - { - internal PointerPointProperties() - { - } - - internal PointerPointProperties(Windows.UI.Input.PointerPointProperties properties) - { - if (properties is null) - { - return; - } - - IsPrimary = properties.IsPrimary; - IsInRange = properties.IsInRange; - IsLeftButtonPressed = properties.IsLeftButtonPressed; - IsMiddleButtonPressed = properties.IsMiddleButtonPressed; - IsRightButtonPressed = properties.IsRightButtonPressed; - IsHorizontalMouseWheel = properties.IsHorizontalMouseWheel; - IsXButton1Pressed = properties.IsXButton1Pressed; - IsXButton2Pressed = properties.IsXButton2Pressed; - IsBarrelButtonPressed = properties.IsBarrelButtonPressed; - IsEraser = properties.IsEraser; - Pressure = properties.Pressure; - Orientation = properties.Orientation; - ContactRect = properties.ContactRect; - TouchConfidence = properties.TouchConfidence; - IsCanceled = properties.IsCanceled; - PointerUpdateKind = (PointerUpdateKind)properties.PointerUpdateKind; - XTilt = properties.XTilt; - YTilt = properties.YTilt; - MouseWheelDelta = properties.MouseWheelDelta; - } - -#if HAS_UNO_WINUI && IS_UNO_UI_PROJECT - public static explicit operator Windows.UI.Input.PointerPointProperties(Microsoft.UI.Input.PointerPointProperties muxProps) - { - var props = new Windows.UI.Input.PointerPointProperties(); - - props.IsPrimary = muxProps.IsPrimary; - props.IsInRange = muxProps.IsInRange; - props.IsLeftButtonPressed = muxProps.IsLeftButtonPressed; - props.IsMiddleButtonPressed = muxProps.IsMiddleButtonPressed; - props.IsRightButtonPressed = muxProps.IsRightButtonPressed; - props.IsHorizontalMouseWheel = muxProps.IsHorizontalMouseWheel; - props.IsXButton1Pressed = muxProps.IsXButton1Pressed; - props.IsXButton2Pressed = muxProps.IsXButton2Pressed; - props.IsBarrelButtonPressed = muxProps.IsBarrelButtonPressed; - props.IsEraser = muxProps.IsEraser; - props.Pressure = muxProps.Pressure; - props.Orientation = muxProps.Orientation; - props.ContactRect = muxProps.ContactRect; - props.TouchConfidence = muxProps.TouchConfidence; - props.IsCanceled = muxProps.IsCanceled; - props.PointerUpdateKind = (Windows.UI.Input.PointerUpdateKind)muxProps.PointerUpdateKind; - props.XTilt = muxProps.XTilt; - props.YTilt = muxProps.YTilt; - props.MouseWheelDelta = muxProps.MouseWheelDelta; - - return props; - } -#endif - - /// - /// This is actually equivalent to pointer.IsInContact - /// - internal bool HasPressedButton => IsLeftButtonPressed || IsMiddleButtonPressed || IsRightButtonPressed || IsXButton1Pressed || IsXButton2Pressed || IsBarrelButtonPressed; - - public bool IsPrimary { get; internal set; } - - public bool IsInRange { get; internal set; } - - /// - /// This is necessary for InteractionTracker, which behaves differently on mouse, touch and trackpad inputs. - /// - internal bool IsTouchPad { get; set; } - - public bool IsLeftButtonPressed { get; internal set; } - - public bool IsMiddleButtonPressed { get; internal set; } - - public bool IsRightButtonPressed { get; internal set; } - - public bool IsHorizontalMouseWheel { get; internal set; } - - public bool IsXButton1Pressed { get; internal set; } - - public bool IsXButton2Pressed { get; internal set; } - - public bool IsBarrelButtonPressed { get; internal set; } - - public bool IsEraser { get; internal set; } - - public float Pressure { get; internal set; } = 0.5f; // According to the doc, the default value is .5 - - [NotImplemented] // This is not implemented, it can only be set using injected inputs - public float Orientation { get; internal set; } - - [NotImplemented] // This is not implemented, it can only be set using injected inputs - public Rect ContactRect { get; internal set; } - - [NotImplemented] // This is not implemented, it can only be set using injected inputs - public bool TouchConfidence { get; internal set; } - - [NotImplemented] // This is not implemented, it can only be set using injected inputs - public bool IsCanceled { get; internal set; } - - public PointerUpdateKind PointerUpdateKind { get; internal set; } - - // Supported only on MacOS - [NotImplemented("__ANDROID__", "__IOS__", "IS_UNIT_TESTS", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__")] - public float XTilt { get; internal set; } - - // Supported only on MacOS - [NotImplemented("__ANDROID__", "__IOS__", "IS_UNIT_TESTS", "__WASM__", "__SKIA__", "__NETSTD_REFERENCE__")] - public float YTilt { get; internal set; } - - [NotImplemented("__ANDROID__", "__IOS__", "__MACOS__")] - public int MouseWheelDelta { get; internal set; } - - /// - public override string ToString() - { - var builder = new StringBuilder(); - - // Common - if (IsPrimary) builder.Append("primary "); - if (IsInRange) builder.Append("in_range "); - - if (IsLeftButtonPressed) builder.Append("left "); - if (IsMiddleButtonPressed) builder.Append("middle "); - if (IsRightButtonPressed) builder.Append("right "); - - // Mouse - if (IsXButton1Pressed) builder.Append("alt_butt_1 "); - if (IsXButton2Pressed) builder.Append("alt_butt_2"); - if (MouseWheelDelta != 0) - { - builder.Append("scroll"); - builder.Append(IsHorizontalMouseWheel ? "X (" : "Y ("); - builder.Append(MouseWheelDelta); - builder.Append("px) "); - } - - // Pen - if (IsBarrelButtonPressed) builder.Append("barrel "); - if (IsEraser) builder.Append("eraser "); - if (IsTouchPad) builder.Append("touchpad "); - - // Misc - builder.Append('('); - builder.Append(PointerUpdateKind); - builder.Append(')'); - - return builder.ToString(); - } - } -} diff --git a/src/Uno.UWP/UI/Input/PointerPointPropertiesExtensions.cs b/src/Uno.UWP/UI/Input/PointerPointPropertiesExtensions.cs deleted file mode 100644 index 431ce6168d9d..000000000000 --- a/src/Uno.UWP/UI/Input/PointerPointPropertiesExtensions.cs +++ /dev/null @@ -1,52 +0,0 @@ -#nullable enable - -using System; -using System.Linq; - -#if HAS_UNO_WINUI && IS_UNO_UI_PROJECT -namespace Microsoft.UI.Input; -#else -namespace Windows.UI.Input; -#endif - -internal static class PointerPointPropertiesExtensions -{ - public static PointerPointProperties SetUpdateKindFromPrevious(this PointerPointProperties current, PointerPointProperties? previous) - { - if (previous is null) - { - return current; - } - - // The PointerUpdateKind is not a [Flags] enum, so we allow only one pointer change. - var result = PointerUpdateKind.Other; - if (HasChanged(previous.IsLeftButtonPressed, current.IsLeftButtonPressed, PointerUpdateKind.LeftButtonPressed, PointerUpdateKind.LeftButtonReleased, ref result) - || HasChanged(previous.IsMiddleButtonPressed, current.IsMiddleButtonPressed, PointerUpdateKind.MiddleButtonPressed, PointerUpdateKind.MiddleButtonReleased, ref result) - || HasChanged(previous.IsRightButtonPressed, current.IsRightButtonPressed, PointerUpdateKind.RightButtonPressed, PointerUpdateKind.RightButtonReleased, ref result) - || HasChanged(previous.IsXButton1Pressed, current.IsXButton1Pressed, PointerUpdateKind.XButton1Pressed, PointerUpdateKind.XButton1Released, ref result) - || HasChanged(previous.IsXButton2Pressed, current.IsXButton2Pressed, PointerUpdateKind.XButton2Pressed, PointerUpdateKind.XButton2Released, ref result)) - { - current.PointerUpdateKind = result; - } - - return current; - - static bool HasChanged(bool was, bool @is, PointerUpdateKind pressed, PointerUpdateKind released, ref PointerUpdateKind update) - { - if (was == @is) - { - return false; - } - else if (was) - { - update = released; - return true; - } - else - { - update = pressed; - return true; - } - } - } -} diff --git a/src/Uno.UWP/UI/Input/PointerUpdateKind.cs b/src/Uno.UWP/UI/Input/PointerUpdateKind.cs deleted file mode 100644 index 44e41142c689..000000000000 --- a/src/Uno.UWP/UI/Input/PointerUpdateKind.cs +++ /dev/null @@ -1,58 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -#if HAS_UNO_WINUI && IS_UNO_UI_PROJECT -namespace Microsoft.UI.Input -#else -namespace Windows.UI.Input -#endif -{ - public enum PointerUpdateKind - { - /// - /// Pointer updates not identified by other PointerUpdateKind values. - /// - Other = 0, - /// - /// Left button pressed. - /// - LeftButtonPressed = 1, - /// - /// Left button released. - /// - LeftButtonReleased = 2, - /// - /// Right button pressed. - /// - RightButtonPressed = 3, - /// - /// Right button released. - /// - RightButtonReleased = 4, - /// - /// Middle button pressed. - /// - MiddleButtonPressed = 5, - /// - /// Middle button released. - /// - MiddleButtonReleased = 6, - /// - /// XBUTTON1 pressed. - /// - XButton1Pressed = 7, - /// - /// XBUTTON1 released. - /// - XButton1Released = 8, - /// - /// XBUTTON2 pressed. - /// - XButton2Pressed = 9, - /// - /// XBUTTON2 released. - /// - XButton2Released = 10, - } -} diff --git a/src/Uno.UWP/Uno.Reference.csproj b/src/Uno.UWP/Uno.Reference.csproj index c2beea1b9478..0a5b7971574f 100644 --- a/src/Uno.UWP/Uno.Reference.csproj +++ b/src/Uno.UWP/Uno.Reference.csproj @@ -30,4 +30,10 @@ + + + + + + diff --git a/src/Uno.UWP/Uno.Skia.csproj b/src/Uno.UWP/Uno.Skia.csproj index 129efae754ab..c722524d9c65 100644 --- a/src/Uno.UWP/Uno.Skia.csproj +++ b/src/Uno.UWP/Uno.Skia.csproj @@ -31,6 +31,13 @@ + + + + + + + diff --git a/src/Uno.UWP/Uno.Tests.csproj b/src/Uno.UWP/Uno.Tests.csproj index 8f9c32431809..2e88fc34dbe1 100644 --- a/src/Uno.UWP/Uno.Tests.csproj +++ b/src/Uno.UWP/Uno.Tests.csproj @@ -27,4 +27,10 @@ + + + + + + diff --git a/src/Uno.UWP/Uno.Wasm.csproj b/src/Uno.UWP/Uno.Wasm.csproj index 9393d352b152..f51af58b898d 100644 --- a/src/Uno.UWP/Uno.Wasm.csproj +++ b/src/Uno.UWP/Uno.Wasm.csproj @@ -26,4 +26,10 @@ + + + + + + diff --git a/src/Uno.UWP/Uno.netcoremobile.csproj b/src/Uno.UWP/Uno.netcoremobile.csproj index 6c150e3fd74a..625269661153 100644 --- a/src/Uno.UWP/Uno.netcoremobile.csproj +++ b/src/Uno.UWP/Uno.netcoremobile.csproj @@ -42,4 +42,10 @@ + + + + + + From 5c7ae5fae0eb6c855a341d41ee3a5ade9a300e78 Mon Sep 17 00:00:00 2001 From: Ramez Ragaa Date: Tue, 19 Nov 2024 16:56:20 +0200 Subject: [PATCH 4/9] chore: remove Colors and FontWeights from Uno.UWP --- src/Uno.UI/UI/Colors.cs | 12 +- src/Uno.UWP/UI/Colors.cs | 563 --------------------------- src/Uno.UWP/UI/Text/FontWeights.cs | 49 --- src/Uno.UWP/Uno.Reference.csproj | 2 + src/Uno.UWP/Uno.Skia.csproj | 2 + src/Uno.UWP/Uno.Tests.csproj | 2 + src/Uno.UWP/Uno.Wasm.csproj | 2 + src/Uno.UWP/Uno.netcoremobile.csproj | 2 + 8 files changed, 17 insertions(+), 617 deletions(-) delete mode 100644 src/Uno.UWP/UI/Colors.cs delete mode 100644 src/Uno.UWP/UI/Text/FontWeights.cs diff --git a/src/Uno.UI/UI/Colors.cs b/src/Uno.UI/UI/Colors.cs index 801f414dc4c3..963bb0d574c5 100644 --- a/src/Uno.UI/UI/Colors.cs +++ b/src/Uno.UI/UI/Colors.cs @@ -1,11 +1,14 @@ using System; using System.Collections.Generic; using System.Text; -using Microsoft.UI; using Color = global::Windows/*Intentional space for WinUI upgrade tool*/.UI.Color; +#if HAS_UNO_WINUI && IS_UNO_UI_PROJECT namespace Microsoft.UI +#else +namespace Windows.UI +#endif { #if HAS_UNO_WINUI && !IS_UNO_UI_PROJECT internal @@ -210,7 +213,7 @@ public static Color FromARGB(string colorCode) else { len = colorCode.Length; - // skip a starting `#` if present + // skip a starting `#` if present offset = (len > 0 && colorCode[0] == '#' ? 1 : 0); len -= offset; } @@ -250,10 +253,9 @@ public static Color FromARGB(string colorCode) } else { - r = 0xFF; - g = 0x0; - b = 0x0; + throw new ArgumentException($"Cannot parse color '{colorCode}'."); } + return new Color(a, r, g, b); } diff --git a/src/Uno.UWP/UI/Colors.cs b/src/Uno.UWP/UI/Colors.cs deleted file mode 100644 index dd9ca564cee2..000000000000 --- a/src/Uno.UWP/UI/Colors.cs +++ /dev/null @@ -1,563 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Windows.UI; - -using Color = global::Windows/*Intentional space for WinUI upgrade tool*/.UI.Color; - -namespace Windows.UI -{ -#if HAS_UNO_WINUI && !IS_UNO_UI_PROJECT - internal -#else - public -#endif - static partial class Colors - { - public static Color FromARGB(byte a, byte r, byte g, byte b) => new(a, r, g, b); - - public static Color FromInteger(int color) => new((uint)color); - - /// - /// Parses a string representing a color - /// - /// - /// - public static Color Parse(string colorCode) - { - if (!string.IsNullOrEmpty(colorCode)) - { - if (colorCode[0] == '#') - { - return FromARGB(colorCode); - } - else - { - uint color = colorCode.ToLowerInvariant() switch - { - "transparent" => 0x00FFFFFF, - "aliceblue" => 0xFFF0F8FF, - "antiquewhite" => 0xFFFAEBD7, - "aqua" => 0xFF00FFFF, - "aquamarine" => 0xFF7FFFD4, - "azure" => 0xFFF0FFFF, - "beige" => 0xFFF5F5DC, - "bisque" => 0xFFFFE4C4, - "black" => 0xFF000000, - "blanchedalmond" => 0xFFFFEBCD, - "blue" => 0xFF0000FF, - "blueviolet" => 0xFF8A2BE2, - "brown" => 0xFFA52A2A, - "burlywood" => 0xFFDEB887, - "cadetblue" => 0xFF5F9EA0, - "chartreuse" => 0xFF7FFF00, - "chocolate" => 0xFFD2691E, - "coral" => 0xFFFF7F50, - "cornflowerblue" => 0xFF6495ED, - "cornsilk" => 0xFFFFF8DC, - "crimson" => 0xFFDC143C, - "cyan" => 0xFF00FFFF, - "darkblue" => 0xFF00008B, - "darkcyan" => 0xFF008B8B, - "darkgoldenrod" => 0xFFB8860B, - "darkgray" => 0xFFA9A9A9, - "darkgreen" => 0xFF006400, - "darkkhaki" => 0xFFBDB76B, - "darkmagenta" => 0xFF8B008B, - "darkolivegreen" => 0xFF556B2F, - "darkorange" => 0xFFFF8C00, - "darkorchid" => 0xFF9932CC, - "darkred" => 0xFF8B0000, - "darksalmon" => 0xFFE9967A, - "darkseagreen" => 0xFF8FBC8F, - "darkslateblue" => 0xFF483D8B, - "darkslategray" => 0xFF2F4F4F, - "darkturquoise" => 0xFF00CED1, - "darkviolet" => 0xFF9400D3, - "deeppink" => 0xFFFF1493, - "deepskyblue" => 0xFF00BFFF, - "dimgray" => 0xFF696969, - "dodgerblue" => 0xFF1E90FF, - "firebrick" => 0xFFB22222, - "floralwhite" => 0xFFFFFAF0, - "forestgreen" => 0xFF228B22, - "fuchsia" => 0xFFFF00FF, - "gainsboro" => 0xFFDCDCDC, - "ghostwhite" => 0xFFF8F8FF, - "gold" => 0xFFFFD700, - "goldenrod" => 0xFFDAA520, - "gray" => 0xFF808080, - "green" => 0xFF008000, - "greenyellow" => 0xFFADFF2F, - "honeydew" => 0xFFF0FFF0, - "hotpink" => 0xFFFF69B4, - "indianred" => 0xFFCD5C5C, - "indigo" => 0xFF4B0082, - "ivory" => 0xFFFFFFF0, - "khaki" => 0xFFF0E68C, - "lavender" => 0xFFE6E6FA, - "lavenderblush" => 0xFFFFF0F5, - "lawngreen" => 0xFF7CFC00, - "lemonchiffon" => 0xFFFFFACD, - "lightblue" => 0xFFADD8E6, - "lightcoral" => 0xFFF08080, - "lightcyan" => 0xFFE0FFFF, - "lightgoldenrodyellow" => 0xFFFAFAD2, - "lightgray" => 0xFFD3D3D3, - "lightgreen" => 0xFF90EE90, - "lightpink" => 0xFFFFB6C1, - "lightsalmon" => 0xFFFFA07A, - "lightseagreen" => 0xFF20B2AA, - "lightskyblue" => 0xFF87CEFA, - "lightslategray" => 0xFF778899, - "lightsteelblue" => 0xFFB0C4DE, - "lightyellow" => 0xFFFFFFE0, - "lime" => 0xFF00FF00, - "limegreen" => 0xFF32CD32, - "linen" => 0xFFFAF0E6, - "magenta" => 0xFFFF00FF, - "maroon" => 0xFF800000, - "mediumaquamarine" => 0xFF66CDAA, - "mediumblue" => 0xFF0000CD, - "mediumorchid" => 0xFFBA55D3, - "mediumpurple" => 0xFF9370DB, - "mediumseagreen" => 0xFF3CB371, - "mediumslateblue" => 0xFF7B68EE, - "mediumspringgreen" => 0xFF00FA9A, - "mediumturquoise" => 0xFF48D1CC, - "mediumvioletred" => 0xFFC71585, - "midnightblue" => 0xFF191970, - "mintcream" => 0xFFF5FFFA, - "mistyrose" => 0xFFFFE4E1, - "moccasin" => 0xFFFFE4B5, - "navajowhite" => 0xFFFFDEAD, - "navy" => 0xFF000080, - "oldlace" => 0xFFFDF5E6, - "olive" => 0xFF808000, - "olivedrab" => 0xFF6B8E23, - "orange" => 0xFFFFA500, - "orangered" => 0xFFFF4500, - "orchid" => 0xFFDA70D6, - "palegoldenrod" => 0xFFEEE8AA, - "palegreen" => 0xFF98FB98, - "paleturquoise" => 0xFFAFEEEE, - "palevioletred" => 0xFFDB7093, - "papayawhip" => 0xFFFFEFD5, - "peachpuff" => 0xFFFFDAB9, - "peru" => 0xFFCD853F, - "pink" => 0xFFFFC0CB, - "plum" => 0xFFDDA0DD, - "powderblue" => 0xFFB0E0E6, - "purple" => 0xFF800080, - "red" => 0xFFFF0000, - "rosybrown" => 0xFFBC8F8F, - "royalblue" => 0xFF4169E1, - "saddlebrown" => 0xFF8B4513, - "salmon" => 0xFFFA8072, - "sandybrown" => 0xFFF4A460, - "seagreen" => 0xFF2E8B57, - "seashell" => 0xFFFFF5EE, - "sienna" => 0xFFA0522D, - "silver" => 0xFFC0C0C0, - "skyblue" => 0xFF87CEEB, - "slateblue" => 0xFF6A5ACD, - "slategray" => 0xFF708090, - "snow" => 0xFFFFFAFA, - "springgreen" => 0xFF00FF7F, - "steelblue" => 0xFF4682B4, - "tan" => 0xFFD2B48C, - "teal" => 0xFF008080, - "thistle" => 0xFFD8BFD8, - "tomato" => 0xFFFF6347, - "turquoise" => 0xFF40E0D0, - "violet" => 0xFFEE82EE, - "wheat" => 0xFFF5DEB3, - "white" => 0xFFFFFFFF, - "whitesmoke" => 0xFFF5F5F5, - "yellow" => 0xFFFFFF00, - "yellowgreen" => 0xFF9ACD32, - _ => throw new InvalidOperationException($"The color {colorCode} is unknown") - }; - - return new Color(color); - } - } - else - { - throw new InvalidOperationException($"Cannot parse an empty color string"); - } - } - - /// - /// Takes a color code as an ARGB, RGB, #ARGB, #RGB string and returns a color. - /// - /// Remark: if single digits are used to define the color, they will - /// be duplicated (example: FFD8 will become FFFFDD88) - /// - /// - /// - public static Color FromARGB(string colorCode) - { - byte a, r, b, g; - int offset; - int len; - - if (colorCode is null) - { - len = 0; - offset = 0; - } - else - { - len = colorCode.Length; - // skip a starting `#` if present - offset = (len > 0 && colorCode[0] == '#' ? 1 : 0); - len -= offset; - } - - // deal with an optional alpha value - if (len == 4) - { - a = ToByte(colorCode[offset++]); - a = (byte)(a << 4 + a); - len = 3; - } - else if (len == 8) - { - a = (byte)((ToByte(colorCode[offset++]) << 4) + ToByte(colorCode[offset++])); - len = 6; - } - else - { - a = 0xFF; - } - - // then process the required R G and B values - if (len == 3) - { - r = ToByte(colorCode[offset++]); - r = (byte)(r << 4 + r); - g = ToByte(colorCode[offset++]); - g = (byte)(g << 4 + g); - b = ToByte(colorCode[offset++]); - b = (byte)(b << 4 + b); - } - else if (len == 6) - { - r = (byte)((ToByte(colorCode[offset++]) << 4) + ToByte(colorCode[offset++])); - g = (byte)((ToByte(colorCode[offset++]) << 4) + ToByte(colorCode[offset++])); - b = (byte)((ToByte(colorCode[offset++]) << 4) + ToByte(colorCode[offset++])); - } - else - { - throw new ArgumentException($"Cannot parse color '{colorCode}'."); - } - - return new Color(a, r, g, b); - } - - private static byte ToByte(char c) - { - if (c >= '0' && c <= '9') - { - return (byte)(c - '0'); - } - else if (c >= 'a' && c <= 'f') - { - return (byte)(c - 'a' + 10); - } - else if (c >= 'A' && c <= 'F') - { - return (byte)(c - 'A' + 10); - } - else - { - throw new FormatException($"The character {c} is not valid for a Color string"); - } - } - - private static Color? _transparent; - private static Color? _aliceBlue; - private static Color? _antiqueWhite; - private static Color? _aqua; - private static Color? _aquamarine; - private static Color? _azure; - private static Color? _beige; - private static Color? _bisque; - private static Color? _black; - private static Color? _blanchedAlmond; - private static Color? _blue; - private static Color? _blueViolet; - private static Color? _brown; - private static Color? _burlyWood; - private static Color? _cadetBlue; - private static Color? _chartreuse; - private static Color? _chocolate; - private static Color? _coral; - private static Color? _cornflowerBlue; - private static Color? _cornsilk; - private static Color? _crimson; - private static Color? _cyan; - private static Color? _darkBlue; - private static Color? _darkCyan; - private static Color? _darkGoldenrod; - private static Color? _darkGray; - private static Color? _darkGreen; - private static Color? _darkKhaki; - private static Color? _darkMagenta; - private static Color? _darkOliveGreen; - private static Color? _darkOrange; - private static Color? _darkOrchid; - private static Color? _darkRed; - private static Color? _darkSalmon; - private static Color? _darkSeaGreen; - private static Color? _darkSlateBlue; - private static Color? _darkSlateGray; - private static Color? _darkTurquoise; - private static Color? _darkViolet; - private static Color? _deepPink; - private static Color? _deepSkyBlue; - private static Color? _dimGray; - private static Color? _dodgerBlue; - private static Color? _firebrick; - private static Color? _floralWhite; - private static Color? _forestGreen; - private static Color? _fuchsia; - private static Color? _gainsboro; - private static Color? _ghostWhite; - private static Color? _gold; - private static Color? _goldenrod; - private static Color? _gray; - private static Color? _green; - private static Color? _greenYellow; - private static Color? _honeydew; - private static Color? _hotPink; - private static Color? _indianRed; - private static Color? _indigo; - private static Color? _ivory; - private static Color? _khaki; - private static Color? _lavender; - private static Color? _lavenderBlush; - private static Color? _lawnGreen; - private static Color? _lemonChiffon; - private static Color? _lightBlue; - private static Color? _lightCoral; - private static Color? _lightCyan; - private static Color? _lightGoldenrodYellow; - private static Color? _lightGray; - private static Color? _lightGreen; - private static Color? _lightPink; - private static Color? _lightSalmon; - private static Color? _lightSeaGreen; - private static Color? _lightSkyBlue; - private static Color? _lightSlateGray; - private static Color? _lightSteelBlue; - private static Color? _lightYellow; - private static Color? _lime; - private static Color? _limeGreen; - private static Color? _linen; - private static Color? _magenta; - private static Color? _maroon; - private static Color? _mediumAquamarine; - private static Color? _mediumBlue; - private static Color? _mediumOrchid; - private static Color? _mediumPurple; - private static Color? _mediumSeaGreen; - private static Color? _mediumSlateBlue; - private static Color? _mediumSpringGreen; - private static Color? _mediumTurquoise; - private static Color? _mediumVioletRed; - private static Color? _midnightBlue; - private static Color? _mintCream; - private static Color? _mistyRose; - private static Color? _moccasin; - private static Color? _navajoWhite; - private static Color? _navy; - private static Color? _oldLace; - private static Color? _olive; - private static Color? _oliveDrab; - private static Color? _orange; - private static Color? _orangeRed; - private static Color? _orchid; - private static Color? _paleGoldenrod; - private static Color? _paleGreen; - private static Color? _paleTurquoise; - private static Color? _paleVioletRed; - private static Color? _papayaWhip; - private static Color? _peachPuff; - private static Color? _peru; - private static Color? _pink; - private static Color? _plum; - private static Color? _powderBlue; - private static Color? _purple; - private static Color? _red; - private static Color? _rosyBrown; - private static Color? _royalBlue; - private static Color? _saddleBrown; - private static Color? _salmon; - private static Color? _sandyBrown; - private static Color? _seaGreen; - private static Color? _seaShell; - private static Color? _sienna; - private static Color? _silver; - private static Color? _skyBlue; - private static Color? _slateBlue; - private static Color? _slateGray; - private static Color? _snow; - private static Color? _springGreen; - private static Color? _steelBlue; - private static Color? _tan; - private static Color? _teal; - private static Color? _thistle; - private static Color? _tomato; - private static Color? _turquoise; - private static Color? _violet; - private static Color? _wheat; - private static Color? _white; - private static Color? _whiteSmoke; - private static Color? _yellow; - private static Color? _yellowGreen; - - public static Color Transparent => _transparent ??= FromInteger(0x00FFFFFF); - public static Color AliceBlue => _aliceBlue ??= FromInteger(unchecked((int)0xFFF0F8FF)); - public static Color AntiqueWhite => _antiqueWhite ??= FromInteger(unchecked((int)0xFFFAEBD7)); - public static Color Aqua => _aqua ??= FromInteger(unchecked((int)0xFF00FFFF)); - public static Color Aquamarine => _aquamarine ??= FromInteger(unchecked((int)0xFF7FFFD4)); - public static Color Azure => _azure ??= FromInteger(unchecked((int)0xFFF0FFFF)); - public static Color Beige => _beige ??= FromInteger(unchecked((int)0xFFF5F5DC)); - public static Color Bisque => _bisque ??= FromInteger(unchecked(unchecked((int)0xFFFFE4C4))); - public static Color Black => _black ??= FromInteger(unchecked((int)0xFF000000)); - public static Color BlanchedAlmond => _blanchedAlmond ??= FromInteger(unchecked((int)0xFFFFEBCD)); - public static Color Blue => _blue ??= FromInteger(unchecked((int)0xFF0000FF)); - public static Color BlueViolet => _blueViolet ??= FromInteger(unchecked((int)0xFF8A2BE2)); - public static Color Brown => _brown ??= FromInteger(unchecked((int)0xFFA52A2A)); - public static Color BurlyWood => _burlyWood ??= FromInteger(unchecked((int)0xFFDEB887)); - public static Color CadetBlue => _cadetBlue ??= FromInteger(unchecked((int)0xFF5F9EA0)); - public static Color Chartreuse => _chartreuse ??= FromInteger(unchecked((int)0xFF7FFF00)); - public static Color Chocolate => _chocolate ??= FromInteger(unchecked((int)0xFFD2691E)); - public static Color Coral => _coral ??= FromInteger(unchecked((int)0xFFFF7F50)); - public static Color CornflowerBlue => _cornflowerBlue ??= FromInteger(unchecked((int)0xFF6495ED)); - public static Color Cornsilk => _cornsilk ??= FromInteger(unchecked((int)0xFFFFF8DC)); - public static Color Crimson => _crimson ??= FromInteger(unchecked((int)0xFFDC143C)); - public static Color Cyan => _cyan ??= FromInteger(unchecked((int)0xFF00FFFF)); - public static Color DarkBlue => _darkBlue ??= FromInteger(unchecked((int)0xFF00008B)); - public static Color DarkCyan => _darkCyan ??= FromInteger(unchecked((int)0xFF008B8B)); - public static Color DarkGoldenrod => _darkGoldenrod ??= FromInteger(unchecked((int)0xFFB8860B)); - public static Color DarkGray => _darkGray ??= FromInteger(unchecked((int)0xFFA9A9A9)); - public static Color DarkGreen => _darkGreen ??= FromInteger(unchecked((int)0xFF006400)); - public static Color DarkKhaki => _darkKhaki ??= FromInteger(unchecked((int)0xFFBDB76B)); - public static Color DarkMagenta => _darkMagenta ??= FromInteger(unchecked((int)0xFF8B008B)); - public static Color DarkOliveGreen => _darkOliveGreen ??= FromInteger(unchecked((int)0xFF556B2F)); - public static Color DarkOrange => _darkOrange ??= FromInteger(unchecked((int)0xFFFF8C00)); - public static Color DarkOrchid => _darkOrchid ??= FromInteger(unchecked((int)0xFF9932CC)); - public static Color DarkRed => _darkRed ??= FromInteger(unchecked((int)0xFF8B0000)); - public static Color DarkSalmon => _darkSalmon ??= FromInteger(unchecked((int)0xFFE9967A)); - public static Color DarkSeaGreen => _darkSeaGreen ??= FromInteger(unchecked((int)0xFF8FBC8F)); - public static Color DarkSlateBlue => _darkSlateBlue ??= FromInteger(unchecked((int)0xFF483D8B)); - public static Color DarkSlateGray => _darkSlateGray ??= FromInteger(unchecked((int)0xFF2F4F4F)); - public static Color DarkTurquoise => _darkTurquoise ??= FromInteger(unchecked((int)0xFF00CED1)); - public static Color DarkViolet => _darkViolet ??= FromInteger(unchecked((int)0xFF9400D3)); - public static Color DeepPink => _deepPink ??= FromInteger(unchecked((int)0xFFFF1493)); - public static Color DeepSkyBlue => _deepSkyBlue ??= FromInteger(unchecked((int)0xFF00BFFF)); - public static Color DimGray => _dimGray ??= FromInteger(unchecked((int)0xFF696969)); - public static Color DodgerBlue => _dodgerBlue ??= FromInteger(unchecked((int)0xFF1E90FF)); - public static Color Firebrick => _firebrick ??= FromInteger(unchecked((int)0xFFB22222)); - public static Color FloralWhite => _floralWhite ??= FromInteger(unchecked((int)0xFFFFFAF0)); - public static Color ForestGreen => _forestGreen ??= FromInteger(unchecked((int)0xFF228B22)); - public static Color Fuchsia => _fuchsia ??= FromInteger(unchecked((int)0xFFFF00FF)); - public static Color Gainsboro => _gainsboro ??= FromInteger(unchecked((int)0xFFDCDCDC)); - public static Color GhostWhite => _ghostWhite ??= FromInteger(unchecked((int)0xFFF8F8FF)); - public static Color Gold => _gold ??= FromInteger(unchecked((int)0xFFFFD700)); - public static Color Goldenrod => _goldenrod ??= FromInteger(unchecked((int)0xFFDAA520)); - public static Color Gray => _gray ??= FromInteger(unchecked((int)0xFF808080)); - public static Color Green => _green ??= FromInteger(unchecked((int)0xFF008000)); - public static Color GreenYellow => _greenYellow ??= FromInteger(unchecked((int)0xFFADFF2F)); - public static Color Honeydew => _honeydew ??= FromInteger(unchecked((int)0xFFF0FFF0)); - public static Color HotPink => _hotPink ??= FromInteger(unchecked((int)0xFFFF69B4)); - public static Color IndianRed => _indianRed ??= FromInteger(unchecked((int)0xFFCD5C5C)); - public static Color Indigo => _indigo ??= FromInteger(unchecked((int)0xFF4B0082)); - public static Color Ivory => _ivory ??= FromInteger(unchecked((int)0xFFFFFFF0)); - public static Color Khaki => _khaki ??= FromInteger(unchecked((int)0xFFF0E68C)); - public static Color Lavender => _lavender ??= FromInteger(unchecked((int)0xFFE6E6FA)); - public static Color LavenderBlush => _lavenderBlush ??= FromInteger(unchecked((int)0xFFFFF0F5)); - public static Color LawnGreen => _lawnGreen ??= FromInteger(unchecked((int)0xFF7CFC00)); - public static Color LemonChiffon => _lemonChiffon ??= FromInteger(unchecked((int)0xFFFFFACD)); - public static Color LightBlue => _lightBlue ??= FromInteger(unchecked((int)0xFFADD8E6)); - public static Color LightCoral => _lightCoral ??= FromInteger(unchecked((int)0xFFF08080)); - public static Color LightCyan => _lightCyan ??= FromInteger(unchecked((int)0xFFE0FFFF)); - public static Color LightGoldenrodYellow => _lightGoldenrodYellow ??= FromInteger(unchecked((int)0xFFFAFAD2)); - public static Color LightGray => _lightGray ??= FromInteger(unchecked((int)0xFFD3D3D3)); - public static Color LightGreen => _lightGreen ??= FromInteger(unchecked((int)0xFF90EE90)); - public static Color LightPink => _lightPink ??= FromInteger(unchecked((int)0xFFFFB6C1)); - public static Color LightSalmon => _lightSalmon ??= FromInteger(unchecked((int)0xFFFFA07A)); - public static Color LightSeaGreen => _lightSeaGreen ??= FromInteger(unchecked((int)0xFF20B2AA)); - public static Color LightSkyBlue => _lightSkyBlue ??= FromInteger(unchecked((int)0xFF87CEFA)); - public static Color LightSlateGray => _lightSlateGray ??= FromInteger(unchecked((int)0xFF778899)); - public static Color LightSteelBlue => _lightSteelBlue ??= FromInteger(unchecked((int)0xFFB0C4DE)); - public static Color LightYellow => _lightYellow ??= FromInteger(unchecked((int)0xFFFFFFE0)); - public static Color Lime => _lime ??= FromInteger(unchecked((int)0xFF00FF00)); - public static Color LimeGreen => _limeGreen ??= FromInteger(unchecked((int)0xFF32CD32)); - public static Color Linen => _linen ??= FromInteger(unchecked((int)0xFFFAF0E6)); - public static Color Magenta => _magenta ??= FromInteger(unchecked((int)0xFFFF00FF)); - public static Color Maroon => _maroon ??= FromInteger(unchecked((int)0xFF800000)); - public static Color MediumAquamarine => _mediumAquamarine ??= FromInteger(unchecked((int)0xFF66CDAA)); - public static Color MediumBlue => _mediumBlue ??= FromInteger(unchecked((int)0xFF0000CD)); - public static Color MediumOrchid => _mediumOrchid ??= FromInteger(unchecked((int)0xFFBA55D3)); - public static Color MediumPurple => _mediumPurple ??= FromInteger(unchecked((int)0xFF9370DB)); - public static Color MediumSeaGreen => _mediumSeaGreen ??= FromInteger(unchecked((int)0xFF3CB371)); - public static Color MediumSlateBlue => _mediumSlateBlue ??= FromInteger(unchecked((int)0xFF7B68EE)); - public static Color MediumSpringGreen => _mediumSpringGreen ??= FromInteger(unchecked((int)0xFF00FA9A)); - public static Color MediumTurquoise => _mediumTurquoise ??= FromInteger(unchecked((int)0xFF48D1CC)); - public static Color MediumVioletRed => _mediumVioletRed ??= FromInteger(unchecked((int)0xFFC71585)); - public static Color MidnightBlue => _midnightBlue ??= FromInteger(unchecked((int)0xFF191970)); - public static Color MintCream => _mintCream ??= FromInteger(unchecked((int)0xFFF5FFFA)); - public static Color MistyRose => _mistyRose ??= FromInteger(unchecked((int)0xFFFFE4E1)); - public static Color Moccasin => _moccasin ??= FromInteger(unchecked((int)0xFFFFE4B5)); - public static Color NavajoWhite => _navajoWhite ??= FromInteger(unchecked((int)0xFFFFDEAD)); - public static Color Navy => _navy ??= FromInteger(unchecked((int)0xFF000080)); - public static Color OldLace => _oldLace ??= FromInteger(unchecked((int)0xFFFDF5E6)); - public static Color Olive => _olive ??= FromInteger(unchecked((int)0xFF808000)); - public static Color OliveDrab => _oliveDrab ??= FromInteger(unchecked((int)0xFF6B8E23)); - public static Color Orange => _orange ??= FromInteger(unchecked((int)0xFFFFA500)); - public static Color OrangeRed => _orangeRed ??= FromInteger(unchecked((int)0xFFFF4500)); - public static Color Orchid => _orchid ??= FromInteger(unchecked((int)0xFFDA70D6)); - public static Color PaleGoldenrod => _paleGoldenrod ??= FromInteger(unchecked((int)0xFFEEE8AA)); - public static Color PaleGreen => _paleGreen ??= FromInteger(unchecked((int)0xFF98FB98)); - public static Color PaleTurquoise => _paleTurquoise ??= FromInteger(unchecked((int)0xFFAFEEEE)); - public static Color PaleVioletRed => _paleVioletRed ??= FromInteger(unchecked((int)0xFFDB7093)); - public static Color PapayaWhip => _papayaWhip ??= FromInteger(unchecked((int)0xFFFFEFD5)); - public static Color PeachPuff => _peachPuff ??= FromInteger(unchecked((int)0xFFFFDAB9)); - public static Color Peru => _peru ??= FromInteger(unchecked((int)0xFFCD853F)); - public static Color Pink => _pink ??= FromInteger(unchecked((int)0xFFFFC0CB)); - public static Color Plum => _plum ??= FromInteger(unchecked((int)0xFFDDA0DD)); - public static Color PowderBlue => _powderBlue ??= FromInteger(unchecked((int)0xFFB0E0E6)); - public static Color Purple => _purple ??= FromInteger(unchecked((int)0xFF800080)); - public static Color Red => _red ??= FromInteger(unchecked((int)0xFFFF0000)); - public static Color RosyBrown => _rosyBrown ??= FromInteger(unchecked((int)0xFFBC8F8F)); - public static Color RoyalBlue => _royalBlue ??= FromInteger(unchecked((int)0xFF4169E1)); - public static Color SaddleBrown => _saddleBrown ??= FromInteger(unchecked((int)0xFF8B4513)); - public static Color Salmon => _salmon ??= FromInteger(unchecked((int)0xFFFA8072)); - public static Color SandyBrown => _sandyBrown ??= FromInteger(unchecked((int)0xFFF4A460)); - public static Color SeaGreen => _seaGreen ??= FromInteger(unchecked((int)0xFF2E8B57)); - public static Color SeaShell => _seaShell ??= FromInteger(unchecked((int)0xFFFFF5EE)); - public static Color Sienna => _sienna ??= FromInteger(unchecked((int)0xFFA0522D)); - public static Color Silver => _silver ??= FromInteger(unchecked((int)0xFFC0C0C0)); - public static Color SkyBlue => _skyBlue ??= FromInteger(unchecked((int)0xFF87CEEB)); - public static Color SlateBlue => _slateBlue ??= FromInteger(unchecked((int)0xFF6A5ACD)); - public static Color SlateGray => _slateGray ??= FromInteger(unchecked((int)0xFF708090)); - public static Color Snow => _snow ??= FromInteger(unchecked((int)0xFFFFFAFA)); - public static Color SpringGreen => _springGreen ??= FromInteger(unchecked((int)0xFF00FF7F)); - public static Color SteelBlue => _steelBlue ??= FromInteger(unchecked((int)0xFF4682B4)); - public static Color Tan => _tan ??= FromInteger(unchecked((int)0xFFD2B48C)); - public static Color Teal => _teal ??= FromInteger(unchecked((int)0xFF008080)); - public static Color Thistle => _thistle ??= FromInteger(unchecked((int)0xFFD8BFD8)); - public static Color Tomato => _tomato ??= FromInteger(unchecked((int)0xFFFF6347)); - public static Color Turquoise => _turquoise ??= FromInteger(unchecked((int)0xFF40E0D0)); - public static Color Violet => _violet ??= FromInteger(unchecked((int)0xFFEE82EE)); - public static Color Wheat => _wheat ??= FromInteger(unchecked((int)0xFFF5DEB3)); - public static Color White => _white ??= FromInteger(unchecked((int)0xFFFFFFFF)); - public static Color WhiteSmoke => _whiteSmoke ??= FromInteger(unchecked((int)0xFFF5F5F5)); - public static Color Yellow => _yellow ??= FromInteger(unchecked((int)0xFFFFFF00)); - public static Color YellowGreen => _yellowGreen ??= FromInteger(unchecked((int)0xFF9ACD32)); - } -} diff --git a/src/Uno.UWP/UI/Text/FontWeights.cs b/src/Uno.UWP/UI/Text/FontWeights.cs deleted file mode 100644 index 473186f8cfd7..000000000000 --- a/src/Uno.UWP/UI/Text/FontWeights.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -#if HAS_UNO_WINUI && IS_UNO_UI_PROJECT -using Windows.UI.Text; -namespace Microsoft.UI.Text -#else -namespace Windows.UI.Text -#endif -{ -#if HAS_UNO_WINUI && !IS_UNO_UI_PROJECT - internal -#else - public -#endif - partial class FontWeights - { - private static FontWeight? _thin; - private static FontWeight? _extraLight; - private static FontWeight? _light; - private static FontWeight? _semiLight; - private static FontWeight? _normal; - private static FontWeight? _medium; - private static FontWeight? _semiBold; - private static FontWeight? _bold; - private static FontWeight? _extraBold; - private static FontWeight? _black; - private static FontWeight? _extraBlack; - - public static FontWeight Thin => _thin ??= new FontWeight(100); - public static FontWeight ExtraLight => _extraLight ??= new FontWeight(200); - public static FontWeight UltraLight => _extraLight ??= new FontWeight(200); - public static FontWeight Light => _light ??= new FontWeight(300); - public static FontWeight SemiLight => _semiLight ??= new FontWeight(350); - public static FontWeight Normal => _normal ??= new FontWeight(400); - public static FontWeight Regular => _normal ??= new FontWeight(400); - public static FontWeight Medium => _medium ??= new FontWeight(500); - public static FontWeight SemiBold => _semiBold ??= new FontWeight(600); - public static FontWeight DemiBold => _semiBold ??= new FontWeight(600); - public static FontWeight Bold => _bold ??= new FontWeight(700); - public static FontWeight ExtraBold => _extraBold ??= new FontWeight(800); - public static FontWeight UltraBold => _extraBold ??= new FontWeight(800); - public static FontWeight Black => _black ??= new FontWeight(900); - public static FontWeight Heavy => _black ??= new FontWeight(900); - public static FontWeight ExtraBlack => _extraBlack ??= new FontWeight(950); - public static FontWeight UltraBlack => _extraBlack ??= new FontWeight(950); - } -} diff --git a/src/Uno.UWP/Uno.Reference.csproj b/src/Uno.UWP/Uno.Reference.csproj index 0a5b7971574f..84534f15a90a 100644 --- a/src/Uno.UWP/Uno.Reference.csproj +++ b/src/Uno.UWP/Uno.Reference.csproj @@ -35,5 +35,7 @@ + + diff --git a/src/Uno.UWP/Uno.Skia.csproj b/src/Uno.UWP/Uno.Skia.csproj index c722524d9c65..337993273208 100644 --- a/src/Uno.UWP/Uno.Skia.csproj +++ b/src/Uno.UWP/Uno.Skia.csproj @@ -37,6 +37,8 @@ + + diff --git a/src/Uno.UWP/Uno.Tests.csproj b/src/Uno.UWP/Uno.Tests.csproj index 2e88fc34dbe1..9ae7678f9b01 100644 --- a/src/Uno.UWP/Uno.Tests.csproj +++ b/src/Uno.UWP/Uno.Tests.csproj @@ -32,5 +32,7 @@ + + diff --git a/src/Uno.UWP/Uno.Wasm.csproj b/src/Uno.UWP/Uno.Wasm.csproj index f51af58b898d..c46d39a227ce 100644 --- a/src/Uno.UWP/Uno.Wasm.csproj +++ b/src/Uno.UWP/Uno.Wasm.csproj @@ -31,5 +31,7 @@ + + diff --git a/src/Uno.UWP/Uno.netcoremobile.csproj b/src/Uno.UWP/Uno.netcoremobile.csproj index 625269661153..d27624bc26a4 100644 --- a/src/Uno.UWP/Uno.netcoremobile.csproj +++ b/src/Uno.UWP/Uno.netcoremobile.csproj @@ -47,5 +47,7 @@ + + From 1af9f0337b482533cf5c314cb7bacb7bff9078d4 Mon Sep 17 00:00:00 2001 From: Ramez Ragaa Date: Wed, 20 Nov 2024 19:14:06 +0200 Subject: [PATCH 5/9] chore: remove ColorHelper from Uno.UWP and fix build --- src/Uno.UI/UI/ColorHelper.cs | 410 +++++++++++++++++++++++++- src/Uno.UWP/UI/ColorHelper.cs | 421 --------------------------- src/Uno.UWP/Uno.Reference.csproj | 8 - src/Uno.UWP/Uno.Skia.csproj | 9 - src/Uno.UWP/Uno.Tests.csproj | 8 - src/Uno.UWP/Uno.Wasm.csproj | 8 - src/Uno.UWP/Uno.netcoremobile.csproj | 8 - src/Uno.WinUIRevert/Program.cs | 24 -- 8 files changed, 405 insertions(+), 491 deletions(-) delete mode 100644 src/Uno.UWP/UI/ColorHelper.cs diff --git a/src/Uno.UI/UI/ColorHelper.cs b/src/Uno.UI/UI/ColorHelper.cs index 8accaeb69db0..4df6787fb020 100644 --- a/src/Uno.UI/UI/ColorHelper.cs +++ b/src/Uno.UI/UI/ColorHelper.cs @@ -1,17 +1,74 @@ -using System.ComponentModel; +using System; +using System.ComponentModel; +using Uno.Extensions; using WindowsColor = Windows/*Intentional space for WinUI upgrade tool*/.UI.Color; -using WindowsColorHelper = Windows.UI.ColorHelper; -namespace Microsoft.UI; +#if HAS_UNO_WINUI && IS_UNO_UI_PROJECT +namespace Microsoft.UI.Text; +#else +namespace Windows.UI.Text; +#endif -public static partial class ColorHelper +#if HAS_UNO_WINUI && !IS_UNO_UI_PROJECT +internal +#else +public +#endif + static partial class ColorHelper { /// /// Retrieves the display name of the specified color. /// /// The color to get the name for. /// The localized display name of the color. - public static string ToDisplayName(WindowsColor color) => WindowsColorHelper.ToDisplayName(color); + public static string ToDisplayName(WindowsColor color) + { + var id = GetColorNameResourceId(color); + //Uno specific + return global::Windows.ApplicationModel.Resources.ResourceLoader.GetForViewIndependentUse("Uno.UI/Resources").GetString(id.ToStringInvariant()); + // WinUI uses the GetLocalizedResourceString from DXamlCore, but it is not available under Windows.UI + //return DirectUI.DXamlCore.Current.GetLocalizedResourceString(id); + } + + /// + /// Converts a color string in hex format to a Windows.UI.Color. + /// + internal static WindowsColor ConvertColorFromHexString(string colorString) + { + try + { + colorString = colorString.Replace("#", string.Empty); + + byte a = 255; + byte r, g, b; + + if (colorString.Length == 6) + { + // #RRGGBB format + r = (byte)Convert.ToUInt32(colorString.Substring(0, 2), 16); + g = (byte)Convert.ToUInt32(colorString.Substring(2, 2), 16); + b = (byte)Convert.ToUInt32(colorString.Substring(4, 2), 16); + } + else if (colorString.Length == 8) + { + // #AARRGGBB format + a = (byte)Convert.ToUInt32(colorString.Substring(0, 2), 16); + r = (byte)Convert.ToUInt32(colorString.Substring(2, 2), 16); + g = (byte)Convert.ToUInt32(colorString.Substring(4, 2), 16); + b = (byte)Convert.ToUInt32(colorString.Substring(6, 2), 16); + } + else + { + return Colors.Black; + } + + return WindowsColor.FromArgb(a, r, g, b); + } + catch + { + return Colors.Black; + } + } [EditorBrowsable(EditorBrowsableState.Never)] public static WindowsColor FromARGB(byte a, byte r, byte g, byte b) @@ -27,4 +84,347 @@ public static WindowsColor FromARGB(byte a, byte r, byte g, byte b) /// The generated Color value. public static WindowsColor FromArgb(byte a, byte r, byte g, byte b) => WindowsColor.FromArgb(a, r, g, b); + + #region Resource IDs Lookup Tables + private static ReadOnlySpan HueLimitsForSatLevel4 => + [ + 0, + 11, + 26, + 0, + 0, + 38, + 45, + 0, + 0, + 56, + 100, + 121, + 129, + 0, + 140, + 0, + 180, + 0, + 0, + 224, + 241, + 0, + 256 + ]; + + private static ReadOnlySpan HueLimitsForSatLevel5 => + [ + 0, + 13, + 27, + 0, + 0, + 36, + 45, + 0, + 0, + 59, + 118, + 0, + 127, + 136, + 142, + 0, + 185, + 0, + 0, + 216, + 239, + 0, + 256 + ]; + + private static ReadOnlySpan HueLimitsForSatLevel3 => + [ + 0, + 8, + 0, + 0, + 39, + 46, + 0, + 0, + 0, + 71, + 120, + 0, + 131, + 144, + 0, + 0, + 163, + 0, + 177, + 211, + 249, + 0, + 256 + ]; + + private static ReadOnlySpan HueLimitsForSatLevel2 => + [ + 0, + 10, + 0, + 32, + 46, + 0, + 0, + 0, + 61, + 0, + 106, + 0, + 136, + 144, + 0, + 0, + 0, + 158, + 166, + 241, + 0, + 0, + 256 + ]; + + private static ReadOnlySpan HueLimitsForSatLevel1 => + [ + 8, + 0, + 0, + 44, + 0, + 0, + 0, + 63, + 0, + 0, + 122, + 0, + 134, + 0, + 0, + 0, + 0, + 166, + 176, + 241, + 0, + 256, + 0 + ]; + + private static ReadOnlySpan LumLimitsForHueIndexHigh => + [ + 170, + 170, + 170, + 155, + 170, + 170, + 170, + 170, + 170, + 115, + 170, + 170, + 170, + 170, + 170, + 170, + 170, + 170, + 150, + 150, + 170, + 140, + 165 + ]; + + private static ReadOnlySpan LumLimitsForHueIndexLow => + [ + 130, + 100, + 115, + 100, + 100, + 100, + 110, + 75, + 100, + 90, + 100, + 100, + 100, + 100, + 80, + 100, + 100, + 100, + 100, + 100, + 100, + 100, + 100 + ]; + + private static ReadOnlySpan ColorNamesMid => + [ + 5119, + 5135, + 5136, + 5137, + 5122, + 5138, + 5139, + 5140, + 5140, + 5141, + 5141, + 5142, + 5143, + 5126, + 5144, + 5129, + 5145, + 5146, + 5147, + 5148, + 5134, + 5137, + 5135 + ]; + + private static ReadOnlySpan ColorNamesDark => + [ + 5137, + 5149, + 5137, + 5137, + 5137, + 5150, + 5150, + 5137, + 5151, + 5151, + 5151, + 5151, + 5152, + 5152, + 5152, + 5153, + 5153, + 5146, + 5147, + 5154, + 5155, + 5137, + 5149 + ]; + + private static ReadOnlySpan ColorNamesLight => + [ + 5119, + 5120, + 5121, + 5122, + 5122, + 5123, + 5123, + 5122, + 5124, + 5125, + 5124, + 5124, + 5126, + 5127, + 5128, + 5129, + 5130, + 5131, + 5132, + 5133, + 5134, + 5122, + 5120 + ]; + #endregion + + private unsafe static uint GetColorNameResourceId(WindowsColor color) + { + var hsl = color.ToHsl(); + double h = hsl.H * 255.0; + double s = hsl.S * 255.0; + double l = hsl.L * 255.0; + + if (l > 240.0) + { + return 5114; + } + + if (l < 20.0) + { + return 5118; + } + + if (s > 20.0) + { + ReadOnlySpan hueLimits; + + if (s > 240.0) + { + hueLimits = HueLimitsForSatLevel5; + } + else if (s > 150.0) + { + hueLimits = HueLimitsForSatLevel4; + } + else if (s > 115.0) + { + hueLimits = HueLimitsForSatLevel3; + } + else if (s > 75.0) + { + hueLimits = HueLimitsForSatLevel2; + } + else + { + hueLimits = HueLimitsForSatLevel1; + } + + var hueIndex = 0; + while (hueIndex < 23 && hueLimits[hueIndex] <= h) + { + hueIndex++; + } + + if (l > LumLimitsForHueIndexHigh[hueIndex]) + { + return ColorNamesLight[hueIndex]; + } + else if (l >= LumLimitsForHueIndexLow[hueIndex]) + { + return ColorNamesMid[hueIndex]; + } + else + { + return ColorNamesDark[hueIndex]; + } + } + else if (l <= 170.0) + { + return (l <= 100.0) ? (uint)5117 : 5116; + } + else + { + return 5115; + } + } } diff --git a/src/Uno.UWP/UI/ColorHelper.cs b/src/Uno.UWP/UI/ColorHelper.cs deleted file mode 100644 index 5f4b834cc808..000000000000 --- a/src/Uno.UWP/UI/ColorHelper.cs +++ /dev/null @@ -1,421 +0,0 @@ -using System; -using System.ComponentModel; -using Uno.Extensions; -using WindowsColor = global::Windows/*Intentional space for WinUI upgrade tool*/.UI.Color; - -namespace Windows.UI; - -public static partial class ColorHelper -{ - /// - /// Retrieves the display name of the specified color. - /// - /// The color to get the name for. - /// The localized display name of the color. - public static string ToDisplayName(WindowsColor color) - { - var id = GetColorNameResourceId(color); - //Uno specific - return ApplicationModel.Resources.ResourceLoader.GetForViewIndependentUse("Uno.UI/Resources").GetString(id.ToStringInvariant()); - // WinUI uses the GetLocalizedResourceString from DXamlCore, but it is not available under Windows.UI - //return DirectUI.DXamlCore.Current.GetLocalizedResourceString(id); - } - - /// - /// Converts a color string in hex format to a Windows.UI.Color. - /// - internal static WindowsColor ConvertColorFromHexString(string colorString) - { - try - { - colorString = colorString.Replace("#", string.Empty); - - byte a = 255; - byte r, g, b; - - if (colorString.Length == 6) - { - // #RRGGBB format - r = (byte)Convert.ToUInt32(colorString.Substring(0, 2), 16); - g = (byte)Convert.ToUInt32(colorString.Substring(2, 2), 16); - b = (byte)Convert.ToUInt32(colorString.Substring(4, 2), 16); - } - else if (colorString.Length == 8) - { - // #AARRGGBB format - a = (byte)Convert.ToUInt32(colorString.Substring(0, 2), 16); - r = (byte)Convert.ToUInt32(colorString.Substring(2, 2), 16); - g = (byte)Convert.ToUInt32(colorString.Substring(4, 2), 16); - b = (byte)Convert.ToUInt32(colorString.Substring(6, 2), 16); - } - else - { - return Colors.Black; - } - - return WindowsColor.FromArgb(a, r, g, b); - } - catch - { - return Colors.Black; - } - } - - [EditorBrowsable(EditorBrowsableState.Never)] - public static WindowsColor FromARGB(byte a, byte r, byte g, byte b) - => WindowsColor.FromArgb(a, r, g, b); - - /// - /// Generates a Color structure, based on discrete Byte values for ARGB components. C# and Microsoft Visual Basic code should use Color.FromArgb instead. - /// - /// The A (transparency) component of the desired color. Range is 0-255. - /// The R component of the desired color. Range is 0-255. - /// The G component of the desired color. Range is 0-255. - /// The B component of the desired color. Range is 0-255. - /// The generated Color value. - public static WindowsColor FromArgb(byte a, byte r, byte g, byte b) - => WindowsColor.FromArgb(a, r, g, b); - - #region Resource IDs Lookup Tables - private static ReadOnlySpan HueLimitsForSatLevel4 => - [ - 0, - 11, - 26, - 0, - 0, - 38, - 45, - 0, - 0, - 56, - 100, - 121, - 129, - 0, - 140, - 0, - 180, - 0, - 0, - 224, - 241, - 0, - 256 - ]; - - private static ReadOnlySpan HueLimitsForSatLevel5 => - [ - 0, - 13, - 27, - 0, - 0, - 36, - 45, - 0, - 0, - 59, - 118, - 0, - 127, - 136, - 142, - 0, - 185, - 0, - 0, - 216, - 239, - 0, - 256 - ]; - - private static ReadOnlySpan HueLimitsForSatLevel3 => - [ - 0, - 8, - 0, - 0, - 39, - 46, - 0, - 0, - 0, - 71, - 120, - 0, - 131, - 144, - 0, - 0, - 163, - 0, - 177, - 211, - 249, - 0, - 256 - ]; - - private static ReadOnlySpan HueLimitsForSatLevel2 => - [ - 0, - 10, - 0, - 32, - 46, - 0, - 0, - 0, - 61, - 0, - 106, - 0, - 136, - 144, - 0, - 0, - 0, - 158, - 166, - 241, - 0, - 0, - 256 - ]; - - private static ReadOnlySpan HueLimitsForSatLevel1 => - [ - 8, - 0, - 0, - 44, - 0, - 0, - 0, - 63, - 0, - 0, - 122, - 0, - 134, - 0, - 0, - 0, - 0, - 166, - 176, - 241, - 0, - 256, - 0 - ]; - - private static ReadOnlySpan LumLimitsForHueIndexHigh => - [ - 170, - 170, - 170, - 155, - 170, - 170, - 170, - 170, - 170, - 115, - 170, - 170, - 170, - 170, - 170, - 170, - 170, - 170, - 150, - 150, - 170, - 140, - 165 - ]; - - private static ReadOnlySpan LumLimitsForHueIndexLow => - [ - 130, - 100, - 115, - 100, - 100, - 100, - 110, - 75, - 100, - 90, - 100, - 100, - 100, - 100, - 80, - 100, - 100, - 100, - 100, - 100, - 100, - 100, - 100 - ]; - - private static ReadOnlySpan ColorNamesMid => - [ - 5119, - 5135, - 5136, - 5137, - 5122, - 5138, - 5139, - 5140, - 5140, - 5141, - 5141, - 5142, - 5143, - 5126, - 5144, - 5129, - 5145, - 5146, - 5147, - 5148, - 5134, - 5137, - 5135 - ]; - - private static ReadOnlySpan ColorNamesDark => - [ - 5137, - 5149, - 5137, - 5137, - 5137, - 5150, - 5150, - 5137, - 5151, - 5151, - 5151, - 5151, - 5152, - 5152, - 5152, - 5153, - 5153, - 5146, - 5147, - 5154, - 5155, - 5137, - 5149 - ]; - - private static ReadOnlySpan ColorNamesLight => - [ - 5119, - 5120, - 5121, - 5122, - 5122, - 5123, - 5123, - 5122, - 5124, - 5125, - 5124, - 5124, - 5126, - 5127, - 5128, - 5129, - 5130, - 5131, - 5132, - 5133, - 5134, - 5122, - 5120 - ]; - #endregion - - private unsafe static uint GetColorNameResourceId(WindowsColor color) - { - var hsl = color.ToHsl(); - double h = hsl.H * 255.0; - double s = hsl.S * 255.0; - double l = hsl.L * 255.0; - - if (l > 240.0) - { - return 5114; - } - - if (l < 20.0) - { - return 5118; - } - - if (s > 20.0) - { - ReadOnlySpan hueLimits; - - if (s > 240.0) - { - hueLimits = HueLimitsForSatLevel5; - } - else if (s > 150.0) - { - hueLimits = HueLimitsForSatLevel4; - } - else if (s > 115.0) - { - hueLimits = HueLimitsForSatLevel3; - } - else if (s > 75.0) - { - hueLimits = HueLimitsForSatLevel2; - } - else - { - hueLimits = HueLimitsForSatLevel1; - } - - var hueIndex = 0; - while (hueIndex < 23 && hueLimits[hueIndex] <= h) - { - hueIndex++; - } - - if (l > LumLimitsForHueIndexHigh[hueIndex]) - { - return ColorNamesLight[hueIndex]; - } - else if (l >= LumLimitsForHueIndexLow[hueIndex]) - { - return ColorNamesMid[hueIndex]; - } - else - { - return ColorNamesDark[hueIndex]; - } - } - else if (l <= 170.0) - { - return (l <= 100.0) ? (uint)5117 : 5116; - } - else - { - return 5115; - } - } -} diff --git a/src/Uno.UWP/Uno.Reference.csproj b/src/Uno.UWP/Uno.Reference.csproj index 84534f15a90a..c2beea1b9478 100644 --- a/src/Uno.UWP/Uno.Reference.csproj +++ b/src/Uno.UWP/Uno.Reference.csproj @@ -30,12 +30,4 @@ - - - - - - - - diff --git a/src/Uno.UWP/Uno.Skia.csproj b/src/Uno.UWP/Uno.Skia.csproj index 337993273208..129efae754ab 100644 --- a/src/Uno.UWP/Uno.Skia.csproj +++ b/src/Uno.UWP/Uno.Skia.csproj @@ -31,15 +31,6 @@ - - - - - - - - - diff --git a/src/Uno.UWP/Uno.Tests.csproj b/src/Uno.UWP/Uno.Tests.csproj index 9ae7678f9b01..8f9c32431809 100644 --- a/src/Uno.UWP/Uno.Tests.csproj +++ b/src/Uno.UWP/Uno.Tests.csproj @@ -27,12 +27,4 @@ - - - - - - - - diff --git a/src/Uno.UWP/Uno.Wasm.csproj b/src/Uno.UWP/Uno.Wasm.csproj index c46d39a227ce..9393d352b152 100644 --- a/src/Uno.UWP/Uno.Wasm.csproj +++ b/src/Uno.UWP/Uno.Wasm.csproj @@ -26,12 +26,4 @@ - - - - - - - - diff --git a/src/Uno.UWP/Uno.netcoremobile.csproj b/src/Uno.UWP/Uno.netcoremobile.csproj index d27624bc26a4..6c150e3fd74a 100644 --- a/src/Uno.UWP/Uno.netcoremobile.csproj +++ b/src/Uno.UWP/Uno.netcoremobile.csproj @@ -42,12 +42,4 @@ - - - - - - - - diff --git a/src/Uno.WinUIRevert/Program.cs b/src/Uno.WinUIRevert/Program.cs index c2748151edc0..bc11045d2161 100644 --- a/src/Uno.WinUIRevert/Program.cs +++ b/src/Uno.WinUIRevert/Program.cs @@ -17,30 +17,6 @@ static void Main(string[] args) DeleteFolder(Path.Combine(basePath, "src", "Uno.UWP", "Generated")); DeleteFolder(Path.Combine(basePath, "src", "Uno.UI", "tsBindings")); // Generated - var colorsFilepath = Path.Combine(basePath, @"src", "Uno.UI", "UI", "Colors.cs"); - if (File.Exists(colorsFilepath)) - { - File.Delete(colorsFilepath); - } - - var colorHelperFilePath = Path.Combine(basePath, @"src", "Uno.UI", "UI", "ColorHelper.cs"); - if (File.Exists(colorHelperFilePath)) - { - File.Delete(colorHelperFilePath); - } - - var fontWeightsFilePath = Path.Combine(basePath, @"src", "Uno.UI", "UI", "Text", "FontWeights.cs"); - if (File.Exists(fontWeightsFilePath)) - { - File.Delete(fontWeightsFilePath); - } - - var inputPath = Path.Combine(basePath, "src", "Uno.UI", "UI", "Input"); - if (Directory.Exists(inputPath)) - { - Directory.Delete(inputPath, true); - } - var dispatcherQueuePath = Path.Combine(basePath, "src", "Uno.UI.Dispatching", "Dispatching"); if (Directory.Exists(dispatcherQueuePath)) { From f6e7f54660599fa31c3b8eb804f9153abc09e69a Mon Sep 17 00:00:00 2001 From: Ramez Ragaa Date: Wed, 20 Nov 2024 19:20:33 +0200 Subject: [PATCH 6/9] chore: fix build --- src/Uno.UI/UI/ColorHelper.cs | 9 ++++++--- src/Uno.UI/UI/Colors.cs | 7 +++++-- src/Uno.UI/UI/Text/FontWeights.cs | 7 +++++-- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/Uno.UI/UI/ColorHelper.cs b/src/Uno.UI/UI/ColorHelper.cs index 4df6787fb020..aa80035a01d5 100644 --- a/src/Uno.UI/UI/ColorHelper.cs +++ b/src/Uno.UI/UI/ColorHelper.cs @@ -1,9 +1,11 @@ -using System; +// On the UWP branch, only include this file in Uno.UWP (as public Window.whatever). On the WinUI branch, include it in both Uno.UWP (internal as Windows.whatever) and Uno.UI (public as Microsoft.whatever) +#if HAS_UNO_WINUI || !IS_UNO_UI_PROJECT +using System; using System.ComponentModel; using Uno.Extensions; using WindowsColor = Windows/*Intentional space for WinUI upgrade tool*/.UI.Color; -#if HAS_UNO_WINUI && IS_UNO_UI_PROJECT +#if IS_UNO_UI_PROJECT namespace Microsoft.UI.Text; #else namespace Windows.UI.Text; @@ -357,7 +359,7 @@ public static WindowsColor FromArgb(byte a, byte r, byte g, byte b) ]; #endregion - private unsafe static uint GetColorNameResourceId(WindowsColor color) + private static uint GetColorNameResourceId(WindowsColor color) { var hsl = color.ToHsl(); double h = hsl.H * 255.0; @@ -428,3 +430,4 @@ private unsafe static uint GetColorNameResourceId(WindowsColor color) } } } +#endif diff --git a/src/Uno.UI/UI/Colors.cs b/src/Uno.UI/UI/Colors.cs index 963bb0d574c5..438266dca91c 100644 --- a/src/Uno.UI/UI/Colors.cs +++ b/src/Uno.UI/UI/Colors.cs @@ -1,10 +1,12 @@ -using System; +// On the UWP branch, only include this file in Uno.UWP (as public Window.whatever). On the WinUI branch, include it in both Uno.UWP (internal as Windows.whatever) and Uno.UI (public as Microsoft.whatever) +#if HAS_UNO_WINUI || !IS_UNO_UI_PROJECT +using System; using System.Collections.Generic; using System.Text; using Color = global::Windows/*Intentional space for WinUI upgrade tool*/.UI.Color; -#if HAS_UNO_WINUI && IS_UNO_UI_PROJECT +#if IS_UNO_UI_PROJECT namespace Microsoft.UI #else namespace Windows.UI @@ -564,3 +566,4 @@ private static byte ToByte(char c) public static Color YellowGreen => _yellowGreen ??= FromInteger(unchecked((int)0xFF9ACD32)); } } +#endif diff --git a/src/Uno.UI/UI/Text/FontWeights.cs b/src/Uno.UI/UI/Text/FontWeights.cs index 473186f8cfd7..e0ad16cd18fb 100644 --- a/src/Uno.UI/UI/Text/FontWeights.cs +++ b/src/Uno.UI/UI/Text/FontWeights.cs @@ -1,8 +1,10 @@ -using System; +// On the UWP branch, only include this file in Uno.UWP (as public Window.whatever). On the WinUI branch, include it in both Uno.UWP (internal as Windows.whatever) and Uno.UI (public as Microsoft.whatever) +#if HAS_UNO_WINUI || !IS_UNO_UI_PROJECT +using System; using System.Collections.Generic; using System.Text; -#if HAS_UNO_WINUI && IS_UNO_UI_PROJECT +#if IS_UNO_UI_PROJECT using Windows.UI.Text; namespace Microsoft.UI.Text #else @@ -47,3 +49,4 @@ partial class FontWeights public static FontWeight UltraBlack => _extraBlack ??= new FontWeight(950); } } +#endif From f53b7bf606555cea7509226e5fbe739ef82e8a7e Mon Sep 17 00:00:00 2001 From: Ramez Ragaa Date: Wed, 20 Nov 2024 22:38:51 +0200 Subject: [PATCH 7/9] chore: fix the build one more time --- src/Uno.UI/UI/ColorHelper.cs | 11 +++-------- src/Uno.UI/UI/Input/PointerPoint.cs | 5 ++++- src/Uno.UI/UI/Input/PointerPointProperties.cs | 3 +++ .../UI/Input/PointerPointPropertiesExtensions.cs | 3 +++ src/Uno.UI/UI/Input/PointerUpdateKind.cs | 5 ++++- src/Uno.UWP/Uno.Reference.csproj | 9 +++++++++ src/Uno.UWP/Uno.Skia.csproj | 10 ++++++++++ src/Uno.UWP/Uno.Tests.csproj | 9 +++++++++ src/Uno.UWP/Uno.Wasm.csproj | 9 +++++++++ src/Uno.UWP/Uno.netcoremobile.csproj | 10 ++++++++++ 10 files changed, 64 insertions(+), 10 deletions(-) diff --git a/src/Uno.UI/UI/ColorHelper.cs b/src/Uno.UI/UI/ColorHelper.cs index aa80035a01d5..6f37d3ef0c74 100644 --- a/src/Uno.UI/UI/ColorHelper.cs +++ b/src/Uno.UI/UI/ColorHelper.cs @@ -6,17 +6,12 @@ using WindowsColor = Windows/*Intentional space for WinUI upgrade tool*/.UI.Color; #if IS_UNO_UI_PROJECT -namespace Microsoft.UI.Text; +namespace Microsoft.UI; #else -namespace Windows.UI.Text; +namespace Windows.UI; #endif -#if HAS_UNO_WINUI && !IS_UNO_UI_PROJECT -internal -#else -public -#endif - static partial class ColorHelper +public static partial class ColorHelper { /// /// Retrieves the display name of the specified color. diff --git a/src/Uno.UI/UI/Input/PointerPoint.cs b/src/Uno.UI/UI/Input/PointerPoint.cs index eb999f10aa7d..d70b5ed43a4e 100644 --- a/src/Uno.UI/UI/Input/PointerPoint.cs +++ b/src/Uno.UI/UI/Input/PointerPoint.cs @@ -1,4 +1,6 @@ -using System; +// On the UWP branch, only include this file in Uno.UWP (as public Window.whatever). On the WinUI branch, include it in both Uno.UWP (internal as Windows.whatever) and Uno.UI (public as Microsoft.whatever) +#if HAS_UNO_WINUI || !IS_UNO_UI_PROJECT +using System; using System.Collections.Generic; using System.ComponentModel; using System.Text; @@ -110,3 +112,4 @@ public override string ToString() => $"[{PointerDevice.PointerDeviceType}-{PointerId}] @{Position.ToDebugString()} (raw: {RawPosition.ToDebugString()} | ts: {Timestamp} | props: {Properties} | inContact: {IsInContact})"; } } +#endif diff --git a/src/Uno.UI/UI/Input/PointerPointProperties.cs b/src/Uno.UI/UI/Input/PointerPointProperties.cs index 27e01bb92a86..3e366a75d24e 100644 --- a/src/Uno.UI/UI/Input/PointerPointProperties.cs +++ b/src/Uno.UI/UI/Input/PointerPointProperties.cs @@ -1,3 +1,5 @@ +// On the UWP branch, only include this file in Uno.UWP (as public Window.whatever). On the WinUI branch, include it in both Uno.UWP (internal as Windows.whatever) and Uno.UI (public as Microsoft.whatever) +#if HAS_UNO_WINUI || !IS_UNO_UI_PROJECT using System.Text; using Windows.Foundation; using Uno; @@ -166,3 +168,4 @@ public override string ToString() } } } +#endif diff --git a/src/Uno.UI/UI/Input/PointerPointPropertiesExtensions.cs b/src/Uno.UI/UI/Input/PointerPointPropertiesExtensions.cs index 431ce6168d9d..5cfb37b94011 100644 --- a/src/Uno.UI/UI/Input/PointerPointPropertiesExtensions.cs +++ b/src/Uno.UI/UI/Input/PointerPointPropertiesExtensions.cs @@ -1,3 +1,5 @@ +// On the UWP branch, only include this file in Uno.UWP (as public Window.whatever). On the WinUI branch, include it in both Uno.UWP (internal as Windows.whatever) and Uno.UI (public as Microsoft.whatever) +#if HAS_UNO_WINUI || !IS_UNO_UI_PROJECT #nullable enable using System; @@ -50,3 +52,4 @@ static bool HasChanged(bool was, bool @is, PointerUpdateKind pressed, PointerUpd } } } +#endif diff --git a/src/Uno.UI/UI/Input/PointerUpdateKind.cs b/src/Uno.UI/UI/Input/PointerUpdateKind.cs index 44e41142c689..784f9a450a99 100644 --- a/src/Uno.UI/UI/Input/PointerUpdateKind.cs +++ b/src/Uno.UI/UI/Input/PointerUpdateKind.cs @@ -1,4 +1,6 @@ -using System; +// On the UWP branch, only include this file in Uno.UWP (as public Window.whatever). On the WinUI branch, include it in both Uno.UWP (internal as Windows.whatever) and Uno.UI (public as Microsoft.whatever) +#if HAS_UNO_WINUI || !IS_UNO_UI_PROJECT +using System; using System.Collections.Generic; using System.Text; @@ -56,3 +58,4 @@ public enum PointerUpdateKind XButton2Released = 10, } } +#endif diff --git a/src/Uno.UWP/Uno.Reference.csproj b/src/Uno.UWP/Uno.Reference.csproj index c2beea1b9478..2acb903642c3 100644 --- a/src/Uno.UWP/Uno.Reference.csproj +++ b/src/Uno.UWP/Uno.Reference.csproj @@ -30,4 +30,13 @@ + + + + + + + + + diff --git a/src/Uno.UWP/Uno.Skia.csproj b/src/Uno.UWP/Uno.Skia.csproj index 129efae754ab..d9e1c1f3dcdc 100644 --- a/src/Uno.UWP/Uno.Skia.csproj +++ b/src/Uno.UWP/Uno.Skia.csproj @@ -31,6 +31,16 @@ + + + + + + + + + + diff --git a/src/Uno.UWP/Uno.Tests.csproj b/src/Uno.UWP/Uno.Tests.csproj index 8f9c32431809..e84beaf52bec 100644 --- a/src/Uno.UWP/Uno.Tests.csproj +++ b/src/Uno.UWP/Uno.Tests.csproj @@ -27,4 +27,13 @@ + + + + + + + + + diff --git a/src/Uno.UWP/Uno.Wasm.csproj b/src/Uno.UWP/Uno.Wasm.csproj index 9393d352b152..b3647f1b81dc 100644 --- a/src/Uno.UWP/Uno.Wasm.csproj +++ b/src/Uno.UWP/Uno.Wasm.csproj @@ -26,4 +26,13 @@ + + + + + + + + + diff --git a/src/Uno.UWP/Uno.netcoremobile.csproj b/src/Uno.UWP/Uno.netcoremobile.csproj index 6c150e3fd74a..802edfb24a69 100644 --- a/src/Uno.UWP/Uno.netcoremobile.csproj +++ b/src/Uno.UWP/Uno.netcoremobile.csproj @@ -42,4 +42,14 @@ + + + + + + + + + + From 1e7970eb859bfe344e712e3e712e0b60b8ee2b7e Mon Sep 17 00:00:00 2001 From: Ramez Ragaa Date: Thu, 21 Nov 2024 12:06:20 +0200 Subject: [PATCH 8/9] chore: fix Given_InputManager --- .../Tests/Uno_UI_Xaml_Core/Given_InputManager.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Uno.UI.RuntimeTests/Tests/Uno_UI_Xaml_Core/Given_InputManager.cs b/src/Uno.UI.RuntimeTests/Tests/Uno_UI_Xaml_Core/Given_InputManager.cs index 57746e4dcbcf..b574c5084f2c 100644 --- a/src/Uno.UI.RuntimeTests/Tests/Uno_UI_Xaml_Core/Given_InputManager.cs +++ b/src/Uno.UI.RuntimeTests/Tests/Uno_UI_Xaml_Core/Given_InputManager.cs @@ -20,6 +20,12 @@ using Uno.Extensions; using Uno.UI.RuntimeTests.Helpers; +#if HAS_UNO_WINUI +using GestureRecognizer = Microsoft.UI.Input.GestureRecognizer; +#else +using GestureRecognizer = Windows.UI.Input.GestureRecognizer; +#endif + namespace Uno.UI.RuntimeTests.Tests.Uno_UI_Xaml_Core; [TestClass] From 022cb54aff8a624c3dd3f8eecd863bf3ff2d128a Mon Sep 17 00:00:00 2001 From: Ramez Ragaa Date: Thu, 21 Nov 2024 12:31:37 +0200 Subject: [PATCH 9/9] chore: bring back all of Windows.UI.Input --- src/Uno.UI/UI/Input/DraggingEventArgs.cs | 3 +++ src/Uno.UI/UI/Input/DraggingState.cs | 3 +++ src/Uno.UI/UI/Input/GestureRecognizer.Gesture.cs | 3 +++ .../Input/GestureRecognizer.Manipulation.InertiaProcessor.cs | 3 +++ src/Uno.UI/UI/Input/GestureRecognizer.Manipulation.cs | 5 ++++- src/Uno.UI/UI/Input/GestureRecognizer.cs | 3 +++ src/Uno.UI/UI/Input/GestureSettings.cs | 3 +++ src/Uno.UI/UI/Input/HoldingEventArgs.cs | 3 +++ src/Uno.UI/UI/Input/HoldingState.cs | 3 +++ src/Uno.UI/UI/Input/ManipulationCompletedEventArgs.cs | 3 +++ src/Uno.UI/UI/Input/ManipulationDelta.cs | 5 ++++- src/Uno.UI/UI/Input/ManipulationInertiaStartingEventArgs.cs | 3 +++ src/Uno.UI/UI/Input/ManipulationStartedEventArgs.cs | 3 +++ src/Uno.UI/UI/Input/ManipulationStartingEventArgs.cs | 3 +++ src/Uno.UI/UI/Input/ManipulationUpdatedEventArgs.cs | 3 +++ src/Uno.UI/UI/Input/ManipulationVelocities.cs | 5 ++++- src/Uno.UI/UI/Input/RightTappedEventArgs.cs | 3 +++ src/Uno.UI/UI/Input/TappedEventArgs.cs | 3 +++ src/Uno.UWP/Uno.Reference.csproj | 5 +---- src/Uno.UWP/Uno.Skia.csproj | 5 +---- src/Uno.UWP/Uno.Tests.csproj | 5 +---- src/Uno.UWP/Uno.Wasm.csproj | 5 +---- src/Uno.UWP/Uno.netcoremobile.csproj | 5 +---- 23 files changed, 62 insertions(+), 23 deletions(-) diff --git a/src/Uno.UI/UI/Input/DraggingEventArgs.cs b/src/Uno.UI/UI/Input/DraggingEventArgs.cs index 8c42b8e819b7..37127f24e610 100644 --- a/src/Uno.UI/UI/Input/DraggingEventArgs.cs +++ b/src/Uno.UI/UI/Input/DraggingEventArgs.cs @@ -1,3 +1,5 @@ +// On the UWP branch, only include this file in Uno.UWP (as public Window.whatever). On the WinUI branch, include it in both Uno.UWP (internal as Windows.whatever) and Uno.UI (public as Microsoft.whatever) +#if HAS_UNO_WINUI || !IS_UNO_UI_PROJECT using Windows.Devices.Input; using Windows.Foundation; @@ -27,3 +29,4 @@ internal DraggingEventArgs(PointerPoint point, DraggingState state, uint contact public uint ContactCount { get; } } } +#endif diff --git a/src/Uno.UI/UI/Input/DraggingState.cs b/src/Uno.UI/UI/Input/DraggingState.cs index 5be560f3a80e..d857160e2fb3 100644 --- a/src/Uno.UI/UI/Input/DraggingState.cs +++ b/src/Uno.UI/UI/Input/DraggingState.cs @@ -1,3 +1,5 @@ +// On the UWP branch, only include this file in Uno.UWP (as public Window.whatever). On the WinUI branch, include it in both Uno.UWP (internal as Windows.whatever) and Uno.UI (public as Microsoft.whatever) +#if HAS_UNO_WINUI || !IS_UNO_UI_PROJECT #if HAS_UNO_WINUI && IS_UNO_UI_PROJECT namespace Microsoft.UI.Input #else @@ -11,3 +13,4 @@ public enum DraggingState Completed, } } +#endif diff --git a/src/Uno.UI/UI/Input/GestureRecognizer.Gesture.cs b/src/Uno.UI/UI/Input/GestureRecognizer.Gesture.cs index cbcba5dce0d4..7b65bd93ac74 100644 --- a/src/Uno.UI/UI/Input/GestureRecognizer.Gesture.cs +++ b/src/Uno.UI/UI/Input/GestureRecognizer.Gesture.cs @@ -1,3 +1,5 @@ +// On the UWP branch, only include this file in Uno.UWP (as public Window.whatever). On the WinUI branch, include it in both Uno.UWP (internal as Windows.whatever) and Uno.UI (public as Microsoft.whatever) +#if HAS_UNO_WINUI || !IS_UNO_UI_PROJECT #nullable enable using System; @@ -398,3 +400,4 @@ public static bool IsOutOfTapRange(Point p1, Point p2) } } } +#endif diff --git a/src/Uno.UI/UI/Input/GestureRecognizer.Manipulation.InertiaProcessor.cs b/src/Uno.UI/UI/Input/GestureRecognizer.Manipulation.InertiaProcessor.cs index 36678009b1bb..53d8b981f8eb 100644 --- a/src/Uno.UI/UI/Input/GestureRecognizer.Manipulation.InertiaProcessor.cs +++ b/src/Uno.UI/UI/Input/GestureRecognizer.Manipulation.InertiaProcessor.cs @@ -1,3 +1,5 @@ +// On the UWP branch, only include this file in Uno.UWP (as public Window.whatever). On the WinUI branch, include it in both Uno.UWP (internal as Windows.whatever) and Uno.UI (public as Microsoft.whatever) +#if HAS_UNO_WINUI || !IS_UNO_UI_PROJECT #nullable enable using System; @@ -216,3 +218,4 @@ public void RunSync() } } } +#endif diff --git a/src/Uno.UI/UI/Input/GestureRecognizer.Manipulation.cs b/src/Uno.UI/UI/Input/GestureRecognizer.Manipulation.cs index da184e43e0ce..84b36d7f493e 100644 --- a/src/Uno.UI/UI/Input/GestureRecognizer.Manipulation.cs +++ b/src/Uno.UI/UI/Input/GestureRecognizer.Manipulation.cs @@ -1,4 +1,6 @@ -#nullable enable +// On the UWP branch, only include this file in Uno.UWP (as public Window.whatever). On the WinUI branch, include it in both Uno.UWP (internal as Windows.whatever) and Uno.UI (public as Microsoft.whatever) +#if HAS_UNO_WINUI || !IS_UNO_UI_PROJECT +#nullable enable using System; using System.Collections.Generic; @@ -751,3 +753,4 @@ public static implicit operator Points(PointerPoint pointer1) } } } +#endif diff --git a/src/Uno.UI/UI/Input/GestureRecognizer.cs b/src/Uno.UI/UI/Input/GestureRecognizer.cs index 7d51ddaec790..977ae308db55 100644 --- a/src/Uno.UI/UI/Input/GestureRecognizer.cs +++ b/src/Uno.UI/UI/Input/GestureRecognizer.cs @@ -1,3 +1,5 @@ +// On the UWP branch, only include this file in Uno.UWP (as public Window.whatever). On the WinUI branch, include it in both Uno.UWP (internal as Windows.whatever) and Uno.UI (public as Microsoft.whatever) +#if HAS_UNO_WINUI || !IS_UNO_UI_PROJECT using System; using System.Collections.Generic; using System.Linq; @@ -291,3 +293,4 @@ private static ulong GetPointerIdentifier(PointerPoint point) } } } +#endif diff --git a/src/Uno.UI/UI/Input/GestureSettings.cs b/src/Uno.UI/UI/Input/GestureSettings.cs index dd15ecaeb438..4ae3e177ca3a 100644 --- a/src/Uno.UI/UI/Input/GestureSettings.cs +++ b/src/Uno.UI/UI/Input/GestureSettings.cs @@ -1,3 +1,5 @@ +// On the UWP branch, only include this file in Uno.UWP (as public Window.whatever). On the WinUI branch, include it in both Uno.UWP (internal as Windows.whatever) and Uno.UI (public as Microsoft.whatever) +#if HAS_UNO_WINUI || !IS_UNO_UI_PROJECT using System; using Windows.Foundation; using Windows.Foundation.Metadata; @@ -108,3 +110,4 @@ internal static class GestureSettingsHelper | GestureSettings.ManipulationRotateInertia; } } +#endif diff --git a/src/Uno.UI/UI/Input/HoldingEventArgs.cs b/src/Uno.UI/UI/Input/HoldingEventArgs.cs index 77530bd2d6ca..5eda3bbe8d3b 100644 --- a/src/Uno.UI/UI/Input/HoldingEventArgs.cs +++ b/src/Uno.UI/UI/Input/HoldingEventArgs.cs @@ -1,3 +1,5 @@ +// On the UWP branch, only include this file in Uno.UWP (as public Window.whatever). On the WinUI branch, include it in both Uno.UWP (internal as Windows.whatever) and Uno.UI (public as Microsoft.whatever) +#if HAS_UNO_WINUI || !IS_UNO_UI_PROJECT using Windows.Devices.Input; using Windows.Foundation; using Uno; @@ -33,3 +35,4 @@ internal HoldingEventArgs(uint pointerId, PointerDeviceType type, Point position public uint CurrentContactCount => HoldingState == HoldingState.Started ? 1u : 0u; } } +#endif diff --git a/src/Uno.UI/UI/Input/HoldingState.cs b/src/Uno.UI/UI/Input/HoldingState.cs index ace2b5fca268..c1678ffc3745 100644 --- a/src/Uno.UI/UI/Input/HoldingState.cs +++ b/src/Uno.UI/UI/Input/HoldingState.cs @@ -1,3 +1,5 @@ +// On the UWP branch, only include this file in Uno.UWP (as public Window.whatever). On the WinUI branch, include it in both Uno.UWP (internal as Windows.whatever) and Uno.UI (public as Microsoft.whatever) +#if HAS_UNO_WINUI || !IS_UNO_UI_PROJECT #if HAS_UNO_WINUI && IS_UNO_UI_PROJECT namespace Microsoft.UI.Input #else @@ -11,3 +13,4 @@ public enum HoldingState Canceled, } } +#endif diff --git a/src/Uno.UI/UI/Input/ManipulationCompletedEventArgs.cs b/src/Uno.UI/UI/Input/ManipulationCompletedEventArgs.cs index a35b0f379ba0..d8bb6b950521 100644 --- a/src/Uno.UI/UI/Input/ManipulationCompletedEventArgs.cs +++ b/src/Uno.UI/UI/Input/ManipulationCompletedEventArgs.cs @@ -1,3 +1,5 @@ +// On the UWP branch, only include this file in Uno.UWP (as public Window.whatever). On the WinUI branch, include it in both Uno.UWP (internal as Windows.whatever) and Uno.UI (public as Microsoft.whatever) +#if HAS_UNO_WINUI || !IS_UNO_UI_PROJECT using System.Linq; using Windows.Devices.Input; using Windows.Foundation; @@ -49,3 +51,4 @@ internal ManipulationCompletedEventArgs( internal bool IsInertial { get; } } } +#endif diff --git a/src/Uno.UI/UI/Input/ManipulationDelta.cs b/src/Uno.UI/UI/Input/ManipulationDelta.cs index ea485bcd5eda..28df4e2ca13d 100644 --- a/src/Uno.UI/UI/Input/ManipulationDelta.cs +++ b/src/Uno.UI/UI/Input/ManipulationDelta.cs @@ -1,4 +1,6 @@ -using System; +// On the UWP branch, only include this file in Uno.UWP (as public Window.whatever). On the WinUI branch, include it in both Uno.UWP (internal as Windows.whatever) and Uno.UI (public as Microsoft.whatever) +#if HAS_UNO_WINUI || !IS_UNO_UI_PROJECT +using System; using System.Collections.Generic; using Windows.Foundation; @@ -80,3 +82,4 @@ public override int GetHashCode() #endregion } } +#endif diff --git a/src/Uno.UI/UI/Input/ManipulationInertiaStartingEventArgs.cs b/src/Uno.UI/UI/Input/ManipulationInertiaStartingEventArgs.cs index c758f69cce2a..b1457fe14206 100644 --- a/src/Uno.UI/UI/Input/ManipulationInertiaStartingEventArgs.cs +++ b/src/Uno.UI/UI/Input/ManipulationInertiaStartingEventArgs.cs @@ -1,3 +1,5 @@ +// On the UWP branch, only include this file in Uno.UWP (as public Window.whatever). On the WinUI branch, include it in both Uno.UWP (internal as Windows.whatever) and Uno.UI (public as Microsoft.whatever) +#if HAS_UNO_WINUI || !IS_UNO_UI_PROJECT using System.Linq; using Windows.Devices.Input; using Windows.Foundation; @@ -48,3 +50,4 @@ internal ManipulationInertiaStartingEventArgs( internal GestureRecognizer.Manipulation.InertiaProcessor Processor { get; } } } +#endif diff --git a/src/Uno.UI/UI/Input/ManipulationStartedEventArgs.cs b/src/Uno.UI/UI/Input/ManipulationStartedEventArgs.cs index dcefc8a274e9..357e33265a06 100644 --- a/src/Uno.UI/UI/Input/ManipulationStartedEventArgs.cs +++ b/src/Uno.UI/UI/Input/ManipulationStartedEventArgs.cs @@ -1,3 +1,5 @@ +// On the UWP branch, only include this file in Uno.UWP (as public Window.whatever). On the WinUI branch, include it in both Uno.UWP (internal as Windows.whatever) and Uno.UI (public as Microsoft.whatever) +#if HAS_UNO_WINUI || !IS_UNO_UI_PROJECT using System.Linq; using Windows.Devices.Input; using Windows.Foundation; @@ -38,3 +40,4 @@ internal ManipulationStartedEventArgs( public uint ContactCount { get; } } } +#endif diff --git a/src/Uno.UI/UI/Input/ManipulationStartingEventArgs.cs b/src/Uno.UI/UI/Input/ManipulationStartingEventArgs.cs index c22e6eeecb06..8b5270d3fe01 100644 --- a/src/Uno.UI/UI/Input/ManipulationStartingEventArgs.cs +++ b/src/Uno.UI/UI/Input/ManipulationStartingEventArgs.cs @@ -1,3 +1,5 @@ +// On the UWP branch, only include this file in Uno.UWP (as public Window.whatever). On the WinUI branch, include it in both Uno.UWP (internal as Windows.whatever) and Uno.UI (public as Microsoft.whatever) +#if HAS_UNO_WINUI || !IS_UNO_UI_PROJECT using System; using System.Linq; using Windows.Devices.Input; @@ -26,3 +28,4 @@ internal ManipulationStartingEventArgs(PointerIdentifier pointer, GestureSetting public GestureSettings Settings { get; set; } } } +#endif diff --git a/src/Uno.UI/UI/Input/ManipulationUpdatedEventArgs.cs b/src/Uno.UI/UI/Input/ManipulationUpdatedEventArgs.cs index 5ec5a2685e9c..a8040b860b64 100644 --- a/src/Uno.UI/UI/Input/ManipulationUpdatedEventArgs.cs +++ b/src/Uno.UI/UI/Input/ManipulationUpdatedEventArgs.cs @@ -1,3 +1,5 @@ +// On the UWP branch, only include this file in Uno.UWP (as public Window.whatever). On the WinUI branch, include it in both Uno.UWP (internal as Windows.whatever) and Uno.UI (public as Microsoft.whatever) +#if HAS_UNO_WINUI || !IS_UNO_UI_PROJECT using System.Linq; using System.Reflection; using Windows.Devices.Input; @@ -52,3 +54,4 @@ internal ManipulationUpdatedEventArgs( internal bool IsInertial { get; } } } +#endif diff --git a/src/Uno.UI/UI/Input/ManipulationVelocities.cs b/src/Uno.UI/UI/Input/ManipulationVelocities.cs index 6734774488f8..1d27fc3c433f 100644 --- a/src/Uno.UI/UI/Input/ManipulationVelocities.cs +++ b/src/Uno.UI/UI/Input/ManipulationVelocities.cs @@ -1,4 +1,6 @@ -using System; +// On the UWP branch, only include this file in Uno.UWP (as public Window.whatever). On the WinUI branch, include it in both Uno.UWP (internal as Windows.whatever) and Uno.UI (public as Microsoft.whatever) +#if HAS_UNO_WINUI || !IS_UNO_UI_PROJECT +using System; using System.Collections.Generic; using Windows.Foundation; @@ -64,3 +66,4 @@ public override int GetHashCode() #endregion } } +#endif diff --git a/src/Uno.UI/UI/Input/RightTappedEventArgs.cs b/src/Uno.UI/UI/Input/RightTappedEventArgs.cs index 015866eec9fe..ee3348042767 100644 --- a/src/Uno.UI/UI/Input/RightTappedEventArgs.cs +++ b/src/Uno.UI/UI/Input/RightTappedEventArgs.cs @@ -1,3 +1,5 @@ +// On the UWP branch, only include this file in Uno.UWP (as public Window.whatever). On the WinUI branch, include it in both Uno.UWP (internal as Windows.whatever) and Uno.UI (public as Microsoft.whatever) +#if HAS_UNO_WINUI || !IS_UNO_UI_PROJECT using Windows.Devices.Input; using Windows.Foundation; @@ -33,3 +35,4 @@ public uint ContactCount } } } +#endif diff --git a/src/Uno.UI/UI/Input/TappedEventArgs.cs b/src/Uno.UI/UI/Input/TappedEventArgs.cs index 8ad7f75d598c..f5c294eb5838 100644 --- a/src/Uno.UI/UI/Input/TappedEventArgs.cs +++ b/src/Uno.UI/UI/Input/TappedEventArgs.cs @@ -1,3 +1,5 @@ +// On the UWP branch, only include this file in Uno.UWP (as public Window.whatever). On the WinUI branch, include it in both Uno.UWP (internal as Windows.whatever) and Uno.UI (public as Microsoft.whatever) +#if HAS_UNO_WINUI || !IS_UNO_UI_PROJECT using Windows.Devices.Input; using Windows.Foundation; @@ -36,3 +38,4 @@ public uint ContactCount } } } +#endif diff --git a/src/Uno.UWP/Uno.Reference.csproj b/src/Uno.UWP/Uno.Reference.csproj index 2acb903642c3..d287e49d868c 100644 --- a/src/Uno.UWP/Uno.Reference.csproj +++ b/src/Uno.UWP/Uno.Reference.csproj @@ -31,10 +31,7 @@ - - - - + diff --git a/src/Uno.UWP/Uno.Skia.csproj b/src/Uno.UWP/Uno.Skia.csproj index d9e1c1f3dcdc..47b2469d1a75 100644 --- a/src/Uno.UWP/Uno.Skia.csproj +++ b/src/Uno.UWP/Uno.Skia.csproj @@ -33,10 +33,7 @@ - - - - + diff --git a/src/Uno.UWP/Uno.Tests.csproj b/src/Uno.UWP/Uno.Tests.csproj index e84beaf52bec..8c49938593e6 100644 --- a/src/Uno.UWP/Uno.Tests.csproj +++ b/src/Uno.UWP/Uno.Tests.csproj @@ -28,10 +28,7 @@ - - - - + diff --git a/src/Uno.UWP/Uno.Wasm.csproj b/src/Uno.UWP/Uno.Wasm.csproj index b3647f1b81dc..61661b784519 100644 --- a/src/Uno.UWP/Uno.Wasm.csproj +++ b/src/Uno.UWP/Uno.Wasm.csproj @@ -27,10 +27,7 @@ - - - - + diff --git a/src/Uno.UWP/Uno.netcoremobile.csproj b/src/Uno.UWP/Uno.netcoremobile.csproj index 802edfb24a69..cce3276ac6a6 100644 --- a/src/Uno.UWP/Uno.netcoremobile.csproj +++ b/src/Uno.UWP/Uno.netcoremobile.csproj @@ -43,10 +43,7 @@ - - - - +