/// <summary>
        /// Creates the DB16 palette.
        /// </summary>
        /// <remarks>http://www.pixeljoint.com/forum/forum_posts.asp?TID=12795</remarks>
        /// <param name="pad">if set to <c>true</c> the palette is padded with black to fill 256 entries.</param>
        protected ColorCollection CreateDawnBringer16Palette(bool pad)
        {
            ColorCollection results;

            results = new ColorCollection();

            results.Add(Color.FromArgb(20, 12, 28));
            results.Add(Color.FromArgb(68, 36, 52));
            results.Add(Color.FromArgb(48, 52, 109));
            results.Add(Color.FromArgb(78, 74, 78));
            results.Add(Color.FromArgb(133, 76, 48));
            results.Add(Color.FromArgb(52, 101, 36));
            results.Add(Color.FromArgb(208, 70, 72));
            results.Add(Color.FromArgb(117, 113, 97));
            results.Add(Color.FromArgb(89, 125, 206));
            results.Add(Color.FromArgb(210, 125, 44));
            results.Add(Color.FromArgb(133, 149, 161));
            results.Add(Color.FromArgb(109, 170, 44));
            results.Add(Color.FromArgb(210, 170, 153));
            results.Add(Color.FromArgb(109, 194, 202));
            results.Add(Color.FromArgb(218, 212, 94));
            results.Add(Color.FromArgb(222, 238, 214));

            if (pad)
            {
                while (results.Count < 256)
                {
                    results.Add(Color.FromArgb(0, 0, 0));
                }
            }

            return(results);
        }
Exemplo n.º 2
0
 protected ColorGrid(ColorCollection colors, ColorCollection customColors, ColorPalette palette)
 {
     _cellBackground = Resources.cellbackground;
     _cellBackgroundBrush = new TextureBrush(_cellBackground, WrapMode.Tile);
     SetStyle(
         ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer |
         ControlStyles.Selectable | ControlStyles.StandardClick | ControlStyles.StandardDoubleClick |
         ControlStyles.SupportsTransparentBackColor, true);
     HotIndex = InvalidIndex;
     ColorRegions = new Dictionary<int, Rectangle>();
     if (Palette != ColorPalette.None)
         Colors = colors;
     else
         Palette = palette;
     CustomColors = customColors;
     ShowCustomColors = true;
     CellSize = new Size(12, 12);
     Spacing = new Size(3, 3);
     Columns = 16;
     AutoSize = true;
     Padding = new Padding(5);
     AutoAddColors = true;
     CellBorderColor = SystemColors.ButtonShadow;
     ShowToolTips = true;
     SeparatorHeight = 8;
     EditMode = ColorEditingMode.CustomOnly;
     Color = Color.Black;
     CellBorderStyle = ColorCellBorderStyle.FixedSingle;
     SelectedCellStyle = ColorGridSelectedCellStyle.Zoomed;
 }
Exemplo n.º 3
0
#pragma warning restore CS0649

        public TrainStyleForm(IPluginInterface pluginInterface)
        {
            this.pluginInterface = pluginInterface;
            var tt    = pluginInterface.Timetable;
            var attrs = new TimetableStyle(tt);

            backupHandle = pluginInterface.BackupTimetable();

            Eto.Serialization.Xaml.XamlReader.Load(this);

            var cc = new ColorCollection(pluginInterface.Settings);
            var ds = new DashStyleHelper();

            var lineWidths = Enumerable.Range(1, 5).Cast <object>().ToArray();

            gridView.AddColumn <TrainStyle>(t => t.Train.TName, "Zugnummer");
            gridView.AddDropDownColumn <TrainStyle>(t => t.HexColor, cc.ColorHexStrings, EtoBindingExtensions.ColorBinding(cc), "Farbe", true);
            gridView.AddDropDownColumn <TrainStyle>(t => t.TrainWidthInt, lineWidths, Binding.Delegate <int, string>(i => i.ToString()), "Linienstärke", true);
            gridView.AddDropDownColumn <TrainStyle>(t => t.LineStyle, ds.Indices.Cast <object>(), Binding.Delegate <int, string>(i => ds.GetDescription(i)), "Linientyp", true);
            gridView.AddCheckColumn <TrainStyle>(t => t.Show, "Zug zeichnen", true);

            gridView.DataStore = tt.Trains.Select(t => new TrainStyle(t, attrs));

            this.AddCloseHandler();
        }
Exemplo n.º 4
0
        private void PopulateCollectionColors(ColorCollection Collection)
        {
            listViewColors.BeginUpdate();
            listViewColors.Items.Clear();

            listViewColors.LargeImageList            = new ImageList();
            listViewColors.LargeImageList.ColorDepth = ColorDepth.Depth32Bit;
            listViewColors.LargeImageList.ImageSize  = new Size(48, 48);

            foreach (Color ColorItem in Collection.Color)
            {
                Bitmap   result = new Bitmap(48, 48);
                Graphics gfx    = Graphics.FromImage(result);
                using (SolidBrush brush = new SolidBrush(ColorItem))
                {
                    gfx.FillRectangle(brush, 0, 0, 48, 48);
                    gfx.DrawRectangle(new Pen(Color.Black, 2), 0, 0, 48, 48);
                }

                listViewColors.LargeImageList.Images.Add(ColorItem.ToString(), result);

                ListViewItem item = new ListViewItem();
                //item.Text = ColorItem.Name;
                item.ToolTipText = string.Format("R: {0} G: {1} B: {2}", ColorItem.R, ColorItem.G, ColorItem.B);

                item.ImageKey = ColorItem.ToString();
                item.Tag      = ColorItem;
                listViewColors.Items.Add(item);
            }
            listViewColors.EndUpdate();
            btnAddColor.Enabled = true;
        }
Exemplo n.º 5
0
        private void ScratchForm_Load(object sender, EventArgs e)
        {
            string          fileName;
            ColorCollection source;
            ColorCollection destination;
            AdobePhotoshopColorSwatchSerializer serializer;

            fileName = Path.GetTempFileName();
            //source = ColorCollection.LoadPalette(Path.Combine(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "palettes"), "grayscale.pal"));
            source     = ColorCollection.LoadPalette(Path.Combine(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "palettes"), "db32.gpl"));
            serializer = new AdobePhotoshopColorSwatchSerializer();

            using (Stream stream = File.Create(fileName))
            {
                serializer.Serialize(stream, source, AdobePhotoshopColorSwatchColorSpace.Hsb);
                //serializer.Serialize(stream, source, AdobePhotoShopColorSwatchColorSpace.Grayscale);
            }

            destination = ColorCollection.LoadPalette(fileName);

            colorGrid1.Colors = source;
            colorGrid2.Colors = destination;

            File.Delete(fileName);
        }
        /// <summary>
        ///     Deserializes the <see cref="ColorCollection" /> contained by the specified <see cref="Stream" />.
        /// </summary>
        /// <param name="stream">The <see cref="Stream" /> that contains the palette to deserialize.</param>
        /// <returns>The <see cref="ColorCollection" /> being deserialized..</returns>
        public override ColorCollection Deserialize(Stream stream)
        {
            ColorCollection results;

            if (stream == null)
                throw new ArgumentNullException("stream");

            results = new ColorCollection();

            using (var reader = new StreamReader(stream))
            {
                while (!reader.EndOfStream)
                {
                    string line;

                    line = reader.ReadLine();
                    if (!string.IsNullOrEmpty(line) && !line.StartsWith(";") && line.Length == 8)
                    {
                        int a;
                        int r;
                        int g;
                        int b;

                        a = int.Parse(line.Substring(0, 2), NumberStyles.HexNumber);
                        r = int.Parse(line.Substring(2, 2), NumberStyles.HexNumber);
                        g = int.Parse(line.Substring(4, 2), NumberStyles.HexNumber);
                        b = int.Parse(line.Substring(6, 2), NumberStyles.HexNumber);

                        results.Add(Color.FromArgb(a, r, g, b));
                    }
                }
            }

            return results;
        }
