Skip to content

Commit 2185c89

Browse files
committed
Adding more samples
1 parent 34e378e commit 2185c89

14 files changed

+851
-113
lines changed

CSharpMath.Uno.Example/CSharpMath.Uno.Example.Shared/App.xaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22
x:Class="CSharpMath.Uno.Example.App"
33
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5-
xmlns:local="using:CSharpMath.Uno.Example">
6-
7-
</Application>
5+
xmlns:local="using:CSharpMath.Uno.Example"
6+
RequestedTheme="Light" />

CSharpMath.Uno.Example/CSharpMath.Uno.Example.Shared/CSharpMath.Uno.Example.Shared.projitems

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,49 @@
1818
<Compile Include="$(MSBuildThisFileDirectory)App.xaml.cs">
1919
<DependentUpon>App.xaml</DependentUpon>
2020
</Compile>
21+
<Compile Include="$(MSBuildThisFileDirectory)ClockPage.xaml.cs">
22+
<DependentUpon>ClockPage.xaml</DependentUpon>
23+
</Compile>
2124
<Compile Include="$(MSBuildThisFileDirectory)MainPage.xaml.cs">
2225
<DependentUpon>MainPage.xaml</DependentUpon>
2326
</Compile>
27+
<Compile Include="$(MSBuildThisFileDirectory)MoreExamples.cs" />
28+
<Compile Include="$(MSBuildThisFileDirectory)MoreExamplesPage.xaml.cs">
29+
<DependentUpon>MoreExamplesPage.xaml</DependentUpon>
30+
</Compile>
31+
<Compile Include="$(MSBuildThisFileDirectory)TextPage.xaml.cs">
32+
<DependentUpon>TextPage.xaml</DependentUpon>
33+
</Compile>
34+
<Compile Include="$(MSBuildThisFileDirectory)TryPage.xaml.cs">
35+
<DependentUpon>TryPage.xaml</DependentUpon>
36+
</Compile>
2437
</ItemGroup>
2538
<ItemGroup>
39+
<Page Include="$(MSBuildThisFileDirectory)ClockPage.xaml">
40+
<SubType>Designer</SubType>
41+
<Generator>MSBuild:Compile</Generator>
42+
</Page>
2643
<Page Include="$(MSBuildThisFileDirectory)MainPage.xaml">
2744
<SubType>Designer</SubType>
2845
<Generator>MSBuild:Compile</Generator>
2946
</Page>
47+
<Page Include="$(MSBuildThisFileDirectory)MoreExamplesPage.xaml">
48+
<SubType>Designer</SubType>
49+
<Generator>MSBuild:Compile</Generator>
50+
</Page>
51+
<Page Include="$(MSBuildThisFileDirectory)TextPage.xaml">
52+
<SubType>Designer</SubType>
53+
<Generator>MSBuild:Compile</Generator>
54+
</Page>
55+
<Page Include="$(MSBuildThisFileDirectory)TryPage.xaml">
56+
<SubType>Designer</SubType>
57+
<Generator>MSBuild:Compile</Generator>
58+
</Page>
59+
</ItemGroup>
60+
<ItemGroup>
61+
<Content Include="$(MSBuildThisFileDirectory)Assets\SharedAssets.md" />
62+
</ItemGroup>
63+
<ItemGroup>
64+
<PRIResource Include="$(MSBuildThisFileDirectory)Strings\en\Resources.resw" />
3065
</ItemGroup>
31-
<ItemGroup>
32-
<Content Include="$(MSBuildThisFileDirectory)Assets\SharedAssets.md" />
33-
</ItemGroup>
34-
<ItemGroup>
35-
<PRIResource Include="$(MSBuildThisFileDirectory)Strings\en\Resources.resw" />
36-
</ItemGroup>
37-
</Project>
66+
</Project>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Page
2+
x:Class="CSharpMath.Uno.Example.Shared.ClockPage"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:local="using:CSharpMath.Uno.Example.Shared"
7+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
8+
xmlns:skia="using:SkiaSharp.Views.UWP"
9+
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
10+
mc:Ignorable="d">
11+
12+
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
13+
<skia:SKXamlCanvas
14+
x:Name="canvasView"
15+
VerticalAlignment="Stretch"
16+
PaintSurface="CanvasView_PaintSurface" />
17+
</Grid>
18+
</Page>
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Runtime.InteropServices.WindowsRuntime;
6+
using CSharpMath.SkiaSharp;
7+
using SkiaSharp;
8+
using SkiaSharp.Views.UWP;
9+
using Windows.Foundation;
10+
using Windows.Foundation.Collections;
11+
using Windows.UI.Xaml;
12+
using Windows.UI.Xaml.Controls;
13+
using Windows.UI.Xaml.Controls.Primitives;
14+
using Windows.UI.Xaml.Data;
15+
using Windows.UI.Xaml.Input;
16+
using Windows.UI.Xaml.Media;
17+
using Windows.UI.Xaml.Navigation;
18+
using static System.Math;
19+
20+
namespace CSharpMath.Uno.Example.Shared {
21+
public sealed partial class ClockPage : Page {
22+
private readonly DispatcherTimer _timer;
23+
24+
public ClockPage() {
25+
this.InitializeComponent();
26+
_timer = new DispatcherTimer();
27+
_timer.Interval = TimeSpan.FromMilliseconds(200);
28+
_timer.Tick += (s, e) => {
29+
canvasView.Invalidate();
30+
};
31+
this.Loaded += ClockPage_Loaded;
32+
this.Unloaded += ClockPage_Unloaded;
33+
}
34+
35+
private void ClockPage_Loaded(object sender, RoutedEventArgs e) {
36+
_timer.Start();
37+
}
38+
39+
private void ClockPage_Unloaded(object sender, RoutedEventArgs e) {
40+
_timer.Stop();
41+
}
42+
43+
readonly SKPaint blackFillPaint = new SKPaint {
44+
Style = SKPaintStyle.Fill,
45+
Color = SKColors.Black
46+
};
47+
readonly SKPaint whiteFillPaint = new SKPaint {
48+
Style = SKPaintStyle.Fill,
49+
Color = SKColors.White
50+
};
51+
readonly SKPaint whiteStrokePaint = new SKPaint {
52+
Style = SKPaintStyle.Stroke,
53+
Color = SKColors.White,
54+
StrokeCap = SKStrokeCap.Round,
55+
IsAntialias = true
56+
};
57+
readonly SKPaint redStrokePaint = new SKPaint {
58+
Style = SKPaintStyle.Stroke,
59+
Color = SKColors.Red,
60+
StrokeCap = SKStrokeCap.Round,
61+
IsAntialias = true
62+
};
63+
readonly string[] labels = {
64+
// Four 4s make 1 to 12 using different operations
65+
@"$\frac{44+4}{4}$",
66+
@"$\frac{44}{44}$",
67+
@"$\frac{4}{4}+\frac{4}{4}$",
68+
@"$\frac{4+4+4}{4}$",
69+
@"$4+\frac{4-4}{4}$",
70+
@"$4+4^{4-4}$",
71+
@"$4+\frac{4+4}{4}$",
72+
@"$\frac{44}{4}-4$",
73+
@"$\sqrt{4}^{4-\frac{4}{4}}$",
74+
@"$\:\:(4-\frac{4}{4})^{\sqrt{4}}$",
75+
@"$\frac{44-4}{4}$",
76+
@"$\frac{4!}{\sqrt{4}}-\frac{4}{4}$"
77+
};
78+
private void CanvasView_PaintSurface(object sender, SKPaintSurfaceEventArgs e) {
79+
var canvas = e.Surface.Canvas;
80+
canvas.Clear(SKColors.CornflowerBlue);
81+
canvas.Translate(e.Info.Width / 2, e.Info.Height / 2);
82+
canvas.Scale(e.Info.Width / 210f);
83+
canvas.DrawCircle(0, 0, 100, blackFillPaint);
84+
var painter = new TextPainter { FontSize = 8, TextColor = SKColors.White };
85+
for (int i = 0; i < 60; i++) {
86+
// Dots
87+
canvas.Save();
88+
canvas.RotateDegrees(6 * i);
89+
canvas.DrawCircle(0, -90, i % 5 == 0 ? 4 : 2, whiteFillPaint);
90+
canvas.Restore();
91+
// Maths
92+
if (i % 5 == 0) {
93+
painter.LaTeX = labels[i / 5];
94+
if (!(painter.Measure(e.Info.Width) is { } measure))
95+
throw new Structures.InvalidCodePathException("Invalid LaTeX");
96+
var θ = (90 - 6 * i) / 180f * PI;
97+
var sinθ = (float)Sin(θ);
98+
var cosθ = (float)Cos(θ);
99+
painter.Draw(canvas,
100+
new System.Drawing.PointF(75 * cosθ - (float)measure.Width / 2,
101+
-75 * sinθ - (float)measure.Height / 2),
102+
float.PositiveInfinity);
103+
}
104+
}
105+
var dateTime = DateTime.Now;
106+
// H
107+
canvas.Save();
108+
canvas.RotateDegrees(30 * dateTime.Hour + dateTime.Minute / 2f);
109+
whiteStrokePaint.StrokeWidth = 12;
110+
canvas.DrawLine(0, 0, 0, -50, whiteStrokePaint);
111+
canvas.Restore();
112+
// M
113+
canvas.Save();
114+
canvas.RotateDegrees(6 * dateTime.Minute + dateTime.Second / 10f);
115+
whiteStrokePaint.StrokeWidth = 6;
116+
canvas.DrawLine(0, 0, 0, -65, whiteStrokePaint);
117+
canvas.Restore();
118+
// S
119+
canvas.Save();
120+
canvas.RotateDegrees(6f * (dateTime.Second + dateTime.Millisecond / 1000f));
121+
redStrokePaint.StrokeWidth = 2;
122+
canvas.DrawLine(0, 0, 0, -75, redStrokePaint);
123+
canvas.Restore();
124+
}
125+
}
126+
}

