Beispiel #1
0
        /// <summary>
        /// Creates an XCImage.
        /// NOTE: Entries must not be compressed.
        /// </summary>
        /// <param name="bindata">the uncompressed source data</param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="pal">pass in null to *bypass* creating the 'Image'; ie,
        /// the PckImage..cTor has already unravelled the compressed image-data
        /// instead</param>
        /// <param name="id"></param>
        internal XCImage(
            byte[] bindata,
            int width,
            int height,
            Palette pal,
            int id)
        {
            TerrainId = id;             // NOTE: Is not necessarily Terrain. Could be Bigobs or Units ...

            Bindata = bindata;
            Pal     = pal;

            if (Pal != null)                                                                            // NOTE: this is to check for a call by BitmapService.CreateSprite()
            {
                Sprite = BitmapService.CreateColorized(                                                 // which is called by
                    width,                                                                              // BitmapService.CreateSpriteset() and
                    height,                                                                             // several PckViewForm contextmenu events
                    Bindata,                                                                            // BUT: the call by PckImage..cTor initializer needs to decode
                    Pal.ColorTable);                                                                    // the file-data first, then it creates its own 'Image'.
            }
        }                                                                                               // that's why i prefer pizza.
Beispiel #2
0
        /// <summary>
        /// Changes a clicked pixel's palette-id (color) to whatever the current
        /// 'PaletteId' is in PalettePanel.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseDown(MouseEventArgs e)
        {
            base.OnMouseDown(e);

            if (Sprite != null)
            {
                if (e.X > 0 && e.X < XCImage.SpriteWidth * _scale &&
                    e.Y > 0 && e.Y < XCImage.SpriteHeight * _scale)
                {
                    int pixelX = e.X / _scale;
                    int pixelY = e.Y / _scale;

                    int bindataId = pixelY * (Sprite.Bindata.Length / XCImage.SpriteHeight) + pixelX;

                    if (bindataId > -1 && bindataId < Sprite.Bindata.Length)                     // safety.
                    {
                        switch (EditorForm.Mode)
                        {
                        case EditorForm.EditMode.ModeEnabled:                                 // paint ->
                        {
                            int palId = PalettePanel.Instance.PaletteId;
                            if (palId > -1 && palId < PckImage.SpriteTransparencyByte)                                          // NOTE: 0xFE and 0xFF are reserved for special
                            {                                                                                                   // stuff when reading/writing the .PCK file.
//									var color = PckViewForm.Pal[palId];

                                Sprite.Bindata[bindataId] = (byte)palId;
                                Sprite.Sprite             = BitmapService.CreateColorized(
                                    XCImage.SpriteWidth,
                                    XCImage.SpriteHeight,
                                    Sprite.Bindata,
                                    PckViewForm.Pal.ColorTable);
                                Refresh();
                                PckViewPanel.Instance.Refresh();
                            }
                            else
                            {
                                switch (palId)
                                {
                                case PckImage.SpriteTransparencyByte:                                                   // #254
                                case PckImage.SpriteStopByte:                                                           // #255
                                    MessageBox.Show(
                                        this,
                                        "The colortable indices #254 and #255 are reserved"
                                        + " for reading and writing the .PCK file."
                                        + Environment.NewLine + Environment.NewLine
                                        + "#254 is used for RLE encoding"
                                        + Environment.NewLine
                                        + "#255 is the end-of-sprite marker",
                                        "Error",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error,
                                        MessageBoxDefaultButton.Button1,
                                        0);
                                    break;
                                }
                            }
                            break;
                        }

                        case EditorForm.EditMode.ModeLocked:                                 // eye-dropper ->
                            PalettePanel.Instance.SelectPaletteId((int)Sprite.Bindata[bindataId]);
                            break;
                        }
                    }
                }
            }
        }