Пример #1
0
        public bool HandleMouse_Palette(int pxX, int pxY)
        {
            if (pxX < 0 || pxY < 0)
            {
                return(false);
            }

            // Convert pixel (x,y) to palette (x,y).
            int nX = pxX / k_pxColorSize;
            int nY = pxY / k_pxColorSize;

            // Ignore if outside the SpriteList bounds.
            if (nX >= k_nPaletteColumns || nY >= k_nPaletteRows)
            {
                return(false);
            }

            int nSelectedColor = nY * k_nPaletteColumns + nX;

            // Update the selection if a new color has been selected.
            Subpalette sp = m_palette.GetCurrentSubpalette();

            if (sp.CurrentColor != nSelectedColor)
            {
                sp.CurrentColor = nSelectedColor;
                return(true);
            }

            return(false);
        }
Пример #2
0
        public void DrawSwatch(Graphics g, int nIndex)
        {
            Subpalette sp = m_palette.GetCurrentSubpalette();

            Font f = new Font("Arial Black", 10);

            // TODO: query fontmetrics and center text in box
            int[] nLabelXOffset = new int[16] {
                6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 6
            };

            int pxX0 = 1;
            int pxY0 = 1;

            g.FillRectangle(sp.Brush(nIndex), pxX0, pxY0, k_pxSwatchSize, k_pxSwatchSize);

            // Draw the transparent color (index 0) using a pattern.
            if (nIndex == 0)
            {
                g.FillRectangle(m_brushTransparent, pxX0, pxY0, k_pxSwatchSize, k_pxSwatchSize);
            }

            // Draw the palette index in each swatch.
            if (Options.Sprite_ShowPaletteIndex)
            {
                int pxLabelOffsetX = nLabelXOffset[nIndex];
                int pxLabelOffsetY = 2;
                g.DrawString(sp.Label(nIndex), f, sp.LabelBrush(nIndex), pxX0 + pxLabelOffsetX, pxY0 + pxLabelOffsetY);
            }

            // Draw a border around each color swatch.
            g.DrawRectangle(Pens.White, pxX0, pxY0, k_pxSwatchSize, k_pxSwatchSize);

            g.DrawRectangle(Pens.Black, 0, 0, 2 + k_pxSwatchSize, 2 + k_pxSwatchSize);
        }
Пример #3
0
 public void Copy(Subpalette pal)
 {
     for (int i = 0; i < k_nColors; i++)
     {
         UpdateColor(i, pal.Red(i), pal.Green(i), pal.Blue(i));
     }
     RecordSnapshot();
 }
Пример #4
0
        public void DrawTile(Graphics g, Tile t, int pxOriginX, int pxOriginY)
        {
            // create a new bitmap
            int pxSize = BigBitmapPixelSize;
            //int pxInset = pxSize / 4;
            Subpalette sp = m_sprite.Subpalette;

            Font f;

            int[] nXOffset;
            int   nYOffset;

            if (pxSize == 16)
            {
                f        = new Font("Arial", 9);
                nXOffset = new int[16] {
                    3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 3
                };
                nYOffset = 1;
            }
            else
            {
                f        = new Font("Arial Black", 10);
                nXOffset = new int[16] {
                    10, 9, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 9, 9, 9, 10
                };
                nYOffset = 6;
            }

            g.FillRectangle(Brushes.White, pxOriginX, pxOriginY, Tile.TileSize * pxSize, Tile.TileSize * pxSize);
            for (int iRow = 0; iRow < Tile.TileSize; iRow++)
            {
                for (int iColumn = 0; iColumn < Tile.TileSize; iColumn++)
                {
                    int nPaletteIndex = t.GetPixel(iColumn, iRow);

                    int pxX0 = pxOriginX + (iColumn * pxSize);
                    int pxY0 = pxOriginY + (iRow * pxSize);
                    g.FillRectangle(sp.Brush(nPaletteIndex), pxX0, pxY0, pxSize, pxSize);

                    // Draw the transparent color (index 0) using a pattern.
                    if (nPaletteIndex == 0 && BigBitmapPixelSize >= 8)
                    {
                        g.FillRectangle(m_brushTransparent, pxX0, pxY0, pxSize, pxSize);
                    }

                    if (Options.Sprite_ShowPaletteIndex && pxSize >= 16)
                    {
                        // Draw the palette index in each pixel.
                        int pxLabelOffsetX = nXOffset[nPaletteIndex];
                        int pxLabelOffsetY = nYOffset;
                        g.DrawString(sp.Label(nPaletteIndex), f, sp.LabelBrush(nPaletteIndex), pxX0 + pxLabelOffsetX, pxY0 + pxLabelOffsetY);
                    }
                }
            }
        }
