protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); e.Graphics.Clear(BackColor); Rectangle clip = e.ClipRectangle; clip.Offset(-AutoScrollPosition.X, -AutoScrollPosition.Y); e.Graphics.TranslateTransform(AutoScrollPosition.X, AutoScrollPosition.Y); int columns = (int)((AutoScrollMinSize.Width - (2 * ElementPadding)) / ItemWidth); int rows = (Elements.Length + columns - 1) / columns; int firstRow = (int)Math.Max(clip.Top / ItemHeight, 0); int lastRow = (int)Math.Min((clip.Bottom - 1 - (2 * ElementPadding)) / ItemHeight, rows - 1); int firstColumn = (int)Math.Max(clip.Left / ItemWidth, 0); int lastColumn = (int)Math.Min((clip.Right - 1 - (2 * ElementPadding)) / ItemWidth, columns - 1); if (Palette != null) { bool swapAxes = (Rotate & 1U) != 0U; bool reverseX = FlipX != (((Rotate + 1U) & 2U) != 0U); bool reverseY = FlipY != ((Rotate & 2U) != 0U); int[,] transform = new int[, ] { { swapAxes ? 0 : 1, swapAxes ? 1 : 0, 0 }, { swapAxes ? 1 : 0, swapAxes ? 0 : 1, 0 }, { 0, 0, 1 } }; if (reverseX) { transform[0, 0] = -transform[0, 0]; transform[0, 1] = -transform[0, 1]; } if (reverseY) { transform[1, 0] = -transform[1, 0]; transform[1, 1] = -transform[1, 1]; } transform[0, 0] *= (int)ScaleX; transform[0, 1] *= (int)ScaleX; transform[1, 0] *= (int)ScaleY; transform[1, 1] *= (int)ScaleY; transform[1, 2] = (int)((ItemHeight * firstRow) + (2 * ElementPadding) + (reverseY ? (((swapAxes ? ElementWidth : ElementHeight) * ScaleY) - 1) : 0)); for (int row = firstRow; row <= lastRow; row++, transform[1, 2] += (int)ItemHeight) { transform[0, 2] = (int)((ItemWidth * firstColumn) + (2 * ElementPadding) + (reverseX ? (((swapAxes ? ElementHeight : ElementWidth) * ScaleX) - 1) : 0)); for (int column = firstColumn; (column <= lastColumn) && (((row * columns) + column) < Elements.Length); column++, transform[0, 2] += (int)ItemWidth) { GfxElement element = Elements[(row * columns) + column]; if (element != null) { element.Draw(e.Graphics, Palette, transform); } } } } }
public void DrawExportTileset(Graphics graphics, long ElementsCount, long RowCount, long ColumnCount) { if (Palette == null) { throw new Exception("Cannot export with null palette."); } else { int rows = (int)RowCount; int columns = (int)ColumnCount; bool swapAxes = (Rotate & 1U) != 0U; bool reverseX = FlipX != (((Rotate + 1U) & 2U) != 0U); bool reverseY = FlipY != ((Rotate & 2U) != 0U); int[,] transform = new int[, ] { { swapAxes ? 0 : 1, swapAxes ? 1 : 0, 0 }, { swapAxes ? 1 : 0, swapAxes ? 0 : 1, 0 }, { 0, 0, 1 } }; if (reverseX) { transform[0, 0] = -transform[0, 0]; transform[0, 1] = -transform[0, 1]; } if (reverseY) { transform[1, 0] = -transform[1, 0]; transform[1, 1] = -transform[1, 1]; } transform[1, 2] = (int)(reverseY ? (swapAxes ? ElementWidth : ElementHeight) : 0); for (int row = 0; row <= rows; row++, transform[1, 2] += (swapAxes ? (int)ElementWidth : (int)ElementHeight)) { transform[0, 2] = (int)((ElementWidth * 0) + (reverseX ? (swapAxes ? ElementHeight : ElementWidth) : 0)); for (int column = 0; (column <= columns) && (((row * columns) + column) < Elements.Length); column++, transform[0, 2] += (swapAxes ? (int)ElementHeight : (int)ElementWidth)) { GfxElement element = Elements[(row * columns) + column]; if (element != null) { element.Draw(graphics, Palette, transform); } } } } }