/// <summary>
        /// Ok button click
        /// </summary>
        private void butOk_Click(object sender, EventArgs e)
        {
            // If all the layers are going to be swapped, set to null, else set to desired layer
            _layer = cboLayers.SelectedIndex == 0 ? null : (GMareLayer)cboLayers.SelectedItem;

            // Set tile ids
            _target = pnlTarget.TileBrush;
            _swap   = pnlReplacement.TileBrush;

            // If the set target empty button is checked
            if (chkEmpty.Checked)
            {
                // Set tile grid to empty tiles
                for (int x = 0; x < _swap.Tiles.GetLength(0); x++)
                {
                    for (int y = 0; y < _swap.Tiles.GetLength(0); y++)
                    {
                        _swap.Tiles[x, y].TileId = -1;
                    }
                }
            }

            // Set dialog result
            DialogResult = DialogResult.OK;
        }
Beispiel #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();
        }
Beispiel #3
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();
        }
Beispiel #4
0
 private void ResetSelection()
 {
     this._targets = (GMareBrush)null;
     this._swaps   = (GMareBrush)null;
     if (this._tileSelection != null)
     {
         this._tileSelection.Dispose();
         this._tileSelection = (Bitmap)null;
     }
     this.Invalidate();
 }
        /// <summary>
        /// On draw backbuffer
        /// </summary>
        protected override void OnDrawOnBackbuffer(ref System.Drawing.Graphics gfx)
        {
            // If the color matrix is empty, create it
            if (_cm == null)
            {
                _cm = new ColorMatrix(new float[][] {
                    new float[] { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f },
                    new float[] { 0.0f, 1.0f, 0.0f, 0.0f, 0.0f },
                    new float[] { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f },
                    new float[] { 0.0f, 0.0f, 0.0f, 0.5f, 0.0f },
                    new float[] { 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }
                });
            }

            // Create new image attributes
            ImageAttributes ia = new ImageAttributes();

            ia.SetColorMatrix(_cm);

            // Get tile size
            Size tileSize = _background.TileSize;

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

            // Iterate through instances
            foreach (GMareInstance inst in App.Room.Blocks)
            {
                // Get the object associated with this instance
                GMareObject obj = App.Room.Objects.Find(delegate(GMareObject o) { return(o.Resource.Id == inst.ObjectId); });

                // If no object was found, continue
                if (obj == null)
                {
                    continue;
                }

                // Get drawing point
                Point point = GMareBrush.TileIdToSourcePosition(inst.TileId, Image.Width, tileSize);
                point.X += 1;
                point.Y += 1;

                Bitmap image = obj.Image.ToBitmap();

                // Draw glyph
                gfx.DrawImage(image, new Rectangle(point.X, point.Y, obj.Image.Width, obj.Image.Height), 0, 0, obj.Image.Width, obj.Image.Height, GraphicsUnit.Pixel, ia);
                image.Dispose();
            }

            // Dispose.
            ia.Dispose();
        }
Beispiel #6
0
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);
            if (this.BackBuffer == null || this._tiles == null || this._tiles.Count == 0)
            {
                return;
            }
            int width = this._cols < this._originalCols ? this._max.Width * this.SnapSize.Width : this.TilesetWidth;

            if (this._dragging && this._targets != null)
            {
                this._dragging      = false;
                this._targets.Tiles = GMareBrush.RectangleToTiles(this._targets.ToTargetRectangle(), width, this.SnapSize);
                foreach (int num in this._targets.ToArray())
                {
                    if (num < 0 || num >= this._tiles.Count)
                    {
                        this.ResetSelection();
                        return;
                    }
                }
                this._tileSelection = this.GetImage().Clone(this._targets.ToTargetRectangle(), PixelFormat.Format32bppArgb);
                this._swaps         = this._targets.Clone();
            }
            if (!this._moving || this._targets == null)
            {
                return;
            }
            this._moving = false;
            if (!new Rectangle(0, 0, this.TilesetWidth, this.TilesetHeight).Contains(this._targets.ToTargetRectangle()))
            {
                this._targets = this._swaps;
                this._swaps   = (GMareBrush)null;
                this.Invalidate();
            }
            else
            {
                this._targets.Tiles = GMareBrush.RectangleToTiles(this._targets.ToTargetRectangle(), width, this.SnapSize);
                foreach (int num in this._targets.ToArray())
                {
                    if (num < 0 || num >= this._tiles.Count)
                    {
                        this._targets = this._swaps;
                        this._swaps   = (GMareBrush)null;
                        this.Invalidate();
                        return;
                    }
                }
                this.SwapTiles(false);
            }
        }
        /// <summary>
        /// Resets selection variables
        /// </summary>
        private void ResetSelection()
        {
            // Empty selections
            _targets = null;
            _swaps   = null;

            // If the tile selection is not empty, dispose and empty
            if (_tileSelection != null)
            {
                _tileSelection.Dispose();
                _tileSelection = null;
            }

            // Force redraw
            Invalidate();
        }
