Exemplo n.º 1
0
        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);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        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);
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void importButton_Click(object sender, EventArgs e)
        {
            Classes.CharLayout layout = Profile.CharLayouts[layoutBox.SelectedIndex];
            byte[]             data   = null;
            uint offset = ParseNumber(offsetBox.Text);
            uint count;

            try
            {
                if (regionBox.SelectedIndex == 0)                                       // "Flat file" selected
                {
                    data  = File.ReadAllBytes((string)fileGrid.Rows[0].Cells[3].Value); // Only one file to open.
                    count = countButton.Checked ? ParseNumber(countBox.Text) : (uint)(8U * data.Length / layout.Stride * fracNumUpDown.Value / fracDenUpDown.Value);
                    uint max = layout.MaxElements((uint)data.Length, offset);
                    if (max < count)
                    {
                        string displayCount = countButton.Checked ? countBox.Text : count.ToString();
                        MessageBox.Show(
                            String.Format(
                                Porno_Graphic.Properties.Resources.TileImporter_ErrorMessage_FileTooSmall,
                                displayCount,
                                offsetBox.Text,
                                data.Length,
                                max),
                            Porno_Graphic.Properties.Resources.TileImporter_ErrorTitle_FileTooSmall);
                        return;
                    }
                }
                else // Load from multiple ROMs
                {
                    Classes.LoadRegion region = Profile.LoadRegions[regionBox.SelectedIndex - 1];
                    count = countButton.Checked ? ParseNumber(countBox.Text) : (uint)(8U * region.Length / layout.Stride * fracNumUpDown.Value / fracDenUpDown.Value);
                    uint max = layout.MaxElements(region.Length, offset);
                    if (max < count)
                    {
                        string displayCount = countButton.Checked ? countBox.Text : count.ToString();
                        MessageBox.Show(
                            String.Format(
                                Porno_Graphic.Properties.Resources.TileImporter_ErrorMessage_RegionTooSmall,
                                region.Name,
                                region.Length,
                                displayCount,
                                offsetBox.Text,
                                max),
                            Porno_Graphic.Properties.Resources.TileImporter_ErrorTitle_RegionTooSmall);
                        return;
                    }
                    string[] paths = new string[fileGrid.Rows.Count];
                    for (int i = 0; i < paths.Length; i++)
                    {
                        paths[i] = (string)fileGrid.Rows[i].Cells[3].Value;
                    }
                    data = region.LoadFiles(paths);
                }
            }
            catch (Classes.LoadPastEndOfFileException ex)
            {
                MessageBox.Show(
                    string.Format(
                        Porno_Graphic.Properties.Resources.TileImporter_ErrorMessage_ReadPastFileEnd,
                        ex.File.Name,
                        ex.Instruction.Offset,
                        ex.Instruction.Size,
                        ex.Read),
                    Porno_Graphic.Properties.Resources.TileImporter_ErrorTitle_ReadPastFileEnd);
                return;
            }
            catch (Classes.LoadOutsideRegionException ex)
            {
                MessageBox.Show(
                    string.Format(
                        Porno_Graphic.Properties.Resources.TileImporter_ErrorMessage_LoadBeyondRegionEnd,
                        ex.Region.Name,
                        ex.Region.Length,
                        ex.Offset,
                        ex.File.Name),
                    Porno_Graphic.Properties.Resources.TileImporter_ErrorTitle_LoadBeyondRegionEnd);
                return;
            }
            catch (Classes.FillOutsideRegionException ex)
            {
                MessageBox.Show(
                    string.Format(
                        Porno_Graphic.Properties.Resources.TileImporter_ErrorMessage_FillBeyondRegionEnd,
                        ex.Region.Name,
                        ex.Region.Length,
                        ex.Offset,
                        ex.Fill.Value),
                    Porno_Graphic.Properties.Resources.TileImporter_ErrorTitle_FillBeyondRegionEnd);
                return;
            }
            catch
            {
                MessageBox.Show(Porno_Graphic.Properties.Resources.TileImporter_ErrorReadingFile);
                return;
            }

            Classes.GfxElement[] elements = new Classes.GfxElement[count];
            Parallel.For(0, count, index => { elements[index] = new Classes.GfxElement(data, layout, offset, (uint)index); });

            Classes.TileImportMetadata metadata = new Classes.TileImportMetadata();
            if (mProfilePath != null)
            {
                metadata.ProfileFile = mProfilePath;
            }
            //metadata.ProfileFile = Path.GetFileName(mProfilePath);
            metadata.ProfileName = mProfile.Name;
            //metadata.RegionName = (string)regionBox.SelectedItem;
            //metadata.LayoutName = (string)layoutBox.SelectedItem;
            if ((regionBox.SelectedIndex - 1) < 0)
            {
                metadata.RegionName = (string)regionBox.SelectedItem;
            }
            else
            {
                metadata.RegionName = mProfile.LoadRegions[regionBox.SelectedIndex - 1].Name;
            }
            metadata.LayoutName = mProfile.CharLayouts[layoutBox.SelectedIndex].Name;
            if (offsetBox.Text.StartsWith("0x"))
            {
                metadata.Offset = offsetBox.Text.Substring(2);
            }
            metadata.Planes = layout.Planes.ToString();

            string[] romPaths = new string[fileGrid.Rows.Count];
            for (int i = 0; i < romPaths.Length; i++)
            {
                romPaths[i] = (string)fileGrid.Rows[i].Cells[3].Value;
            }
            metadata.RomFilenames = romPaths;
            Classes.GfxElementSet elementSet = new Classes.GfxElementSet();
            elementSet.Name           = "TestName";
            elementSet.ElementWidth   = layout.Width;
            elementSet.ElementHeight  = layout.Height;
            elementSet.Elements       = elements;
            elementSet.ImportMetadata = metadata;
            mParent.CreateImportProject(elementSet, (layout.Planes > 3) ? Classes.IndexedPalette.RGBI : Classes.IndexedPalette.RGB);
            Close();
        }
