/// <summary> /// Perform a complete recalculation of the control. /// </summary> /// <remarks></remarks> private void Recalculate() { if (this.DrawingArea is null) { return; } _refSize = this.DrawingArea.RenderSize; if (_refSize.Height == 0d) { return; } // UpdateOutline() // ' this is the current angle calculated from the current box dimensions var pol = PolarCoordinates.ToPolarCoordinates(_refSize.Width, _refSize.Height); _angle = pol.Arc; CalculateSections(); }
/// <summary> /// Calculate and position the polygon sections, based on geometry, for the current size, position, and number of bars. /// </summary> /// <remarks></remarks> private void CalculateSections() { var s = _refSize; PointCollection pc; int d = (int)(Sections - 1L); Polygon p; double wHeight = s.Height - Blunting; double wWidth = s.Width; SolidColorBrush bc = (SolidColorBrush)Application.Current.Resources["TrippLiteLcdType"]; // ' the width of each section will be calculated here, subtracting initial width by the spacing var pol = PolarCoordinates.ToPolarCoordinates(wWidth, wHeight); double w = (wWidth - SectionSpacing * (Sections - 1L)) / Sections; double sw = SectionSpacing; LinearCoordinates pt; int i; double x = 0d; // ' calculate from hypoteneuse side. double fr = pol.Radius / wWidth; var cblin = CalcBars(LoadValue, (int)Sections) - 1; this.BarsArea.Children.Clear(); System.Threading.Thread.Sleep(0); var c = (int)(Sections - 1L); for (i = 0; i <= c; i++) { // ' fresh point collection pc = new PointCollection(); p = _polyCache[i]; pol.Radius = x + w; pol.Radius *= fr; pt = PolarCoordinates.ToLinearCoordinates(pol); pc.Add(new Point(x, s.Height)); pc.Add(new Point(pt.X, s.Height)); pc.Add(new Point(pt.X, Math.Max(0d, wHeight - pt.Y))); pol.Radius = x; pol.Radius *= fr; pt = PolarCoordinates.ToLinearCoordinates(pol); pc.Add(new Point(pt.X, Math.Max(0d, wHeight - pt.Y))); pc.Add(new Point(pt.X, s.Height)); p.Points = pc; p.Fill = bc; p.Effect = this.BackingBar.Effect; if (cblin < i) { p.Opacity = 0.33d; } else { p.Opacity = 1d; } this.BarsArea.Children.Add(p); x += w; x += sw; } }