示例#1
0
        void s_MouseDown(object sender, MouseEventArgs e)
        {
            this._dragging = true;
            Swatch s = (Swatch)sender;
            if (((int)System.Windows.Forms.Form.ModifierKeys & (int)Keys.Shift) == 0)
            {
                //holding SHIFT key

                if (((int)System.Windows.Forms.Form.ModifierKeys & (int)Keys.Control) == 0)
                {
                    //Control is NOT held down, just SHIFT
                    this.DeselectAll();
                    if (this._selectionStartSwatch != null)
                    {
                        int from = this._swatches.IndexOfValue(this._selectionStartSwatch);
                        int to = this._swatches.IndexOfValue(s);
                        int diff = to - from;
                        int dir = (diff > 0) ? 1 : -1;
                        for (int i = 0; i <= diff * dir; i++)
                        {
                            ((Swatch)this._swatches.GetByIndex(from + i * dir)).Selected = true;
                        }
                    }
                    else
                    {
                        //there was no selectionstart, so just select the clicked one
                        s.Selected = !s.Selected;
                        this._selectionStartSwatch = s;
                    }
                }
                else
                {
                    //Holding SHIFT and CONTROL
                    //TODO: make it work exactly like Explorer file selection
                }
            }
            else if (System.Windows.Forms.Form.ModifierKeys == Keys.Control)
            {
                s.Selected = !s.Selected;
                this._selectionStartSwatch = s;
            }
            else
            {
                bool wasSelected = s.Selected;
                this.DeselectAll();
                if (!wasSelected)
                    s.Selected = true;
                this._selectionStartSwatch = s;
            }

            this._lastClickedSwatch = s;
        }
示例#2
0
        private void UpdateSwatches()
        {
            if (this._swatches == null)
            {
                this._swatches = new PropList(); // Dictionary<ColorBase, Swatch>();
            }
            int newNumColors = 0;

            if (this._palette != null)
            {
                newNumColors = this._palette.Count;
            }

            int diffNum = newNumColors - this._swatches.Count;

            this.SuspendLayout();

            if (diffNum < 0) //less color in palette than we have swatches - remove!
            {
                for (int i = 0; i < -diffNum; i++)
                {
                    this.RemoveAtNoUpdate(this._swatches.Count - 1);
                }
                Console.WriteLine("Less");
            }
            else if (diffNum > 0)
            {
                for (int i = 0; i < diffNum; i++)
                {
                    this.InsertAtNoUpdate(this._swatches.Count, "", null);
                }
                Console.WriteLine("More");
            }
            else
            {
                Console.WriteLine("No changre");
            }

            if (this._palette != null)
            {
                PropList newSwatches = new PropList();
                Point    currentLoc  = new Point();

                int i = 0;
                foreach (KeyValuePair <string, ColorBase> kv in this._palette)
                {
                    Swatch s = (Swatch)this._swatches.GetByIndex(i);
                    s.SuspendLayout();
                    s.Color = kv.Value;
                    newSwatches.Add(s.Color, s);

                    s.Size     = this._swatchSize.ToSize();
                    s.Location = currentLoc;
                    s.ResumeLayout();

                    currentLoc.X += this._swatchSize.X;
                    if (currentLoc.X + this._swatchSize.X >= this.Right - 5) //TODO: why need -5?
                    {
                        currentLoc.Y += this._swatchSize.Y;
                        currentLoc.X  = 0;
                    }
                    i++;
                }
                this._swatches = newSwatches;
                this.Height    = currentLoc.Y + this._swatchSize.Y;
            }
            this.ResumeLayout();
            this.Invalidate();
        }
示例#3
0
 private void InsertAtNoUpdate(int index, string name, ColorBase color)
 {
     Swatch s = new Swatch();
     s.BorderStyle = BorderStyle.FixedSingle;
     this.Controls.Add(s);
     if (color != null)
         s.Color = color;
     s.Name = name;
     s.MouseDown += new MouseEventHandler(s_MouseDown);
     s.MouseMove += new MouseEventHandler(s_MouseMove);
     s.MouseUp += new MouseEventHandler(s_MouseUp);
     this._swatches.Add(color, s);
 }