Beispiel #8
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);
            if (this.BackBuffer == null || this._tiles == null || this._tiles.Count == 0)
            {
                return;
            }
            this.Focus();
            Point snappedPoint = this.GetSnappedPoint(e.Location);

            if (!new Rectangle(0, 0, this.TilesetWidth, this.TilesetHeight).Contains(snappedPoint))
            {
                return;
            }
            if (e.Button == MouseButtons.Left && this._tiles != null)
            {
                if (this._targets != null && this._targets.ToTargetRectangle().Contains(snappedPoint))
                {
                    this._moving = true;
                    this._pos.X  = snappedPoint.X;
                    this._pos.Y  = snappedPoint.Y;
                }
                if (!this._moving)
                {
                    if (this._tileSelection != null)
                    {
                        this._tileSelection.Dispose();
                        this._tileSelection = (Bitmap)null;
                    }
                    this._targets        = new GMareBrush();
                    this._dragging       = true;
                    this._targets.StartX = snappedPoint.X;
                    this._targets.StartY = snappedPoint.Y;
                    this._targets.EndX   = this._targets.StartX + this.SnapSize.Width;
                    this._targets.EndY   = this._targets.StartY + this.SnapSize.Height;
                }
            }
            if (e.Button == MouseButtons.Right)
            {
                if (this._targets == null || !this._targets.ToTargetRectangle().Contains(snappedPoint))
                {
                    return;
                }
                this.mnuOptions.Show(this.PointToScreen(e.Location));
            }
            this.Invalidate();
        }
        /// <summary>
        /// On mouse move
        /// </summary>
        protected override void OnMouseMove(MouseEventArgs e)
        {
            // Do base mouse move
            base.OnMouseMove(e);

            // If not pressing the left mouse button or if the image is empty or fixed selection, return
            if (_avoidMouseEvents || e.Button != MouseButtons.Left || Image == null || _selectMode == SelectType.Fixed)
            {
                _avoidMouseEvents = false;
                return;
            }

            // Get the snapped point
            Point snap = GetSnappedPoint(e.Location);

            snap.X += snap.X >= _origin.X ? SnapSize.Width : 0;
            snap.Y += snap.Y >= _origin.Y ? SnapSize.Height : 0;

            // Get selection rectangle
            Rectangle rect = new Rectangle();

            rect.X      = Math.Max(Math.Min(_origin.X, snap.X), 0);
            rect.Y      = Math.Max(Math.Min(_origin.Y, snap.Y), 0);
            rect.Width  = Math.Abs(Math.Max(snap.X, 0) - _origin.X);
            rect.Height = Math.Abs(Math.Max(snap.Y, 0) - _origin.Y);

            // Stay in bounds
            rect.Width  = rect.Right > Image.Width ? Image.Width - rect.X : rect.Width;
            rect.Height = rect.Bottom > Image.Height ? Image.Height - rect.Y : rect.Height;
            rect.Width  = rect.Width <= 0 ? SnapSize.Width : rect.Width;
            rect.Height = rect.Height <= 0 ? SnapSize.Height : rect.Height;

            // If there has been no change in movement, return
            if (rect == _selection)
            {
                return;
            }

            // Set new selection rectangle
            _selection = rect;

            // Create tiles based on rectangle
            _tileBrush = GMareBrush.RectangleToTileBrush(_selection, ImageWidthUnscaled, SnapSize);

            // Update
            UpdateBackBuffer();
        }
Beispiel #10
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);
                    }
                }
            }
        }
        /// <summary>
        /// On image set
        /// </summary>
        /// <param name="image">Image reference</param>
        protected override void OnImageSet(ref Bitmap image)
        {
            // Scale the image by the image scale value
            ScaleImage();

            // Set new selection rectangle
            _selection = new Rectangle(Point.Empty, SnapSize);

            // Create new tile brush
            if (!DesignMode)
            {
                _tileBrush = new GMareBrush();
            }

            // Reset selection
            _tileBrush = GMareBrush.RectangleToTileBrush(new Rectangle(Point.Empty, SnapSize), SnapSize.Width, SnapSize);

            // Update
            UpdateBackBuffer();

            // Scroll to zero
            AutoScrollPosition = Point.Empty;
        }
Beispiel #13
0
        /// <summary>
        /// Paste click.
        /// </summary>
        public void tsmi_SelectionPaste_Click(object sender, EventArgs e)
        {
            // If there was a previous selection.
            if (_selection != null)
            {
                // Room is about to change, record it.
                RoomChanging();
                SetTiles(_selection.StartX, _selection.StartY, false, _selection, true);
            }

            // Set the selection.
            _selection = _selectionClip.Clone();

            // Clipboard changed.
            ClipboardChanged();

            // Get the smallest size.
            Size size = GetSmallestCanvas();

            // Get tile size.
            Size tileSize = ProjectManager.Room.TileSize;

            // Get centered position.
            int x = (size.Width / 2) - (_selection.Width / 2);
            int y = (size.Height / 2) - (_selection.Height / 2);

            // Remember original size before transform.
            int width = _selection.Width;
            int height = _selection.Height;

            // Get the center point snapped.
            Point snap = GetSnappedPoint(new Point(x, y), tileSize);

            // Set the new selection position.
            _selection.StartX = snap.X;
            _selection.StartY = snap.Y;
            _selection.EndX = snap.X + width;
            _selection.EndY = snap.Y + height;

            // Set moved flag.
            _moved = true;

            // Force redraw.
            Invalidate();
        }
Beispiel #14
0
        /// <summary>
        /// Delete click.
        /// </summary>
        public void tsmi_SelectionDelete_Click(object sender, EventArgs e)
        {
            // If the selection has not moved, set tiles empty under selection.
            if (_selection != null && _moved == false)
            {
                // Room is about to change, record it.
                RoomChanging();
                SetTiles(_selection.ToRectangle().X, _selection.ToRectangle().Y, true, _selection, true);
            }

            // Reset moved flag.
            _moved = false;

            // Empty tile selection.
            _selection = null;

            // Clipboard changed.
            ClipboardChanged();

            // Force redraw.
            Invalidate();
        }
Beispiel #15
0
        /// <summary>
        /// Cut click.
        /// </summary>
        public void tsmi_SelectionCut_Click(object sender, EventArgs e)
        {
            // If there is a selection.
            if (_selection != null)
            {
                // Set clipboard.
                _selectionClip = _selection.Clone();

                // If the selection has not moved, set tiles empty under selection.
                if (_moved == false)
                {
                    // Room is about to change, record it.
                    RoomChanging();
                    SetTiles(_selection.ToRectangle().X, _selection.ToRectangle().Y, true, _selection, true);
                }
            }

            // Empty the selection.
            _selection = null;

            // Clipboard changed.
            if (ClipboardChanged != null)
                ClipboardChanged();

            // Force redraw.
            Invalidate();
        }
