示例#1
0
        /// <summary>
        /// Creates individual tiles from the existing background
        /// </summary>
        /// <param name="tileset">The tileset to grid to individual tiles</param>
        private void PopulateTiles(Bitmap tileset)
        {
            // Get background data
            List <Bitmap> tiles      = new List <Bitmap>();
            Size          size       = App.Room.Backgrounds[0].GetGridSize();
            Size          tileSize   = App.Room.Backgrounds[0].TileSize;
            Size          seperation = new Size(App.Room.Backgrounds[0].SeparationX, App.Room.Backgrounds[0].SeparationY);
            Point         offset     = new Point(App.Room.Backgrounds[0].OffsetX, App.Room.Backgrounds[0].OffsetY);
            Rectangle     rect       = new Rectangle(Point.Empty, tileSize);

            pnlTileset.Columns = size.Width;

            // Iterate through image columns and rows
            for (int row = 0; row < size.Height; row++)
            {
                for (int col = 0; col < size.Width; col++)
                {
                    // Set position
                    rect.X = col * tileSize.Width;
                    rect.Y = row * tileSize.Height;

                    // Create a tile bitmap, and remember it's original id
                    Bitmap tile = tileset.Clone(rect, tileset.PixelFormat);
                    tile.Tag = GMareBrush.PositionToSourceTileId(rect.Location.X, rect.Location.Y, tileset.Width, tileSize);

                    // Add bitmap to tiles
                    tiles.Add(tile);
                }
            }

            // Populate tile editor
            pnlTileset.SnapSize = tileSize;
            pnlTileset.Tiles    = tiles;
            tileset.Dispose();
        }
示例#2
0
        private void PopulateTiles(Bitmap tileset)
        {
            List <Bitmap> bitmapList = new List <Bitmap>();
            Size          gridSize   = App.Room.Backgrounds[0].GetGridSize();
            Size          tileSize   = App.Room.Backgrounds[0].TileSize;
            Size          size       = new Size(App.Room.Backgrounds[0].SeparationX, App.Room.Backgrounds[0].SeparationY);
            Point         point      = new Point(App.Room.Backgrounds[0].OffsetX, App.Room.Backgrounds[0].OffsetY);
            Rectangle     rect       = new Rectangle(Point.Empty, tileSize);

            this.pnlTileset.Columns = gridSize.Width;
            for (int index1 = 0; index1 < gridSize.Height; ++index1)
            {
                for (int index2 = 0; index2 < gridSize.Width; ++index2)
                {
                    rect.X = index2 * tileSize.Width;
                    rect.Y = index1 * tileSize.Height;
                    Bitmap bitmap = tileset.Clone(rect, tileset.PixelFormat);
                    bitmap.Tag = (object)GMareBrush.PositionToSourceTileId(rect.Location.X, rect.Location.Y, tileset.Width, tileSize);
                    bitmapList.Add(bitmap);
                }
            }
            this.pnlTileset.SnapSize = tileSize;
            this.pnlTileset.Tiles    = bitmapList;
            tileset.Dispose();
        }
示例#3
0
        /// <summary>
        /// On mouse down
        /// </summary>
        protected override void OnMouseDown(MouseEventArgs e)
        {
            // If the project or tileset do not exist or the object id is empty, return
            if (App.Room == null || Image == null)
            {
                return;
            }

            // Focus for scroll support
            Focus();

            // Get start snapped position
            Point snap = GetOffsetSnappedPoint(e.Location);

            // If the mouse is within the image dimensions
            if (!new Rectangle(0, 0, Image.Width, Image.Height).Contains(snap))
            {
                return;
            }

            // Set id
            Size tileSize = _background.TileSize;

            tileSize.Width  += 1;
            tileSize.Height += 1;

            int tileId = GMareBrush.PositionToSourceTileId(snap.X, snap.Y, Image.Width, tileSize);

            // If left click and not an empty tile id, set object, if right click, erase
            if (e.Button == MouseButtons.Left && _objectId != -1)
            {
                App.Room.AddBlock(_objectId, tileId);
            }
            else if (e.Button == MouseButtons.Right)
            {
                App.Room.DeleteBlock(_objectId, tileId);
            }

            // Update backbuffer
            UpdateBackBuffer();

            // Allow hooking of this event
            base.OnMouseDown(e);
        }
        /// <summary>
        /// Draws highlight over tile
        /// </summary>
        private void DrawHighlights(System.Drawing.Graphics gfx)
        {
            // If there isn't a highlight brush, return
            if (_highlighter == null)
            {
                return;
            }

            // Calculate row and column amounts
            int cols = (int)Math.Floor((double)(Image.Width) / (double)(SnapSize.Width));
            int rows = (int)Math.Floor((double)(Image.Height) / (double)(SnapSize.Height));

            // Create a rectangle
            Rectangle cell = new Rectangle(0, 0, SnapSize.Width, SnapSize.Height);

            // Draw the tile highlight
            using (SolidBrush highlighter = new SolidBrush(Color.FromArgb(128, Color.Yellow)))
            {
                // Iterate through vertical tiles
                for (int row = 0; row < rows; row++)
                {
                    // Iterate through horizontal tiles
                    for (int col = 0; col < cols; col++)
                    {
                        // Get position coordinates
                        cell.X = (int)(col * SnapSize.Width);
                        cell.Y = (int)(row * SnapSize.Height);

                        // If the highlight brush does not contain the iterated tile id, continue
                        if (!_highlighter.Contains(GMareBrush.PositionToSourceTileId(cell.X, cell.Y, Image.Width, SnapSize)))
                        {
                            continue;
                        }

                        // Draw highlight
                        gfx.FillRectangle(highlighter, cell);
                    }
                }
            }
        }