Exemplo n.º 1
0
        internal void Update()//на будущее - для MapPresenter.cs
        {
            Geometry.Figures.Point p0;
            if (origin != null)
            {
                p0          = Transformer.ConvertToScreen(origin);
                OrderOrigin = new System.Windows.Point(p0.X, p0.Y);
            }

            Geometry.Figures.Point p1;
            if (origin != null)
            {
                p1          = Transformer.ConvertToScreen(target);
                OrderTarget = new System.Windows.Point(target.X, target.Y);
            }

            if (action is GameEngine.Characters.MoveAction)
            {
                if (action.Completed == true)
                {
                    VisibleWayAim   = Visibility.Collapsed;
                    TurnsToComplete = 0;
                }
                else
                {
                    Margin = new Thickness(((action as GameEngine.Characters.MoveAction).Destination.X - (action as GameEngine.Characters.MoveAction).Origin.X) * 100,
                                           ((action as GameEngine.Characters.MoveAction).Destination.Y - (action as GameEngine.Characters.MoveAction).Origin.Y) * 100,
                                           0, 0);

                    VisibleWayAim   = Visibility.Visible;
                    TurnsToComplete = (action as GameEngine.Characters.MoveAction).TurnsToComplete;
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Calculates a displaced center of a figure according to current Transformer state.
        /// </summary>
        /// <remarks>
        /// A center is displaced equally by X and Y coordinates for a value of Radius property.
        /// Before that Radius property is recalculated according to figure type and current Transformer state.
        /// </remarks>
        /// <returns>System.Windows.Point of a displaced center</returns>
        private void UpdateCenter()
        {
            Geometry.Figures.Point p = new Geometry.Figures.Point(0, 0);

            if (original is Circle)
            {
                p = (original as Circle).Center;
            }
            else if (original is Geometry.Figures.Point)
            {
                p = original as Geometry.Figures.Point;
            }
            else if (original is ConvexPolygon)
            {
                p = (original as ConvexPolygon).Center();
            }
            else if (original is Polyline)
            {
                p = (original as Polyline).Center();
            }
            else if (original is Segment)
            {
                var segment = original as Segment;
                var v       = Geometry.Vector.RadiusVector(segment.Begin) + Geometry.Vector.RadiusVector(segment.End);
                p = new Geometry.Figures.Point(v.X / 2, v.Y / 2);
            }

            Geometry.Figures.Point q = Transformer.ConvertToScreen(p);

            UpdateRadius();
            q.X -= Radius; q.Y -= Radius;

            Center = new System.Windows.Point(q.X, q.Y);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Calculates relative (to the Center) screen points of a polygon, segment or polyline.
        /// For a convex polygon also counts the smoothed path to be used in rendering
        /// </summary>
        private void UpdatePoints()
        {
            List <Geometry.Figures.Point> originalPoints = new List <Geometry.Figures.Point>();
            List <System.Windows.Point>   result         = null;

            if (original is Polyline)
            {
                originalPoints.AddRange((original as Polyline).Points);
            }
            else if (original is ConvexPolygon)
            {
                originalPoints.AddRange((original as ConvexPolygon).Points);
            }
            else if (original is Segment)
            {
                var segment = original as Segment;
                originalPoints.Add(segment.Begin);
                originalPoints.Add(segment.End);
            }

            if (originalPoints.Count != 0)
            {
                result = new List <System.Windows.Point>();
                foreach (var p in originalPoints)
                {
                    var screenPoint         = Transformer.ConvertToScreen(p);
                    var relativeScreenPoint = new System.Windows.Point(screenPoint.X - Center.X, screenPoint.Y - Center.Y);
                    result.Add(relativeScreenPoint);
                }
            }

            if (result != null)
            {
                Points = new PointCollection(result);

                // smoothing insertion -- for now it is for polygons only
                if (original is ConvexPolygon)
                {
                    SmoothedPath = BezierSmoothing(Points, Smoothing);
                }
            }
        }