Beispiel #16
0
        /// <summary>
        /// Copy click.
        /// </summary>
        public void tsmi_SelectionCopy_Click(object sender, EventArgs e)
        {
            // If there is a selection.
            if (_selection != null)
            {
                // Set clipboard.
                _selectionClip = _selection.Clone();

                // Room changed, selected tiles set.
                if (_moved == true)
                    RoomChanging();

                // Set selection tiles to layer.
                SetTiles(_selection.ToRectangle().X, _selection.ToRectangle().Y, false, _selection, true);
            }

            // Reset moved flag.
            _moved = false;

            // Empty the selection.
            _selection = null;

            // Clipboard changed.
            if (ClipboardChanged != null)
                ClipboardChanged();

            // Force redraw.
            Invalidate();
        }
Beispiel #17
0
        /// <summary>
        /// Reset the control to empty state.
        /// </summary>
        public void Reset()
        {
            _selection = null;
            _selectedInstance = null;
            _selectedObject = null;
            _selectedShape = null;
            _selectionClip = null;
            _instanceClip = null;

            // Delete textures.
            GraphicsManager.DeleteTextures();
            GraphicsManager.DeleteTilemaps();
        }
Beispiel #18
0
        /// <summary>
        /// Deselect click.
        /// </summary>
        private void tsmi_SelectionDeselect_Click(object sender, EventArgs e)
        {
            // Room changed, selected tiles set, and If there was a previous selection, set it to the layer.
            if (_moved == true && _selection != null)
            {
                // Room is about to change, record it.
                RoomChanging();
                SetTiles(_selection.ToRectangle().X, _selection.ToRectangle().Y, false, _selection, true);
            }

            // Reset moved flag.
            _moved = false;

            // Empty the selection.
            _selection = null;

            // Clipboard changed.
            if (ClipboardChanged != null)
                ClipboardChanged();

            // Force redraw.
            Invalidate();
        }
Beispiel #19
0
        /// <summary>
        /// Brush from selection click.
        /// </summary>
        private void tsmi_SelectionBrush_Click(object sender, EventArgs e)
        {
            // Get point.
            Point point = (sender as ToolStripMenuItem).GetCurrentParent().Location;

            // If not in selection mode, return.
            if (_editMode != EditType.Layers || _toolMode != ToolType.Selection || _selection == null)
                return;

            // Set brush to selection.
            _brush = _selection.Clone();
        }
Beispiel #20
0
        /// <summary>
        /// Create a brushes edit form.
        /// </summary>
        private void tsmi_BrushEdit_Click(object sender, EventArgs e)
        {
            // If a room is not being edited, return.
            if (RoomExists() == false)
                return;

            // Create a new array of brushes.
            GMareBrush[] brushes = new GMareBrush[ProjectManager.Room.Brushes.Count];

            for (int i = 0; i < ProjectManager.Room.Brushes.Count; i++)
                brushes[i] = ProjectManager.Room.Brushes[i].Clone();

            // Create a new brushes edit.
            using (BrushEditForm form = new BrushEditForm(brushes))
            {
                // If Ok was clicked.
                if (form.ShowDialog() == DialogResult.OK)
                {
                    ProjectManager.Room.Brushes.Clear();
                    ProjectManager.Room.Brushes.AddRange(form.Brushes);
                }
            }
        }
