コード例 #1
0
ファイル: SpriteRecolorForm.cs プロジェクト: Grovespaz/MLLE
        private void PaletteImageMouseMove(object sender, MouseEventArgs e)
        {
            if (!(sender as Control).ClientRectangle.Contains(e.Location))
            {
                return;
            }
            PaletteImage paletteImage  = sender as PaletteImage;
            int          selectedColor = paletteImage.getSelectedColor(e);

            if (e.Button != MouseButtons.None && paletteImage.NumberOfSelectedColors > 0)
            {
                paletteImage.Moved(sender, e);
                ButtonNearestColors.Enabled = (paletteImage == RemappingPalette && paletteImage.NumberOfSelectedColors > 0);
            }
            else
            {
                PaletteImage otherPaletteImage          = GetOtherPalette(paletteImage);
                int[]        otherPaletteSelectedColors = otherPaletteImage.GetSelectedIndices();
                if (otherPaletteSelectedColors.Length > 0)
                {
                    SetMatchingSelectedColorsBasedOnOtherPaletteImage(paletteImage, selectedColor, ref otherPaletteSelectedColors);
                    paletteImage.Update(PaletteImage.AllPaletteColors);
                    paletteImage.SetSelected(otherPaletteSelectedColors, true); //visual change only, to be undone below
                    foreach (var selected in otherPaletteSelectedColors)
                    {
                        paletteImage.ColorsSelected[selected] = false;
                    }
                }
            }

            Text = "Remap Image Palette \u2013 " + selectedColor;
        }
コード例 #2
0
ファイル: SpriteRecolorForm.cs プロジェクト: Grovespaz/MLLE
        private static void SetMatchingSelectedColorsBasedOnOtherPaletteImage(PaletteImage paletteImage, int selectedColor, ref int[] otherPaletteSelectedColors)
        {
            int offset = selectedColor - otherPaletteSelectedColors[0];

            for (int i = 0; i < otherPaletteSelectedColors.Length; ++i)
            {
                int proposedOffsetSelectedColor = (otherPaletteSelectedColors[i] + offset) & byte.MaxValue;
                while (paletteImage.ColorDisabled[proposedOffsetSelectedColor])
                {
                    proposedOffsetSelectedColor = (proposedOffsetSelectedColor + 1) & byte.MaxValue;
                    offset += 1;
                }
                otherPaletteSelectedColors[i] = proposedOffsetSelectedColor;
            }
        }
コード例 #3
0
ファイル: SpriteRecolorForm.cs プロジェクト: Grovespaz/MLLE
        private void PaletteImageMouseDown(object sender, MouseEventArgs e)
        {
            PaletteImage paletteImage      = sender as PaletteImage;
            PaletteImage otherPaletteImage = GetOtherPalette(paletteImage);

            if (otherPaletteImage.NumberOfSelectedColors == 0)
            {
                paletteImage.Clicked(sender, e);
                ButtonNearestColors.Enabled = (paletteImage == RemappingPalette && paletteImage.NumberOfSelectedColors > 0);
            }
            else
            {
                int[] otherPaletteSelectedColors = otherPaletteImage.GetSelectedIndices();
                int[] thisPaletteSelectedColors  = otherPaletteSelectedColors.Clone() as int[];
                SetMatchingSelectedColorsBasedOnOtherPaletteImage(paletteImage, paletteImage.getSelectedColor(e), ref thisPaletteSelectedColors);

                if (paletteImage == RemappingPalette)
                {
                    for (int i = 0; i < thisPaletteSelectedColors.Length; ++i)
                    {
                        ColorRemappings[thisPaletteSelectedColors[i]] = (byte)otherPaletteSelectedColors[i];
                    }
                }
                else
                {
                    for (int i = 0; i < thisPaletteSelectedColors.Length; ++i)
                    {
                        ColorRemappings[otherPaletteSelectedColors[i]] = (byte)thisPaletteSelectedColors[i];
                    }
                }

                for (int i = 0; i < Palette.PaletteSize; ++i)
                {
                    var remappedColor = LevelPalette.Palette[ColorRemappings[i]];
                    RemappingPalette.Palette[i]    = remappedColor;
                    ImageWorkingPalette.Entries[i] = Palette.Convert(remappedColor);
                }
                pictureBox1.Image.Palette = ImageWorkingPalette;
                pictureBox1.Refresh();

                LevelPalette.SetSelected(PaletteImage.AllPaletteColors, false);
                RemappingPalette.SetSelected(PaletteImage.AllPaletteColors, false);

                paletteImage.CurrentlySelectingColors = false;
                ButtonNearestColors.Enabled           = false;
            }
        }
