/// <summary> /// Constructor /// </summary> public KnobColorTable() { _KnobFaceColor = new LinearGradientColorTable(); _KnobFaceColor.ColorTableChanged += KnobColorTableChanged; _KnobIndicatorColor = new LinearGradientColorTable(); _KnobIndicatorColor.ColorTableChanged += KnobColorTableChanged; _MinZoneIndicatorColor = new LinearGradientColorTable(); _MinZoneIndicatorColor.ColorTableChanged += KnobColorTableChanged; _MaxZoneIndicatorColor = new LinearGradientColorTable(); _MaxZoneIndicatorColor.ColorTableChanged += KnobColorTableChanged; _MidZoneIndicatorColor = new LinearGradientColorTable(); _MidZoneIndicatorColor.ColorTableChanged += KnobColorTableChanged; }
/// <summary> /// Renders a gradient indicator arc by dividing /// the arc into sub-arcs, enabling us to utilize normal /// rectangle gradient support /// </summary> /// <param name="g"></param> /// <param name="a1">Starting angle</param> /// <param name="s1">Sweep angle</param> /// <param name="ct"></param> private void RenderArc(Graphics g, float a1, float s1, LinearGradientColorTable ct) { float n1 = Math.Abs(s1); Color c1 = ct.Start; Color c2 = ct.End.IsEmpty == false ? ct.End : ct.Start; // Calculate our rect and inflate to // make room for the indicator arc Rectangle rect = new Rectangle(ZoneIndicatorBounds.Location, ZoneIndicatorBounds.Size); int dw = (int)(ZoneIndWidth / 2); rect.Inflate(-dw, -dw); // Calculate the RGB color deltas float dr = (c2.R - c1.R) / n1; float dg = (c2.G - c1.G) / n1; float db = (c2.B - c1.B) / n1; // Set our initial starting color and range Color c3 = Color.FromArgb(c1.ToArgb()); float s2 = s1; float a2 = a1; int pa = (s1 > 0) ? 100 : -100; // Loop through the arc, processing sub-arcs less // than 180 degrees so that we can use GDI+ built-in // gradient rectangle support while (s2 != 0) { // Limit our sweep angle pass to 90 degrees float sw = (s2 > 0) ? Math.Min(s2, 90) : Math.Max(s2, -90); // Calculate our sub-sweep angle points. This // enables us to create an associated bounding // rectangle for the sub-sweep arc Point pt1 = CalcCoord(a2); Point pt2 = CalcCoord(a2 + sw); Rectangle r = new Rectangle(); r.Location = new Point(Math.Min(pt1.X, pt2.X), Math.Min(pt1.Y, pt2.Y)); r.Size = new Size(Math.Abs(pt1.X - pt2.X), Math.Abs(pt1.Y - pt2.Y)); if (r.Width == 0) r.Width = 1; if (r.Height == 0) r.Height = 1; // Calculate the terminal color for the // sub-sweep arc float n = Math.Abs(sw); int red = (int)(c3.R + n * dr); red = Math.Max(Math.Min(red, 255), 0); int green = (int)(c3.G + n * dg); green = Math.Max(Math.Min(green, 255), 0); int blue = (int)(c3.B + n * db); blue = Math.Max(Math.Min(blue, 255), 0); Color c4 = Color.FromArgb(red, green, blue); // Tally up this sub-sweep s2 -= sw; // Render the sub-arc with an appropriately // orientated gradient brush, and draw the arc using (LinearGradientBrush lbr = new LinearGradientBrush(r, c3, c4, a2 + pa)) { using (Pen pen = new Pen(lbr, (int)ZoneIndWidth)) g.DrawArc(pen, rect, a2, sw); } // Bump up our starting angle to reflect the // processing of this sub-arc a2 += sw; // Set the next starting color to the // ending color for this arc c3 = c4; } // Render the bounding indicator arcs using (GraphicsPath p1 = new GraphicsPath()) { rect.Inflate(-dw, -dw); p1.AddArc(ZoneIndicatorBounds, a1, s1); p1.AddArc(rect, a1 + s1, -s1); // Let Windows close the arcs, and then // render them p1.CloseFigure(); using (Pen pen = new Pen(ZoneIndicatorColor, MinorTickSize.Width)) g.DrawPath(pen, p1); } }
/// <summary> /// ApplyColor /// </summary> /// <param name="c"></param> /// <param name="d"></param> /// <returns></returns> private LinearGradientColorTable ApplyColor( LinearGradientColorTable c, LinearGradientColorTable d) { if (c.IsEmpty == true) return (d); if (c.Start.IsEmpty == false && c.End.IsEmpty == false) return (c); return (new LinearGradientColorTable( c.Start.IsEmpty ? d.Start : c.Start, c.End.IsEmpty ? d.End : c.End, c.GradientAngle)); }
/// <summary> /// MyColorConverter /// </summary> /// <param name="ct">ColorTable</param> /// <param name="cvt">ColorConverter</param> /// <returns>string or null</returns> private string MyColorConverter(LinearGradientColorTable ct, ColorConverter cvt) { if (ct.Start.IsEmpty == false) return (cvt.ConvertToString(ct.Start)); if (ct.End.IsEmpty == false) return (cvt.ConvertToString(ct.Start)); return (null); }
public void ResetMidZoneIndicatorColor() { MidZoneIndicatorColor = LinearGradientColorTable.Empty; }
public void ResetKnobIndicatorColor() { KnobIndicatorColor = LinearGradientColorTable.Empty; }
public void ResetKnobFaceColor() { KnobFaceColor = LinearGradientColorTable.Empty; }