Exemplo n.º 7
0
            void OnCalendarViewDayItemChanging(object sender,
                                               CalendarViewDayItemChangingEventArgs e)
            {
                // phase 2: set density bar
                // phase 5: blackout
                // phase 7: end cic event

                if (e.Phase == 2)
                {
                    ColorCollection colors = new ColorCollection();
                    colors.Append(Colors.Red);
                    colors.Append(Colors.Green);
                    colors.Append(Colors.Blue);
                    colors.Append(Colors.Yellow);
                    e.Item.SetDensityColors(colors);
                }
                else if (e.Phase == 5)
                {
                    e.Item.IsBlackout = true;
                }
                else if (e.Phase == 7)
                {
                    m_cicEvent.Set();
                }

                // keep subscribing cic event until phase 7.
                if (e.Phase < 7)
                {
                    e.RegisterUpdateCallback(
                        (sender, e) =>
                    {
                        OnCalendarViewDayItemChanging(sender, e);
                    });
                }
            }
Exemplo n.º 8
0
 private void comboBoxCollections_SelectedIndexChanged(object sender, EventArgs e)
 {
     _currentCollection             = (ColorCollection)comboBoxCollections.SelectedItem;
     textBoxDescription.Text        = _currentCollection.Description;
     buttonDeleteCollection.Enabled = textBoxDescription.Enabled = true;
     PopulateCollectionColors(_currentCollection);
 }
Exemplo n.º 9
0
        private void PopulateCollectionColors(ColorCollection collection)
        {
            listViewColors.BeginUpdate();
            listViewColors.Items.Clear();

            listViewColors.LargeImageList            = new ImageList();
            listViewColors.LargeImageList.ColorDepth = ColorDepth.Depth32Bit;
            listViewColors.LargeImageList.ImageSize  = new Size(48, 48);

            foreach (Color colorItem in collection.Color)
            {
                Bitmap   result = new Bitmap(48, 48);
                Graphics gfx    = Graphics.FromImage(result);
                using (SolidBrush brush = new SolidBrush(colorItem))
                {
                    gfx.FillRectangle(brush, 0, 0, 48, 48);
                    gfx.DrawRectangle(_borderPen, 0, 0, 48, 48);
                }

                listViewColors.LargeImageList.Images.Add(colorItem.ToString(), result);

                ListViewItem item = new ListViewItem
                {
                    ToolTipText = string.Format("R: {0} G: {1} B: {2}", colorItem.R, colorItem.G, colorItem.B),
                    ImageKey    = colorItem.ToString(),
                    Tag         = colorItem
                };

                listViewColors.Items.Add(item);
            }
            listViewColors.EndUpdate();
            buttonAddColor.Enabled = true;
        }
        /// <summary>
        /// Deserializes the <see cref="ColorCollection" /> contained by the specified <see cref="Stream" />.
        /// </summary>
        /// <param name="stream">The <see cref="Stream" /> that contains the palette to deserialize.</param>
        /// <returns>The <see cref="ColorCollection" /> being deserialized.</returns>
        public override ColorCollection Deserialize(Stream stream)
        {
            ColorCollection results;

              if (stream == null)
              {
            throw new ArgumentNullException("stream");
              }

              results = new ColorCollection();

              for (int i = 0; i < stream.Length / 3; i++)
              {
            int r;
            int g;
            int b;

            r = stream.ReadByte();
            g = stream.ReadByte();
            b = stream.ReadByte();

            results.Add(Color.FromArgb(r, g, b));
              }

              return results;
        }
Exemplo n.º 11
0
 private void palettesListBox_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (palettesListBox.SelectedIndex != -1)
     {
         colorGrid.Colors = ColorCollection.LoadPalette(Path.Combine(this.PalettePath, palettesListBox.SelectedItem.ToString()));
     }
 }
    /// <summary>
    /// Serializes the specified <see cref="ColorCollection" /> and writes the palette to a file using the specified <see cref="Stream" />.
    /// </summary>
    /// <param name="stream">The <see cref="Stream" /> used to write the palette.</param>
    /// <param name="palette">The <see cref="ColorCollection" /> to serialize.</param>
    public override void Serialize(Stream stream, ColorCollection palette)
    {
      if (stream == null)
        throw new ArgumentNullException("stream");

      if (palette == null)
        throw new ArgumentNullException("palette");

      // TODO: Allow name and columns attributes to be specified

      using (StreamWriter writer = new StreamWriter(stream, Encoding.UTF8))
      {
        writer.WriteLine("GIMP Palette");
        writer.WriteLine("Name: ");
        writer.WriteLine("Columns: 8");
        writer.WriteLine("#");
        foreach (Color color in palette)
        {
          writer.Write("{0,-3} ", color.R);
          writer.Write("{0,-3} ", color.G);
          writer.Write("{0,-3} ", color.B);
          if (color.IsNamedColor)
            writer.Write(color.Name);
          else
            writer.Write("#{0:X2}{1:X2}{2:X2}", color.R, color.G, color.B);
          writer.WriteLine();
        }
      }
    }
Exemplo n.º 13
0
 public HueColorSlider()
 {
     BarStyle = ColorBarStyle.Custom;
     Maximum = 359;
     CustomColors =
         new ColorCollection(Enumerable.Range(0, 359).Select(h => new HslColor(h, 1, 0.5).ToRgbColor()));
 }
    /// <summary>
    /// Creates the DB16 palette.
    /// </summary>
    /// <remarks>http://www.pixeljoint.com/forum/forum_posts.asp?TID=12795</remarks>
    /// <param name="pad">if set to <c>true</c> the palette is padded with black to fill 256 entries.</param>
    protected ColorCollection CreateDawnBringer16Palette(bool pad)
    {
      ColorCollection results;

      results = new ColorCollection();

      results.Add(Color.FromArgb(20, 12, 28));
      results.Add(Color.FromArgb(68, 36, 52));
      results.Add(Color.FromArgb(48, 52, 109));
      results.Add(Color.FromArgb(78, 74, 78));
      results.Add(Color.FromArgb(133, 76, 48));
      results.Add(Color.FromArgb(52, 101, 36));
      results.Add(Color.FromArgb(208, 70, 72));
      results.Add(Color.FromArgb(117, 113, 97));
      results.Add(Color.FromArgb(89, 125, 206));
      results.Add(Color.FromArgb(210, 125, 44));
      results.Add(Color.FromArgb(133, 149, 161));
      results.Add(Color.FromArgb(109, 170, 44));
      results.Add(Color.FromArgb(210, 170, 153));
      results.Add(Color.FromArgb(109, 194, 202));
      results.Add(Color.FromArgb(218, 212, 94));
      results.Add(Color.FromArgb(222, 238, 214));

      if (pad)
      {
        while (results.Count < 256)
        {
          results.Add(Color.FromArgb(0, 0, 0));
        }
      }

      return results;
    }