Beispiel #21
0
        /// <summary>
        /// Gets a string representation of a layer
        /// </summary>
        /// <param name="layer">The layer to get tile data from</param>
        /// <param name="dataType">The type of data to present</param>
        /// <param name="arrayType">The type of array style to use when writing the string</param>
        private void SetText(GMareLayer layer, DataType dataType, ArrayType arrayType)
        {
            // If no layers, display nothing
            if (layer == null)
            {
                return;
            }

            // Clear any existing text
            txtText.Clear();

            // Local variables
            int index     = 0;
            int roomWidth = 0;

            if (App.Room.Backgrounds[0].Image != null)
            {
                roomWidth = App.Room.Backgrounds[0].Image.Width;
            }

            Size roomTileSize = App.Room.Backgrounds[0].TileSize;
            bool tileData     = TilesExist(layer.Tiles);

            // Create new text
            StringBuilder text    = new StringBuilder();
            string        layerId = "layer" + layer.Depth.ToString();

            layerId = layerId.Replace("-", "_");

            // Do action based on array type
            switch (arrayType)
            {
            // If the array present type is a list
            case ArrayType.List:
                // Do action based on data type
                switch (dataType)
                {
                // Sector data type
                case DataType.Sectors:
                    // Create array variable string
                    text.AppendLine(layerId + " = ds_list_create();");
                    text.AppendLine();
                    break;

                // All other data types
                default:
                    // If there is tile data, create array variable string
                    if (tileData)
                    {
                        text.AppendLine(layerId + " = ds_list_create();");
                        text.AppendLine();
                    }

                    break;
                }

                break;

            // If the array present type is a grid
            case ArrayType.Grid:
                // If the data type is sectors, create a grid variable
                if (dataType == DataType.Sectors)
                {
                    text.AppendLine(layerId + " = ds_grid_create();");
                    text.AppendLine();
                }

                break;
            }

            // Calculate columns and rows
            int rows = layer.Tiles.GetLength(1);
            int cols = layer.Tiles.GetLength(0);

            // Iterate through rows
            for (int row = 0; row < rows; row++)
            {
                // Create a new line
                StringBuilder line = new StringBuilder();

                // Iterate through columns
                for (int col = 0; col < cols; col++)
                {
                    // Do action based on data type
                    switch (dataType)
                    {
                    // If sector data must be displayed
                    case DataType.Sectors:
                        // Set sector data text based on desired array type
                        switch (arrayType)
                        {
                        case ArrayType.Raw: line.Append((layer.Tiles[col, row].TileId).ToString() + ", "); break;

                        case ArrayType.Standard: line.Append(layerId + "[" + col + "," + row + "] = " + layer.Tiles[col, row].TileId.ToString() + "; "); break;

                        case ArrayType.List: line.Append("ds_list_add(" + layerId + "," + layer.Tiles[col, row].TileId.ToString() + "); "); break;

                        case ArrayType.Grid: line.Append("ds_grid_add(" + layerId + "," + col + "," + row + "," + layer.Tiles[col, row].TileId.ToString() + "); "); break;
                        }

                        break;

                    // If point data must be displayed
                    case DataType.Points:
                        // If the tile id is -1, don't bother with rectangle data
                        if (layer.Tiles[col, row].TileId == -1)
                        {
                            continue;
                        }

                        // Create a new rectangle that represents the source rectangle
                        Point point = GMareBrush.TileIdToSourcePosition(layer.Tiles[col, row].TileId, roomWidth, roomTileSize);

                        // Set tile data text based on desired array type
                        switch (arrayType)
                        {
                        case ArrayType.Raw:
                            text.AppendLine(new Point(col * roomTileSize.Width, row * roomTileSize.Height).ToString() + " // Destination point.");
                            text.AppendLine(point.ToString() + " // Source Point");
                            break;

                        case ArrayType.Standard:
                            text.AppendLine(layerId + "[" + index + "] = " + col * roomTileSize.Width + "; " + " // Destination X."); index++;
                            text.AppendLine(layerId + "[" + index + "] = " + row * roomTileSize.Height + "; " + " // Destination Y."); index++;
                            text.AppendLine(layerId + "[" + index + "] = " + point.X + "; " + " // Source X."); index++;
                            text.AppendLine(layerId + "[" + index + "] = " + point.Y + "; " + " // Source Y."); index++;
                            break;

                        case ArrayType.List:
                            text.AppendLine("ds_list_add(" + layerId + ", " + col * roomTileSize.Width + "); " + " // Destination X.");
                            text.AppendLine("ds_list_add(" + layerId + ", " + row * roomTileSize.Height + "); " + " // Destination Y.");
                            text.AppendLine("ds_list_add(" + layerId + ", " + point.X + "); " + " // Source X.");
                            text.AppendLine("ds_list_add(" + layerId + ", " + point.Y + "); " + " // Source Y.");
                            break;
                        }

                        break;

                    // If rectangle data must be displayed
                    case DataType.Rectangles:
                        // If the tile id is -1, don't bother with rectangle data
                        if (layer.Tiles[col, row].TileId == -1)
                        {
                            continue;
                        }

                        // Create a new rectangle that represents the source rectangle
                        Rectangle rect = new Rectangle();
                        rect.Location = GMareBrush.TileIdToSourcePosition(layer.Tiles[col, row].TileId, roomWidth, roomTileSize);
                        rect.Size     = roomTileSize;

                        // Set tile data text based on desired array type
                        switch (arrayType)
                        {
                        case ArrayType.Raw:
                            text.AppendLine(new Point(col * roomTileSize.Width, row * roomTileSize.Height).ToString() + " // Destination point.");
                            text.AppendLine(rect.ToString() + " // Source rectangle.");
                            break;

                        case ArrayType.Standard:
                            text.AppendLine(layerId + "[" + index + "] = " + col * roomTileSize.Width + "; " + " // Destination X."); index++;
                            text.AppendLine(layerId + "[" + index + "] = " + row * roomTileSize.Height + "; " + " // Destination Y."); index++;
                            text.AppendLine(layerId + "[" + index + "] = " + rect.X + "; " + " // Source X."); index++;
                            text.AppendLine(layerId + "[" + index + "] = " + rect.Y + "; " + " // Source Y."); index++;
                            text.AppendLine(layerId + "[" + index + "] = " + rect.Width + "; " + " // Tile Width."); index++;
                            text.AppendLine(layerId + "[" + index + "] = " + rect.Height + "; " + " // Tile Height."); index++;
                            break;

                        case ArrayType.List:
                            text.AppendLine("ds_list_add(" + layerId + "," + col * roomTileSize.Width + "); " + " // Destination X.");
                            text.AppendLine("ds_list_add(" + layerId + "," + row * roomTileSize.Height + "); " + " // Destination Y.");
                            text.AppendLine("ds_list_add(" + layerId + "," + rect.X + "); " + " // Source X.");
                            text.AppendLine("ds_list_add(" + layerId + "," + rect.Y + "); " + " // Source Y.");
                            text.AppendLine("ds_list_add(" + layerId + "," + rect.Width + "); " + " // Tile Width.");
                            text.AppendLine("ds_list_add(" + layerId + "," + rect.Height + "); " + " // Tile Height.");
                            break;
                        }

                        break;
                    }
                }

                // Append line to text
                if (dataType == DataType.Sectors)
                {
                    text.AppendLine(line.ToString());
                }
            }

            // Set rich text box text
            txtText.Text = text.ToString();
        }
Beispiel #22
0
 /// <summary>
 /// Replace the target tile grid tile ids with the desired tile id.
 /// </summary>
 /// <param name="target">The target tile grid to swap.</param>
 /// <param name="replacement">The replacement tile id to replace the target.</param>
 public void Replace(GMareBrush target, int replacement)
 {
     // Iterate through tile columns.
     for (int col = 0; col < target.Tiles.GetLength(0); col++)
     {
         // Iterate through tile rows.
         for (int row = 0; row < target.Tiles.GetLength(1); row++)
         {
             // Swap tile.
             Replace(target.Tiles[col, row].TileId, replacement);
         }
     }
 }