Пример #5
0
        public ColorEditor16(ProjectMainForm parent, Palette16Form p16, Subpalette sp)
        {
            m_parent     = parent;
            m_winPalette = p16;
            m_subpalette = sp;

            InitializeComponent();

            UpdateColorScrollbars();
        }
Пример #6
0
        public ColorEditor16(ProjectMainForm parent, Palette16Form p16, Subpalette sp)
        {
            m_parent = parent;
            m_winPalette = p16;
            m_subpalette = sp;

            InitializeComponent();

            UpdateColorScrollbars();
        }
Пример #7
0
        /// <summary>
        /// Get the pixel at the given (x,y) coord.
        /// Assumes that x,y are valid pixel coords.
        /// </summary>
        /// <returns>The rgb color value of the specified pixel</returns>
        public Color GetPixelColor(int pxX, int pxY)
        {
            Subpalette p      = m_sprite.Subpalette;
            int        nIndex = m_data.pixels[pxX, pxY];
            int        cRed   = p.Red(nIndex);
            int        cGreen = p.Green(nIndex);
            int        cBlue  = p.Blue(nIndex);

            return(Color.FromArgb(cRed * 8, cGreen * 8, cBlue * 8));
        }
Пример #8
0
        private void pbPalette_MouseUp(object sender, MouseEventArgs e)
        {
            m_fPalette_Selecting = false;

            // Record an undo action if the current color selection has changed
            if (m_fPalette_OriginalColor != m_palette.GetCurrentSubpalette().CurrentColor)
            {
                Subpalette sp = m_palette.GetCurrentSubpalette();
                //sp.RecordUndoAction("select color", m_parent.ActiveUndo());
            }
        }
Пример #9
0
        public static void DrawPalette(Graphics g, Subpalette sp)
        {
            Font f = new Font("Arial Black", 10);

            // TODO: query fontmetrics and center text in box
            int[] nLabelXOffset = new int[16] {
                6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 6
            };

            int nRows    = k_nPaletteRows;
            int nColumns = k_nPaletteColumns;
            int pxSize   = k_pxColorSize;

            for (int iRow = 0; iRow < nRows; iRow++)
            {
                for (int iColumn = 0; iColumn < nColumns; iColumn++)
                {
                    int nIndex = iRow * nColumns + iColumn;

                    int pxX0 = 1 + iColumn * pxSize;
                    int pxY0 = 1 + iRow * pxSize;

                    g.FillRectangle(sp.Brush(nIndex), pxX0, pxY0, pxSize, pxSize);

                    // Draw the transparent color (index 0) using a pattern.
                    if (nIndex == 0)
                    {
                        g.FillRectangle(m_brushTransparent, pxX0, pxY0, pxSize, pxSize);
                    }

                    // Draw the palette index in each swatch.
                    if (Options.Sprite_ShowPaletteIndex)
                    {
                        int pxLabelOffsetX = nLabelXOffset[nIndex];
                        int pxLabelOffsetY = 2;
                        g.DrawString(sp.Label(nIndex), f, sp.LabelBrush(nIndex), pxX0 + pxLabelOffsetX, pxY0 + pxLabelOffsetY);
                    }

                    // Draw a border around each color swatch.
                    g.DrawRectangle(Pens.White, pxX0, pxY0, pxSize, pxSize);
                }
            }

            g.DrawRectangle(Pens.Black, 0, 0, 2 + nColumns * pxSize, 2 + nRows * pxSize);

            // Hilight the currently selected color.
            int x = (sp.CurrentColor % nColumns) * pxSize;
            int y = (sp.CurrentColor / nColumns) * pxSize;

            g.DrawRectangle(m_penHilight, x + 1, y + 1, pxSize, pxSize);
        }
