-
Notifications
You must be signed in to change notification settings - Fork 621
Expand file tree
/
Copy pathCpuPage.xaml.cs
More file actions
69 lines (60 loc) · 1.83 KB
/
CpuPage.xaml.cs
File metadata and controls
69 lines (60 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using SkiaSharp;
using SkiaSharp.Views.Windows;
namespace SkiaSharpSample;
public sealed partial class CpuPage : Page
{
static readonly (float X, float Y, float R, SKColor Color)[] circles =
{
(0.20f, 0.30f, 0.10f, new SKColor(0xFF, 0x4D, 0x66, 0xCC)),
(0.75f, 0.25f, 0.08f, new SKColor(0x4D, 0xB3, 0xFF, 0xCC)),
(0.15f, 0.70f, 0.07f, new SKColor(0xFF, 0x99, 0x1A, 0xCC)),
(0.80f, 0.70f, 0.12f, new SKColor(0x66, 0xFF, 0xB3, 0xCC)),
(0.50f, 0.15f, 0.06f, new SKColor(0xB3, 0x4D, 0xFF, 0xCC)),
(0.40f, 0.80f, 0.09f, new SKColor(0xFF, 0xE6, 0x33, 0xCC)),
};
static readonly SKColor[] gradientColors =
{
new SKColor(0x44, 0x88, 0xFF),
new SKColor(0x88, 0x33, 0xCC),
};
public CpuPage()
{
InitializeComponent();
}
private void OnPaintSurface(object? sender, SKPaintSurfaceEventArgs e)
{
var canvas = e.Surface.Canvas;
var width = e.Info.Width;
var height = e.Info.Height;
var center = new SKPoint(width / 2f, height / 2f);
var radius = Math.Max(width, height) / 2f;
canvas.Clear(SKColors.White);
// Background gradient
using var shader = SKShader.CreateRadialGradient(center, radius, gradientColors, SKShaderTileMode.Clamp);
using var bgPaint = new SKPaint
{
IsAntialias = true,
Shader = shader,
};
canvas.DrawRect(0, 0, width, height, bgPaint);
// Circles
using var circlePaint = new SKPaint
{
IsAntialias = true,
Style = SKPaintStyle.Fill,
};
foreach (var (x, y, r, color) in circles)
{
circlePaint.Color = color;
canvas.DrawCircle(x * width, y * height, r * Math.Min(width, height), circlePaint);
}
// Centered text
using var textPaint = new SKPaint
{
Color = SKColors.White,
IsAntialias = true,
};
using var font = new SKFont { Size = width * 0.12f };
canvas.DrawText("SkiaSharp", center.X, center.Y + font.Size / 3f, SKTextAlign.Center, font, textPaint);
}
}