fix: add explicit using aliases to resolve System.Drawing ambiguity
This commit is contained in:
@@ -1,3 +1,6 @@
|
|||||||
|
using Brush = System.Windows.Media.Brush;
|
||||||
|
using Pen = System.Windows.Media.Pen;
|
||||||
|
using Point = System.Windows.Point;
|
||||||
using System;
|
using System;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
@@ -18,7 +21,6 @@ public class GaugeControl : FrameworkElement
|
|||||||
public double Percent { get => (double)GetValue(PercentProperty); set => SetValue(PercentProperty, value); }
|
public double Percent { get => (double)GetValue(PercentProperty); set => SetValue(PercentProperty, value); }
|
||||||
public Brush Accent { get => (Brush)GetValue(AccentProperty); set => SetValue(AccentProperty, value); }
|
public Brush Accent { get => (Brush)GetValue(AccentProperty); set => SetValue(AccentProperty, value); }
|
||||||
|
|
||||||
// Arc sweeps 270° starting at 135° (bottom-left to bottom-right, like macOS version)
|
|
||||||
private const double StartAngleDeg = 135;
|
private const double StartAngleDeg = 135;
|
||||||
private const double SweepDeg = 270;
|
private const double SweepDeg = 270;
|
||||||
private const double StrokeWidth = 6;
|
private const double StrokeWidth = 6;
|
||||||
@@ -29,38 +31,30 @@ public class GaugeControl : FrameworkElement
|
|||||||
var cy = RenderSize.Height / 2;
|
var cy = RenderSize.Height / 2;
|
||||||
var radius = Math.Min(cx, cy) - StrokeWidth / 2 - 1;
|
var radius = Math.Min(cx, cy) - StrokeWidth / 2 - 1;
|
||||||
|
|
||||||
// Track
|
|
||||||
DrawArc(dc, cx, cy, radius, StartAngleDeg, SweepDeg,
|
DrawArc(dc, cx, cy, radius, StartAngleDeg, SweepDeg,
|
||||||
new Pen(new SolidColorBrush(Color.FromArgb(28, 255, 255, 255)), StrokeWidth));
|
new Pen(new SolidColorBrush(Color.FromArgb(28, 255, 255, 255)), StrokeWidth));
|
||||||
|
|
||||||
// Fill
|
|
||||||
if (Percent > 0)
|
if (Percent > 0)
|
||||||
{
|
DrawArc(dc, cx, cy, radius, StartAngleDeg, SweepDeg * (Percent / 100.0),
|
||||||
var sweep = SweepDeg * (Percent / 100.0);
|
new Pen(Accent, StrokeWidth));
|
||||||
DrawArc(dc, cx, cy, radius, StartAngleDeg, sweep, new Pen(Accent, StrokeWidth));
|
|
||||||
}
|
|
||||||
|
|
||||||
var dpi = VisualTreeHelper.GetDpi(this).PixelsPerDip;
|
var dpi = VisualTreeHelper.GetDpi(this).PixelsPerDip;
|
||||||
|
|
||||||
// Percent label
|
|
||||||
var pctText = new FormattedText(
|
var pctText = new FormattedText(
|
||||||
$"{(int)Math.Round(Percent)}%",
|
$"{(int)Math.Round(Percent)}%",
|
||||||
CultureInfo.CurrentCulture,
|
CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
|
||||||
FlowDirection.LeftToRight,
|
|
||||||
new Typeface(new FontFamily("Segoe UI"), FontStyles.Normal, FontWeights.Bold, FontStretches.Normal),
|
new Typeface(new FontFamily("Segoe UI"), FontStyles.Normal, FontWeights.Bold, FontStretches.Normal),
|
||||||
14, Brushes.White, dpi);
|
14, Brushes.White, dpi);
|
||||||
|
|
||||||
dc.DrawText(pctText, new Point(cx - pctText.Width / 2, cy - pctText.Height - 1));
|
dc.DrawText(pctText, new Point(cx - pctText.Width / 2, cy - pctText.Height - 1));
|
||||||
|
|
||||||
// Sub-label
|
|
||||||
var sub = new FormattedText(
|
var sub = new FormattedText(
|
||||||
"Updated\nnow",
|
"Updated\nnow",
|
||||||
CultureInfo.CurrentCulture,
|
CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
|
||||||
FlowDirection.LeftToRight,
|
new Typeface("Segoe UI"), 7,
|
||||||
new Typeface("Segoe UI"),
|
new SolidColorBrush(Color.FromRgb(0x88, 0x88, 0x88)), dpi)
|
||||||
7, new SolidColorBrush(Color.FromRgb(0x88, 0x88, 0x88)), dpi);
|
{
|
||||||
sub.TextAlignment = TextAlignment.Center;
|
TextAlignment = TextAlignment.Center
|
||||||
|
};
|
||||||
dc.DrawText(sub, new Point(cx - sub.Width / 2, cy + 2));
|
dc.DrawText(sub, new Point(cx - sub.Width / 2, cy + 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,10 +62,9 @@ public class GaugeControl : FrameworkElement
|
|||||||
double startDeg, double sweepDeg, Pen pen)
|
double startDeg, double sweepDeg, Pen pen)
|
||||||
{
|
{
|
||||||
if (sweepDeg <= 0) return;
|
if (sweepDeg <= 0) return;
|
||||||
|
var start = PointOnCircle(cx, cy, r, startDeg);
|
||||||
var start = PointOnCircle(cx, cy, r, startDeg);
|
var end = PointOnCircle(cx, cy, r, startDeg + sweepDeg);
|
||||||
var end = PointOnCircle(cx, cy, r, startDeg + sweepDeg);
|
var isLarge = sweepDeg > 180;
|
||||||
var isLarge = sweepDeg > 180;
|
|
||||||
|
|
||||||
var geo = new StreamGeometry();
|
var geo = new StreamGeometry();
|
||||||
using (var ctx = geo.Open())
|
using (var ctx = geo.Open())
|
||||||
|
|||||||
Reference in New Issue
Block a user