Пример #10
0
        public Palette16(Document doc, Palettes pals, string strName, int id, string strDesc)
            : base(doc, pals, strName, id, strDesc)
        {
            m_type = Palette.Type.Color16;
            m_nMaxSubpalettes = 16;

            m_subpalettes = new Subpalette[m_nMaxSubpalettes];
            for (int i = 0; i < m_nMaxSubpalettes; i++)
                m_subpalettes[i] = new Subpalette(doc, this, i, Subpalette.DefaultColorSet.BlackAndWhite);

            CurrentSubpaletteId = 0;

            if (m_doc.Owner != null)
                m_winPalette = new Palette16Form(m_doc.Owner, this);
        }
        public UndoAction_Subpalette16Edit(UndoMgr mgr, Subpalette subpalette, PaletteColorData before, PaletteColorData after, string strDesc)
        {
            m_mgr = mgr;
            m_subpalette = subpalette;
            m_before = new PaletteColorData(before);
            m_after = new PaletteColorData(after);

            int b = before.currentColor;
            int a = after.currentColor;
            Description = "Subpalette16Edit " + subpalette.SubpaletteID + "," + before.currentColor + " ("
                + before.cRed[b] + "," + before.cGreen[b] + "," + before.cBlue[b]
                + ") -> ("
                + after.cRed[a] + "," + after.cGreen[a] + "," + after.cBlue[a]
                + ")";
        }
Пример #12
0
        PaletteColorData m_after;               // Redo

        public UndoAction_Subpalette16Edit(UndoMgr mgr, Subpalette subpalette, PaletteColorData before, PaletteColorData after, string strDesc)
        {
            m_mgr        = mgr;
            m_subpalette = subpalette;
            m_before     = new PaletteColorData(before);
            m_after      = new PaletteColorData(after);

            int b = before.currentColor;
            int a = after.currentColor;

            Description = "Subpalette16Edit " + subpalette.SubpaletteID + "," + before.currentColor + " ("
                          + before.cRed[b] + "," + before.cGreen[b] + "," + before.cBlue[b]
                          + ") -> ("
                          + after.cRed[a] + "," + after.cGreen[a] + "," + after.cBlue[a]
                          + ")";
        }
Пример #13
0
        public ColorEncodingView(ProjectMainForm parent, Subpalette p)
        {
            m_parent = parent;

            InitializeComponent();
            this.DialogResult = DialogResult.No;

            m_subpalette = p;

            AdjustColorScrollbars();

            if (m_brushTransparent == null)
            {
                m_brushTransparent = new System.Drawing.Drawing2D.HatchBrush(
                    Options.TransparentPattern,
                    Color.LightGray, Color.Transparent);
            }
        }
Пример #14
0
        // create a bitmap from this tile data
        private Bitmap CreateBitmap(int pxSize)
        {
            // create a new bitmap
            Bitmap     bm = new Bitmap(TileSize * pxSize, TileSize * pxSize);        //, PixelFormat.Format32bppArgb);
            Graphics   g  = Graphics.FromImage(bm);
            Subpalette sp = m_sprite.Subpalette;

            g.FillRectangle(Brushes.White, 0, 0, TileSize * pxSize, TileSize * pxSize);
            for (int iRow = 0; iRow < TileSize; iRow++)
            {
                for (int iColumn = 0; iColumn < TileSize; iColumn++)
                {
                    g.FillRectangle(sp.Brush(GetPixel(iColumn, iRow)), iColumn * pxSize, iRow * pxSize, pxSize, pxSize);
                }
            }

            return(bm);
        }
Пример #15
0
        public ColorEncodingView(ProjectMainForm parent, Subpalette p)
        {
            m_parent = parent;

            InitializeComponent();
            this.DialogResult = DialogResult.No;

            m_subpalette = p;

            AdjustColorScrollbars();

            if (m_brushTransparent == null)
            {
                m_brushTransparent = new System.Drawing.Drawing2D.HatchBrush(
                        Options.TransparentPattern,
                        Color.LightGray, Color.Transparent);
            }
        }
