示例#1
0
        public bool LoadSpecialGraphics(string fileName)
        {
            if (!File.Exists(fileName)) return false;
            int dataPointer = 0;
            FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read);
            byte[] data = new byte[fs.Length];
            fs.Read(data, 0, (int) fs.Length);
            fs.Close();

            SpecialBanks.Clear();
            for (int i = 0; i < 4; i++)
            {
                GraphicsBank nextBank = new GraphicsBank();
                for (int j = 0; j < 64; j++)
                {
                    byte[] nextTileChunk = new byte[16];
                    for (int k = 0; k < 16; k++) nextTileChunk[k] = data[dataPointer++];
                    nextBank[j] = new Tile(nextTileChunk);
                }
                SpecialBanks.Add(nextBank);
            }

            SpecialTable = new PatternTable();
            for (int j = 0; j < 4; j++)
            {
                SpecialTable.SetGraphicsbank(j, SpecialBanks[j]);
            }
            return true;
        }
示例#2
0
        public void LoadDefault()
        {
            byte[] graphicsData = Resource.default_graphics;
            int dataPointer = 0;

            GraphicsBanks.Clear();

            for (int i = 0; i < 256; i++)
            {
                GraphicsBank nextBank = new GraphicsBank();
                for (int j = 0; j < 64; j++)
                {
                    byte[] nextTileChunk = new byte[16];
                    for (int k = 0; k < 16; k++) nextTileChunk[k] = graphicsData[dataPointer++];
                    nextBank[j] = new Tile(nextTileChunk);
                }
                GraphicsBanks.Add(nextBank);
            }

            XDocument xDoc = XDocument.Parse(Resource.default_graphics_names);
            foreach (var e in xDoc.Element("graphicsinfo").Elements("graphics"))
            {
                GraphicsInfo gi = new GraphicsInfo();
                gi.LoadFromElement(e);
                GraphicsInfo.Add(gi);
            }
        }
 public PatternTableViewer()
 {
     TileMap = new Tile[16, 16];
     BackBuffer = new Bitmap(128, 128);
     IndexMap = new int[16, 16];
     QuickColorLookup = new Color[4];
     this.Width = this.Height = 256;
     SelectedTiles = new Tile[4];
     this.MouseDown += new MouseEventHandler(PatternTableViewer_MouseDown);
     FullRender();
 }
示例#4
0
        public void LoadDefaultSpecialGraphics()
        {
            int dataPointer = 0;
            byte[] data = Resource.special_graphics;

            SpecialBanks.Clear();
            for (int i = 0; i < 4; i++)
            {
                GraphicsBank nextBank = new GraphicsBank();
                for (int j = 0; j < 64; j++)
                {
                    byte[] nextTileChunk = new byte[16];
                    for (int k = 0; k < 16; k++) nextTileChunk[k] = data[dataPointer++];
                    nextBank[j] = new Tile(nextTileChunk);
                }
                SpecialBanks.Add(nextBank);
            }

            SpecialTable = new PatternTable();
            for (int j = 0; j < 4; j++)
            {
                SpecialTable.SetGraphicsbank(j, SpecialBanks[j]);
            }
        }
示例#5
0
        private void RenderSpecialTileAlpha(Tile tile, int x, int y, int PaletteIndex, BitmapData data, double alpha)
        {
            byte* dataPointer = (byte*)data.Scan0;

            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    long offset = (data.Stride * (y + i)) + (x * 4);
                    long xOffset = (j * 4) + offset;
                    Color c = SpecialColors[PaletteIndex, tile[j, i]];
                    if(c == Color.Empty) continue;

                    if (_ShowGrid)
                    {
                        if ((j == 0 && x % 16 == 0) || (i == 0 && y % 16 == 0))
                            c = Color.FromArgb(255, 255, 255);
                    }

                    *(dataPointer + xOffset) = (byte) ((1 - alpha) * (*(dataPointer + xOffset)) + (alpha * c.B));
                    *(dataPointer + xOffset + 1) = (byte)((1 - alpha) * (*(dataPointer + xOffset + 1)) + (alpha * c.G));
                    *(dataPointer + xOffset + 2) = (byte)((1 - alpha) * (*(dataPointer + xOffset + 2)) + (alpha * c.R));
                    *(dataPointer + xOffset + 3) = 255;
                }
            }
        }