Beispiel #23
0
        private string _brushName = string.Empty; // The name for the brush.

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Constructs a new name form.
        /// </summary>
        /// <param name="background">The background to render from.</param>
        /// <param name="brush">Brush to save.</param>
        /// <param name="tileSize">Size of a single tile.</param>
        public BrushForm(Bitmap background, GMareBrush brush, Size tileSize)
        {
            InitializeComponent();

            // Create new graphics object.
            Bitmap image = new Bitmap(brush.Width, brush.Height);
            System.Drawing.Graphics gfx = System.Drawing.Graphics.FromImage(image);

            // Iterate through tiles horizontally.
            for (int col = 0; col < brush.Columns; col++)
            {
                // Iterate through tiles vertically.
                for (int row = 0; row < brush.Rows; row++)
                {
                    // If the tile is empty, continue looping.
                    if (brush.Tiles[col, row].TileId == -1)
                        continue;

                    // Calculate source point.
                    Rectangle source = new Rectangle(GMareBrush.TileIdToPosition(brush.Tiles[col, row].TileId, background.Width, tileSize), tileSize);
                    Rectangle dest = new Rectangle(new Point(col * tileSize.Width, row * tileSize.Height), tileSize);

                    // Get tile.
                    Bitmap temp = Graphics.PixelMap.PixelDataToBitmap(Graphics.PixelMap.GetPixels(background, source));

                    Color color = brush.Tiles[col, row].Blend;
                    float red = color.R / 255.0f;
                    float green = color.G / 255.0f;
                    float blue = color.B / 255.0f;

                    // Alpha changing color matrix.
                    ColorMatrix cm = new ColorMatrix(new float[][] {
                        new float[]{ red, 0.0f, 0.0f, 0.0f, 0.0f},
                        new float[]{ 0.0f, green, 0.0f, 0.0f, 0.0f},
                        new float[]{ 0.0f, 0.0f, blue, 0.0f, 0.0f},
                        new float[]{ 0.0f, 0.0f, 0.0f, 1.0f, 0.0f},
                        new float[]{ 0.0f, 0.0f, 0.0f, 0.0f, 1.0f} });

                    // Create new image attributes.
                    ImageAttributes ia = new ImageAttributes();
                    ia.SetColorMatrix(cm);

                    // Flip tile.
                    switch (brush.Tiles[col, row].FlipMode)
                    {
                        case FlipType.Horizontal: temp.RotateFlip(RotateFlipType.RotateNoneFlipX); break;
                        case FlipType.Vertical: temp.RotateFlip(RotateFlipType.RotateNoneFlipY); break;
                        case FlipType.Both: temp.RotateFlip(RotateFlipType.RotateNoneFlipX); temp.RotateFlip(RotateFlipType.RotateNoneFlipY); break;
                    }

                    // Draw tile.
                    gfx.DrawImage(temp, dest, 0, 0, tileSize.Width, tileSize.Height, GraphicsUnit.Pixel, ia);

                    // Dispose.
                    temp.Dispose();
                    ia.Dispose();
                }
            }

            // Set brush image.
            pnl_Brush.Image = image;

            // Dispose of the graphics.
            gfx.Dispose();

            // Validate
            Check();
        }
        /// <summary>
        /// On mouse up
        /// </summary>
        protected override void OnMouseUp(MouseEventArgs e)
        {
            // Allow others to hook this event
            base.OnMouseUp(e);

            // If the backbuffer or tiles are empty, return
            if (BackBuffer == null || _tiles == null || _tiles.Count == 0)
            {
                return;
            }

            // Get width based on column size versus the original size
            int width = _cols < _originalCols ? _max.Width * SnapSize.Width : TilesetWidth;

            // If selecting, and there are tiles selected
            if (_dragging && _targets != null)
            {
                // Stop selection operation
                _dragging = false;

                // Get an array of tile ids
                _targets.Tiles = GMareBrush.RectangleToTiles(_targets.ToTargetRectangle(), width, SnapSize);

                // Get target tiles
                int[] tiles = _targets.ToArray();

                // Check if all selected tiles are valid
                foreach (int tile in tiles)
                {
                    // If the tile id is out of bounds
                    if (tile < 0 || tile >= _tiles.Count)
                    {
                        // Reset selection, and return
                        ResetSelection();
                        return;
                    }
                }

                // Set tile selection graphic
                _tileSelection = GetImage().Clone(_targets.ToTargetRectangle(), PixelFormat.Format32bppArgb);

                // Create a copy of the selection for swapping
                _swaps = _targets.Clone();
            }

            // If the slection was moved and there are tiles
            if (_moving && _targets != null)
            {
                // Stop moving operation
                _moving = false;

                // Check tileset bounds
                if (new Rectangle(0, 0, TilesetWidth, TilesetHeight).Contains(_targets.ToTargetRectangle()) == false)
                {
                    // Reset to original selection, and return
                    _targets = _swaps;
                    _swaps   = null;
                    Invalidate();
                    return;
                }

                // Get an array of selected tile ids
                _targets.Tiles = GMareBrush.RectangleToTiles(_targets.ToTargetRectangle(), width, SnapSize);

                // Get new target tiles
                int[] tiles = _targets.ToArray();

                // Check to see if the drop is valid
                foreach (int tile in tiles)
                {
                    // If the tile id is out of bounds
                    if (tile < 0 || tile >= _tiles.Count)
                    {
                        // Reset to original selection, and return
                        _targets = _swaps;
                        _swaps   = null;
                        Invalidate();
                        return;
                    }
                }

                // Swap tiles
                SwapTiles(false);
            }
        }
        /// <summary>
        /// On mouse down
        /// </summary>
        protected override void OnMouseDown(MouseEventArgs e)
        {
            // Do base mouse down
            base.OnMouseDown(e);

            // Set focus on this control
            Focus();

            // If the image is empty or not pressing the left mouse button, return
            if (Image == null)
            {
                return;
            }

            // If the right mouse button was clicked, show brush information
            if (e.Button == MouseButtons.Right && _tileBrush != null)
            {
                _tileIdTip.Hide(this);
                _tileIdTip.Show(_tileBrush.To2DArrayString(), this, 5000);
            }

            // If the left mouse button was not clicked, return
            if (e.Button != MouseButtons.Left)
            {
                return;
            }

            // Get the snapped point
            Point snap = GetSnappedPoint(e.Location);

            // If not within bounds
            if (new Rectangle(0, 0, Image.Width, Image.Height).Contains(snap) == false)
            {
                return;
            }

            // Starting point of the selection
            _origin = snap;

            // Set new selection rectangle
            switch (_selectMode)
            {
            case SelectType.Normal: _selection = new Rectangle(_origin, SnapSize); break;

            case SelectType.Fixed:
                _selection = new Rectangle(_origin, _selection.Size);

                // If the selection is out of bounds, reposition till it is not
                while (true)
                {
                    // Move more in bounds
                    _selection.X -= _selection.Right > Image.Width ? SnapSize.Width : 0;
                    _selection.Y -= _selection.Bottom > Image.Height ? SnapSize.Height : 0;

                    // If within bounds, break
                    if (new Rectangle(0, 0, Image.Width, Image.Height).Contains(_selection) == true)
                    {
                        break;
                    }
                }

                break;
            }

            // Create tiles based on rectangle
            _tileBrush = GMareBrush.RectangleToTileBrush(_selection, ImageWidthUnscaled, SnapSize);

            // Update
            UpdateBackBuffer();
        }
        /// <summary>
        /// On mouse down
        /// </summary>
        protected override void OnMouseDown(MouseEventArgs e)
        {
            // Allow hooking of this event
            base.OnMouseDown(e);

            // If the project and tileset do not exist, return
            if (BackBuffer == null || _tiles == null || _tiles.Count == 0)
            {
                return;
            }

            // Focus for scroll support
            Focus();

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

            // Check if the click is within bounds
            if (new Rectangle(0, 0, TilesetWidth, TilesetHeight).Contains(snap) == false)
            {
                return;
            }

            // If left button was clicked, and there are tiles to select
            if (e.Button == MouseButtons.Left && _tiles != null)
            {
                // If cursor is within selection
                if (_targets != null && _targets.ToTargetRectangle().Contains(snap) == true)
                {
                    // Selection clicked
                    _moving = true;

                    // Set zero position
                    _pos.X = snap.X;
                    _pos.Y = snap.Y;
                }

                // If not moving a selection
                if (!_moving)
                {
                    // Dispose of old tile selection bitmap
                    if (_tileSelection != null)
                    {
                        _tileSelection.Dispose();
                        _tileSelection = null;
                    }

                    // Create a new brush
                    _targets = new GMareBrush();

                    // Start collecting tiles
                    _dragging = true;

                    // Set selection tile sector
                    _targets.StartX = snap.X;
                    _targets.StartY = snap.Y;
                    _targets.EndX   = _targets.StartX + SnapSize.Width;
                    _targets.EndY   = _targets.StartY + SnapSize.Height;
                }
            }

            // If right button was clicked
            if (e.Button == MouseButtons.Right)
            {
                // Empty selection
                if (_targets == null || _targets.ToTargetRectangle().Contains(snap) == false)
                {
                    return;
                }

                // Show options menu
                mnuOptions.Show(this.PointToScreen(e.Location));
            }

            // Force redraw
            Invalidate();
        }
