Exemple #1
0
 public static System.Drawing.RectangleF AnchorWithin(this System.Drawing.SizeF that, System.Drawing.RectangleF there, AnchorPoints anchor)
 {
     switch (anchor)
     {
         case AnchorPoints.TopLeft:
             return that.ToRectF(new System.Drawing.PointF(there.Left                  , there.Top), anchor);
         case AnchorPoints.TopMiddle:
             return that.ToRectF(new System.Drawing.PointF(there.Left + there.Width / 2, there.Top), anchor);
         case AnchorPoints.TopRight:
             return that.ToRectF(new System.Drawing.PointF(there.Right, there.Top), anchor);
         case AnchorPoints.MiddleLeft:
             return that.ToRectF(new System.Drawing.PointF(there.Left, (there.Top + there.Bottom) / 2), anchor);
         case AnchorPoints.Center:
             return that.ToRectF(new System.Drawing.PointF(there.Left + there.Width / 2, (there.Top + there.Bottom) / 2), anchor);
         case AnchorPoints.MiddleRight:
             return that.ToRectF(new System.Drawing.PointF(there.Right, (there.Top + there.Bottom) / 2), anchor);
         case AnchorPoints.BottomLeft:
             return that.ToRectF(new System.Drawing.PointF(there.Left, there.Bottom), anchor);
         case AnchorPoints.BottomMiddle:
             return that.ToRectF(new System.Drawing.PointF(there.Left + there.Width / 2, there.Bottom), anchor);
         case AnchorPoints.BottomRight:
             return that.ToRectF(new System.Drawing.PointF(there.Right, there.Bottom), anchor);
         default:
             throw new ArgumentException("Unknown anchor enumeration value.");
     }
 }
Exemple #2
0
    public Spline()
    {
        AnchorPoints.Add(new Vector2(-1, 0));
        ControlPoints.Add(new ControlPointPair(NULL, new Vector2(-0.5f, -0.5f)));

        AnchorPoints.Add(new Vector2(1, 0));
        ControlPoints.Add(new ControlPointPair(new Vector2(0.5f, 0.5f), NULL));
    }
Exemple #3
0
    public void AddPoint(Vector2 newPoint)
    {
        Vector2          lastAnchorPoint  = AnchorPoints[AnchorPoints.Count - 1];
        ControlPointPair lastControlPoint = ControlPoints[ControlPoints.Count - 1];
        Vector2          distance         = lastAnchorPoint - lastControlPoint.leftControlPoint;

        lastControlPoint.rightControlPoint     = lastAnchorPoint + distance;
        ControlPoints[ControlPoints.Count - 1] = lastControlPoint;

        AnchorPoints.Add(newPoint);
        ControlPointPair newLastControlPointPair =
            new ControlPointPair(newPoint - distance, NULL);

        ControlPoints.Add(newLastControlPointPair);
    }
 /// <summary>
 /// Builds the form around the newly selected anchor point.
 /// </summary>
 /// <param name="anchor">Anchor point.</param>
 private void SetAnchor(AnchorPoints anchor)
 {
     DisableAll();
     switch (anchor)
     {
         case AnchorPoints.Center:
             chkCenter.Checked = true;
             AnchorPoint = AnchorPoints.Center;
             break;
         case AnchorPoints.Up:
             chkUp.Checked = true;
             AnchorPoint = AnchorPoints.Up;
             break;
         case AnchorPoints.UpRight:
             chkUpRight.Checked = true;
             AnchorPoint = AnchorPoints.UpRight;
             break;
         case AnchorPoints.Right:
             chkRight.Checked = true;
             AnchorPoint = AnchorPoints.Right;
             break;
         case AnchorPoints.DownRight:
             chkDownRight.Checked = true;
             AnchorPoint = AnchorPoints.DownRight;
             break;
         case AnchorPoints.Down:
             chkDown.Checked = true;
             AnchorPoint = AnchorPoints.Down;
             break;
         case AnchorPoints.DownLeft:
             chkDownLeft.Checked = true;
             AnchorPoint = AnchorPoints.DownLeft;
             break;
         case AnchorPoints.Left:
             chkLeft.Checked = true;
             AnchorPoint = AnchorPoints.Left;
             break;
         case AnchorPoints.UpLeft:
             chkUpLeft.Checked = true;
             AnchorPoint = AnchorPoints.UpLeft;
             break;
     }
     SetArrows();
 }
