public static CpalTable Load(BigEndianBinaryReader reader)
        {
            // FORMAT 0

            // Type      | Name                            | Description
            // ----------|---------------------------------|----------------------------------------------------------------------------------------------------
            // uint16    | version                         | Table version number (=0).
            // uint16    | numPaletteEntries               | Number of palette entries in each palette.
            // uint16    | numPalettes                     | Number of palettes in the table.
            // uint16    | numColorRecords                 | Total number of color records, combined for all palettes.
            // Offset32  | offsetFirstColorRecord          | Offset from the beginning of CPAL table to the first ColorRecord.
            // uint16    | colorRecordIndices[numPalettes] | Index of each paletteā€™s first color record in the combined color record array.

            // additional format 1 fields
            // Offset32  | offsetPaletteTypeArray          | Offset from the beginning of CPAL table to the Palette Type Array. Set to 0 if no array is provided.
            // Offset32  | offsetPaletteLabelArray         | Offset from the beginning of CPAL table to the Palette Labels Array. Set to 0 if no array is provided.
            // Offset32  | offsetPaletteEntryLabelArray    | Offset from the beginning of CPAL table to the Palette Entry Label Array.Set to 0 if no array is provided.
            ushort version                = reader.ReadUInt16();
            ushort numPaletteEntries      = reader.ReadUInt16();
            ushort numPalettes            = reader.ReadUInt16();
            ushort numColorRecords        = reader.ReadUInt16();
            uint   offsetFirstColorRecord = reader.ReadOffset32();

            ushort[]? colorRecordIndices = reader.ReadUInt16Array(numPalettes);

            uint offsetPaletteTypeArray       = 0;
            uint offsetPaletteLabelArray      = 0;
            uint offsetPaletteEntryLabelArray = 0;

            if (version == 1)
            {
                offsetPaletteTypeArray       = reader.ReadOffset32();
                offsetPaletteLabelArray      = reader.ReadOffset32();
                offsetPaletteEntryLabelArray = reader.ReadOffset32();
            }

            reader.Seek(offsetFirstColorRecord, System.IO.SeekOrigin.Begin);
            var palettes = new GlyphColor[numColorRecords];

            for (int n = 0; n < numColorRecords; n++)
            {
                byte blue  = reader.ReadByte();
                byte green = reader.ReadByte();
                byte red   = reader.ReadByte();
                byte alpha = reader.ReadByte();
                palettes[n] = new GlyphColor(blue, green, red, alpha);
            }

            return(new CpalTable(colorRecordIndices, palettes));
        }
Example #2
0
        public override void SaveSettingsToStorage()
        {
            SaveProperty("DeletingALineDeletesTheBookmark", DeletingALineDeletesTheBookmark);
            SaveProperty("NavigateInFolderIncludesSubfolders", NavigateInFolderIncludesSubfolders);
            SaveProperty("DeleteAllInFolderIncludesSubfolders", DeleteAllInFolderIncludesSubfolders);
            SaveProperty("ShowMenuOption", (int)ShowMenuOption);
            SaveProperty("GlyphColor", GlyphColor.ToArgb());
            SaveProperty("MergeWhenImporting", MergeWhenImporting);

            if (CustomColors != null)
            {
                SaveProperty("CustomColors",
                             string.Join(",", CustomColors.Select(rgb => rgb.ToString())));
            }
        }
Example #3
0
        private void UpdateColorPaletteFromGrid()
        {
            if (_currentColorPalette == null)
            {
                throw new Exception("No ColorPalette selected.");
            }

            var newColors = new GlyphColor[ColorGrid.ColumnCount, ColorGrid.RowCount];

            // fill with patches in Grid
            foreach (var colorPatch in ColorGrid.ColorPatches)
            {
                newColors[colorPatch.GridLocation.X, colorPatch.GridLocation.Y] = colorPatch.Color.ToGlyphColor();
            }

            _currentColorPalette.ChangeColors(newColors);
        }
Example #4
0
        public static Document Load(string filename)
        {
            using (var stream = File.OpenRead(filename))
            {
                var zipStream = new GZipStream(stream, CompressionMode.Decompress);
                using (var reader = new BinaryReader(zipStream))
                {
                    var documentVersion = reader.ReadInt32();
                    var width           = reader.ReadInt16();
                    var height          = reader.ReadInt16();
                    var layerCount      = reader.ReadInt16();

                    var layers = new List <Layer>(layerCount);
                    for (var i = 0; i < layerCount; i++)
                    {
                        var layer = new Layer(Guid.NewGuid(), width, height);
                        for (var x = 0; x < width; x++)
                        {
                            for (var y = 0; y < height; y++)
                            {
                                var glyph      = reader.ReadChar();
                                var background = GlyphColor.FromPacked(reader.ReadUInt32());
                                var foreground = GlyphColor.FromPacked(reader.ReadUInt32());
                                layer.Elements[x, y] = new DocumentElement
                                {
                                    Glyph      = glyph,
                                    Foreground = foreground,
                                    Background = background
                                };
                            }
                        }
                        layers.Add(layer);
                    }

                    var document = new Document(width, height, true, layers);

                    return(document);
                }
            }
        }
Example #5
0
 void IColorGlyphRenderer.SetColor(GlyphColor color)
 => this.currentColor = new Color(new Rgba32(color.Red, color.Green, color.Blue, color.Alpha));
Example #6
0
 internal GlyphVectorWithColor(GlyphVector vector, GlyphColor color)
 {
     this.Vector = vector;
     this.Color  = color;
 }
Example #7
0
 public ChangeForegroundColorCommand(GlyphColor color)
 {
     Color = color;
 }
 public static Color ToMonogameColor(this GlyphColor color)
 {
     return(new Color(color.R, color.G, color.B, color.A));
 }
Example #9
0
 public ForegroundColorChangedEvent(GlyphColor color)
 {
     Color = color;
 }
Example #10
0
 public BackgroundColorChangedEvent(GlyphColor color)
 {
     Color = color;
 }
Example #11
0
 public static Color ToWpfColor(this GlyphColor glyphColor)
 {
     return(Color.FromArgb(glyphColor.A, glyphColor.R, glyphColor.G, glyphColor.B));
 }
Example #12
0
 private void ChangeForegroundColor(GlyphColor color)
 {
     Brush.ForegroundColor = color;
 }
Example #13
0
 private void ChangeBackgroundColor(GlyphColor color)
 {
     Brush.BackgroundColor = color;
 }
Example #14
0
 public ChangeBackgroundColorCommand(GlyphColor color)
 {
     Color = color;
 }
Example #15
0
 private void ChangeBackgroundColor(GlyphColor color)
 {
     MessageBus.Publish(new BackgroundColorChangedEvent(color));
 }
 public void SetColor(GlyphColor color)
 {
     this.SetLayerColor(new Color(new Rgba32(color.Red, color.Green, color.Blue, color.Alpha)));
 }
 public void SetColor(GlyphColor color) => this.Colors.Add(color);
 public ColorButtonViewModel(GlyphColor glyphColor)
 {
     GlyphColor = glyphColor;
     Color      = glyphColor.ToWpfColor();
 }