Esempio n. 1
0
 public void UpdateDirection(Geometry.Direction direction)
 {
     if (direction != _currentDirection && direction != Geometry.Direction.Neutral)
     {
         _currentDirection = direction;
         UpdateAnimation();
     }
 }
Esempio n. 2
0
        static public bool select_pos_for_middle_point(GuiConnectionPoint p1, GuiConnectionPoint p2, out int x, out int y)
        {
            int x1 = p1.x, y1 = p1.y, x2 = p2.x, y2 = p2.y;

            Geometry.Direction d1 = Geometry.Direction.Null;
            Rectangle          r1 = Rectangle.Empty, r2 = Rectangle.Empty;

            if (p1.item is GuiItem)
            {
                d1 = (p1.item as GuiItem).direction(p1.ux);
                r1 = (p1.item as GuiItem).AroundRect;
            }
            if (p2.item is GuiItem)
            {
                r2 = (p2.item as GuiItem).AroundRect;
            }

            // try two solutions (x1, y2) and (x2, y1)
            bool sol1 = !Geometry.rect_inters_with_quadric_segment(r1, x1, y1, x1, y2) &&
                        !Geometry.rect_inters_with_quadric_segment(r2, x1, y1, x1, y2) &&
                        !Geometry.rect_inters_with_quadric_segment(r1, x2, y2, x1, y2) &&
                        !Geometry.rect_inters_with_quadric_segment(r2, x2, y2, x1, y2);
            bool sol2 = !Geometry.rect_inters_with_quadric_segment(r1, x1, y1, x2, y1) &&
                        !Geometry.rect_inters_with_quadric_segment(r2, x1, y1, x2, y1) &&
                        !Geometry.rect_inters_with_quadric_segment(r1, x2, y2, x2, y1) &&
                        !Geometry.rect_inters_with_quadric_segment(r2, x2, y2, x2, y1);

            if (p2.item == null && r1.Contains(x2, y2))
            {
                sol1 = true;
            }

            if (sol1 && sol2)
            {
                if (d1 == Geometry.Direction.South || d1 == Geometry.Direction.North)
                {
                    sol2 = false;                      // select sol1
                }
                else
                {
                    sol1 = false;
                }
            }

            if (sol1 || !sol2 && (d1 == Geometry.Direction.South && y2 - y1 > 0 || d1 == Geometry.Direction.North && y2 - y1 < 0 || d1 == Geometry.Direction.West && x2 - x1 > 0 || d1 == Geometry.Direction.East && x2 - x1 < 0))
            {
                x = x1;
                y = y2;
            }
            else
            {
                x = x2;
                y = y1;
            }
            return(sol1 || sol2);
        }
Esempio n. 3
0
 public void Initialize(SpriteSheet sheet, Vector2 position)
 {
     PlayerSheet      = sheet;
     PlayerTexture    = sheet.Texture;
     Position         = position;
     CurrentDirection = Geometry.Direction.Down;
     Console.WriteLine("setting currentsprite");
     CurrentSprite = new MovingAnimatedSprite("CuboneMarowak", Position, CurrentDirection);
     SetAnimation("Asleep");
 }
Esempio n. 4
0
        public void Apply(ObjectState v)
        {
            State s = v as State;

            Invalidate();
            root.Invalidate();
            ux         = s.ux;
            uy         = s.uy;
            x          = s.x;
            y          = s.y;
            hx         = s.hx;
            hy         = s.hy;
            hyphen     = s.hyphen;
            hyphen_dir = s.hyphen_dir;
            UpdatePlaceRect();
            root.Invalidate();
            Invalidate();
        }
Esempio n. 5
0
        private GuiBoundString create_label(string label, int ux, float uy, Geometry.Direction dir, int offset, bool hidden)
        {
            GuiBoundString bs = new GuiBoundString(label, this, 0, -offset, ux, uy, hidden);

            switch (dir)
            {
            case Geometry.Direction.West:
                bs.pos_x -= bs.place.Width;
                bs.RecalculatePosition();
                break;

            case Geometry.Direction.North:
                bs.pos_y -= bs.place.Height;
                bs.RecalculatePosition();
                break;
            }
            return(bs);
        }
