Skip to content

Commit 114bfce

Browse files
committed
First working Android, UWP samples
1 parent cb747a0 commit 114bfce

File tree

17 files changed

+739
-11
lines changed

17 files changed

+739
-11
lines changed

CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.Droid/CSharpMath.UWPUno.Example.Droid.csproj

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<AndroidUseAapt2>true</AndroidUseAapt2>
1818
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
1919
<AndroidUseLatestPlatformSdk>False</AndroidUseLatestPlatformSdk>
20-
<TargetFrameworkVersion>v10.0</TargetFrameworkVersion>
20+
<TargetFrameworkVersion>v11.0</TargetFrameworkVersion>
2121
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
2222
<AndroidUseIntermediateDesignerFile>True</AndroidUseIntermediateDesignerFile>
2323
<ResourcesDirectory>..\CSharpMath.UWPUno.Example.Shared\Strings</ResourcesDirectory>
@@ -65,6 +65,9 @@
6565
<PackageReference Include="Uno.UniversalImageLoader" Version="1.9.33" />
6666
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.1" />
6767
<PackageReference Include="Microsoft.Extensions.Logging.Filter" Version="1.1.1" />
68+
<PackageReference Include="Validation">
69+
<Version>2.4.22</Version>
70+
</PackageReference>
6871
</ItemGroup>
6972
<ItemGroup>
7073
<Compile Include="MainActivity.cs" />
@@ -89,10 +92,26 @@
8992
<AndroidResource Include="Resources\values\Styles.xml" />
9093
</ItemGroup>
9194
<ItemGroup>
95+
<ProjectReference Include="..\..\CSharpMath.Editor\CSharpMath.Editor.csproj">
96+
<Project>{38f58489-ede4-4289-8acf-a9756977a7a6}</Project>
97+
<Name>CSharpMath.Editor</Name>
98+
</ProjectReference>
99+
<ProjectReference Include="..\..\CSharpMath.Rendering\CSharpMath.Rendering.csproj">
100+
<Project>{65016a61-2125-4e0c-90e8-a915230c7826}</Project>
101+
<Name>CSharpMath.Rendering</Name>
102+
</ProjectReference>
103+
<ProjectReference Include="..\..\CSharpMath.SkiaSharp\CSharpMath.SkiaSharp.csproj">
104+
<Project>{35b4bb5b-2202-436e-9afe-00997ca2cc65}</Project>
105+
<Name>CSharpMath.SkiaSharp</Name>
106+
</ProjectReference>
92107
<ProjectReference Include="..\..\CSharpMath.UWPUno\CSharpMath.UWPUno.csproj">
93108
<Project>{5c46ca75-fa31-4281-80eb-a07750e1fecb}</Project>
94109
<Name>CSharpMath.UWPUno</Name>
95110
</ProjectReference>
111+
<ProjectReference Include="..\..\CSharpMath\CSharpMath.csproj">
112+
<Project>{5157367b-f03e-4acb-83a1-0de414a3bfca}</Project>
113+
<Name>CSharpMath</Name>
114+
</ProjectReference>
96115
</ItemGroup>
97116
<Import Project="..\CSharpMath.UWPUno.Example.Shared\CSharpMath.UWPUno.Example.Shared.projitems" Label="Shared" Condition="Exists('..\CSharpMath.UWPUno.Example.Shared\CSharpMath.UWPUno.Example.Shared.projitems')" />
98117
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="CSharpMath.UWPUno.Example" android:versionCode="1" android:versionName="1.0">
3-
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="29" />
4-
<application android:label="CSharpMath.UWPUno.Example"></application>
5-
</manifest>
3+
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="30" />
4+
<application android:label="CSharpMath.UWPUno.Example"></application>
5+
</manifest>

CSharpMath.UWPUno.Example/CSharpMath.UWPUno.Example.Shared/CSharpMath.UWPUno.Example.Shared.projitems

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,33 @@
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>
2431
<Compile Include="$(MSBuildThisFileDirectory)TryPage.xaml.cs">
2532
<DependentUpon>TryPage.xaml</DependentUpon>
2633
</Compile>
2734
</ItemGroup>
2835
<ItemGroup>
36+
<Page Include="$(MSBuildThisFileDirectory)ClockPage.xaml">
37+
<SubType>Designer</SubType>
38+
<Generator>MSBuild:Compile</Generator>
39+
</Page>
2940
<Page Include="$(MSBuildThisFileDirectory)MainPage.xaml">
3041
<SubType>Designer</SubType>
3142
<Generator>MSBuild:Compile</Generator>
3243
</Page>
44+
<Page Include="$(MSBuildThisFileDirectory)MoreExamplesPage.xaml">
45+
<SubType>Designer</SubType>
46+
<Generator>MSBuild:Compile</Generator>
47+
</Page>
3348
<Page Include="$(MSBuildThisFileDirectory)TryPage.xaml">
3449
<SubType>Designer</SubType>
3550
<Generator>MSBuild:Compile</Generator>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Page
2+
x:Class="CSharpMath.UWPUno.Example.ClockPage"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:local="using:CSharpMath.UWPUno.Example"
6+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
8+
mc:Ignorable="d"
9+
xmlns:skia="using:SkiaSharp.Views.UWP"
10+
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
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.UWPUno.Example {
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.UWPUno.Example/CSharpMath.UWPUno.Example.Shared/MainPage.xaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
<PivotItem Header="Try">
1313
<local:TryPage />
1414
</PivotItem>
15-
<!--<PivotItem Header="More examples">
16-
<shared:MoreExamplesPage />
15+
<PivotItem Header="More examples">
16+
<local:MoreExamplesPage />
1717
</PivotItem>
1818
<PivotItem Header="Clock">
19-
<shared:ClockPage />
20-
</PivotItem>-->
19+
<local:ClockPage />
20+
</PivotItem>
2121
</Pivot>
2222
</Grid>
2323
</Page>

0 commit comments

Comments
 (0)