public static void Write(BinaryWriter writer, ImageGrid grid)
        {
            if (grid == null)
            {
                writer.Write(false);
            }
            else
            {
                writer.Write(true);

                writer.Write(grid.Width);
                writer.Write(grid.Height);

                for (int x = 0; x < grid.Width; x++)
                {
                    for (int y = 0; y < grid.Height; y++)
                    {
                        IPaletteItem cell = grid[x, y];

                        if (cell == null)
                        {
                            writer.Write(false);
                        }
                        else
                        {
                            writer.Write(true);
                            writer.Write(cell.Color.ToArgb());
                        }
                    }
                }
            }
        }
Exemple #2
0
        public PaletteItemControl(
            IPaletteItem paletteItem)
        {
            InitializeComponent();
            this.label1.BackColor = paletteItem.Color;
            this.label1.Text      = paletteItem.Text;
            this.label1.ForeColor = ColorHelper.ContrastingColor(paletteItem.Color);
            this.Color            = paletteItem.Color;

            clickTimer.Tick += (s, e) =>
            {
                this.clickTimer.Enabled = false;
                this.PaletteItemClick?.Invoke(this, new PaletteItemClickEventArgs(false, this));
            };

            label1.DoubleClick += (s, e) =>
            {
                this.clickTimer.Enabled = false;
                this.PaletteItemDoubleClick?.Invoke(this, new PaletteItemClickEventArgs(true, this));
            };

            label1.MouseClick += (s, e) =>
            {
                if (e.Button == MouseButtons.Left)
                {
                    this.clickTimer.Enabled = true;
                }
            };
        }
Exemple #3
0
        /// <summary>
        /// Implementation of IComparable.CompareTo method.  For the sake of a palette item,
        /// two elements are equal when they have the same icon source and description.
        /// Note that this method isn't set up to do value comparisons (greater / less than)
        /// as that doesn't make sense in this context.
        /// </summary>
        /// <param name="obj">The other palette item used in the comparison</param>
        /// <returns></returns>
        public int CompareTo(object obj)
        {
            //if we're dealing with something that isn't the same class, then they're
            //definately not the same
            if (!(obj is IPaletteItem))
            {
                return(-1);
            }

            //as noted in the method header, the two objects are equal when their icon
            //sorce and descriptions match
            IPaletteItem otherPaletteItem = (IPaletteItem)obj;

            if (this.IconSource == otherPaletteItem.IconSource
                &&
                this.Description.CompareTo(otherPaletteItem.Description) == 0
                )
            {
                return(0);
            }
            else
            {
                return(-1);
            }
        }
Exemple #4
0
        public string GenerateTextPattern(TextPatternStart textPatternStart = TextPatternStart.BottomRight)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine($"Pattern starts {(textPatternStart == TextPatternStart.TopLeft ? "top left" : "bottom right")}");
            sb.AppendLine("Odd rows (1, 3 etc) are down rows");
            sb.AppendLine();

            int rowNumber = 1;

            foreach (List <IPaletteItem> row in GenerateRows(textPatternStart))
            {
                IPaletteItem lastColor      = null;
                int          lastColorCount = 0;

                Action <bool> appendColor = (includeComma) =>
                {
                    if (lastColorCount > 0)
                    {
                        string colorString = lastColor.Text;
                        sb.Append(lastColorCount);
                        sb.Append(colorString);
                        if (includeComma)
                        {
                            sb.Append(",");
                        }
                    }

                    lastColorCount = 0;
                };

                sb.Append(rowNumber++);
                sb.Append(":");
                sb.Append("\t");

                for (int i = 0; i < row.Count; i++)
                {
                    if (row[i] != lastColor)
                    {
                        appendColor(true);
                        lastColor = row[i];
                    }

                    lastColorCount++;
                }

                appendColor(false);
                sb.AppendFormat("({0})", row.Count);
                sb.AppendLine();
            }

            return(sb.ToString());
        }
Exemple #5
0
        private void HighlightItem(IPaletteItem item)
        {
            if (item.CompareTo(selectedItem) != 0)
            {
                //set the new selected item
                SelectedItem = item;

                //clear any current selection
                ClearSelection();

                //highlight current selection
                item.Selected = true;
            }
        }