Esempio n. 6
0
        public void UpdatePosition(bool process_endpoints)
        {
            if (item != null)
            {
                IHyphenSupport m = item as IHyphenSupport;
                if (m != null)
                {
                    hyphen_dir = m.direction(ux);
                }
                int tx, ty, sx, sy;
                item.coord_getxy(ux, uy, out tx, out ty);
                Geometry.shift_direction(tx, ty, out sx, out sy, hyphen_dir, DELTA);

                if ((!Hyphen && (tx != x || ty != y)) || (Hyphen && (sx != x || sy != y)) || hx == 0 && hy == 0)
                {
                    Invalidate();
                    root.Invalidate();
                    if (!Hyphen)
                    {
                        x = tx;
                        y = ty;
                    }
                    else
                    {
                        x  = sx;
                        y  = sy;
                        hx = tx;
                        hy = ty;
                    }
                    if (root != null && process_endpoints)
                    {
                        (root as GuiConnection).EndPointPositionChanging(this);
                    }
                    UpdatePlaceRect();
                    root.Invalidate();
                    Invalidate();
                }
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Given a line from the center of a circle to a point, what degrees is the line angle at? 0 degrees is East from center, and increases clockwise.
        /// </summary>
        public double DegreesAtPoint(Point lineEnd)
        {
            if (Geometry.CoordinatePlane == Geometry.CoordinatePlanes.None)
            {
                throw new ArgumentException("Coordinate plane required.");
            }

            Geometry.Direction direction = Geometry.LineDirection(Center, lineEnd);
            switch (direction)
            {
            case Geometry.Direction.East: return(0);

            case Geometry.Direction.South: return(90);

            case Geometry.Direction.West: return(180);

            case Geometry.Direction.North: return(270);
            }

            double lineLength = Center.Distance(lineEnd);
            double radians    = Math.Abs(Math.Asin((lineEnd.Y - Center.Y) / lineLength));
            double degrees    = Shapes.Circle.RadiansToDegrees(radians) % DEGREES_IN_CIRCLE;

            switch (direction)
            {
            case Geometry.Direction.SouthEast: return(degrees);

            case Geometry.Direction.SouthWest: return(DEGREES_IN_HALF_CIRCLE - degrees);

            case Geometry.Direction.NorthWest: return(DEGREES_IN_HALF_CIRCLE + degrees);

            case Geometry.Direction.NorthEast: return(DEGREES_IN_CIRCLE - degrees);
            }

            throw new NotImplementedException(String.Format("Direction not supported: {0}.", direction));
        }
Esempio n. 8
0
        public static Point[] polyline_quadric_DummyWay(GuiConnectionPoint p1, GuiConnectionPoint p2, ArrayList active)
        {
            int x1 = p1.x, y1 = p1.y, x2 = p2.x, y2 = p2.y;

            Geometry.Direction d1 = Geometry.Direction.Null, d2 = Geometry.Direction.Null;
            Rectangle          r1 = Rectangle.Empty, r2 = Rectangle.Empty;

            if (p1.item is GuiItem)
            {
                d1 = (p1.item as GuiItem).direction(p1.ux);
                r1 = (p1.item as GuiItem).AroundRect;
            }
            if (p2.item is GuiItem)
            {
                d2 = (p2.item as GuiItem).direction(p2.ux);
                r2 = (p2.item as GuiItem).AroundRect;
            }

            if ((x1 == x2 || y1 == y2) && !Geometry.rect_inters_with_quadric_segment(r1, x1, y1, x2, y2) &&
                !Geometry.rect_inters_with_quadric_segment(r2, x1, y1, x2, y2))
            {
                return new Point[] {}
            }
            ;

            // try two solutions (x1, y2) and (x2, y1)
            int xm, ym;

            if (select_pos_for_middle_point(p1, p2, out xm, out ym))
            {
                return new Point[] { new Point(xm, ym) }
            }
            ;

            // try solutions of 3 segments
            bool sol1, sol2;

            Point[] ans1 = new Point[] { new Point(x1, y1), new Point(x2, y2) },
            ans2 = new Point[] { new Point(x1, y1), new Point(x2, y2) };
            sol2 = sol1 = false;

            if ((d1 == Geometry.Direction.East && x2 < x1) ||
                (d1 == Geometry.Direction.West && x2 > x1) ||
                (d1 == Geometry.Direction.South && y2 < y1) ||
                (d1 == Geometry.Direction.North && y2 > y1))
            {
                if (d1 == Geometry.Direction.North || d1 == Geometry.Direction.South)
                {
                    if (d2 == Geometry.Direction.North || d2 == Geometry.Direction.South)
                    {
                        if (x2 > x1)
                        {
                            ans1[0].X = ans1[1].X = (r2.Left > r1.Right) ? (r2.Left + r1.Right) / 2 : Math.Max(r1.Right, r2.Right);
                        }
                        else
                        {
                            ans1[0].X = ans1[1].X = (r2.Right < r1.Left) ? (r1.Left + r2.Right) / 2 : Math.Min(r1.Left, r2.Left);
                        }
                    }
                    else if (d2 == Geometry.Direction.West)
                    {
                        ans1[0].X = ans1[1].X = r1.Left;
                    }
                    else
                    {
                        ans1[0].X = ans1[1].X = r1.Right;
                    }
                }
                else
                {
                    if (d2 == Geometry.Direction.West || d2 == Geometry.Direction.East)
                    {
                        if (y2 > y1)
                        {
                            ans1[0].Y = ans1[1].Y = Math.Max(r1.Bottom, r2.Bottom);
                        }
                        else
                        {
                            ans1[0].Y = ans1[1].Y = Math.Min(r1.Top, r2.Top);
                        }
                    }
                    else if (d2 == Geometry.Direction.North)
                    {
                        ans1[0].Y = ans1[1].Y = r1.Top;
                    }
                    else
                    {
                        ans1[0].Y = ans1[1].Y = r1.Bottom;
                    }
                }
                sol1 = true;
            }

            if ((d2 == Geometry.Direction.East && x1 < x2) ||
                (d2 == Geometry.Direction.West && x1 > x2) ||
                (d2 == Geometry.Direction.South && y1 < y2) ||
                (d2 == Geometry.Direction.North && y1 > y2))
            {
                if (d2 == Geometry.Direction.North || d2 == Geometry.Direction.South)
                {
                    if (d1 == Geometry.Direction.North || d1 == Geometry.Direction.South)
                    {
                        if (x1 > x2)
                        {
                            ans2[0].X = ans2[1].X = (r1.Left > r2.Right) ? (r1.Left + r2.Right) / 2 : Math.Max(r1.Right, r2.Right);
                        }
                        else
                        {
                            ans2[0].X = ans2[1].X = (r1.Right < r2.Left) ? (r2.Left + r1.Right) / 2 : Math.Min(r1.Left, r2.Left);
                        }
                    }
                    else if (d1 == Geometry.Direction.West)
                    {
                        ans2[0].X = ans2[1].X = r2.Left;
                    }
                    else
                    {
                        ans2[0].X = ans2[1].X = r2.Right;
                    }
                }
                else
                {
                    if (d1 == Geometry.Direction.West || d1 == Geometry.Direction.East)
                    {
                        if (y1 > y2)
                        {
                            ans2[0].Y = ans2[1].Y = Math.Max(r1.Bottom, r2.Bottom);
                        }
                        else
                        {
                            ans2[0].Y = ans2[1].Y = Math.Min(r1.Top, r2.Top);
                        }
                    }
                    else if (d1 == Geometry.Direction.North)
                    {
                        ans2[0].Y = ans2[1].Y = r2.Top;
                    }
                    else
                    {
                        ans2[0].Y = ans2[1].Y = r2.Bottom;
                    }
                }
                sol2 = true;
            }

            // try to select best one
            if (sol1 && sol2)
            {
                if (!Geometry.rect_inters_with_quadric_segment(r1, x1, y1, ans1[0].X, ans1[0].Y) &&
                    !Geometry.rect_inters_with_quadric_segment(r2, x1, y1, ans1[0].X, ans1[0].Y) &&
                    !Geometry.rect_inters_with_quadric_segment(r1, x2, y2, ans1[1].X, ans1[1].Y) &&
                    !Geometry.rect_inters_with_quadric_segment(r2, x2, y2, ans1[1].X, ans1[1].Y) &&
                    !Geometry.rect_inters_with_quadric_segment(r1, ans1[0].X, ans1[0].Y, ans1[1].X, ans1[1].Y) &&
                    !Geometry.rect_inters_with_quadric_segment(r2, ans1[0].X, ans1[0].Y, ans1[1].X, ans1[1].Y))
                {
                    sol2 = false;
                }
                else
                {
                    sol1 = false;
                }
            }

            return(sol1 ? ans1 : ans2);
        }
Esempio n. 9
0
 public void Apply(ObjectState v)
 {
     State s = v as State;
     Invalidate();
     root.Invalidate();
     ux = s.ux;
     uy = s.uy;
     x = s.x;
     y = s.y;
     hx = s.hx;
     hy = s.hy;
     hyphen = s.hyphen;
     hyphen_dir = s.hyphen_dir;
     UpdatePlaceRect();
     root.Invalidate();
     Invalidate();
 }
Esempio n. 10
0
        public void UpdatePosition( bool process_endpoints )
        {
            if( item != null ) {
                IHyphenSupport m = item as IHyphenSupport;
                if( m != null )
                    hyphen_dir = m.direction( ux );
                int tx, ty, sx, sy;
                item.coord_getxy( ux, uy, out tx, out ty );
                Geometry.shift_direction( tx, ty, out sx, out sy, hyphen_dir, DELTA );

                if( (!Hyphen && (tx != x || ty != y)) || ( Hyphen && (sx != x || sy != y) ) || hx == 0 && hy == 0 ) {
                    Invalidate();
                    root.Invalidate();
                    if( !Hyphen ) {
                        x = tx;
                        y = ty;
                    } else {
                        x = sx;
                        y = sy;
                        hx = tx;
                        hy = ty;
                    }
                    if( root != null && process_endpoints )
                        (root as GuiConnection).EndPointPositionChanging( this );
                    UpdatePlaceRect();
                    root.Invalidate();
                    Invalidate();
                }
            }
        }
Esempio n. 11
0
 public MovingAnimatedSprite(string name, Vector2 position, Geometry.Direction direction) : base(name, position)
 {
     _currentDirection = direction;
 }
Esempio n. 12
0
 public MovingAnimatedSprite(string name, Vector2 position) : base(name, position)
 {
     _currentDirection = Geometry.Direction.Neutral;
 }
Esempio n. 13
0
 public void Move(Vector2 moveVector)
 {
     CurrentDirection = Geometry.VectorToQuarterDirection(moveVector);
     CurrentSprite.UpdateDirection(CurrentDirection);
     Position += moveVector;
 }