Exemplo n.º 4
0
        public void DrawIndexedGif(Bitmap bitmap, uint[] mapData, uint mapWidth, uint mapHeight, uint tileWidth, uint tileHeight, uint offset, uint rotate, bool flipX, bool flipY)
        {
            int  rows     = (int)mapHeight;
            int  columns  = (int)mapWidth;
            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);

            int        StrideMultiplier = bitmap.Width;
            BitmapData bmpData          = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);
            IntPtr     ptr = bmpData.Scan0;

            byte[] pixels = new byte[bitmap.Width * bitmap.Height];
            System.Runtime.InteropServices.Marshal.Copy(ptr, pixels, 0, pixels.Length);

            for (int row = 0; row < rows; row++, transform[1, 2] += (swapAxes ? (int)ElementWidth : (int)ElementHeight))
            {
                transform[0, 2] = (int)(reverseX ? (swapAxes ? ElementHeight : ElementWidth) : 0);
                for (int column = 0; column < columns; column++)
                {
                    uint tileID = mapData[(row * columns) + column];

                    if (tileID == 0U)
                    {
                        // Fill blank tile
                        for (int y = 0; y < (swapAxes ? (int)ElementWidth : (int)ElementHeight); y++)
                        {
                            for (int x = 0; x < (swapAxes ? (int)ElementHeight : (int)ElementWidth); x++)
                            {
                                int pixelDest = (row * (((int)ElementWidth * (int)ElementHeight) * columns))
                                                + (column * (swapAxes ? (int)ElementHeight : (int)ElementWidth))
                                                + (y * StrideMultiplier)
                                                + x;
                                pixels[pixelDest] = 0xFF;
                            }
                        }
                    }
                    else
                    {
                        tileID -= 1U;
                        GfxElement element = Elements[tileID];
                        if (element != null)
                        {
                            element.DrawIndexed(pixels, transform, StrideMultiplier, column * (swapAxes ? (int)ElementHeight : (int)ElementWidth));
                        }
                    }
                }
            }

            System.Runtime.InteropServices.Marshal.Copy(pixels, 0, ptr, pixels.Length);
            bitmap.UnlockBits(bmpData);
        }