示例#6
0
        private void RenderTile(Tile tile, int x, int y, int PaletteIndex, BitmapData data)
        {
            byte* dataPointer = (byte*)data.Scan0;

            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    long offset = (data.Stride * (y + i)) + (x * 4);
                    long xOffset = (j * 4) + offset;
                    Color c = QuickColorLookup[PaletteIndex, tile[j, i]];
                    if (_ShowGrid)
                    {
                        if ((j == 0 && x % 16 == 0) || (i == 0 && y % 16 == 0))
                        {
                            if (((j + i) % 2) > 0)
                                c = Color.FromArgb(255, 255, 255);
                            else
                                c = Color.FromArgb(0, 0, 0);
                        }
                    }
                    
                    *(dataPointer + xOffset) = c.B;
                    *(dataPointer + xOffset + 1) = c.G;
                    *(dataPointer + xOffset + 2) = c.R;
                    *(dataPointer + xOffset + 3) = 255;
                }
            }
        }
示例#7
0
        private void RenderSpriteHorizontalVerticalFlip(Tile tile, int x, int y, int PaletteIndex, BitmapData data)
        {
            byte* dataPointer = (byte*)data.Scan0;

            for (int i = 7; i >= 0; i--)
            {
                for (int j = 7; j >= 0; j--)
                {
                    if (tile[j, i] == 0) continue;
                    if (x + (7 - j) < 0 || x + (7 - j) >= data.Width) continue;
                    if (y + (7 - i) < 0 || y + (7 - i) >= data.Height) continue;
                    long offset = (data.Stride * (y + (7 - i))) + (x * 4);
                    long xOffset = ((7 - j) * 4) + offset;
                    Color c;
                    if (PaletteIndex > 0)
                    {
                        c = QuickColorLookup[PaletteIndex + 4, tile[j, i]];
                    }
                    else
                    {
                        c = SpecialColors[PaletteIndex * -1, tile[j, i]];
                    }

                    *(dataPointer + xOffset) = c.B;
                    *(dataPointer + xOffset + 1) = c.G;
                    *(dataPointer + xOffset + 2) = c.R;
                    *(dataPointer + xOffset + 3) = 255;
                }
            }
        }
示例#8
0
        private void RenderSprite(Tile tile, int x, int y, int PaletteIndex, BitmapData data)
        {
            byte* dataPointer = (byte*)data.Scan0;

            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    if (tile[j, i] == 0) continue;
                    if (x + j < 0 || x + j >= data.Width) continue;
                    if (y + i < 0 || y + i >= data.Height) continue;
                    long offset = (data.Stride * (y + i)) + (x * 4);
                    long xOffset = (j * 4) + offset;
                    Color c;
                    if (PaletteIndex > 0)
                    {
                        c = QuickColorLookup[PaletteIndex + 4, tile[j, i]];
                    }
                    else
                    {
                        c = SpecialColors[PaletteIndex * -1, tile[j, i]];
                    }

                    *(dataPointer + xOffset) = c.B;
                    *(dataPointer + xOffset + 1) = c.G;
                    *(dataPointer + xOffset + 2) = c.R;
                    *(dataPointer + xOffset + 3) = 255;
                }
            }
        }
示例#9
0
        private void RenderSpecialTileAlpha(Tile tile, int x, int y, int PaletteIndex, BitmapData data)
        {
            byte* dataPointer = (byte*)data.Scan0;
            double alpha = .5;
            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    long offset = (data.Stride * (y + i)) + (x * 3);
                    long xOffset = (j * 3) + offset;
                    Color c = SpecialColors[PaletteIndex, tile[j, i]];
                    if (c == Color.Empty) continue;

                    *(dataPointer + xOffset) = (byte)((1 - alpha) * (*(dataPointer + xOffset)) + (alpha * c.B));
                    *(dataPointer + xOffset + 1) = (byte)((1 - alpha) * (*(dataPointer + xOffset + 1)) + (alpha * c.G));
                    *(dataPointer + xOffset + 2) = (byte)((1 - alpha) * (*(dataPointer + xOffset + 2)) + (alpha * c.R));
                }
            }
        }
示例#10
0
        private void RenderTile(Tile tile, int x, int y, int PaletteIndex, BitmapData data)
        {
            byte* dataPointer = (byte*)data.Scan0;

            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 8; j++)
                {
                    long offset = (data.Stride * (y + i)) + (x * 3);
                    long xOffset = (j * 3) + offset;
                    Color c = QuickColorLookup[PaletteIndex, tile[j, i]];
                    *(dataPointer + xOffset) = c.B;
                    *(dataPointer + xOffset + 1) = c.G;
                    *(dataPointer + xOffset + 2) = c.R;
                }
            }
        }