Exemplo n.º 15
0
    public void ChangeLiquidColor(ItemData itemdata)
    {
        Color localColor = m_image.color;
        Color itemColor  = ColorCollection.HexToColor(itemdata.itemColor);
        Color newColor   = ColorCollection.ColorMix(localColor, itemColor);

        m_image.color = newColor;
    }
    // Use this for initialization
    void Start()
    {
        colors = GetComponent <ColorCollection>();

        argsBuffer = new ComputeBuffer(1, args.Length * sizeof(uint), ComputeBufferType.IndirectArguments);

        UpdateBuffers();
    }
Exemplo n.º 17
0
        private void GenerateColumns()
        {
            DataGridViewColumn col = new DataGridViewTextBoxColumn();

            col.DataPropertyName = "Name";
            col.HeaderText       = "Group Name";
            dgvLevels.Columns.Add(col);

            col                  = new DataGridViewTextBoxColumn();
            col.HeaderText       = "ID";
            col.DataPropertyName = "ID";
            dgvLevels.Columns.Add(col);

            col                  = new DataGridViewTextBoxColumn();
            col.HeaderText       = "Block Level";
            col.DataPropertyName = "BlockLevel";
            dgvLevels.Columns.Add(col);

            col                  = new DataGridViewComboBoxColumn();
            col.HeaderText       = "Color Char";
            col.DataPropertyName = "GroupColor";
            (col as DataGridViewComboBoxColumn).DisplayMember = "Name";
            (col as DataGridViewComboBoxColumn).ValueMember   = "Key";
            (col as DataGridViewComboBoxColumn).DataSource    = ColorCollection.GetInstance().Items;
            dgvLevels.Columns.Add(col);

            col                  = new DataGridViewCheckBoxColumn();
            col.HeaderText       = "Allow Destroy";
            col.DataPropertyName = "AllowDestroy";
            dgvLevels.Columns.Add(col);

            col = new DataGridViewCheckBoxColumn();

            col.HeaderText       = "Allow Build";
            col.DataPropertyName = "AllowBuild";
            dgvLevels.Columns.Add(col);

            col = new DataGridViewCheckBoxColumn();

            col.HeaderText       = "Allow Chat";
            col.DataPropertyName = "AllowChat";
            dgvLevels.Columns.Add(col);

            //col = new DataGridViewCheckBoxColumn();
            //col.HeaderText = "Instant Destroy";
            //col.DataPropertyName = "InstantDestroy";
            //dgvLevels.Columns.Add(col);

            col                  = new DataGridViewCheckBoxColumn();
            col.HeaderText       = "Self Response";
            col.DataPropertyName = "OwnExecuteResponse";
            dgvLevels.Columns.Add(col);

            col                  = new DataGridViewCheckBoxColumn();
            col.HeaderText       = "Other Response";
            col.DataPropertyName = "OtherExecuteResponse";
            dgvLevels.Columns.Add(col);
        }
Exemplo n.º 18
0
        private void MouseEvent(Point p)
        {
            var col = GetColorByPos((int)p.X, (int)p.Y, (int)ActualWidth, ColorCollection.ToArray());

            if (!col.Equals(SelectedColor))
            {
                SelectedColor = col;
            }
        }
Exemplo n.º 19
0
        public static void Color <T>(ISettings settings, DropDown dropDown, string property)
        {
            var cc = new ColorCollection(settings);

            var p = GetProperty <T>(property);

            dropDown.ItemTextBinding = EtoBindingExtensions.ColorBinding(cc);
            dropDown.DataStore       = cc.ColorHexStrings;
            dropDown.SelectedValueBinding.BindDataContext <T>(a => ColorFormatter.ToString((MColor)p.GetValue(a) !),
                                                              (a, val) => p.SetValue(a, ColorFormatter.FromHexString((string)val)));
        }
Exemplo n.º 20
0
 public void OnPointerUp(BaseEventData eventData)
 {
     if (!isAllowDrag)
     {
         return;
     }
     m_rect.localScale    = normalScale;
     m_rect.localPosition = itemOriginPos;
     dragPos       = itemOriginPos;
     m_image.color = ColorCollection.GetVecClear();
 }
        public ColorPickerButton()
        {
            AutoAddColors = false;

            Columns          = 1;
            EditMode         = ColorEditingMode.None;
            ShowCustomColors = false;

            Colors = new ColorCollection(new[] { Color.HotPink });

            MouseDoubleClick += ThisOnMouseClick;
        }
Exemplo n.º 22
0
 public void ChangeBindItem(CraftItem binditem, Sprite spr)
 {
     bindItem = binditem;
     try {
         //m_image.sprite = spr;
         UICollection.SetImage(bindItem.GetComponent <Image>().sprite, m_image);
         m_image.color = ColorCollection.GetVecClear();
     }
     catch (Exception e) {
         Debug.Log("这里的报错应该是因为Awake事件还未执行造成");
         Debug.Log(e);
     }
 }
Exemplo n.º 23
0
 // Start is called before the first frame update
 void Awake()
 {
     //得到自己的必要组件
     m_rect  = GetComponent <RectTransform>();
     m_image = GetComponent <Image>();
     //设置拖动部件初始不可见
     //m_image.sprite = bindItem.GetComponent<Image>().sprite;
     UICollection.SetImage(bindItem.GetComponent <Image>().sprite, m_image);
     m_image.color = ColorCollection.GetVecClear();
     //设置用于拖动逻辑的坐标
     itemOriginPos = m_rect.localPosition;
     dragPos       = itemOriginPos;
 }
Exemplo n.º 24
0
        //This function, as the name suggests; shuffles the colors in it's collection
        private ColorCollection shuffle(ColorCollection input)
        {
            ColorCollection shuffledCollection = input;

            for (int i = 0; i < shuffledCollection.Count; i++)
            {
                Color tmp         = shuffledCollection[i];
                int   randomIndex = Random.Range(i, shuffledCollection.Count);
                shuffledCollection[i]           = shuffledCollection[randomIndex];
                shuffledCollection[randomIndex] = tmp;
            }
            return(shuffledCollection);
        }
        /// <summary>
        ///     Deserializes the <see cref="ColorCollection" /> contained by the specified <see cref="Stream" />.
        /// </summary>
        /// <param name="stream">The <see cref="Stream" /> that contains the palette to deserialize.</param>
        /// <returns>The <see cref="ColorCollection" /> being deserialized..</returns>
        public override ColorCollection Deserialize(Stream stream)
        {
            ColorCollection results;

            if (stream == null)
                throw new ArgumentNullException("stream");

            results = new ColorCollection();

            using (var reader = new StreamReader(stream))
            {
                string header;
                string startHeader;

                // check signature
                header = reader.ReadLine();
                startHeader = reader.ReadLine();

                if (header != "GIMP Palette")
                    throw new InvalidDataException("Invalid palette file");

                while (startHeader != "#")
                    startHeader = reader.ReadLine();

                while (!reader.EndOfStream)
                {
                    int r;
                    int g;
                    int b;
                    string data;
                    string[] parts;

                    data = reader.ReadLine();
                    parts = !string.IsNullOrEmpty(data)
                        ? data.Split(new[]
                        {
                            ' ', '\t'
                        }, StringSplitOptions.RemoveEmptyEntries)
                        : new string[0];

                    if (!int.TryParse(parts[0], out r) || !int.TryParse(parts[1], out g) ||
                        !int.TryParse(parts[2], out b))
                        throw new InvalidDataException(string.Format("Invalid palette contents found with data '{0}'",
                            data));

                    results.Add(Color.FromArgb(r, g, b));
                }
            }

            return results;
        }