Exemple #5
0
 public static System.Drawing.Rectangle ToRect(this System.Drawing.Size that, System.Drawing.Point position, AnchorPoints anchor)
 {
     return that.ToRect(position.X, position.Y, anchor);
 }
Exemple #6
0
 public static System.Drawing.RectangleF Anchor(this System.Drawing.RectangleF that, System.Drawing.PointF position, AnchorPoints anchor)
 {
     return that.Anchor(position.X, position.Y, anchor);
 }
Exemple #7
0
 public static System.Drawing.Rectangle AnchorWithin(this System.Drawing.Size that, System.Drawing.Rectangle there, AnchorPoints anchor)
 {
     return System.Drawing.Rectangle.Truncate(new System.Drawing.SizeF(that.Width, that.Height).AnchorWithin(there, anchor));
 }
Exemple #8
0
 public static System.Drawing.RectangleF Anchor(this System.Drawing.RectangleF that, float x, float y, AnchorPoints anchor)
 {
     switch (anchor)
     {
         case AnchorPoints.TopLeft:
             return new System.Drawing.RectangleF(x, y, that.Width, that.Height);
         case AnchorPoints.TopMiddle:
             return new System.Drawing.RectangleF(x - that.Width / 2, y, that.Width, that.Height);
         case AnchorPoints.TopRight:
             return new System.Drawing.RectangleF(x - that.Width, y, that.Width, that.Height);
         case AnchorPoints.MiddleLeft:
             return new System.Drawing.RectangleF(x, y - that.Height / 2, that.Width, that.Height);
         case AnchorPoints.Center:
             return new System.Drawing.RectangleF(x - that.Width / 2, y - that.Height / 2, that.Width, that.Height);
         case AnchorPoints.MiddleRight:
             return new System.Drawing.RectangleF(x - that.Width, y - that.Height / 2, that.Width, that.Height);
         case AnchorPoints.BottomLeft:
             return new System.Drawing.RectangleF(x, y - that.Height, that.Width, that.Height);
         case AnchorPoints.BottomMiddle:
             return new System.Drawing.RectangleF(x - that.Width / 2, y - that.Height, that.Width, that.Height);
         case AnchorPoints.BottomRight:
             return new System.Drawing.RectangleF(x - that.Width, y - that.Height, that.Width, that.Height);
         default:
             throw new ArgumentException("Unknown anchor enumeration value.");
     }
 }
Exemple #9
0
 public static System.Drawing.RectangleF ToRectF(this System.Drawing.SizeF that, float x, float y, AnchorPoints anchor)
 {
     return new System.Drawing.RectangleF(0, 0, that.Width, that.Height).Anchor(x, y, anchor);
 }
Exemple #10
0
 public static System.Drawing.RectangleF ToRectF(this System.Drawing.Size that, Vector2 position, AnchorPoints anchor)
 {
     return that.ToRectF(position.X, position.Y, anchor);
 }