Beispiel #27
0
 /// <summary>
 /// Item click.
 /// </summary>
 private void cms_BrushOptions_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
 {
     // If the tag holds a brush, set brush.
     if (e.ClickedItem.Tag is GMareBrush)
         _brush = e.ClickedItem.Tag as GMareBrush;
 }
Beispiel #28
0
        /// <summary> 
        /// Get a selection of tiles from the selected layer.
        /// </summary>
        /// <param name="grid">The grid to use for selection data.</param>
        /// <returns>An array of tiles.</returns>
        private GMareTile[,] GetTiles(GMareBrush grid)
        {
            // A new array of tile ids.
            Rectangle rect = grid.ToRectangle();
            Size tileSize = ProjectManager.Room.TileSize;
            GMareTile[,] tiles = new GMareTile[rect.Width / tileSize.Width, rect.Height / tileSize.Height];

            // Iterate through columns.
            for (int col = 0; col < tiles.GetLength(0); col++)
            {
                // Iterate through rows.
                for (int row = 0; row < tiles.GetLength(1); row++)
                {
                    // Calculate source position.
                    int x = ((col * tileSize.Width) + rect.X) / tileSize.Width;
                    int y = ((row * tileSize.Height) + rect.Y) / tileSize.Height;

                    // Set tile id.
                    tiles[col, row] = ProjectManager.Room.Layers[_layerIndex].Tiles2[x, y].Clone();
                }
            }

            // Return selected tiles.
            return tiles;
        }
