Ejemplo n.º 1
0
        public void SetEntries(List <Color?> palette, int maxEntries)
        {
            _maxEntries = maxEntries;
            _palette    = palette;

            SuspendLayout();
            Visible = false;
            Controls.Clear();

            if (_entryIndexes != null)
            {
                foreach (var entry in _entryIndexes.Keys)
                {
                    entry.Dispose();
                }
            }

            _entryIndexes = new Dictionary <Control, int>();
            for (var i = 0; i < palette.Count; i++)
            {
                var entry = new PaletteEntry(palette[i], i >= maxEntries)
                {
                    Location = GetEntryPosition(i)
                };
                //if (i >= maxEntries)
                Controls.Add(entry);
                _entryIndexes.Add(entry, i);

                var paletteColor = palette[i];
                entry.MouseDown += (s, e) => { if (MouseOverColor != null)
                                               {
                                                   MouseOverColor(new [] { paletteColor });
                                               }
                };
                entry.MouseDown += (s, e) => { if (e.Button == MouseButtons.Left)
                                               {
                                                   BeginDrag(entry);
                                               }
                };
            }

            if (MouseOverColor != null)
            {
                MouseOverColor(palette.ToArray());
            }

            Visible = true;
            ResumeLayout();
            Refresh();

            var mouseEvents = new OsFeatures.GlobalMouseHandler();

            Application.AddMessageFilter(mouseEvents);
            mouseEvents.MouseMoved += MovedMouse;
            mouseEvents.MouseUp    += StopDragging;
            ControlRemoved         += (s, a) => Application.RemoveMessageFilter(mouseEvents);
        }
Ejemplo n.º 2
0
        private void BeginDrag(PaletteEntry entry)
        {
            if (!entry.PaletteColor.HasValue || !EnableEdit)
            {
                return;
            }

            _dragging   = entry;
            _dragOffset = Cursor.Position;
            _dragIndex  = _entryIndexes[entry];
            Controls.SetChildIndex(_dragging, 0);

            Debug.WriteLine("start drag");
        }