예제 #1
0
파일: TouchEffect.cs 프로젝트: liaoyu45/LY
        public TouchEffect(Grid self, Trace t, double minRange)
        {
            center = t.Center;
            InputDevice d = null;

            MainBall = new Ellipse {
                Fill = DefaultBrush,
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment   = VerticalAlignment.Top,
                Height = t.Radius * 2,
                Width  = t.Radius * 2,
                Margin = new Thickness {
                    Left = t.Center.X - t.Radius, Top = t.Center.Y - t.Radius
                }
            };
            Ball = new Ellipse {
                Fill   = DefaultBrush,
                Width  = t.Radius,
                Height = t.Radius,
                HorizontalAlignment = HorizontalAlignment.Left,
                VerticalAlignment   = VerticalAlignment.Top,
            };
            Line = new Line {
                StrokeThickness     = t.Radius / 11,
                HorizontalAlignment = HorizontalAlignment.Left,
                Stroke            = DefaultBrush,
                VerticalAlignment = VerticalAlignment.Top,
                IsHitTestVisible  = false
            };
            EventHandler <TouchEventArgs> start = (s, e) => {
                if (Disabled || d != null)
                {
                    return;
                }
                d = e.Device;
                MoveTo(e.GetTouchPoint(self).Position);
                t.Released = false;
                var sc = RandomColor();
                Ball.Fill   = MainBall.Fill = new RadialGradientBrush(sc);
                Line.Stroke = new LinearGradientBrush(sc);
                ReadyToMove?.Invoke(t.Clone());
            };

            MainBall.TouchDown += start;
            Ball.TouchDown     += start;
            Line.X1             = t.Center.X;
            Line.Y1             = t.Center.Y;
            MoveTo(t.Center);
            self.Children.Add(Line);
            self.Children.Add(Ball);
            self.Children.Add(MainBall);
            Func <TouchEventArgs, bool> tryMove = e => {
                if (e.Device != d)
                {
                    return(false);
                }
                var to = e.GetTouchPoint(self).Position;
                t.Direction = to - t.Center;
                MoveTo(to);
                return(true);
            };

            self.TouchMove += (s, e) => {
                if (tryMove(e))
                {
                    Moving?.Invoke(t.Clone());
                }
            };
            self.TouchLeave += (s, e) => {
                if (!tryMove(e))
                {
                    return;
                }
                d          = null;
                t.Released = true;
                if (t.Direction.Length < minRange)
                {
                    t.Direction = new Vector();
                    Reset();
                }
                else
                {
                    StopMoving?.Invoke(t.Clone());
                }
            };
        }
예제 #2
0
 protected void StopMovingMethod(object?o)
 {
     Velocity = new THUnity2D.Vector(Velocity.angle, 0);
     StopMoving?.Invoke(o);
 }