Skip to content

Commit

Permalink
Merge branch 'winui3-project'
Browse files Browse the repository at this point in the history
  • Loading branch information
aesalazar committed Sep 4, 2024
2 parents 2ddc86f + 7821c8b commit 700ae40
Show file tree
Hide file tree
Showing 206 changed files with 699 additions and 34,952 deletions.
6 changes: 3 additions & 3 deletions Asteroids.Blazor.Maui/Asteroids.Blazor.Maui.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebView.Maui" Version="8.0.20" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebView.Maui" Version="8.0.82" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
<PackageReference Include="Microsoft.Maui.Controls" Version="8.0.20" />
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.20" />
<PackageReference Include="Microsoft.Maui.Controls" Version="8.0.82" />
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.82" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions Asteroids.Blazor.Wasm/Asteroids.Blazor.Wasm.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.4" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.4" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.8" PrivateAssets="all" />
<PackageReference Include="System.Net.Http.Json" Version="8.0.0" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="8.0.4" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="8.0.8" />
</ItemGroup>

<ItemGroup>
Expand Down
319 changes: 130 additions & 189 deletions Asteroids.Standard.sln

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions Asteroids.WinUi3/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<Application
x:Class="Asteroids.WinUi3.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Asteroids.WinUi3">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
<!-- Other merged dictionaries here -->
</ResourceDictionary.MergedDictionaries>
<!-- Other app resources here -->
</ResourceDictionary>
</Application.Resources>
</Application>
34 changes: 34 additions & 0 deletions Asteroids.WinUi3/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Microsoft.UI.Xaml;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace Asteroids.WinUi3
{
/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
public partial class App : Application
{
/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public App()
{
InitializeComponent();
}

/// <summary>
/// Invoked when the application is launched.
/// </summary>
/// <param name="args">Details about the launch request and process.</param>
protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
{
m_window = new MainWindow();
m_window.Activate();
}

private Window m_window;
}
}
Binary file added Asteroids.WinUi3/Assets/LockScreenLogo.scale-200.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Asteroids.WinUi3/Assets/StoreLogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
65 changes: 65 additions & 0 deletions Asteroids.WinUi3/Asteroids.WinUi3.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<RootNamespace>Asteroids.WinUi3</RootNamespace>
<ApplicationManifest>app.manifest</ApplicationManifest>
<Platforms>x86;x64;ARM64</Platforms>
<RuntimeIdentifiers Condition="$([MSBuild]::GetTargetFrameworkVersion('$(TargetFramework)')) &gt;= 8">win-x86;win-x64;win-arm64</RuntimeIdentifiers>
<RuntimeIdentifiers Condition="$([MSBuild]::GetTargetFrameworkVersion('$(TargetFramework)')) &lt; 8">win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers>
<PublishProfile>win-$(Platform).pubxml</PublishProfile>
<UseWinUI>true</UseWinUI>
<EnableMsixTooling>true</EnableMsixTooling>
</PropertyGroup>

<ItemGroup>
<Content Include="Assets\SplashScreen.scale-200.png" />
<Content Include="Assets\LockScreenLogo.scale-200.png" />
<Content Include="Assets\Square150x150Logo.scale-200.png" />
<Content Include="Assets\Square44x44Logo.scale-200.png" />
<Content Include="Assets\Square44x44Logo.targetsize-24_altform-unplated.png" />
<Content Include="Assets\StoreLogo.png" />
<Content Include="Assets\Wide310x150Logo.scale-200.png" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26100.1" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.240802000" />
<PackageReference Include="SkiaSharp.Views.WinUI" Version="2.88.8" />
<Manifest Include="$(ApplicationManifest)" />
</ItemGroup>

<!--
Defining the "Msix" ProjectCapability here allows the Single-project MSIX Packaging
Tools extension to be activated for this project even if the Windows App SDK Nuget
package has not yet been restored.
-->
<ItemGroup Condition="'$(DisableMsixProjectCapabilityAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
<ProjectCapability Include="Msix" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Asteroids.Standard\Asteroids.Standard.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Helpers\" />
</ItemGroup>

<!--
Defining the "HasPackageAndPublishMenuAddedByProject" property here allows the Solution
Explorer "Package and Publish" context menu entry to be enabled for this project even if
the Windows App SDK Nuget package has not yet been restored.
-->
<PropertyGroup Condition="'$(DisableHasPackageAndPublishMenuAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
<HasPackageAndPublishMenu>true</HasPackageAndPublishMenu>
</PropertyGroup>