Exemplo n.º 26
0
        public void EqualsNullTest()
        {
            // arrange
            ColorCollection target;
            bool            actual;

            target = new ColorCollection();

            // act
            actual = target.Equals(null);

            // assert
            actual.Should().BeFalse();
        }
Exemplo n.º 27
0
        protected override void OnRender(DrawingContext drawingContext)
        {
            base.OnRender(drawingContext);
            var colorArray = ColorCollection.ToArray();

            for (var i = 0; i < ActualWidth; i++)
            {
                var upperPen = new Pen(new SolidColorBrush(GetColorByPos(i, 0, (int)ActualWidth, colorArray)), 1);
                drawingContext.DrawLine(upperPen, new Point(i, 0), new Point(i, (int)ActualHeight / 2));
                var lowerPen = new Pen(
                    new SolidColorBrush(colorArray[GetColorNumber(i, (int)ActualWidth, colorArray)]), 1);
                drawingContext.DrawLine(lowerPen, new Point(i, (int)ActualHeight / 2), new Point(i, (int)ActualHeight));
            }
        }
    public void EqualsNullTest()
    {
      // arrange
      ColorCollection target;
      bool actual;

      target = new ColorCollection();

      // act
      actual = target.Equals(null);

      // assert
      actual.Should().BeFalse();
    }
        /// <summary>
        ///     Deserializes the <see cref="ColorCollection" /> contained by the specified <see cref="Stream" />.
        /// </summary>
        /// <param name="stream">The <see cref="Stream" /> that contains the palette to deserialize.</param>
        /// <returns>The <see cref="ColorCollection" /> being deserialized..</returns>
        public override ColorCollection Deserialize(Stream stream)
        {
            ColorCollection results;

            if (stream == null)
                throw new ArgumentNullException("stream");

            results = new ColorCollection();

            using (var reader = new StreamReader(stream))
            {
                string header;
                string version;
                int colorCount;

                // check signature
                header = reader.ReadLine();
                version = reader.ReadLine();

                if (header != "JASC-PAL" || version != "0100")
                    throw new InvalidDataException("Invalid palette file");

                colorCount = Convert.ToInt32(reader.ReadLine());
                for (int i = 0; i < colorCount; i++)
                {
                    int r;
                    int g;
                    int b;
                    string data;
                    string[] parts;

                    data = reader.ReadLine();
                    parts = !string.IsNullOrEmpty(data)
                        ? data.Split(new[]
                        {
                            ' ', '\t'
                        }, StringSplitOptions.RemoveEmptyEntries)
                        : new string[0];

                    if (!int.TryParse(parts[0], out r) || !int.TryParse(parts[1], out g) ||
                        !int.TryParse(parts[2], out b))
                        throw new InvalidDataException(string.Format("Invalid palette contents found with data '{0}'",
                            data));

                    results.Add(Color.FromArgb(r, g, b));
                }
            }

            return results;
        }
Exemplo n.º 30
0
        /// <summary>
        /// Creates the DB32 palette.
        /// </summary>
        /// <remarks>http://www.pixeljoint.com/forum/forum_posts.asp?TID=16247</remarks>
        /// <param name="pad">if set to <c>true</c> the palette is padded with black to fill 256 entries.</param>
        protected ColorCollection CreateDawnBringer32Palette(bool pad)
        {
            ColorCollection results;

            results = new ColorCollection();

            results.Add(Color.FromArgb(0, 0, 0));
            results.Add(Color.FromArgb(34, 32, 52));
            results.Add(Color.FromArgb(69, 40, 60));
            results.Add(Color.FromArgb(102, 57, 49));
            results.Add(Color.FromArgb(143, 86, 59));
            results.Add(Color.FromArgb(223, 113, 38));
            results.Add(Color.FromArgb(217, 160, 102));
            results.Add(Color.FromArgb(238, 195, 154));
            results.Add(Color.FromArgb(251, 242, 54));
            results.Add(Color.FromArgb(153, 229, 80));
            results.Add(Color.FromArgb(106, 190, 48));
            results.Add(Color.FromArgb(55, 148, 110));
            results.Add(Color.FromArgb(75, 105, 47));
            results.Add(Color.FromArgb(82, 75, 36));
            results.Add(Color.FromArgb(50, 60, 57));
            results.Add(Color.FromArgb(63, 63, 116));
            results.Add(Color.FromArgb(48, 96, 130));
            results.Add(Color.FromArgb(91, 110, 225));
            results.Add(Color.FromArgb(99, 155, 255));
            results.Add(Color.FromArgb(95, 205, 228));
            results.Add(Color.FromArgb(203, 219, 252));
            results.Add(Color.FromArgb(255, 255, 255));
            results.Add(Color.FromArgb(155, 173, 183));
            results.Add(Color.FromArgb(132, 126, 135));
            results.Add(Color.FromArgb(105, 106, 106));
            results.Add(Color.FromArgb(89, 86, 82));
            results.Add(Color.FromArgb(118, 66, 138));
            results.Add(Color.FromArgb(172, 50, 50));
            results.Add(Color.FromArgb(217, 87, 99));
            results.Add(Color.FromArgb(215, 123, 186));
            results.Add(Color.FromArgb(143, 151, 74));
            results.Add(Color.FromArgb(138, 111, 48));

            if (pad)
            {
                while (results.Count < 256)
                {
                    results.Add(Color.FromArgb(0, 0, 0));
                }
            }

            return(results);
        }
    /// <summary>
    /// Creates the DB32 palette.
    /// </summary>
    /// <remarks>http://www.pixeljoint.com/forum/forum_posts.asp?TID=16247</remarks>
    /// <param name="pad">if set to <c>true</c> the palette is padded with black to fill 256 entries.</param>
    protected ColorCollection CreateDawnBringer32Palette(bool pad)
    {
      ColorCollection results;

      results = new ColorCollection();

      results.Add(Color.FromArgb(0, 0, 0));
      results.Add(Color.FromArgb(34, 32, 52));
      results.Add(Color.FromArgb(69, 40, 60));
      results.Add(Color.FromArgb(102, 57, 49));
      results.Add(Color.FromArgb(143, 86, 59));
      results.Add(Color.FromArgb(223, 113, 38));
      results.Add(Color.FromArgb(217, 160, 102));
      results.Add(Color.FromArgb(238, 195, 154));
      results.Add(Color.FromArgb(251, 242, 54));
      results.Add(Color.FromArgb(153, 229, 80));
      results.Add(Color.FromArgb(106, 190, 48));
      results.Add(Color.FromArgb(55, 148, 110));
      results.Add(Color.FromArgb(75, 105, 47));
      results.Add(Color.FromArgb(82, 75, 36));
      results.Add(Color.FromArgb(50, 60, 57));
      results.Add(Color.FromArgb(63, 63, 116));
      results.Add(Color.FromArgb(48, 96, 130));
      results.Add(Color.FromArgb(91, 110, 225));
      results.Add(Color.FromArgb(99, 155, 255));
      results.Add(Color.FromArgb(95, 205, 228));
      results.Add(Color.FromArgb(203, 219, 252));
      results.Add(Color.FromArgb(255, 255, 255));
      results.Add(Color.FromArgb(155, 173, 183));
      results.Add(Color.FromArgb(132, 126, 135));
      results.Add(Color.FromArgb(105, 106, 106));
      results.Add(Color.FromArgb(89, 86, 82));
      results.Add(Color.FromArgb(118, 66, 138));
      results.Add(Color.FromArgb(172, 50, 50));
      results.Add(Color.FromArgb(217, 87, 99));
      results.Add(Color.FromArgb(215, 123, 186));
      results.Add(Color.FromArgb(143, 151, 74));
      results.Add(Color.FromArgb(138, 111, 48));

      if (pad)
      {
        while (results.Count < 256)
        {
          results.Add(Color.FromArgb(0, 0, 0));
        }
      }

      return results;
    }