コード例 #4
0
        internal bool ShowForm(ref byte[] image, byte[] originalImage, Palette palette)
        {
            if (EditingImage = (palette != null)) //image
            {
                originalPalette             = new PaletteImage(5, 0, true, false);
                originalPalette.Palette     = palette;
                originalPalette.Location    = new Point(OKButton.Location.X, ButtonCancel.Location.Y + (ButtonCancel.Location.Y - OKButton.Location.Y));
                originalPalette.MouseLeave += control_MouseLeave;
                originalPalette.MouseMove  += pictureBox_MouseMove;
                originalPalette.MouseDown  += pictureBox_MouseDown;
                Controls.Add(originalPalette);

                for (uint i = 0; i < Palette.PaletteSize; ++i)
                {
                    Colors[i] = new SolidBrush(Palette.Convert(palette.Colors[i]));
                }

                PrimaryColor = SecondaryColor = 0;

                FormTitle = "Edit Tile Image";
            }
            else //mask
            {
                Colors[0] = new SolidBrush(BackColor);
                Colors[1] = new SolidBrush(Color.Black);

                PrimaryColor   = 1;
                SecondaryColor = 0;

                Text = FormTitle = "Edit Tile Mask";

                toolStrip1.Items.Remove(ReplaceColorButton);
            }
            if (image != null)
            {
                Text = (FormTitle += "*");
            }

            Image         = (image ?? originalImage).Clone() as byte[];
            OriginalImage = originalImage;
            ImageImage    = new Bitmap(pictureBox1.Width, pictureBox1.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            DrawImage();

            pasteToolStripMenuItem.Enabled      = EditingImage || ClipboardMask != null;
            pasteUnderToolStripMenuItem.Enabled = EditingImage; //no use in pasting under a mask

            ShowDialog();

            foreach (var brush in Colors)
            {
                if (brush != null)
                {
                    brush.Dispose();
                }
            }

            if (result && (image == null || !Image.SequenceEqual(image)))
            {
                image = (Image.SequenceEqual(originalImage)) ? null : Image;
                return(true);
            }

            return(false);
        }
コード例 #5
0
ファイル: SpriteRecolorForm.cs プロジェクト: Grovespaz/MLLE
        /*internal bool ShowForm(Palette palette, J2TFile tileset)
         * {
         *  //CreateImageFromTileset(tileset);
         *  ShowDialog();
         *  return Result;
         * }*/
        internal bool ShowForm(Palette palette, Bitmap bitmap, ref byte[] colorRemappings, Color imageBackgroundColor)
        {
            //CreateImageFromTileset(tileset);

            if (colorRemappings == null)
            {
                for (uint i = 0; i < Palette.PaletteSize; ++i)
                {
                    ColorRemappings[i] = (byte)i;
                }
            }
            else
            {
                colorRemappings.CopyTo(ColorRemappings, 0);
            }

            LevelPalette.Palette    = palette;
            LevelPalette.Palette[0] = Palette.Convert(imageBackgroundColor);
            for (int i = 0; i < Palette.PaletteSize; ++i)
            {
                RemappingPalette.Palette[i] = LevelPalette.Palette[ColorRemappings[i]];
            }
            ImageWorkingPalette = bitmap.Palette;
            PaletteImage original = new PaletteImage(5, 0, true, false);

            for (uint i = 0; i < Palette.PaletteSize; ++i)
            {
                original.Palette.Colors[i]     = Palette.Convert(ImageWorkingPalette.Entries[i]);
                ImageWorkingPalette.Entries[i] = Palette.Convert(LevelPalette.Palette.Colors[ColorRemappings[i]]);
            }
            OriginalPalette.CopyFrom(original.Palette);
            bitmap.Palette = ImageWorkingPalette;

            pictureBox1.Image = bitmap;
            pictureBox1.Size  = bitmap.Size;
            Width            -= (320 - pictureBox1.Width);

            original.Location    = new Point(label1.Location.X, label1.Location.Y + 16);
            original.MouseMove  += PaletteImageMouseMove;
            original.MouseLeave += PaletteImageMouseLeave;
            Controls.Add(original);

            LevelPalette.Location    = new Point(label3.Left, panel1.Top);
            LevelPalette.MouseMove  += PaletteImageMouseMove;
            LevelPalette.MouseLeave += PaletteImageMouseLeave;
            LevelPalette.MouseDown  += PaletteImageMouseDown;
            Controls.Add(LevelPalette);

            RemappingPalette.Location    = new Point(label4.Left, label4.Location.Y + 16);
            RemappingPalette.MouseMove  += PaletteImageMouseMove;
            RemappingPalette.MouseLeave += PaletteImageMouseLeave;
            RemappingPalette.MouseDown  += PaletteImageMouseDown;
            Controls.Add(RemappingPalette);

            var data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed);

            ImageIndices = new byte[data.Width * data.Height];
            for (int y = 0; y < bitmap.Height; ++y)
            {
                Marshal.Copy(new IntPtr((int)data.Scan0 + data.Stride * y), ImageIndices, bitmap.Width * y, bitmap.Width);
            }
            bitmap.UnlockBits(data);

            for (uint i = 0; i < Palette.PaletteSize; ++i)
            {
                original.ColorDisabled[i] = RemappingPalette.ColorDisabled[i] = i == 0 || !ImageIndices.Contains((byte)i);
            }
            for (int i = 0; i < 10; ++i)
            {
                LevelPalette.ColorDisabled[i] = LevelPalette.ColorDisabled[Palette.PaletteSize - 10 + i] = true; //transparency, and default windows colors
            }
            original.Update(PaletteImage.AllPaletteColors);
            LevelPalette.Update(PaletteImage.AllPaletteColors);
            RemappingPalette.Update(PaletteImage.AllPaletteColors);

            ShowDialog();

            if (Result)
            {
                colorRemappings = ColorRemappings;
            }
            return(Result);
        }
コード例 #6
0
ファイル: SpriteRecolorForm.cs プロジェクト: Grovespaz/MLLE
 private PaletteImage GetOtherPalette(PaletteImage thisOne)
 {
     return((thisOne == LevelPalette) ? RemappingPalette : LevelPalette);
 }