示例#11
0
 private void RenderTile(Tile tile, int x, int y, Graphics g)
 {
     for (int i = 0; i < 8; i++)
     {
         for (int j = 0; j < 8; j++)
         {
             Color c = QuickColorLookup[tile[j, i]];
             Brush b = new SolidBrush(Color.FromArgb(c.R, c.G, c.B));
             g.FillRectangle(b, new Rectangle((x * 16) + (j * 16), (y * 16) + (i * 16), 16, 16));
         }
     }
 }
示例#12
0
 public void UpdateTile(int tileNumber, Tile tile)
 {
     CurrentTiles[tileNumber] = tile;
     FullRender();
 }
示例#13
0
        public bool LoadGraphics(string filename)
        {
            if (!File.Exists(filename)) return false;
            FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read);
            byte[] graphicsData = new byte[0x40000];

            fs.Read(graphicsData, 0, (int)fs.Length);
            fs.Close();
            int dataPointer = 0;

            GraphicsBanks.Clear();

            for (int i = 0; i < 256; i++)
            {
                GraphicsBank nextBank = new GraphicsBank();
                for (int j = 0; j < 64; j++)
                {
                    byte[] nextTileChunk = new byte[16];
                    for (int k = 0; k < 16; k++) nextTileChunk[k] = graphicsData[dataPointer++];
                    nextBank[j] = new Tile(nextTileChunk);
                }
                GraphicsBanks.Add(nextBank);
            }

            LastModified = File.GetLastWriteTime(filename);
            return true;
        }
示例#14
0
        public bool ImportGraphics(string filename)
        {
            if (!File.Exists(filename)) return false;
            bool IsChr = Path.GetExtension(filename) == "chr";
            FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read);
            byte[] graphicsData = new byte[0x40000];
            int length, offset;

            if (!IsChr)
            {
                byte[] header = new byte[16];
                fs.Read(header, 0, 16);

                length = header[5] * 8192;
                offset = header[4] * 16384 + 16;
            }
            else
            {
                length = (int)fs.Length;
                offset = 0;
            }

            fs.Seek(offset, SeekOrigin.Begin);
            fs.Read(graphicsData, 0, length);
            fs.Close();
            int dataPointer = 0;

            GraphicsBanks.Clear();

            for (int i = 0; i < 256; i++)
            {
                GraphicsBank nextBank = new GraphicsBank();
                for (int j = 0; j < 64; j++)
                {
                    byte[] nextTileChunk = new byte[16];
                    for (int k = 0; k < 16; k++) nextTileChunk[k] = graphicsData[dataPointer++];
                    nextBank[j] = new Tile(nextTileChunk);
                }
                GraphicsBanks.Add(nextBank);
            }

            if (GraphicsUpdated != null)
            {
                GraphicsUpdated(this, null);
            }

            LastModified = File.GetLastWriteTime(filename);
            //ProjectController.GraphicsManager.SaveGraphics(ProjectController.RootDirectory + @"\" + ProjectController.ProjectName + ".chr");
            return true;
        }
示例#15
0
        private void RenderSpriteVerticalFlip(Tile tile, int x, int y, int PaletteIndex, BitmapData data)
        {
            byte* dataPointer = (byte*)data.Scan0;

            if (x < 0 || y < 0 || x >= SpriteBuffer.Width || (y + 8) > SpriteBuffer.Height) return;
            for (int i = 7; i >= 0; i--)
            {
                for (int j = 0; j < 8; j++)
                {
                    if (tile[j, i] == 0) continue;
                    long offset = (data.Stride * (y + (7 - i))) + (x * 3);
                    long xOffset = (j * 3) + offset;
                    Color c;
                    if (PaletteIndex > 0)
                    {
                        c = QuickColorLookup[PaletteIndex + 4, tile[j, i]];
                    }
                    else
                    {
                        c = SpecialColors[PaletteIndex * -1, tile[j, i]];
                    }

                    *(dataPointer + xOffset) = c.B;
                    *(dataPointer + xOffset + 1) = c.G;
                    *(dataPointer + xOffset + 2) = c.R;
                }
            }
        }