Exemplo n.º 32
0
#pragma warning restore CS0649

        private TrainColorEditForm(ISettings settings)
        {
            Eto.Serialization.Xaml.XamlReader.Load(this);

            cc = new ColorCollection(settings);
            ds = new DashStyleHelper();

            colorComboBox.DataStore       = cc.ColorHexStrings;
            colorComboBox.ItemTextBinding = Shared.UI.ExtBind.ColorBinding(cc);

            widthComboBox.DataStore       = Enumerable.Range(1, 5).Cast <object>();
            widthComboBox.ItemTextBinding = Binding.Property <int, string>(c => c.ToString());

            dashComboBox.DataStore       = ds.Indices.Cast <object>();
            dashComboBox.ItemTextBinding = Binding.Property <int, string>(i => ds.GetDescription(i));
        }
Exemplo n.º 33
0
        public void EqualsObjectTest()
        {
            // arrange
            ColorCollection target;
            object          other;
            bool            actual;

            target = new ColorCollection();
            other  = target;

            // act
            actual = target.Equals(other);

            // assert
            actual.Should().BeTrue();
        }
Exemplo n.º 34
0
 public void OnPointerDown(BaseEventData eventData)
 {
     if (!isAllowDrag)
     {
         return;
     }
     //Debug.Log("被点击了");
     //Debug.Log("鼠标位置:" + Input.mousePosition);
     //Debug.Log("localPosition:" + m_rect.localPosition);
     //Debug.Log("anchoredPosition:" + m_rect.anchoredPosition);
     //Debug.Log("Position:" + m_rect.position);
     FxCollection.PlayLowFx();
     m_image.color     = ColorCollection.GetVecNormal();
     m_rect.localScale = smallScale;
     mouseOriginPos    = Input.mousePosition;
 }
Exemplo n.º 35
0
    private void Awake()
    {
        //场景重新加载时,之前的第一个block索引没被删除,造成第二次启动时应该为头的block成了列表中的第二个,而且
        //第一个是null,所以判断一下
        if (blockTextList.Count == 1 && blockTextList[0] == null)
        {
            blockTextList.Clear();
        }
        Debug.Log("执行");
        m_rect = GetComponent <RectTransform>();
        m_text = GetComponent <Text>();
        blockTextList.Add(this);
        m_index = blockTextList.Count - 1;

        m_text.color = ColorCollection.GetRandomGoodColor();
    }
Exemplo n.º 36
0
        public void EqualsSameReferenceTest()
        {
            // arrange
            ColorCollection target;
            ColorCollection other;
            bool            actual;

            target = new ColorCollection();
            other  = target;

            // act
            actual = other == target;

            // assert
            actual.Should().BeTrue();
            ((object)other).Should().BeSameAs(target);
        }
Exemplo n.º 37
0
        private void colorHandle()
        {
            LinearScale linearScale = new LinearScale();

            linearScale.MinimumValue = 0;
            linearScale.MaximumValue = 100;

            ColorCollection colors = new ColorCollection();

            colors.Add(System.Windows.Media.Colors.Blue);
            colors.Add(System.Windows.Media.Colors.Pink);
            colors.Add(System.Windows.Media.Colors.Red);


            linearScale.Colors = colors;

            SetColors = linearScale;
        }
Exemplo n.º 38
0
        public void FindTest()
        {
            // arrange
            ColorCollection target;
            int             expected;
            int             actual;

            target = new ColorCollection();
            target.Add(Color.Black);
            target.Add(Color.CornflowerBlue);
            target.Add(Color.Violet);
            expected = 1;

            // act
            actual = target.Find(Color.FromArgb(100, 149, 237));

            // assert
            actual.Should().Be(expected);
        }
Exemplo n.º 39
0
        public void FindNegativeTest()
        {
            // arrange
            ColorCollection target;
            int             expected;
            int             actual;

            target = new ColorCollection();
            target.Add(Color.Black);
            target.Add(Color.CornflowerBlue);
            target.Add(Color.Violet);
            expected = -1;

            // act
            actual = target.Find(Color.Yellow);

            // assert
            actual.Should().Be(expected);
        }
Exemplo n.º 40
0
        public void FindIgnoreAlphaNegativeTest()
        {
            // arrange
            ColorCollection target;
            int             expected;
            int             actual;

            target = new ColorCollection();
            target.Add(Color.Black);
            target.Add(Color.CornflowerBlue);
            target.Add(Color.Violet);
            expected = -1;

            // act
            actual = target.Find(Color.FromArgb(128, Color.CornflowerBlue), false);

            // assert
            actual.Should().Be(expected);
        }
    /// <summary>
    /// Serializes the specified <see cref="ColorCollection" /> and writes the palette to a file using the specified <see cref="Stream" />.
    /// </summary>
    /// <param name="stream">The <see cref="Stream" /> used to write the palette.</param>
    /// <param name="palette">The <see cref="ColorCollection" /> to serialize.</param>
    public override void Serialize(Stream stream, ColorCollection palette)
    {
      if (stream == null)
        throw new ArgumentNullException("stream");

      if (palette == null)
        throw new ArgumentNullException("palette");

      using (StreamWriter writer = new StreamWriter(stream, Encoding.UTF8))
      {
        writer.WriteLine("JASC-PAL");
        writer.WriteLine("0100");
        writer.WriteLine(palette.Count);
        foreach (Color color in palette)
        {
          writer.Write("{0} ", color.R);
          writer.Write("{0} ", color.G);
          writer.Write("{0} ", color.B);
          writer.WriteLine();
        }
      }
    }
    /// <summary>
    /// Serializes the specified <see cref="ColorCollection" /> and writes the palette to a file using the specified <see cref="Stream" />.
    /// </summary>
    /// <param name="stream">The <see cref="Stream" /> used to write the palette.</param>
    /// <param name="palette">The <see cref="ColorCollection" /> to serialize.</param>
    public override void Serialize(Stream stream, ColorCollection palette)
    {
      if (stream == null)
        throw new ArgumentNullException("stream");

      if (palette == null)
        throw new ArgumentNullException("palette");

      // TODO: Not writing 96 colors, but the entire contents of the palette, wether that's less than 96 or more

      using (StreamWriter writer = new StreamWriter(stream, Encoding.UTF8))
      {
        writer.WriteLine(@"; Paint.NET Palette File
; Lines that start with a semicolon are comments
; Colors are written as 8-digit hexadecimal numbers: aarrggbb
; For example, this would specify green: FF00FF00
; The alpha ('aa') value specifies how transparent a color is. FF is fully opaque, 00 is fully transparent.
; A palette must consist of ninety six (96) colors. If there are less than this, the remaining color
; slots will be set to white (FFFFFFFF). If there are more, then the remaining colors will be ignored.");
        foreach (Color color in palette)
          writer.WriteLine("{0:X2}{1:X2}{2:X2}{3:X2}", color.A, color.R, color.G, color.B);
      }
    }
Exemplo n.º 43
0
 protected ColorGrid(ColorCollection colors, ColorCollection customColors, ColorPalette palette)
 {
     this.BeginUpdate();
       this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.Selectable | ControlStyles.StandardClick | ControlStyles.StandardDoubleClick | ControlStyles.SupportsTransparentBackColor, true);
       _previousHotIndex = InvalidIndex;
       _previousColorIndex = InvalidIndex;
       _hotIndex = InvalidIndex;
       this.ColorRegions = new Dictionary<int, Rectangle>();
       if (this.Palette != ColorPalette.None)
       {
     this.Colors = colors;
       }
       else
       {
     this.Palette = palette;
       }
       this.CustomColors = customColors;
       this.ShowCustomColors = true;
       this.CellSize = new Size(12, 12);
       this.Spacing = new Size(3, 3);
       this.Columns = 16;
       this.AutoSize = true;
       this.Padding = new Padding(5);
       this.AutoAddColors = true;
       this.CellBorderColor = SystemColors.ButtonShadow;
       this.ShowToolTips = true;
       this.SeparatorHeight = 8;
       this.EditMode = ColorEditingMode.CustomOnly;
       this.Color = Color.Black;
       this.CellBorderStyle = ColorCellBorderStyle.FixedSingle;
       this.SelectedCellStyle = ColorGridSelectedCellStyle.Zoomed;
       this.EndUpdate();
 }