<!--ADDED TO ALLOW DEUGGING WITHOUT INSTALLING THE PACKAGE TO THE OS-->
<PropertyGroup>
<!--SUPRESS PACKAGING-->
<WindowsPackageType>None</WindowsPackageType>

<!-- Bundle the WinUI3 components -->
<WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@
using Asteroids.Standard.Enums;
using Asteroids.Standard.Interfaces;
using SkiaSharp;
using SkiaSharp.Views.Forms;
using Xamarin.Forms;
using SkiaSharp.Views.Windows;

namespace Asteroids.Xamarin.Classes
namespace Asteroids.WinUi3.Classes
{
internal sealed class GraphicsContainer : SKCanvasView, IGraphicContainer, IRegisterable
/// <summary>
/// Canvas Control to paint vectors.
/// </summary>
internal sealed class GraphicsContainer : SKXamlCanvas, IGraphicContainer, IDisposable
{
private bool _isDisposed;
private IDictionary<DrawColor, SKColor> _colorCache = new Dictionary<DrawColor, SKColor>();
private IEnumerable<IGraphicLine> _lastLines = new List<IGraphicLine>();
private IEnumerable<IGraphicPolygon> _lastPolygons = new List<IGraphicPolygon>();
private IEnumerable<IGraphicLine> _lastLines = [];
private IEnumerable<IGraphicPolygon> _lastPolygons = [];

public Task Initialize(IDictionary<DrawColor, string> drawColorMap)
{
Expand All @@ -32,16 +35,26 @@ public Task Initialize(IDictionary<DrawColor, string> drawColorMap)

public Task Draw(IEnumerable<IGraphicLine> lines, IEnumerable<IGraphicPolygon> polygons)
{
if (_isDisposed)
return Task.CompletedTask;

_lastLines = lines;
_lastPolygons = polygons;

InvalidateSurface();

Invalidate();
return Task.CompletedTask;
}

public void Dispose()
{
_isDisposed = true;
}

private void OnPaintSurface(object sender, SKPaintSurfaceEventArgs e)
{
if (_isDisposed)
return;

var canvas = e.Surface.Canvas;
canvas.Clear();

Expand All @@ -65,7 +78,7 @@ private void OnPaintSurface(object sender, SKPaintSurfaceEventArgs e)
{
Color = _colorCache[gpoly.Color],
IsStroke = true,
};
};

var path = new SKPath();
path.AddPoly(gpoly.Points.Select(p => new SKPoint(p.X, p.Y)).ToArray());
Expand Down
28 changes: 28 additions & 0 deletions Asteroids.WinUi3/Helpers/SoundPlayerHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.IO;
using Windows.Storage.Streams;

/// <summary>
/// Helper methods for playing sound in WinUI.
/// </summary>
public static class SoundPlayerHelper
{
/// <summary>
/// Converts a standard <see cref="Stream"/> into an <see cref="IRandomAccessStream"/> that can be played by WinUI.
/// </summary>
/// <param name="inputStream">IO Stream to convert.</param>
/// <returns>Initialized WinUI Stream.</returns>
public static IRandomAccessStream ToRandomAccessStream(this Stream inputStream)
{
var randomAccessStream = new InMemoryRandomAccessStream();
using (var outputStream = randomAccessStream.GetOutputStreamAt(0))
{
var writer = new DataWriter(outputStream);
var buffer = new byte[inputStream.Length];
inputStream.Read(buffer, 0, buffer.Length);
writer.WriteBytes(buffer);
writer.StoreAsync().GetResults();
}
randomAccessStream.Seek(0);
return randomAccessStream;
}
}
19 changes: 19 additions & 0 deletions Asteroids.WinUi3/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<Window
x:Class="Asteroids.WinUi3.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Asteroids.WinUi3"
xmlns:classes="using:Asteroids.WinUi3.Classes"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:skiasharp="using:SkiaSharp.Views.Windows"
>
<classes:GraphicsContainer
Loaded="GraphicsContainer_Loaded"
SizeChanged="GraphicsContainer_SizeChanged"
KeyUp="GraphicsContainer_KeyUp"
KeyDown="GraphicsContainer_KeyDown"
/>
</Window>
Loading

0 comments on commit 700ae40

Please sign in to comment.