void DrawElement() { elementView.Image = null; if (currentTexture != null) { currentTexture.Dispose(); } if (set == null) { return; } if (scale == 1) { currentTexture = set.GenerateImage(); Brush br = new SolidBrush(overColor); Graphics g = Graphics.FromImage(currentTexture); g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Half; g.FillRectangle(br, 0, 0, currentTexture.Width, currentTexture.Height); br.Dispose(); g.Dispose(); } else { if (set.Width < 3 && set.Height < 3) { scale = 1; currentTexture = set.GenerateImage(); if (overColor.A != 0) { Brush br = new SolidBrush(overColor); Graphics g = Graphics.FromImage(currentTexture); g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Half; g.FillRectangle(br, 0, 0, currentTexture.Width, currentTexture.Height); br.Dispose(); g.Dispose(); } } else { int he = set.Height == 3 ? 3 + scale - 1 : set.Height; int wi = set.Width == 3 ? 3 + scale - 1 : set.Width; currentTexture = new Bitmap(wi * 8, he * 8, System.Drawing.Imaging.PixelFormat.Format32bppArgb); Graphics g = Graphics.FromImage(currentTexture); g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Half; var charImages = set.GenerateCharImages(); for (int y = 0; y < he; y++) { for (int x = 0; x < wi; x++) { int xI = set.Width == 3 ? (x == 0 ? 0 : (x == wi - 1 ? 2 : 1)) : x; int yI = set.Height == 3 ? (y == 0 ? 0 : (y == he - 1 ? 2 : 1)) : y; int index = set.GetCharIndex(xI, yI); g.DrawImageUnscaled(charImages[index], x * 8, y * 8); } } if (overColor.A != 0) { Brush br = new SolidBrush(overColor); g.FillRectangle(br, 0, 0, currentTexture.Width, currentTexture.Height); br.Dispose(); } foreach (var image in charImages) { image.Dispose(); } g.Dispose(); } } elementView.Image = currentTexture; this.Width = currentTexture.Width * pixelScale; this.Height = currentTexture.Height * pixelScale; }
private byte[] GenerateShiftedData(CharSet set) { if (set.Sort != CharSetSort.UpDown) { return(new byte[0]); } var byteData = set.Data; //First, generate the only vertically shifted sprite. //Its used for unshifted or only vertically shifted sprites on screen. List <byte> shiftedData = new List <byte>(); for (int x = 0; x < set.Width; x++) { //First, add four empty bytes to the column shiftedData.Add(0); shiftedData.Add(0); shiftedData.Add(0); shiftedData.Add(0); //Then add the unshifted bytes for (int y = 0; y < set.Height; y++) { shiftedData.AddRange(byteData[set.GetCharIndex(x, y)]); } //And add the final four empty bytes shiftedData.Add(0); shiftedData.Add(0); shiftedData.Add(0); shiftedData.Add(0); } //Now, create the real shifted sprites. //To ease the calculations first we create rows of bytes and after that we will reoirder it in columns List <byte[]> shiftedRows = new List <byte[]>(); int rowWidth = set.Width + 1; byte[] emptyRow = new byte[rowWidth]; //Add four empty rows shiftedRows.Add(emptyRow); shiftedRows.Add(emptyRow); shiftedRows.Add(emptyRow); shiftedRows.Add(emptyRow); //Now, shift the data for (int y = 0; y < set.Height; y++) { for (int charRow = 0; charRow < 8; charRow++) { byte[] newRow = new byte[rowWidth]; for (int x = 0; x < set.Width; x++) { newRow[x] = byteData[set.GetCharIndex(x, y)][charRow]; } newRow.ShiftRight(); newRow.ShiftRight(); newRow.ShiftRight(); newRow.ShiftRight(); shiftedRows.Add(newRow); } } shiftedRows.Add(emptyRow); shiftedRows.Add(emptyRow); shiftedRows.Add(emptyRow); shiftedRows.Add(emptyRow); for (int x = 0; x < rowWidth; x++) { for (int y = 0; y < shiftedRows.Count; y++) { shiftedData.Add(shiftedRows[y][x]); } } return(shiftedData.ToArray()); }