Пример #16
0
        public Palette16(Document doc, Palettes pals, string strName, int id, string strDesc) :
            base(doc, pals, strName, id, strDesc)
        {
            m_type            = Palette.Type.Color16;
            m_nMaxSubpalettes = 16;

            m_subpalettes = new Subpalette[m_nMaxSubpalettes];
            for (int i = 0; i < m_nMaxSubpalettes; i++)
            {
                m_subpalettes[i] = new Subpalette(doc, this, i, Subpalette.DefaultColorSet.BlackAndWhite);
            }

            CurrentSubpaletteId = 0;

            if (m_doc.Owner != null)
            {
                m_winPalette = new Palette16Form(m_doc.Owner, this);
            }
        }
Пример #17
0
        private void menuPalette_EditColors_Click(object sender, EventArgs e)
        {
            Subpalette p = ActivePalette().GetCurrentSubpalette();

            if (p == null)
            {
                return;
            }

            ColorEncodingView cedit  = new ColorEncodingView(this, p);
            DialogResult      result = cedit.ShowDialog();

            //UpdatePaletteColor(tab);
            if (result == DialogResult.Yes)
            {
                m_doc.HasUnsavedChanges = true;
                HandleColorDataChange(ActivePalette());
            }
        }
Пример #18
0
        public static void DrawPalette(Graphics g, Subpalette sp)
        {
            Font f = new Font("Arial Black", 10);

            // TODO: query fontmetrics and center text in box
            int[] nLabelXOffset = new int[16] { 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 6 };

            int nRows = k_nPaletteRows;
            int nColumns = k_nPaletteColumns;
            int pxSize = k_pxColorSize;

            for (int iRow = 0; iRow < nRows; iRow++)
            {
                for (int iColumn = 0; iColumn < nColumns; iColumn++)
                {
                    int nIndex = iRow * nColumns + iColumn;

                    int pxX0 = 1 + iColumn * pxSize;
                    int pxY0 = 1 + iRow * pxSize;

                    g.FillRectangle(sp.Brush(nIndex), pxX0, pxY0, pxSize, pxSize);

                    // Draw the transparent color (index 0) using a pattern.
                    if (nIndex == 0)
                        g.FillRectangle(m_brushTransparent, pxX0, pxY0, pxSize, pxSize);

                    // Draw the palette index in each swatch.
                    if (Options.Sprite_ShowPaletteIndex)
                    {
                        int pxLabelOffsetX = nLabelXOffset[nIndex];
                        int pxLabelOffsetY = 2;
                        g.DrawString(sp.Label(nIndex), f, sp.LabelBrush(nIndex), pxX0 + pxLabelOffsetX, pxY0 + pxLabelOffsetY);
                    }

                    // Draw a border around each color swatch.
                    g.DrawRectangle(Pens.White, pxX0, pxY0, pxSize, pxSize);
                }
            }

            g.DrawRectangle(Pens.Black, 0, 0, 2 + nColumns * pxSize, 2 + nRows * pxSize);

            // Hilight the currently selected color.
            int x = (sp.CurrentColor % nColumns) * pxSize;
            int y = (sp.CurrentColor / nColumns) * pxSize;
            g.DrawRectangle(m_penHilight, x + 1, y + 1, pxSize, pxSize);
        }
Пример #19
0
 public void SetDefaultSubpaletteColors(int nId, Subpalette.DefaultColorSet colorset)
 {
     if (nId < 0 || nId >= m_nMaxSubpalettes)
         return;
     m_subpalettes[nId].SetDefaultSubpaletteColors(colorset);
 }
Пример #20
0
 public void Copy(Subpalette pal)
 {
     for (int i = 0; i < k_nColors; i++)
         UpdateColor(i, pal.Red(i), pal.Green(i), pal.Blue(i));
     RecordSnapshot();
 }
Пример #21
0
        private void pbFgSwatch_Paint(object sender, PaintEventArgs e)
        {
            Subpalette sp = m_palette.GetCurrentSubpalette();

            DrawSwatch(e.Graphics, sp.CurrentColor);
        }