Exemplo n.º 44
0
        protected void DefineColorRegions(ColorCollection colors, int rangeStart, int offset)
        {
            if (colors != null)
              {
            int rows;
            int index;

            rows = this.GetRows(colors.Count);
            index = 0;

            for (int row = 0; row < rows; row++)
            {
              for (int column = 0; column < this.ActualColumns; column++)
              {
            if (index < colors.Count)
            {
              this.ColorRegions.Add(rangeStart + index, new Rectangle(this.Padding.Left + (column * (this.CellSize.Width + this.Spacing.Width)), offset + (row * (this.CellSize.Height + this.Spacing.Height)), this.CellSize.Width, this.CellSize.Height));
            }

            index++;
              }
            }
              }
        }
Exemplo n.º 45
0
 public ColorGrid(ColorCollection colors, ColorCollection customColors)
     : this(colors, customColors, ColorPalette.None)
 {
 }
Exemplo n.º 46
0
 public ColorGrid(ColorCollection colors)
     : this(colors, new ColorCollection(Enumerable.Repeat(Color.White, 16)))
 {
 }
    protected virtual void WritePalette(Stream stream, ColorCollection palette, AdobePhotoshopColorSwatchFileVersion version, AdobePhotoshopColorSwatchColorSpace colorSpace)
    {
      int swatchIndex;

      this.WriteInt16(stream, (short)version);
      this.WriteInt16(stream, (short)palette.Count);

      swatchIndex = 0;

      foreach (Color color in palette)
      {
        short value1;
        short value2;
        short value3;
        short value4;

        swatchIndex++;

        switch (colorSpace)
        {
          case AdobePhotoshopColorSwatchColorSpace.Rgb:
            value1 = (short)(color.R * 256);
            value2 = (short)(color.G * 256);
            value3 = (short)(color.B * 256);
            value4 = 0;
            break;
          case AdobePhotoshopColorSwatchColorSpace.Hsb:
            value1 = (short)(color.GetHue() * 182.04);
            value2 = (short)(color.GetSaturation() * 655.35);
            value3 = (short)(color.GetBrightness() * 655.35);
            value4 = 0;
            break;
          case AdobePhotoshopColorSwatchColorSpace.Grayscale:
            if (color.R == color.G && color.R == color.B)
            {
              // already grayscale
              value1 = (short)(color.R * 39.0625);
            }
            else
            {
              // color is not grayscale, convert
              value1 = (short)(((color.R + color.G + color.B) / 3.0) * 39.0625);
            }
            value2 = 0;
            value3 = 0;
            value4 = 0;
            break;
          default:
            throw new InvalidOperationException("Color space not supported.");
        }

        this.WriteInt16(stream, (short)colorSpace);
        this.WriteInt16(stream, value1);
        this.WriteInt16(stream, value2);
        this.WriteInt16(stream, value3);
        this.WriteInt16(stream, value4);

        if (version == AdobePhotoshopColorSwatchFileVersion.Version2)
        {
          string name;

#if USENAMEHACK
          name = palette.GetName(swatchIndex - 1);
          if (string.IsNullOrEmpty(name))
          {
            name = string.Format("Swatch {0}", swatchIndex);
          }
#else
          name = color.IsNamedColor ? color.Name : string.Format("Swatch {0}", swatchIndex);
#endif

          this.WriteInt32(stream, name.Length);
          this.WriteString(stream, name);
        }
      }
    }
Exemplo n.º 48
0
 private void comboBoxCollections_SelectedIndexChanged(object sender, EventArgs e)
 {
     _currentCollection = (ColorCollection)comboBoxCollections.SelectedItem;
     textBoxDescription.Text = _currentCollection.Description;
     buttonDeleteCollection.Enabled = textBoxDescription.Enabled = true;
     PopulateCollectionColors(_currentCollection);
 }
 public void Serialize(Stream stream, ColorCollection palette, AdobePhotoshopColorSwatchFileVersion version)
 {
   this.Serialize(stream, palette, version, AdobePhotoshopColorSwatchColorSpace.Rgb);
 }
 public void Serialize(Stream stream, ColorCollection palette, AdobePhotoshopColorSwatchColorSpace colorSpace)
 {
   this.Serialize(stream, palette, AdobePhotoshopColorSwatchFileVersion.Version2, colorSpace);
 }
 /// <summary>
 /// Serializes the specified <see cref="ColorCollection" /> and writes the palette to a file using the specified <see cref="Stream" />.
 /// </summary>
 /// <param name="stream">The <see cref="Stream" /> used to write the palette.</param>
 /// <param name="palette">The <see cref="ColorCollection" /> to serialize.</param>
 public override void Serialize(Stream stream, ColorCollection palette)
 {
   this.Serialize(stream, palette, AdobePhotoshopColorSwatchColorSpace.Rgb);
 }
