/// /// <summary> /// Draw all color pointers for palette</summary> /// protected void DrawPointers( ) { int radius = (int)Radius; double ewidth = COLOR_POINTER_DIAMETER; double pinradius = ewidth / 2; if (Palette != null) { double gradRadius = ValueRadius; double[] angles = new double[Palette.Colors.Count]; double[] radCoff = new double[Palette.Colors.Count]; DoubleColor[] wheelColors = new DoubleColor[Palette.Colors.Count]; for (int i = 0; i < angles.Length; ++i) { PaletteColor pc = Palette.Colors[i]; double coff = 1; switch (PaintMethod) { case WheelPaintMethod.Brightness: coff = pc.DoubleColor.ToAHSB().Brightness; var c = pc.DoubleColor.ToAHSB(); c.Saturation = 1.0; wheelColors[i] = c.Double(); break; case WheelPaintMethod.InverseLuminance: coff = pc.DoubleColor.ToAHSL().Luminance; var c1 = pc.DoubleColor.ToAHSL(); c1.Saturation = 1.0; wheelColors[i] = c1.Double(); break; case WheelPaintMethod.Saturation: coff = pc.DoubleColor.Saturation; var c2 = pc.DoubleColor.ToAHSB(); c2.Brightness = 1.0; wheelColors[i] = c2.Double(); break; case WheelPaintMethod.Luminance: coff = 1.0 - pc.DoubleColor.ToAHSL().Luminance; var c3 = pc.DoubleColor.ToAHSL(); c3.Saturation = 1.0; wheelColors[i] = c3.Double(); break; default: throw new NotImplementedException(); } angles[i] = Wheel.GetAngle(pc.DoubleColor); radCoff[i] = coff; } if (m_schemaElements == null || m_schemaElements.Length != angles.Length) { if (m_schemaElements != null) { foreach (Line l in m_lines) { canvas.Children.Remove(l); } foreach (ColorPinpoint e in m_schemaElements) { canvas.Children.Remove(e); } } m_schemaElements = new ColorPinpoint[angles.Length]; m_lines = new Line[angles.Length]; for (int i = 0; i < m_schemaElements.Length; ++i) { m_schemaElements[i] = new ColorPinpoint() { Opacity = 0.9, IsHitTestVisible = true, // Width = ewidth, Height = ewidth, CurrentColor = Colors.Black, Tag = i, PaletteColor = Palette.Colors[i] }; m_schemaElements[i].SetValue(Canvas.ZIndexProperty, COLOR_POINTER_ZORDER); m_schemaElements[i].SetValue(ToolTipService.ToolTipProperty, Palette.Colors[i].Name); canvas.Children.Add(m_schemaElements[i]); m_lines[i] = new Line() { Opacity = 0.0, StrokeThickness = 2, Stroke = Colors.Black.ToBrush() }; m_lines[i].SetValue(Canvas.ZIndexProperty, COLOR_LINE_ZORDER); canvas.Children.Add(m_lines[i]); if (i == 0) { m_main = m_schemaElements[i]; m_main.IsMain = true; SetMainPointEvents(m_main); } else { SetSecondaryPointEvents(m_schemaElements[i]); } } } for (int i = 0; i < m_schemaElements.Length; ++i) { double angle = Wheel.FixAngle(angles[i] - m_angleShift); double rad = MathEx.ToRadians(angle); double coff = radCoff[i]; double x = Math.Cos(rad) * (gradRadius - pinradius) * coff + radius; double y = -Math.Sin(rad) * (gradRadius - pinradius) * coff + radius; AHSB hsb = Palette.Colors[i].Color; x -= pinradius; y -= pinradius; m_schemaElements[i].SetValue(Canvas.LeftProperty, x); m_schemaElements[i].SetValue(Canvas.TopProperty, y); m_schemaElements[i].CurrentColor = hsb.Double().ToColor(); m_lines[i].X1 = radius; m_lines[i].Y1 = radius; m_lines[i].X2 = x + pinradius; m_lines[i].Y2 = y + pinradius; } } }