Beispiel #29
0
        /// <summary>
        /// Layer mode mouse down.
        /// </summary>
        /// <param name="mouse">Mouse event arguments.</param>
        private void LayersMouseDown(MouseEventArgs mouse)
        {
            // Get snapped position.
            Size tileSize = ProjectManager.Room.TileSize;
            Point snap = GetSnappedPoint(mouse.Location, tileSize);

            // Check that the mouse is within room bounds.
            if (CheckBounds(mouse.X, mouse.Y) == false)
                return;

            // Do action based on tool.
            switch (_toolMode)
            {
                // Brush tool.
                case ToolType.Brush:

                    // If left click set tile, right click set tile empty.
                    if (mouse.Button == MouseButtons.Left)
                    {
                        // Room is about to change, record it.
                        RoomChanging();

                        // If the shift key is being held down erase tile, else paint tile.
                        if (_shiftKey == true)
                            SetTiles(mouse.X, mouse.Y, true, _brush, false);
                        else
                            SetTiles(mouse.X, mouse.Y, false, _brush, false);
                    }
                    else if (mouse.Button == MouseButtons.Right)
                    {
                        // Show context menu.
                        ShowBrushesContext(mouse.Location);
                    }

                    // Force redraw.
                    Invalidate();
                    break;

                // Bucket fill tool.
                case ToolType.Bucket:

                    // If left click fill tile(s), right click set tile(s) empty.
                    if (mouse.Button == MouseButtons.Left)
                    {
                        // Room is changing.
                        RoomChanging();

                        // Calculate starting point in tiles.
                        Point tile = new Point(snap.X / tileSize.Width, snap.Y / tileSize.Height);

                        // If the shift key is being held down, erase tiles else, fill with brush.
                        if (_shiftKey == true)
                            ProjectManager.Room.Layers[_layerIndex].Fill(tile, -1);
                        else
                            ProjectManager.Room.Layers[_layerIndex].Fill(tile, _brush.Tiles);
                    }
                    else if (mouse.Button == MouseButtons.Right)
                    {
                        // Set context menu.
                        if (ProjectManager.Room.Brushes.Count == 0)
                        {
                            tsmi_BrushEdit.Visible = false;
                            tsmi_BrushNone.Visible = true;
                        }
                        else
                        {
                            tsmi_BrushEdit.Visible = true;
                            tsmi_BrushNone.Visible = false;
                        }

                        // Show context menu.
                        cms_BrushOptions.Show(PointToScreen(mouse.Location));
                    }

                    // Force redraw.
                    Invalidate();
                    break;

                // Selection tool.
                case ToolType.Selection:

                    // If left mouse button click.
                    if (mouse.Button == MouseButtons.Left)
                    {
                        // If a selection exists, and the mouse is within the selection.
                        if (_selection != null && _selection.ToRectangle().Contains(snap))
                        {
                            // Selection clicked.
                            _moving = true;

                            // If the selection has never been clicked to be moved.
                            if (_moved == false)
                            {
                                // Room is about to change, record it.
                                RoomChanging();

                                // Set tiles empty under selection.
                                SetTiles(_selection.ToRectangle().X, _selection.ToRectangle().Y, true, _selection, true);

                                // Set one time moving flag.
                                _moved = true;
                            }

                            // Set zero position.
                            _posX = snap.X;
                            _posY = snap.Y;
                        }

                        // If not moving an existing selection.
                        if (_moving == false)
                        {
                            // If there is a previous selection, set it.
                            if (_selection != null)
                                SetTiles(_selection.StartX, _selection.StartY, false, _selection, true);

                            // Create a new selection.
                            _selection = new GMareBrush();

                            // Start collecting other tiles.
                            _dragging = true;

                            // Set selection dimensions.
                            _selection.StartX = snap.X;
                            _selection.StartY = snap.Y;
                            _selection.EndX = _selection.StartX + tileSize.Width;
                            _selection.EndY = _selection.StartY + tileSize.Height;

                            // Force redraw.
                            Invalidate();
                        }
                    }
                    else if (mouse.Button == MouseButtons.Right)  // Show selection options.
                    {
                        // Disable all options by default.
                        for (int i = 0; i < cms_SelectionOptions.Items.Count; i++)
                            cms_SelectionOptions.Items[i].Enabled = false;

                        // If the selection is not empty.
                        if (_selection != null)
                        {
                            // Allow options.
                            tsmi_SelectionCopy.Enabled = true;
                            tsmi_SelectionCut.Enabled = true;
                            tsmi_SelectionDelete.Enabled = true;
                            tsmi_SelectionDeselect.Enabled = true;
                            tsmi_SelectionBrush.Enabled = true;
                            tsmi_SelectionAddBrush.Enabled = true;
                            tsmi_SelectionFlipHorizontal.Enabled = true;
                            tsmi_SelectionFlipVertical.Enabled = true;
                            tsmi_SelectionColor.Enabled = true;
                        }

                        // If the clipboard is empty, do not enable the paste function, else allow it.
                        tsmi_SelectionPaste.Enabled = _selectionClip == null ? false : true;

                        // Show menu.
                        cms_SelectionOptions.Show(PointToScreen(mouse.Location));
                    }

                    break;
            }
        }
Beispiel #30
0
        /// <summary>
        /// Constructs a new brush form
        /// </summary>
        /// <param name="background">The background to render from</param>
        /// <param name="brush">Brush to save</param>
        /// <param name="tileSize">Size of a single tile</param>
        public SaveBrushForm(Bitmap background, GMareBrush brush, Size tileSize)
        {
            InitializeComponent();

            // Create new graphics object
            Bitmap image = new Bitmap(brush.Width, brush.Height);

            System.Drawing.Graphics gfx = System.Drawing.Graphics.FromImage(image);

            // Iterate through tiles horizontally
            for (int col = 0; col < brush.Columns; col++)
            {
                // Iterate through tiles vertically
                for (int row = 0; row < brush.Rows; row++)
                {
                    // If the tile is empty, continue looping
                    if (brush.Tiles[col, row].TileId == -1)
                    {
                        continue;
                    }

                    // Calculate source point
                    Rectangle source = new Rectangle(GMareBrush.TileIdToSourcePosition(brush.Tiles[col, row].TileId, background.Width, tileSize), tileSize);
                    Rectangle dest   = new Rectangle(new Point(col * tileSize.Width, row * tileSize.Height), tileSize);

                    // Get tile
                    Bitmap temp = Graphics.PixelMap.PixelDataToBitmap(Graphics.PixelMap.GetPixels(background, source));

                    Color color = brush.Tiles[col, row].Blend;
                    float red   = color.R / 255.0f;
                    float green = color.G / 255.0f;
                    float blue  = color.B / 255.0f;

                    // Alpha changing color matrix
                    ColorMatrix cm = new ColorMatrix(new float[][] {
                        new float[] { red, 0.0f, 0.0f, 0.0f, 0.0f },
                        new float[] { 0.0f, green, 0.0f, 0.0f, 0.0f },
                        new float[] { 0.0f, 0.0f, blue, 0.0f, 0.0f },
                        new float[] { 0.0f, 0.0f, 0.0f, 1.0f, 0.0f },
                        new float[] { 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }
                    });

                    // Create new image attributes
                    ImageAttributes ia = new ImageAttributes();
                    ia.SetColorMatrix(cm);

                    // Flip tile
                    switch (brush.Tiles[col, row].FlipMode)
                    {
                    case FlipType.Horizontal: temp.RotateFlip(RotateFlipType.RotateNoneFlipX); break;

                    case FlipType.Vertical: temp.RotateFlip(RotateFlipType.RotateNoneFlipY); break;

                    case FlipType.Both: temp.RotateFlip(RotateFlipType.RotateNoneFlipX); temp.RotateFlip(RotateFlipType.RotateNoneFlipY); break;
                    }

                    // Draw tile
                    gfx.DrawImage(temp, dest, 0, 0, tileSize.Width, tileSize.Height, GraphicsUnit.Pixel, ia);

                    // Dispose
                    temp.Dispose();
                    ia.Dispose();
                }
            }

            // Set brush image
            pnlBrush.Image = image;

            // Dispose of the graphics
            gfx.Dispose();

            // Validate
            CheckText();
        }
