Inheritance: ICloneable
Esempio n. 1
0
 public object Clone()
 {
     var ret = new MPalette(this.Count);
     for (int i = 0; i < this.ColorCount; i++)
         ret.SetColorAt(i, this.GetColorAt(i));
     return ret;
 }
Esempio n. 2
0
        public object Clone()
        {
            var ret = new MPalette(this.Count);

            for (int i = 0; i < this.ColorCount; i++)
            {
                ret.SetColorAt(i, this.GetColorAt(i));
            }
            return(ret);
        }
 public static void UpdatePal(MPalette pal, GfxBattleBg bg, int t)
 {
     // Rotate pal to the t'th frame
     if ((t > 0) && (bg.PalDelay > 0))
     {
         t = t % (((bg.PalEnd - bg.PalStart) + 1) * bg.PalDelay);
         for (int i = bg.PalDelay; i < t; i += bg.PalDelay)
         {
             RotatePal(pal, bg);
         }
     }
 }
        public static Bitmap RenderArrangement(ArrEntry[] arr, int tileWidth, int tileHeight,
                                               byte[] gfxData, int gfxDataOffset, MPalette palette, bool usecache, bool transparent)
        {
            // Construct the bitmap
            Bitmap bmp = new Bitmap(tileWidth << 3, tileHeight << 3, PixelFormat.Format8bppIndexed);

            // Create the palette
            bmp.CopyPalette(palette, transparent);

            // Lock and render
            BitmapData bd = bmp.LockBits(ImageLockMode.WriteOnly);

            RenderArrangement(bd, arr, tileWidth, tileHeight, gfxData, gfxDataOffset, usecache, transparent);
            bmp.UnlockBits(bd);
            return(bmp);
        }
        public static void RotatePal(MPalette pal, GfxBattleBg bg)
        {
            if (bg.PalDir == 2)
            {
                // Forward
                Color tmp = pal.GetColorAt(bg.PalEnd);
                for (int j = bg.PalEnd; j > bg.PalStart; j--)
                {
                    pal.SetColorAt(j, pal.GetColorAt(j - 1));
                }
                pal.SetColorAt(bg.PalStart, tmp);
            }

            else
            {
                // Backward
                Color tmp = pal.GetColorAt(bg.PalStart);
                for (int j = bg.PalStart; j < bg.PalEnd; j++)
                {
                    pal.SetColorAt(j, pal.GetColorAt(j + 1));
                }
                pal.SetColorAt(bg.PalEnd, tmp);
            }
        }
 public void SetPalette(MPalette pal)
 {
     palSelector.Palettes = pal;
 }
 public static Bitmap RenderSprites(OamSprite[] oam, byte[] gfxData, MPalette palette)
 {
     return(RenderSprites(oam, gfxData, 0, palette));
 }
 public static void SetLogoPalettes(MPalette pal)
 {
     Rom.WritePal(GetPointer(1), pal);
 }
        public static Bitmap RenderSprites(OamSprite[] oam, byte[] gfxData, int gfxPointer, MPalette palette, bool transparent = true)
        {
            if (oam.Length < 1)
            {
                return(null);
            }

            // Figure out the relative min/max for X/Y
            short minX = oam[0].CoordX;
            sbyte minY = oam[0].CoordY;
            int   maxX = minX + oam[0].Width;
            int   maxY = minY + oam[0].Height;

            for (int j = 1; j < oam.Length; j++)
            {
                var o = oam[j];

                if (o.CoordX < minX)
                {
                    minX = o.CoordX;
                }

                if (o.CoordY < minY)
                {
                    minY = o.CoordY;
                }

                if ((o.CoordX + o.Width) > maxX)
                {
                    maxX = o.CoordX + o.Width;
                }

                if ((o.CoordY + o.Height) > maxY)
                {
                    maxY = o.CoordY + o.Height;
                }
            }

            int width  = maxX - minX;
            int height = maxY - minY;

            // Construct the bitmap
            Bitmap bmp = new Bitmap(width, height, PixelFormat.Format8bppIndexed);

            bmp.CopyPalette(palette, transparent);
            BitmapData bd = bmp.LockBits(ImageLockMode.WriteOnly);

            if (Helpers.IsLinux)
            {
                Helpers.FillBitmap(bd);
            }

            RenderSprites(bd, -minX, -minY, oam, gfxData, gfxPointer, palette, transparent);

            bmp.UnlockBits(bd);
            return(bmp);
        }
        public static void RenderSprites(BitmapData canvas, int center_x, int center_y, OamSprite[] oam, byte[] gfxData, int gfxPointer, MPalette palettenum, bool transparent = true)
        {
            for (int priority = 3; priority >= 0; priority--)
            {
                for (int oamIndex = 0; oamIndex < oam.Length; oamIndex++)
                {
                    var o = oam[oamIndex];
                    if (o.Priority == priority)
                    {
                        // Draw the subsprite
                        int tilePointer = o.Tile << 5;
                        for (int y = 0; y < o.Height; y += 8)
                        {
                            int actualY = o.FlipV ? (o.Height - y - 8) : y;

                            for (int x = 0; x < o.Width; x += 8)
                            {
                                byte[,] pixelData = gfxData.Read4BppTile(gfxPointer + tilePointer);
                                tilePointer      += 0x20;

                                int actualX = o.FlipH ? (o.Width - x - 8) : x;

                                GfxProvider.RenderToBitmap(canvas, pixelData,
                                                           (o.CoordX + center_x) + actualX,
                                                           (o.CoordY + center_y) + actualY,
                                                           o.FlipH, o.FlipV,
                                                           o.Palette, transparent);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 11
0
        public static void RenderPalette(MPalette Enemy, ColorPalette CanvasPal, ColorPalette CanvasPal2, int Latest, out MPalette[] UpdatePal, out int Last, out MPalette[] UpdatePal2, out int palettenum, bool transparent = true)
        {
            Last = Latest;
            int u = 0;

            palettenum = 0;
            UpdatePal  = new MPalette[16];
            for (int k = 0; k < 16; k++)
            {
                UpdatePal[k] = new MPalette(1);
            }
            UpdatePal2 = new MPalette[16];
            for (int k = 0; k < 16; k++)
            {
                UpdatePal2[k] = new MPalette(1);
            }
            for (int j = 0; j < 16; j++)
            {
                for (int i = 0; i < 16; i++)
                {
                    UpdatePal[j].Entries[0][i] = CanvasPal.Entries[(j * 16) + i];
                }
            }
            for (int j = 0; j < 16; j++)
            {
                for (int i = 0; i < 16; i++)
                {
                    UpdatePal2[j].Entries[0][i] = CanvasPal2.Entries[(j * 16) + i];
                }
            }
            for (int j = 0; j < Last; j++)
            {
                u = 0;
                for (int i = 0; i < 16; i++)
                {
                    if (j <= 15)
                    {
                        if (CanvasPal.Entries[(j * 16) + i] == Enemy.Entries[0][i])
                        {
                            u += 1;
                        }
                    }
                    else
                    {
                        if (CanvasPal2.Entries[((j - 16) * 16) + i] == Enemy.Entries[0][i])
                        {
                            u += 1;
                        }
                    }
                }
                if ((u == 15))
                {
                    palettenum = j;
                    u          = 17;
                    j          = Last;
                }
            }
            if ((u != 17) && (Last < 16))
            {
                palettenum      = Last;
                UpdatePal[Last] = Enemy;
                Last           += 1;
            }
            else if (u != 17)
            {
                palettenum            = Last;
                UpdatePal2[Last - 16] = Enemy;
                Last += 1;
            }
        }