Exemplo n.º 52
0
        private void ApplyColorCollection(ColorCollection Collection, bool RandomOrder)
        {
            if (!Collection.Color.Any())
                return;

            bool strayElement = false;
            Color thisColor, thisColor2 = Color.White;
            int iPos = 0;

            foreach (Element elem in TimelineControl.SelectedElements)
            {
                string effectName = elem.EffectNode.Effect.EffectName;
                object[] parms = new object[elem.EffectNode.Effect.ParameterValues.Count()];
                List<Color> validColors = new List<Color>();

                Array.Copy(elem.EffectNode.Effect.ParameterValues, parms, parms.Count());
                validColors.AddRange(elem.EffectNode.Effect.TargetNodes.SelectMany(x => ColorModule.getValidColorsForElementNode(x, true)));

                if (RandomOrder)
                {
                    int r1 = rnd.Next(Collection.Color.Count());
                    int r2 = rnd.Next(Collection.Color.Count());

                    int n = 0;
                    while (r1 == r2 && n <= 5)
                    {
                        r2 = rnd.Next(Collection.Color.Count());
                        n++;
                    }

                    thisColor = Collection.Color[r1];
                    thisColor2 = Collection.Color[r2];
                }
                else
                {
                    if (iPos == Collection.Color.Count()) { iPos = 0; }
                    thisColor = Collection.Color[iPos];
                    iPos++;
                    if (effectName == "Alternating")
                    {
                        thisColor2 = Collection.Color[iPos];
                        iPos++;
                    }
                }

                if (validColors.Any() && !validColors.Contains(thisColor)) { thisColor = validColors[rnd.Next(validColors.Count())]; }

                if (effectName == "Alternate")
                {
                    if (validColors.Any() && !validColors.Contains(thisColor2)) { thisColor2 = validColors[rnd.Next(validColors.Count())]; }

                    int n2 = 0;
                    while (thisColor2 == thisColor && n2 <= 5)
                    {
                        thisColor2 = validColors[rnd.Next(validColors.Count())];
                        n2++;
                    }
                }

                switch (effectName)
                {
                    case "Candle Flicker":
                    case "LipSync":
                    case "Nutcracker":
                    case "Launcher":
                    case "RDS":
                        strayElement = true;
                        break;
                    case "Custom Value":
                        //Disabled until we fix the custom value null reference errors - not related to this.
                        //parms[0] = 4; //Set it to a type of color value
                        //parms[5] = thisColor;
                        strayElement = true;
                        break;
                    case "Alternating":
                        parms[1] = thisColor;
                        parms[3] = thisColor2;
                        parms[8] = parms[9] = true;
                        break;
                    case "Set Level":
                        parms[1] = thisColor;
                        break;
                    case "Pulse":
                        parms[1] = new ColorGradient(thisColor);
                        break;
                    case "Chase":
                        parms[0] = 0; // StaticColor
                        parms[3] = thisColor;
                        break;
                    case "Spin":
                        parms[2] = 0; // StaticColor
                        parms[9] = thisColor;
                        break;
                    case "Twinkle":
                        parms[7] = 0; // StaticColor
                        parms[8] = thisColor;
                        break;
                    case "Wipe":
                        parms[0] = new ColorGradient(thisColor);
                        break;
                }

                elem.EffectNode.Effect.ParameterValues = parms;
                TimelineControl.grid.RenderElement(elem);
            }
            sequenceModified();
            if (strayElement) MessageBox.Show("One or more effects were selected that do not support curves.\nAll effects that do were updated.");
        }
Exemplo n.º 53
0
        private void PopulateCollectionColors(ColorCollection collection)
        {
            listViewColors.BeginUpdate();
            listViewColors.Items.Clear();

            listViewColors.LargeImageList = new ImageList();
            listViewColors.LargeImageList.ColorDepth = ColorDepth.Depth32Bit;
            listViewColors.LargeImageList.ImageSize = new Size(48, 48);

            foreach (Color colorItem in collection.Color)
            {
                Bitmap result = new Bitmap(48,48);
                Graphics gfx = Graphics.FromImage(result);
                using (SolidBrush brush = new SolidBrush(colorItem))
                {
                    gfx.FillRectangle(brush, 0, 0, 48, 48);
                    gfx.DrawRectangle(_borderPen, 0, 0, 48, 48);
                }

                listViewColors.LargeImageList.Images.Add(colorItem.ToString(), result);

                ListViewItem item = new ListViewItem
                {
                    ToolTipText = string.Format("R: {0} G: {1} B: {2}", colorItem.R, colorItem.G, colorItem.B),
                    ImageKey = colorItem.ToString(),
                    Tag = colorItem
                };

                listViewColors.Items.Add(item);
            }
            listViewColors.EndUpdate();
            buttonAddColor.Enabled = true;
        }
Exemplo n.º 54
0
        private void NewColorCollection()
        {
            Common.Controls.TextDialog dialog = new Common.Controls.TextDialog("Collecton Name?");
            while (dialog.ShowDialog() == DialogResult.OK)
            {
                if (dialog.Response == string.Empty)
                {
                    //messageBox Arguments are (Text, Title, No Button Visible, Cancel Button Visible)
                    MessageBoxForm.msgIcon = SystemIcons.Error; //this is used if you want to add a system icon to the message form.
                    var messageBox = new MessageBoxForm("Please enter a name.", "Color Collection Name", false, false);
                    messageBox.ShowDialog();
                    continue;
                }
                ColorCollection item = new ColorCollection {Name = dialog.Response};
                if (ColorCollections.Contains(item))
                {
                    //messageBox Arguments are (Text, Title, No Button Visible, Cancel Button Visible)
                    MessageBoxForm.msgIcon = SystemIcons.Warning; //this is used if you want to add a system icon to the message form.
                    var messageBox = new MessageBoxForm("A collection with the name " + item.Name + @" already exists. Do you want to overwrite it?", "Overwrite collection?", true, true);
                    messageBox.ShowDialog();
                    if (messageBox.DialogResult == DialogResult.OK)
                    {
                        ColorCollections.Remove(item);
                        ColorCollections.Add(item);
                        _isDirty = true;
                        PopulateCollectionList();
                        comboBoxCollections.Text = item.Name;
                    }

                    break;

                }

                ColorCollections.Add(item);
                _isDirty = true;
                PopulateCollectionList();
                comboBoxCollections.Text = item.Name;
                break;

            }
        }
    public static ColorCollection ScaledPalette(IEnumerable<Color> topRow)
    {
      ColorCollection results;

      results = new ColorCollection();

      topRow = topRow.ToArray();
      results.AddRange(topRow);

      for (int i = 5; i >= 0; i--)
      {
        foreach (Color color in topRow)
        {
          HslColor hsl;

          hsl = new HslColor(color);
          hsl.L = (5 + i + (16 * i)) / 100D;

          results.Add(hsl.ToRgbColor());
        }
      }

      return results;
    }
    public void Serialize(Stream stream, ColorCollection palette, AdobePhotoshopColorSwatchFileVersion version, AdobePhotoshopColorSwatchColorSpace colorSpace)
    {
      if (stream == null)
      {
        throw new ArgumentNullException(nameof(stream));
      }

      if (palette == null)
      {
        throw new ArgumentNullException(nameof(palette));
      }

      if (version == AdobePhotoshopColorSwatchFileVersion.Version2)
      {
        this.WritePalette(stream, palette, AdobePhotoshopColorSwatchFileVersion.Version1, colorSpace);
      }
      this.WritePalette(stream, palette, version, colorSpace);
    }
    public static ColorCollection GetPalette(ColorPalette palette)
    {
      ColorCollection result;

      switch (palette)
      {
        case ColorPalette.Named:
          result = NamedColors;
          break;
        case ColorPalette.Office2010:
          result = Office2010Standard;
          break;
        case ColorPalette.Paint:
          result = PaintPalette;
          break;
        case ColorPalette.Standard:
          result = QbColors;
          break;
        case ColorPalette.None:
          result = new ColorCollection();
          break;
        default:
          throw new ArgumentException("Invalid palette", "palette");
      }

      return result;
    }
    protected virtual ColorCollection ReadPalette(Stream stream, AdobePhotoshopColorSwatchFileVersion version)
    {
      int colorCount;
      ColorCollection results;

      results = new ColorCollection();

      // read the number of colors, which also occupies two bytes
      colorCount = this.ReadInt16(stream);

      for (int i = 0; i < colorCount; i++)
      {
        AdobePhotoshopColorSwatchColorSpace colorSpace;
        int value1;
        int value2;
        int value3;
        string name;

        // again, two bytes for the color space
        colorSpace = (AdobePhotoshopColorSwatchColorSpace)(this.ReadInt16(stream));

        value1 = this.ReadInt16(stream);
        value2 = this.ReadInt16(stream);
        value3 = this.ReadInt16(stream);
        this.ReadInt16(stream); // only CMYK supports this field. As we can't handle CMYK colors, we read the value to advance the stream but don't do anything with it

        if (version == AdobePhotoshopColorSwatchFileVersion.Version2)
        {
          int length;

          // need to read the name even though currently our colour collection doesn't support names
          length = ReadInt32(stream);
          name = this.ReadString(stream, length);
        }
        else
        {
          name = string.Empty;
        }

        switch (colorSpace)
        {
          case AdobePhotoshopColorSwatchColorSpace.Rgb:
            int red;
            int green;
            int blue;

            // RGB.
            // The first three values in the color data are red , green , and blue . They are full unsigned
            //  16-bit values as in Apple's RGBColor data structure. Pure red = 65535, 0, 0.

            red = value1 / 256;
            green = value2 / 256;
            blue = value3 / 256;

            results.Add(Color.FromArgb(red, green, blue));
            break;

          case AdobePhotoshopColorSwatchColorSpace.Hsb:
            double hue;
            double saturation;
            double brightness;

            // HSB.
            // The first three values in the color data are hue , saturation , and brightness . They are full 
            // unsigned 16-bit values as in Apple's HSVColor data structure. Pure red = 0,65535, 65535.

            hue = value1 / 182.04;
            saturation = value2 / 655.35;
            brightness = value3 / 655.35;

            results.Add(new HslColor(hue, saturation, brightness).ToRgbColor());
            break;

          case AdobePhotoshopColorSwatchColorSpace.Grayscale:

            int gray;

            // Grayscale.
            // The first value in the color data is the gray value, from 0...10000.
            gray = (int)(value1 / 39.0625);

            results.Add(Color.FromArgb(gray, gray, gray));
            break;

          default:
            throw new InvalidDataException(string.Format("Color space '{0}' not supported.", colorSpace));
        }

#if USENAMEHACK
        results.SetName(i, name);
#endif
      }

      return results;
    }
        public static ColorCollection GetPalette(ColorPalette palette)
        {
            ColorCollection result;

              switch (palette)
              {
            case ColorPalette.Recent:
              string sRecentFile = Assembly.GetExecutingAssembly().Location + ".recent";
              if (File.Exists(sRecentFile))
              {
            result = new ColorCollection();
            result.Load(sRecentFile);
            break;
              }else
              {
            result = NamedColors;
            break;
              }
            case ColorPalette.Named:
              result = NamedColors;
              break;
            case ColorPalette.Office2010:
              result = Office2010Standard;
              break;
            case ColorPalette.Paint:
              result = PaintPalette;
              break;
            case ColorPalette.Standard:
              result = QbColors;
              break;
            case ColorPalette.None:
              result = new ColorCollection();
              break;
            case ColorPalette.WebSafe:
              result = WebSafe;
              break;
            case ColorPalette.Standard256:
              result = StandardPalette;
              break;
            default:
              throw new ArgumentException("Invalid palette", "palette");
              }

              return result;
        }