Beispiel #31
0
        /// <summary>
        /// Sets a tile index based on mouse coordinates.
        /// </summary>
        /// <param name="x">Mouse X position.</param>
        /// <param name="y">Mouse Y position.</param>
        private void SetTiles(int x, int y, bool setEmpty, GMareBrush tiles, bool absolute)
        {
            // Calculate tilesize.
            Size tileSize = ProjectManager.Room.TileSize;

            // Set snap point.
            Point snap = new Point(x, y);

            // If snap has not been pre-calculated, calculate snapped position.
            if (absolute == false)
                snap = GetSnappedPoint(new Point(x, y), tileSize);

            // Iterate through columns.
            for (int col = 0; col < tiles.Tiles.GetLength(0); col++)
            {
                // Iterate through rows.
                for (int row = 0; row < tiles.Tiles.GetLength(1); row++)
                {
                    // Calculate destination tile position.
                    int destCol = (snap.X / tileSize.Width) + col;
                    int destRow = (snap.Y / tileSize.Height) + row;

                    // If index not within bounds, continue.
                    if (destRow < 0 || destCol > ProjectManager.Room.Columns - 1 ||
                        destCol < 0 || destRow > ProjectManager.Room.Rows - 1)
                        continue;

                    // If set empty is true, set tile id to -1, else set the target tile.
                    if (setEmpty == true)
                        ProjectManager.Room.Layers[_layerIndex].Tiles2[destCol, destRow] = new GMareTile();
                    else
                        ProjectManager.Room.Layers[_layerIndex].Tiles2[destCol, destRow] = tiles.Tiles[col, row].Clone();
                }
            }
        }
Beispiel #32
0
        /// <summary>
        /// Ok button click.
        /// </summary>
        private void tsb_Ok_Click(object sender, EventArgs e)
        {
            // If all the layers are going to be swapped, set to null, else set to desired layer.
            if (tscb_Layers.SelectedIndex == 0)
                _layer = null;
            else
                _layer = (GMareLayer)tscb_Layers.SelectedItem;

            // Set tile ids.
            _target = pnl_Target.Selection;
            _swap = pnl_Swap.Selection;

            // If the set target empty button is checked.
            if (tsb_Empty.Checked)
            {
                // Set tile grid to empty tiles.
                for (int x = 0; x < _swap.Tiles.GetLength(0); x++)
                    for (int y = 0; y < _swap.Tiles.GetLength(0); y++)
                        _swap.Tiles[x, y].TileId = -1;
            }

            // Set dialog result.
            DialogResult = DialogResult.OK;

            // Close the form.
            Close();
        }
        /// <summary>
        /// On get glyph
        /// </summary>
        public override System.Drawing.Bitmap OnGetGlyph(DrawItemEventArgs e)
        {
            // Get glyph based on data type
            switch (_listboxMode)
            {
            case ListboxType.Brushes:

                // Get brush, return the glyph of the brush
                GMareBrush brush = Items[e.Index] as GMareBrush;
                return(brush == null || brush.Glyph == null ? (GDI.Bitmap)GMare.Properties.Resources.brush.Clone() : (GDI.Bitmap)brush.Glyph.Clone());

            case ListboxType.Projects:

                // Get background
                GMareBackground background = (Items[e.Index] as ExportProject).Background;

                // If the background is empty, return null
                if (background == null)
                {
                    return(null);
                }

                // Image to draw
                GDI.Bitmap image = null;

                // Get the background image
                if (background.Image != null)
                {
                    image = ScaleImage(background.Image.ToBitmap(), _cellSize.Width, _cellSize.Height);
                }
                else
                {
                    // Create an empty image
                    image = new GDI.Bitmap(_cellSize.Width, _cellSize.Height);
                    GDI.Pen             border      = new GDI.Pen(GDI.Color.Gray);
                    GDI.Pen             innerBorder = new GDI.Pen(GDI.Color.White);
                    GDI.Graphics        gfx         = GDI.Graphics.FromImage(image);
                    GDI.Rectangle       rect        = new GDI.Rectangle(0, 0, image.Width - 1, image.Height - 1);
                    GDI.RectangleF      rectF       = new GDI.RectangleF(0, 0, image.Width, image.Height);
                    LinearGradientBrush gradient    = new LinearGradientBrush(rect.Location, new GDI.Point(rect.Right, rect.Bottom), GDI.Color.Gray, GDI.Color.LightGray);

                    // String render format
                    GDI.StringFormat stringFormat = new GDI.StringFormat();
                    stringFormat.Alignment     = GDI.StringAlignment.Center;
                    stringFormat.LineAlignment = GDI.StringAlignment.Center;

                    // Draw image
                    gfx.FillRectangle(gradient, rect);
                    gfx.DrawRectangle(border, rect);
                    rect.Inflate(new GDI.Size(-1, -1));
                    gfx.DrawRectangle(innerBorder, rect);
                    rect.Inflate(new GDI.Size(-1, -1));
                    gfx.DrawRectangle(border, rect);
                    gfx.DrawString("?", this.DisplayFont, GDI.Brushes.White, rectF, stringFormat);

                    // Dispose
                    border.Dispose();
                    innerBorder.Dispose();
                    stringFormat.Dispose();
                    gradient.Dispose();
                    gfx.Dispose();
                }

                return(image);

            default: return(Glyph);
            }
        }