Exemple #6
0
        public static string Show(IWin32Window owner, IPaletteItem paletteItem)
        {
            using (var form = new ColorNameForm())
            {
                form.BackColor     = paletteItem.Color;
                form.textBox1.Text = paletteItem.Text;

                if (form.ShowDialog(owner) == DialogResult.OK)
                {
                    return(form.textBox1.Text.Trim());
                }
            }

            return(null);
        }
        public static bool Load(Stream stream, Corner2CornerProject project)
        {
            using (BinaryReader reader = new BinaryReader(stream))
            {
                if (!HeaderPersistence.Read(reader))
                {
                    stream.Position = 0;
                    return(false);
                }

                Image image = ImagePersistence.Read(reader);
                int   width = reader.ReadInt32();

                int paletteItemCount         = reader.ReadInt32();
                Corner2CornerPalette palette = new Corner2CornerPalette();

                for (int i = 0; i < paletteItemCount; i++)
                {
                    var pi = PaletteItemPersistence.Read(reader);
                    palette.Add(color: pi.Color, text: pi.Text);
                }

                IPaletteItem selectedPaletteItem = PaletteItemPersistence.Read(reader);
                palette.Find(selectedPaletteItem?.Color ?? Color.Empty, out selectedPaletteItem);

                ImageGrid imageGrid = ImageGridPersistence.Read(reader, palette);

                Color gridBackgroundColor = Color.FromArgb(reader.ReadInt32());

                //read everything successfully so populate the project;

                project.Image               = image;
                project.Width               = width;
                project.Palette             = palette;
                project.SelectedPaletteItem = selectedPaletteItem;
                project.ImageGrid           = imageGrid;
                project.GridBackgroundColor = gridBackgroundColor;
                project.ChangeTracking.Track(ChangeTrackingOperation.SetSaved);

                return(true);
            }
        }
Exemple #8
0
        private void PopulatePalette()
        {
            this.palettePanel.Controls.Clear();

            List <PaletteItemControl> newControls = new List <PaletteItemControl>();

            foreach (IPaletteItem item in this.project.Palette)
            {
                PaletteItemControl paletteItemControl = new PaletteItemControl(item);
                paletteItemControl.Width             = this.palettePanel.ClientRectangle.Width - 4;
                paletteItemControl.PaletteItemClick += (s, e) => this.currentPaletteItem = e.PaletteItem;
                paletteItemControl.PaletteItemClick += (s, e) => this.undoRedoManager.Do(this.project.Commands.GetCommand(Corner2CornerCommand.SetSelectedPaletteItem));

                paletteItemControl.PaletteItemDoubleClick += (s, e) => this.currentPaletteItem = e.PaletteItem;
                paletteItemControl.PaletteItemDoubleClick += (s, e) => this.undoRedoManager.Do(this.project.Commands.GetCommand(Corner2CornerCommand.SetPaletteItemText));

                newControls.Add(paletteItemControl);
            }

            this.palettePanel.Controls.AddRange(newControls.ToArray());
        }
        public static void Write(BinaryWriter writer, IPaletteItem paletteItem)
        {
            if (paletteItem == null)
            {
                writer.Write(false);
            }
            else
            {
                writer.Write(true);
                writer.Write(paletteItem.Color.ToArgb());

                if (String.IsNullOrWhiteSpace(paletteItem.Text))
                {
                    writer.Write(false);
                }
                else
                {
                    writer.Write(true);
                    writer.Write(paletteItem.Text);
                }
            }
        }
Exemple #10
0
 public PaletteItem(IPaletteItem item = null, Color?color = null, string text = null)
 {
     this.Color = color ?? item?.Color ?? Color.Empty;
     this.Text  = text ?? item?.Text;
 }
Exemple #11
0
 public PaletteItemClickEventArgs(bool isDoubleClick, IPaletteItem paletteItem)
 {
     this.IsDoubleClick = IsDoubleClick;
     this.PaletteItem   = paletteItem;
 }
Exemple #12
0
 public bool GetPaletteItemText(IPaletteItem paletteItem, out string newText)
 {
     newText = ColorNameForm.Show(this, paletteItem);
     return(!string.IsNullOrWhiteSpace(newText));
 }
Exemple #13
0
 public bool GetCurrentPaletteItem(out IPaletteItem paletteItem)
 {
     paletteItem = this.currentPaletteItem;
     return(paletteItem != null);
 }