Exemplo n.º 60
0
        private void ApplyColorCollection(ColorCollection collection, bool randomOrder)
        {
            if (!collection.Color.Any())
                return;

            bool skipElements = false;
            int index = 0;

            foreach (Element elem in TimelineControl.SelectedElements)
            {
                if (!SupportsColor(elem))
                {
                    skipElements = true;
                    continue;
                }
                var colors = GetSupportedColorsFromCollection(elem, collection.Color);

                var properties = MetadataRepository.GetProperties(elem.EffectNode.Effect).Where(x => (x.PropertyType == typeof(Color) ||
                    x.PropertyType == typeof(ColorGradient) || x.PropertyType == typeof(List<ColorGradient>) || x.PropertyType == typeof(List<GradientLevelPair>)) && x.IsBrowsable);

                Dictionary<Element, Tuple<Object, PropertyDescriptor>> elementValues = new Dictionary<Element, Tuple<object, PropertyDescriptor>>();

                foreach (var propertyData in properties)
                {

                    if (propertyData.PropertyType == typeof (Color))
                    {
                        var color = randomOrder ? GetRandomColorFromCollection(colors) : colors[index++ % colors.Count];
                        elementValues.Add(elem,
                            new Tuple<object, PropertyDescriptor>(propertyData.Descriptor.GetValue(elem.EffectNode.Effect),
                                propertyData.Descriptor));
                        UpdateEffectProperty(propertyData.Descriptor, elem, color);
                    }
                    else
                    {
                        //The rest take a gradient.
                        if (propertyData.PropertyType == typeof(ColorGradient))
                        {
                            var color = randomOrder ? GetRandomColorFromCollection(colors) : colors[index++ % colors.Count];
                            elementValues.Add(elem,
                                new Tuple<object, PropertyDescriptor>(propertyData.Descriptor.GetValue(elem.EffectNode.Effect),
                                    propertyData.Descriptor));
                            UpdateEffectProperty(propertyData.Descriptor, elem, new ColorGradient(color));
                        }
                        else if (propertyData.PropertyType == typeof(List<ColorGradient>))
                        {
                            var gradients = propertyData.Descriptor.GetValue(elem.EffectNode.Effect) as List<ColorGradient>;
                            if (gradients != null)
                            {
                                var newGradients = gradients.ToList();
                                for (int i = 0; i < newGradients.Count; i++)
                                {
                                    newGradients[i] =
                                        new ColorGradient(randomOrder ? GetRandomColorFromCollection(colors) : colors[index++ % colors.Count]);
                                }
                                elementValues.Add(elem,
                                    new Tuple<object, PropertyDescriptor>(gradients,
                                        propertyData.Descriptor));
                                UpdateEffectProperty(propertyData.Descriptor, elem, newGradients);
                            }

                        }
                        else if (propertyData.PropertyType == typeof(List<GradientLevelPair>))
                        {
                            var gradients = propertyData.Descriptor.GetValue(elem.EffectNode.Effect) as List<GradientLevelPair>;
                            if (gradients != null)
                            {
                                var newGradients = gradients.ToList();
                                for (int i = 0; i < newGradients.Count; i++)
                                {
                                    newGradients[i] = new GradientLevelPair(new ColorGradient(randomOrder ? GetRandomColorFromCollection(colors) : colors[index++ % colors.Count]), new Curve(gradients[i].Curve));
                                }
                                elementValues.Add(elem,
                                    new Tuple<object, PropertyDescriptor>(gradients,
                                        propertyData.Descriptor));
                                UpdateEffectProperty(propertyData.Descriptor, elem, newGradients);
                            }

                        }

                    }
                }

                if (elementValues.Any())
                {
                    var undo = new EffectsPropertyModifiedUndoAction(elementValues);
                    AddEffectsModifiedToUndo(undo);
                }
            }

            if (skipElements)
            {
                MessageBoxForm.msgIcon = SystemIcons.Information; //this is used if you want to add a system icon to the message form.
                var messageBox = new MessageBoxForm("One or more effects were selected that do not support colors.\nAll effects that do were updated.",
                                    @"Information", true, false);
                messageBox.ShowDialog();
            }
            SequenceModified();
        }