Esempio n. 1
0
        /// <summary>
        /// Converts the input to the outputType using a fast conversion, for known system types.
        /// </summary>
        /// <param name="outputType">The target type</param>
        /// <param name="input">The input value to use</param>
        /// <param name="output">The input value converted to the <paramref name="outputType"/>.</param>
        /// <returns>True if the conversion succeeded, otherwise false.</returns>
        /// <remarks>
        /// This is a fast path conversion that avoids going through the TypeConverter
        /// infrastructure for known system types.
        /// </remarks>
        private static bool FastConvert(Type outputType, object input, out object output)
        {
            output = null;

            if (
                input is string stringInput &&
                FastStringConvert(outputType, stringInput, ref output)
                )
            {
                return(true);
            }

            if (FastNumberConvert(outputType, input, ref output))
            {
                return(true);
            }

            return(input switch
            {
                Enum _ => FastEnumConvert(outputType, input, ref output),
                bool boolInput => FastBooleanConvert(outputType, boolInput, ref output),
                Windows.UI.Color color => FastColorConvert(outputType, color, ref output),
                SolidColorBrush solidColorBrush => FastSolidColorBrushConvert(outputType, solidColorBrush, ref output),
                ColorOffset colorOffsetInput => FastColorOffsetConvert(outputType, colorOffsetInput, ref output),
                Thickness thicknessInput => FastThicknessConvert(outputType, thicknessInput, ref output),
                _ => false
            });
Esempio n. 2
0
        /// <summary>
        /// Apply easing function on each component of a ColorOffset
        /// </summary>
        public static ColorOffset Ease(this IEasingFunction easing, long frame, ColorOffset from, ColorOffset to, long duration)
        {
            var a = (int)easing.Ease(frame, from.A, to.A, duration);
            var r = (int)easing.Ease(frame, from.R, to.R, duration);
            var g = (int)easing.Ease(frame, from.G, to.G, duration);
            var b = (int)easing.Ease(frame, from.B, to.B, duration);

            return(ColorOffset.FromArgb(a, r, g, b));
        }
Esempio n. 3
0
        /// <summary>
        /// Creates the actual animator instance
        /// </summary>
        private static IValueAnimator CreateColor(Timeline timeline, ColorOffset startingValue, ColorOffset targetValue)
        {
            // TODO: GPU-bound color animations - https://github.com/unoplatform/uno/issues/2947

            var startingColor = (Android.Graphics.Color)(Color) startingValue;
            var targetColor   = (Android.Graphics.Color)(Color) targetValue;
            var valueAnimator = ValueAnimator.OfArgb(startingColor, targetColor);

            return(new NativeValueAnimatorAdapter(valueAnimator));
        }
Esempio n. 4
0
        private static bool FastColorOffsetConvert(Type outputType, ColorOffset input, ref object output)
        {
            if (outputType == typeof(Windows.UI.Color))
            {
                output = (Windows.UI.Color)input;
                return(true);
            }

            return(false);
        }
Esempio n. 5
0
        private static IValueAnimator CreateColor(Timeline timeline, ColorOffset startingValue, ColorOffset targetValue)
        {
            if (timeline.GetIsDurationZero())
            {
                // Avoid unnecessary JS interop in the case of a zero-duration animation
                return(new ImmediateAnimator <ColorOffset>(startingValue, targetValue));
            }

            // TODO: GPU-bound color animations - https://github.com/unoplatform/uno/issues/2947

            return(new RenderingLoopColorAnimator(startingValue, targetValue));
        }
Esempio n. 6
0
        private static IValueAnimator CreateColor(Timeline timeline, ColorOffset startingValue, ColorOffset targetValue)
        {
            // TODO: GPU-bound color animations - https://github.com/unoplatform/uno/issues/2947

            return(new ColorValueAnimator(startingValue, targetValue));
        }
Esempio n. 7
0
 private static byte GetColorByte(ColorOffset offset, int pixel)
 {
     return(Convert.ToByte((pixel >> (int)offset) & 0xff));
 }
Esempio n. 8
0
 private static IValueAnimator CreateColor(Timeline timeline, ColorOffset startingValue, ColorOffset targetValue)
 {
     return(new NotSupportedAnimator());
 }
 public static int GetPixelColorIndex(int row, int column, ColorOffset colorOffset, int stride, int bytesPerPixel)
 {
     return((row * stride) + column * bytesPerPixel + (int)colorOffset);
 }
Esempio n. 10
0
 private static IValueAnimator CreateColor(Timeline timeline, ColorOffset startingValue, ColorOffset targetValue)
 => new ImmediateAnimator <ColorOffset>(startingValue, targetValue);
Esempio n. 11
0
 public ColorValueAnimator(ColorOffset from, ColorOffset to)
 {
     _to   = to;
     _from = from;
 }