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> /// 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); } }