private void SetPointEvents( ColorPinpoint e ) { var drag = false; PaletteColor selected = null; Point? prev = null; e.MouseLeftButtonDown += (s, ev) => { drag = true; prev = null; SelectColor(s as ColorPinpoint); selected = Palette.Colors[(int)(s as FrameworkElement).Tag]; e.CaptureMouse(); }; e.MouseLeftButtonUp += (s, ev) => { drag = false; e.ReleaseMouseCapture(); }; e.MouseMove += (s, ev) => { if (drag) { double width = brisat.Width; double height = brisat.Height; double diam = (s as ColorPinpoint).ActualWidth; Point p = ev.GetPosition(canvasBriSat); AHSB hsb = selected.Color; hsb.Saturation = p.X / width; hsb.Brightness = 1 - p.Y / height; if (prev != null) { selected.Color = hsb; double x = (hsb.Saturation * width) - diam / 2; double y = (height - (hsb.Brightness * height)) - diam / 2; (s as FrameworkElement).SetValue(Canvas.LeftProperty, x); (s as FrameworkElement).SetValue(Canvas.TopProperty, y); DrawPointers(); if (ColorsUpdated != null) { ColorsUpdated(this, EventArgs.Empty); } } prev = p; } }; }
private void SetPointEvents( ColorPinpoint e ) { var drag = false; PaletteColor selected = null; Point? prev = null; Point shift = new Point(); e.MouseLeftButtonDown += (s, ev) => { drag = true; prev = null; shift = ev.GetPosition(s as FrameworkElement); SelectColor(s as ColorPinpoint); selected = Palette.Colors[(int)(s as FrameworkElement).Tag]; e.CaptureMouse(); }; e.MouseLeftButtonUp += (s, ev) => { drag = false; e.ReleaseMouseCapture(); }; e.MouseMove += (s, ev) => { if (drag) { double width = spectrum.Width; double height = spectrum.Height; double diam = (s as ColorPinpoint).ActualWidth; Point p = ev.GetPosition(canvasSpectrum); p.X = p.X - shift.X + diam / 2; p.Y = p.Y - shift.Y + diam / 2; AHSL hsl = selected.DoubleColor.ToAHSL(); double x = Math.Min(Math.Max(p.X, 0), width); double y = Math.Min(Math.Max(p.Y, 0), height); hsl.Luminance = 1 - (y / height); hsl.HueDegree = 360 * (x / width); hsl.Saturation = Saturation; if (prev != null) { selected.DoubleColor = hsl.Double(); if (ColorsUpdated != null) { ColorsUpdated(this, EventArgs.Empty); } } prev = p; } }; }
/// /// <summary> /// Main color pointer event handle initialize</summary> /// private void SetMainPointEvents( ColorPinpoint e ) { var drag = false; Point?prev = null; e.MouseEnter += (s, ev) => { ShowLines(true); (s as UIElement).SetValue(Canvas.ZIndexProperty, COLOR_POINTER_ZORDER_SELECTED); m_main.SetValue(Canvas.ZIndexProperty, COLOR_POINTER_ZORDER_SELECTED + 1); }; e.MouseLeave += (s, ev) => { if (!drag) { ShowLines(false); (s as UIElement).SetValue(Canvas.ZIndexProperty, COLOR_POINTER_ZORDER); m_main.SetValue(Canvas.ZIndexProperty, COLOR_POINTER_ZORDER); } }; e.MouseLeftButtonDown += (s, ev) => { drag = true; e.CaptureMouse(); e.Cursor = Cursors.Hand; ShowLines(true); SelectColor(m_main); }; e.MouseLeftButtonUp += (s, ev) => { drag = false; prev = null; e.ReleaseMouseCapture(); e.Cursor = Cursors.Arrow; ShowLines(false); (s as UIElement).SetValue(Canvas.ZIndexProperty, COLOR_POINTER_ZORDER); m_main.SetValue(Canvas.ZIndexProperty, COLOR_POINTER_ZORDER); }; e.MouseMove += (s, ev) => { if (drag) { Point p = ev.GetPosition(wheel); if (prev != null) { ChangePrimaryColorForPointer(prev.Value, p); } prev = p; } }; }
/// /// <summary> /// Main color pointer event handle initializer</summary> /// private void SetSecondaryPointEvents( ColorPinpoint e ) { var drag = false; Point?prev = null; e.MouseEnter += (s, ev) => { ShowLines(true); (s as UIElement).SetValue(Canvas.ZIndexProperty, COLOR_POINTER_ZORDER_SELECTED); }; e.MouseLeave += (s, ev) => { if (!drag) { ShowLines(false); (s as UIElement).SetValue(Canvas.ZIndexProperty, COLOR_POINTER_ZORDER); } }; e.MouseLeftButtonDown += (s, ev) => { if (ev.ClickCount == 2) { int id = (int)(s as FrameworkElement).Tag; if (Palette.MaxVectorIndex > 0) { Palette.Colors[id].VectorIndex++; Palette.Colors[id].VectorIndex %= Palette.MaxVectorIndex; Palette.Refresh(); } } else { drag = true; prev = null; e.CaptureMouse(); e.Cursor = Cursors.Hand; ShowLines(true); SelectColor(s as ColorPinpoint); } }; e.MouseLeftButtonUp += (s, ev) => { drag = false; prev = null; e.ReleaseMouseCapture(); ShowLines(false); (s as UIElement).SetValue(Canvas.ZIndexProperty, COLOR_POINTER_ZORDER); }; e.MouseMove += (s, ev) => { double diam = (s as ColorPinpoint).ActualWidth; if (drag) { Point p = ev.GetPosition(wheel); if (prev != null) { ChangeSecondaryColorsForPointer((int)((s as FrameworkElement).Tag), prev.Value, p); } prev = p; } }; }