예제 #1
0
        public override void Run(Window window)
        {
            Rect   square  = window.GetInnerSquare();
            Button button1 = new Button(window)
            {
                Text = "Effect",
            };

            button1.Move(square.X, square.Y);
            button1.Resize(square.Width / 2, square.Height / 2);
            button1.Show();

            Button button2 = new Button(window)
            {
                Text = "Chain Effect",
            };

            button2.Move(square.X + square.Width / 2, square.Y + square.Height / 2);
            button2.Resize(square.Width / 2, square.Height / 2);
            button2.Show();

            Point begin = new Point();

            begin.X = begin.Y = 0;
            Point end = new Point();

            end.X = end.Y = square.Height / 2;
            TranslationEffect translation = new TranslationEffect(begin, end);

            translation.EffectEnded += (s, e) => { Console.WriteLine("Translation Effect Ended"); };

            RotationEffect rotation = new RotationEffect(0, 180);

            rotation.EffectEnded += (s, e) => { Console.WriteLine("Rotation Effect Ended"); };

            button1.Clicked += (s, e) => {
                Transit transit1 = CreateTransit();
                transit1.Objects.Add(button1);
                transit1.Objects.Add(button2);
                transit1.AddEffect(translation);
                transit1.AddEffect(rotation);
                transit1.Go();
            };

            button2.Clicked += (s, e) => {
                Transit transit1 = CreateTransit();
                transit1.Objects.Add(button1);
                transit1.AddEffect(translation);
                transit1.AddEffect(rotation);

                Transit transit2 = CreateTransit();
                transit2.Objects.Add(button2);
                transit2.AddEffect(translation);
                transit2.AddEffect(rotation);

                transit1.Chains.Add(transit2);
                transit1.Go();
            };
        }
예제 #2
0
        public override void Run(Window window)
        {
            Button button1 = new Button(window)
            {
                Text = "Effect",
            };

            button1.Move(0, 0);
            button1.Resize(270, 200);
            button1.Show();

            Button button2 = new Button(window)
            {
                Text = "Chain Effect",
            };

            button2.Move(270, 200);
            button2.Resize(270, 200);
            button2.Show();

            Point begin = new Point();

            begin.X = begin.Y = 0;
            Point end = new Point();

            end.X = end.Y = 200;
            TranslationEffect translation = new TranslationEffect(begin, end);

            translation.EffectEnded += (s, e) => { Console.WriteLine("Translation Effect Ended"); };

            RotationEffect rotation = new RotationEffect(0, 180);

            rotation.EffectEnded += (s, e) => { Console.WriteLine("Rotation Effect Ended"); };

            button1.Clicked += (s, e) => {
                Transit transit1 = CreateTransit();
                transit1.Objects.Add(button1);
                transit1.Objects.Add(button2);
                transit1.AddEffect(translation);
                transit1.AddEffect(rotation);
                transit1.Go();
            };

            button2.Clicked += (s, e) => {
                Transit transit1 = CreateTransit();
                transit1.Objects.Add(button1);
                transit1.AddEffect(translation);
                transit1.AddEffect(rotation);

                Transit transit2 = CreateTransit();
                transit2.Objects.Add(button2);
                transit2.AddEffect(translation);
                transit2.AddEffect(rotation);

                transit1.Chains.Add(transit2);
                transit1.Go();
            };
        }
예제 #3
0
        public void HandleTouch(TouchStatus status, TouchInteractionStatus?touchInteractionStatus = null)
        {
            if (IsCanceled || effect == null)
            {
                return;
            }

            if (effect?.IsDisabled ?? true)
            {
                return;
            }

            if (touchInteractionStatus == TouchInteractionStatus.Started)
            {
                effect?.HandleUserInteraction(TouchInteractionStatus.Started);
                touchInteractionStatus = null;
            }

            effect.HandleTouch(status);
            if (touchInteractionStatus.HasValue)
            {
                effect.HandleUserInteraction(touchInteractionStatus.Value);
            }

            if (!effect.NativeAnimation)
            {
                return;
            }

            if (longTapStarted && !tapCompleted)
            {
                return;
            }

            var control = effect.Element;

            if (!(Platform.GetOrCreateRenderer(control)?.NativeView is Widget nativeView))
            {
                return;
            }

            if (status == TouchStatus.Started)
            {
                var startColor = nativeView.BackgroundColor;
                if (startColor.IsDefault)
                {
                    return;
                }

                var endColor = effect.NativeAnimationColor.ToNative();
                if (endColor.IsDefault)
                {
                    startColor = EColor.FromRgba(startColor.R, startColor.G, startColor.B, startColor.A / 2);
                    endColor   = startColor;
                }

                var transit = new Transit
                {
                    Repeat   = 1,
                    Duration = .2
                };
                var colorEffect = new ColorEffect(startColor, endColor);
                colorEffect.EffectEnded += (s, e) => { transit?.Dispose(); };
                transit.Objects.Add(nativeView);
                transit.AddEffect(colorEffect);
                transit.Go(.2);
            }
        }
예제 #4
0
        public void HandleTouch(TouchStatus status, UserInteractionState?userInteractionState = null)
        {
            if (IsCanceled || _effect == null)
            {
                return;
            }

            if (_effect?.IsDisabled ?? true)
            {
                return;
            }

            _effect.HandleTouch(status);
            if (userInteractionState.HasValue)
            {
                _effect.HandleUserInteraction(userInteractionState.Value);
            }

            if (!_effect.NativeAnimation)
            {
                return;
            }

            if (_longTapStarted && !_tapCompleted)
            {
                return;
            }

            var control    = _effect.Control;
            var nativeView = Platform.GetOrCreateRenderer(control)?.NativeView as Widget;

            if (nativeView == null)
            {
                return;
            }

            if (status == TouchStatus.Started)
            {
                var startColor = nativeView.BackgroundColor;
                if (startColor.IsDefault)
                {
                    return;
                }

                var endColor = _effect.NativeAnimationColor.ToNative();;
                if (endColor.IsDefault)
                {
                    startColor = EColor.FromRgba(startColor.R, startColor.G, startColor.B, startColor.A / 2);
                    endColor   = startColor;
                }

                Transit transit = new Transit
                {
                    Repeat   = 1,
                    Duration = .2
                };
                var colorEffect = new ColorEffect(startColor, endColor);
                colorEffect.EffectEnded += (s, e) => { transit?.Dispose(); };
                transit.Objects.Add(nativeView);
                transit.AddEffect(colorEffect);
                transit.Go(.2);
            }
        }