CSharpMath.Uno.Example/CSharpMath.Uno.Example.Shared/MainPage.xaml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,21 @@
55
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
66
xmlns:local="using:CSharpMath.Uno.Example"
77
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
8+
xmlns:shared="using:CSharpMath.Uno.Example.Shared"
89
xmlns:skia="using:SkiaSharp.Views.UWP"
910
mc:Ignorable="d">
1011

1112
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
12-
<skia:SKXamlCanvas
13-
x:Name="canvasView"
14-
VerticalAlignment="Stretch"
15-
PaintSurface="CanvasView_PaintSurface" />
13+
<Pivot>
14+
<PivotItem Header="Try">
15+
<shared:TryPage />
16+
</PivotItem>
17+
<PivotItem Header="More examples">
18+
<shared:MoreExamplesPage />
19+
</PivotItem>
20+
<PivotItem Header="Clock">
21+
<shared:ClockPage />
22+
</PivotItem>
23+
</Pivot>
1624
</Grid>
1725
</Page>

CSharpMath.Uno.Example/CSharpMath.Uno.Example.Shared/MainPage.xaml.cs

Lines changed: 1 addition & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -24,103 +24,8 @@ namespace CSharpMath.Uno.Example {
2424
/// An empty page that can be used on its own or navigated to within a Frame.
2525
/// </summary>
2626
public sealed partial class MainPage : Page {
27-
private readonly DispatcherTimer _timer;
28-
2927
public MainPage() {
30-
this.InitializeComponent();
31-
_timer = new DispatcherTimer();
32-
_timer.Interval = TimeSpan.FromMilliseconds(200);
33-
_timer.Tick += (s, e) => {
34-
canvasView.Invalidate();
35-
};
36-
}
37-
38-
protected override void OnNavigatedTo(NavigationEventArgs e) {
39-
base.OnNavigatedTo(e);
40-
_timer.Start();
41-
}
42-
43-
readonly SKPaint blackFillPaint = new SKPaint {
44-
Style = SKPaintStyle.Fill,
45-
Color = SKColors.Black
46-
};
47-
readonly SKPaint whiteFillPaint = new SKPaint {
48-
Style = SKPaintStyle.Fill,
49-
Color = SKColors.White
50-
};
51-
readonly SKPaint whiteStrokePaint = new SKPaint {
52-
Style = SKPaintStyle.Stroke,
53-
Color = SKColors.White,
54-
StrokeCap = SKStrokeCap.Round,
55-
IsAntialias = true
56-
};
57-
readonly SKPaint redStrokePaint = new SKPaint {
58-
Style = SKPaintStyle.Stroke,
59-
Color = SKColors.Red,
60-
StrokeCap = SKStrokeCap.Round,
61-
IsAntialias = true
62-
};
63-
readonly string[] labels = {
64-
// Four 4s make 1 to 12 using different operations
65-
@"$\frac{44+4}{4}$",
66-
@"$\frac{44}{44}$",
67-
@"$\frac{4}{4}+\frac{4}{4}$",
68-
@"$\frac{4+4+4}{4}$",
69-
@"$4+\frac{4-4}{4}$",
70-
@"$4+4^{4-4}$",
71-
@"$4+\frac{4+4}{4}$",
72-
@"$\frac{44}{4}-4$",
73-
@"$\sqrt{4}^{4-\frac{4}{4}}$",
74-
@"$\:\:(4-\frac{4}{4})^{\sqrt{4}}$",
75-
@"$\frac{44-4}{4}$",
76-
@"$\frac{4!}{\sqrt{4}}-\frac{4}{4}$"
77-
};
78-
private void CanvasView_PaintSurface(object sender, SKPaintSurfaceEventArgs e) {
79-
var canvas = e.Surface.Canvas;
80-
canvas.Clear(SKColors.CornflowerBlue);
81-
canvas.Translate(e.Info.Width / 2, e.Info.Height / 2);
82-
canvas.Scale(e.Info.Width / 210f);
83-
canvas.DrawCircle(0, 0, 100, blackFillPaint);
84-
var painter = new TextPainter { FontSize = 8, TextColor = SKColors.White };
85-
for (int i = 0; i < 60; i++) {
86-
// Dots
87-
canvas.Save();
88-
canvas.RotateDegrees(6 * i);
89-
canvas.DrawCircle(0, -90, i % 5 == 0 ? 4 : 2, whiteFillPaint);
90-
canvas.Restore();
91-
// Maths
92-
if (i % 5 == 0) {
93-
painter.LaTeX = labels[i / 5];
94-
if (!(painter.Measure(e.Info.Width) is { } measure))
95-
throw new Structures.InvalidCodePathException("Invalid LaTeX");
96-
var θ = (90 - 6 * i) / 180f * PI;
97-
var sinθ = (float)Sin(θ);
98-
var cosθ = (float)Cos(θ);
99-
painter.Draw(canvas,
100-
new System.Drawing.PointF(75 * cosθ - (float)measure.Width / 2,
101-
-75 * sinθ - (float)measure.Height / 2),
102-
float.PositiveInfinity);
103-
}
104-
}
105-
var dateTime = DateTime.Now;
106-
// H
107-
canvas.Save();
108-
canvas.RotateDegrees(30 * dateTime.Hour + dateTime.Minute / 2f);
109-
whiteStrokePaint.StrokeWidth = 12;
110-
canvas.DrawLine(0, 0, 0, -50, whiteStrokePaint);
111-
canvas.Restore();
112-
// M
113-
canvas.Save();
114-
canvas.RotateDegrees(6 * dateTime.Minute + dateTime.Second / 10f);
115-
whiteStrokePaint.StrokeWidth = 6;
116-
canvas.DrawLine(0, 0, 0, -65, whiteStrokePaint);
117-
canvas.Restore();
118-
// S
119-
canvas.Save();
120-
canvas.RotateDegrees(6f * (dateTime.Second + dateTime.Millisecond / 1000f));
121-
redStrokePaint.StrokeWidth = 2;
122-
canvas.DrawLine(0, 0, 0, -75, redStrokePaint);
123-
canvas.Restore();
28+
this.InitializeComponent();
12429
}
12530
}
12631
}

0 commit comments

Comments
 (0)