Exemple #11
0
 public static System.Drawing.Rectangle ToRect(this System.Drawing.Size that, int x, int y, AnchorPoints anchor)
 {
     return System.Drawing.Rectangle.Round(that.ToRectF(x, y, anchor));
 }
        /// <summary>
        /// Re-sizes the map based on the anchor and size.
        /// </summary>
        /// <param name="width">New width of the map.</param>
        /// <param name="height">New height of the map.</param>
        /// <param name="tilewidth">New width of the tiles.</param>
        /// <param name="tileheight">New height of the tiles.</param>
        /// <param name="anchor">Anchor point to resize around.</param>
        public void ResizeMap(int width, int height, int tilewidth, int tileheight, AnchorPoints anchor)
        {
            if (tilewidth != TileWidth) TileWidth = tilewidth;
            if (tileheight != TileHeight) TileHeight = tileheight;

            if (Width == width && Height == height) return;

            using (UndoRedoArea.Start("Map Size Changed"))
            {
                /*
                 * The actual re-sizing the array (when it's actually resized) is in the
                 * property changed events for the "Width" and "Height" properties.
                 *
                 * Here we'll simply move the tiles around based on the anchor point passed
                 * by the user.
                 *
                 * We cannot destroy objects, so we'll be copying over data between tiles
                 * directly in to the tile properties. This allows us to retain the undo/redo
                 * stack of each tile without moving the objects themselves.
                 *
                 * After that, setting the Width and Height properties will cause the array
                 * itself to resize (or not, depending) and pass through the changes
                 * to the ScrollMap controls accordingly.
                 *
                 * If the new width is less than the old one, then we'll move the tiles
                 * before changing the size.
                 *
                 * If the new width is more than the old one, then we'll change the size
                 * and then move the tiles.
                 *
                 */

                var oldWidth = Width;
                var oldHeight = Height;

                var difference = 0;

                _building = true;

                if (width < oldWidth)
                {
                    switch (anchor)
                    {
                        case AnchorPoints.Right:
                        case AnchorPoints.UpRight:
                        case AnchorPoints.DownRight:
                            difference = oldWidth - width;
                            foreach (var layer in Layers)
                            {
                                for (int x = 0; x < oldWidth; x++)
                                {
                                    for (int y = 0; y < oldHeight; y++)
                                    {
                                        if (x < oldWidth - difference)
                                        {
                                            var tile = layer.Tiles[x + difference, y];
                                            layer.Tiles[x, y].SrcX = tile.SrcX;
                                            layer.Tiles[x, y].SrcY = tile.SrcY;
                                            layer.Tiles[x, y].Terrain = tile.Terrain;
                                            layer.Tiles[x, y].Tileset = tile.Tileset;
                                        }
                                    }
                                }
                            }
                            break;
                        case AnchorPoints.Center: case AnchorPoints.Up: case AnchorPoints.Down:
                            difference = (oldWidth / 2) - (width / 2);
                            foreach (var layer in Layers)
                            {
                                for (int x = 0; x < oldWidth; x++)
                                {
                                    for (int y = 0; y < oldHeight; y++)
                                    {
                                        if (x < oldWidth - (oldWidth - width))
                                        {
                                            var tile = layer.Tiles[x + difference, y];
                                            layer.Tiles[x, y].SrcX = tile.SrcX;
                                            layer.Tiles[x, y].SrcY = tile.SrcY;
                                            layer.Tiles[x, y].Terrain = tile.Terrain;
                                            layer.Tiles[x, y].Tileset = tile.Tileset;
                                        }
                                    }
                                }
                            }
                            break;
                    }
                }

                if (height < oldHeight)
                {
                    switch (anchor)
                    {
                        case AnchorPoints.Down:
                        case AnchorPoints.DownRight:
                        case AnchorPoints.DownLeft:
                            difference = oldHeight - height;
                            foreach (var layer in Layers)
                            {
                                for (int x = 0; x < oldWidth; x++)
                                {
                                    for (int y = 0; y < oldHeight; y++)
                                    {
                                        if (y < oldHeight - difference)
                                        {
                                            var tile = layer.Tiles[x, y + difference];
                                            layer.Tiles[x, y].SrcX = tile.SrcX;
                                            layer.Tiles[x, y].SrcY = tile.SrcY;
                                            layer.Tiles[x, y].Terrain = tile.Terrain;
                                            layer.Tiles[x, y].Tileset = tile.Tileset;
                                        }
                                    }
                                }
                            }
                            break;
                        case AnchorPoints.Center:
                        case AnchorPoints.Left:
                        case AnchorPoints.Right:
                            difference = (oldHeight / 2) - (height / 2);
                            foreach (var layer in Layers)
                            {
                                for (int x = 0; x < oldWidth; x++)
                                {
                                    for (int y = 0; y < oldHeight; y++)
                                    {
                                        if (y < oldHeight - (oldHeight - height))
                                        {
                                            var tile = layer.Tiles[x, y + difference];
                                            layer.Tiles[x, y].SrcX = tile.SrcX;
                                            layer.Tiles[x, y].SrcY = tile.SrcY;
                                            layer.Tiles[x, y].Terrain = tile.Terrain;
                                            layer.Tiles[x, y].Tileset = tile.Tileset;
                                        }
                                    }
                                }
                            }
                            break;
                    }
                }

                Width = width;
                Height = height;

                // resize

                foreach (var layer in Layers)
                {
                    if (width > layer.Tiles.GetLength(0) || height > layer.Tiles.GetLength(1))
                    {
                        EditorTile[,] tmpArray = layer.Tiles;

                        var newwidth = Math.Max(width, layer.Tiles.GetLength(0));
                        var newheight = Math.Max(height, layer.Tiles.GetLength(1));

                        layer.Tiles = new EditorTile[newwidth, newheight];

                        layer.Sprites = new Sprite[width, height];
                        layer.TerrainCache = new TerrainCache[width, height];

                        for (int x = 0; x < newwidth; x++)
                        {
                            for (int y = 0; y < newheight; y++)
                            {
                                if (x >= tmpArray.GetLength(0) || y >= tmpArray.GetLength(1))
                                {
                                    var tile = new EditorTile(x, y, 0, 0, 0, 0, layer);
                                    layer.Tiles[x, y] = tile;
                                    layer.Tiles[x, y].PropertyChanged += Tile_PropertyChanged;
                                }
                                else
                                {
                                    layer.Tiles[x, y] = tmpArray[x, y];
                                    layer.Tiles[x, y].X = x;
                                    layer.Tiles[x, y].Y = y;
                                }
                            }
                        }
                    }

                    if (width < layer.Tiles.GetLength(0) || height < layer.Tiles.GetLength(1))
                    {
                        var arrwidth = layer.Tiles.GetLength(0);
                        var arrheight = layer.Tiles.GetLength(1);
                        var newwidth = Math.Min(width, arrwidth);
                        var newheight = Math.Min(height, arrheight);

                        for (int x = 0; x < arrwidth; x++)
                        {
                            for (int y = 0; y < arrheight; y++)
                            {
                                if (x > newwidth || y > newheight)
                                {
                                    layer.Tiles[x, y].SrcX = 0;
                                    layer.Tiles[x, y].SrcY = 0;
                                    layer.Tiles[x, y].Terrain = 0;
                                    layer.Tiles[x, y].Tileset = 0;
                                }
                            }
                        }
                    }
                }

                // end resize

                if (width > oldWidth)
                {
                    switch (anchor)
                    {
                        case AnchorPoints.Right:
                        case AnchorPoints.UpRight:
                        case AnchorPoints.DownRight:
                            difference = width - oldWidth;
                            foreach (var layer in Layers)
                            {
                                for (int x = width - 1; x > 0; x--)
                                {
                                    for (int y = 0; y < Height; y++)
                                    {
                                        if (x - difference >= 0)
                                        {
                                            var tile = layer.Tiles[x - difference, y];
                                            layer.Tiles[x, y].SrcX = tile.SrcX;
                                            layer.Tiles[x, y].SrcY = tile.SrcY;
                                            layer.Tiles[x, y].Terrain = tile.Terrain;
                                            layer.Tiles[x, y].Tileset = tile.Tileset;
                                        }
                                    }
                                }
                                for (int x = 0; x < difference; x++)
                                {
                                    for (int y = 0; y < Height; y++)
                                    {
                                        layer.Tiles[x, y].SrcX = 0;
                                        layer.Tiles[x, y].SrcY = 0;
                                        layer.Tiles[x, y].Terrain = 0;
                                        layer.Tiles[x, y].Tileset = 0;
                                    }
                                }
                            }
                            break;
                        case AnchorPoints.Center:
                        case AnchorPoints.Up:
                        case AnchorPoints.Down:
                            difference = (width / 2) - (oldWidth / 2);
                            foreach (var layer in Layers)
                            {
                                for (int x = width - 1; x > 0; x--)
                                {
                                    for (int y = 0; y < Height; y++)
                                    {
                                        if (x - difference >= 0)
                                        {
                                            var tile = layer.Tiles[x - difference, y];
                                            layer.Tiles[x, y].SrcX = tile.SrcX;
                                            layer.Tiles[x, y].SrcY = tile.SrcY;
                                            layer.Tiles[x, y].Terrain = tile.Terrain;
                                            layer.Tiles[x, y].Tileset = tile.Tileset;
                                        }
                                    }
                                }
                                for (int x = 0; x < difference; x++)
                                {
                                    for (int y = 0; y < Height; y++)
                                    {
                                        layer.Tiles[x, y].SrcX = 0;
                                        layer.Tiles[x, y].SrcY = 0;
                                        layer.Tiles[x, y].Terrain = 0;
                                        layer.Tiles[x, y].Tileset = 0;
                                    }
                                }
                            }
                            break;
                    }
                }

                if (height > oldHeight)
                {
                    switch (anchor)
                    {
                        case AnchorPoints.Down:
                        case AnchorPoints.DownRight:
                        case AnchorPoints.DownLeft:
                            difference = height - oldHeight;
                            foreach (var layer in Layers)
                            {
                                for (int x = 0; x < Width; x++)
                                {
                                    for (int y = height - 1; y > 0; y--)
                                    {
                                        if (y - difference >= 0)
                                        {
                                            var tile = layer.Tiles[x, y - difference];
                                            layer.Tiles[x, y].SrcX = tile.SrcX;
                                            layer.Tiles[x, y].SrcY = tile.SrcY;
                                            layer.Tiles[x, y].Terrain = tile.Terrain;
                                            layer.Tiles[x, y].Tileset = tile.Tileset;
                                        }
                                    }
                                }
                                for (int x = 0; x < Width; x++)
                                {
                                    for (int y = 0; y < difference; y++)
                                    {
                                        layer.Tiles[x, y].SrcX = 0;
                                        layer.Tiles[x, y].SrcY = 0;
                                        layer.Tiles[x, y].Terrain = 0;
                                        layer.Tiles[x, y].Tileset = 0;
                                    }
                                }
                            }
                            break;
                        case AnchorPoints.Center:
                        case AnchorPoints.Left:
                        case AnchorPoints.Right:
                            difference = (height / 2) - (oldHeight / 2);
                            foreach (var layer in Layers)
                            {
                                for (int x = 0; x < Width; x++)
                                {
                                    for (int y = height - 1; y > 0; y--)
                                    {
                                        if (y - difference >= 0)
                                        {
                                            var tile = layer.Tiles[x, y - difference];
                                            layer.Tiles[x, y].SrcX = tile.SrcX;
                                            layer.Tiles[x, y].SrcY = tile.SrcY;
                                            layer.Tiles[x, y].Terrain = tile.Terrain;
                                            layer.Tiles[x, y].Tileset = tile.Tileset;
                                        }
                                    }
                                }
                                for (int x = 0; x < Width; x++)
                                {
                                    for (int y = 0; y < difference; y++)
                                    {
                                        layer.Tiles[x, y].SrcX = 0;
                                        layer.Tiles[x, y].SrcY = 0;
                                        layer.Tiles[x, y].Terrain = 0;
                                        layer.Tiles[x, y].Tileset = 0;
                                    }
                                }
                            }
                            break;
                    }
                }

                UnsavedChanges = true;

                _building = false;

                CacheAllTiles();
                SizeChanged.Invoke(this, new EventArgs());

                UndoRedoArea.Commit();
            };
        }