Skip to content

Commit

Permalink
Try add Microsoft.Maui.Graphics.Uno
Browse files Browse the repository at this point in the history
  • Loading branch information
lindexi committed Jan 18, 2024
1 parent 5db72c3 commit daf3e44
Show file tree
Hide file tree
Showing 22 changed files with 193 additions and 34 deletions.
19 changes: 19 additions & 0 deletions KefalurcilaybelJallbuderenajel/KefalurcilaybelJallbuderenajel.sln
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SamplesApp", "KefalurcilaybelJallbuderenajel\SamplesApp\SamplesApp.csproj", "{F48FF10C-BA84-40C2-9405-254DF90E962C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Maui.Graphics.UnoAbstract", "KefalurcilaybelJallbuderenajel\Microsoft.Maui.Graphics.UnoAbstract\Microsoft.Maui.Graphics.UnoAbstract.csproj", "{E10D2E6D-7157-49D5-85DD-D7D55E08852F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -144,6 +146,22 @@ Global
{F48FF10C-BA84-40C2-9405-254DF90E962C}.Release|x64.Build.0 = Release|Any CPU
{F48FF10C-BA84-40C2-9405-254DF90E962C}.Release|x86.ActiveCfg = Release|Any CPU
{F48FF10C-BA84-40C2-9405-254DF90E962C}.Release|x86.Build.0 = Release|Any CPU
{E10D2E6D-7157-49D5-85DD-D7D55E08852F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E10D2E6D-7157-49D5-85DD-D7D55E08852F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E10D2E6D-7157-49D5-85DD-D7D55E08852F}.Debug|arm64.ActiveCfg = Debug|Any CPU
{E10D2E6D-7157-49D5-85DD-D7D55E08852F}.Debug|arm64.Build.0 = Debug|Any CPU
{E10D2E6D-7157-49D5-85DD-D7D55E08852F}.Debug|x64.ActiveCfg = Debug|Any CPU
{E10D2E6D-7157-49D5-85DD-D7D55E08852F}.Debug|x64.Build.0 = Debug|Any CPU
{E10D2E6D-7157-49D5-85DD-D7D55E08852F}.Debug|x86.ActiveCfg = Debug|Any CPU
{E10D2E6D-7157-49D5-85DD-D7D55E08852F}.Debug|x86.Build.0 = Debug|Any CPU
{E10D2E6D-7157-49D5-85DD-D7D55E08852F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E10D2E6D-7157-49D5-85DD-D7D55E08852F}.Release|Any CPU.Build.0 = Release|Any CPU
{E10D2E6D-7157-49D5-85DD-D7D55E08852F}.Release|arm64.ActiveCfg = Release|Any CPU
{E10D2E6D-7157-49D5-85DD-D7D55E08852F}.Release|arm64.Build.0 = Release|Any CPU
{E10D2E6D-7157-49D5-85DD-D7D55E08852F}.Release|x64.ActiveCfg = Release|Any CPU
{E10D2E6D-7157-49D5-85DD-D7D55E08852F}.Release|x64.Build.0 = Release|Any CPU
{E10D2E6D-7157-49D5-85DD-D7D55E08852F}.Release|x86.ActiveCfg = Release|Any CPU
{E10D2E6D-7157-49D5-85DD-D7D55E08852F}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -156,6 +174,7 @@ Global
{925EC5D6-48F5-4478-AC0B-F0480EA42146} = {9FA3C93B-E0D0-475D-B65E-CD65987B81A1}
{515FCB6A-C5FE-40AE-90EE-235ED45D8B51} = {9FA3C93B-E0D0-475D-B65E-CD65987B81A1}
{F48FF10C-BA84-40C2-9405-254DF90E962C} = {EC5677AD-1FE3-4096-9237-5891B9F18FA9}
{E10D2E6D-7157-49D5-85DD-D7D55E08852F} = {EC5677AD-1FE3-4096-9237-5891B9F18FA9}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B410F6AC-862B-47CE-B1F2-FC30B7CAD6F2}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<Project ToolsVersion="15.0">
<ItemGroup>
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
<PackageVersion Include="Microsoft.Maui.Graphics" Version="8.0.6" />
<PackageVersion Include="Microsoft.Maui.Graphics.Skia" Version="8.0.6" />
<PackageVersion Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.756" />
<PackageVersion Include="Microsoft.WindowsAppSDK" Version="1.4.231008000" />
<PackageVersion Include="SkiaSharp.Skottie" Version="2.88.7" />
Expand All @@ -15,4 +17,4 @@
<PackageVersion Include="Uno.WinUI.Skia.Gtk" Version="5.0.143" />
<PackageVersion Include="Uno.WinUI.Skia.Wpf" Version="5.0.143" />
</ItemGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
using Microsoft.Maui.Graphics.UnoAbstract;
using Microsoft.UI.Xaml;
using SamplesApp;

namespace KefalurcilaybelJallbuderenajel.Skia.Gtk;

public class Hack : IHack
{
public FrameworkElement Create()
{
return new GraphicsCanvasElement()
{
Width = 200,
Height = 100
};
return new HackElement();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Microsoft.Maui.Graphics.UnoAbstract;
using SamplesApp;

namespace KefalurcilaybelJallbuderenajel.Skia.Gtk;

public partial class HackElement : GraphicsCanvasElement, IDrawableNotify
{
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Microsoft.Maui.Graphics.UnoAbstract;

namespace KefalurcilaybelJallbuderenajel.Skia.Gtk;

static class HackInitializer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<PackageReference Include="SkiaSharp.Skottie" />
<PackageReference Include="Uno.WinUI.DevServer" Condition="'$(Configuration)'=='Debug'" />
<PackageReference Include="Uno.UI.Adapter.Microsoft.Extensions.Logging" />
<PackageReference Include="Microsoft.Maui.Graphics.Skia" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\KefalurcilaybelJallbuderenajel\KefalurcilaybelJallbuderenajel.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<PackageReference Include="SkiaSharp.Skottie" />
<PackageReference Include="Uno.WinUI.DevServer" Condition="'$(Configuration)'=='Debug'" />
<PackageReference Include="Uno.UI.Adapter.Microsoft.Extensions.Logging" />
<PackageReference Include="Microsoft.Maui.Graphics.Skia" />
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="Wpf\App.xaml" XamlRuntime="Wpf" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
using Microsoft.Maui.Graphics.UnoAbstract;
using Microsoft.UI.Xaml;
using SamplesApp;

namespace KefalurcilaybelJallbuderenajel.WPF;

public class Hack : IHack
{
public FrameworkElement Create()
{
return new GraphicsCanvasElement()
{
Width = 200,
Height = 100
};
return new HackElement();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Microsoft.Maui.Graphics.UnoAbstract;
using SamplesApp;

namespace KefalurcilaybelJallbuderenajel.WPF;

public partial class HackElement : GraphicsCanvasElement, IDrawableNotify
{
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Microsoft.Maui.Graphics.UnoAbstract;

namespace KefalurcilaybelJallbuderenajel.WPF;

static class HackInitializer
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<PackageReference Include="Uno.WinUI" />
<PackageReference Include="Uno.Resizetizer" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" />
<PackageReference Include="Microsoft.Maui.Graphics" />
</ItemGroup>


Expand Down Expand Up @@ -55,4 +56,8 @@
<UnoImage Include="Assets\**\*.svg" />
<UpToDateCheckInput Include="**\*.xaml" Exclude="bin\**\*.xaml;obj\**\*.xaml" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Microsoft.Maui.Graphics.UnoAbstract\Microsoft.Maui.Graphics.UnoAbstract.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:KefalurcilaybelJallbuderenajel"
xmlns:graphics="using:Microsoft.Maui.Graphics.UnoAbstract"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<StackPanel x:Name="StackPanel"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<TextBlock x:Name="TextBlock" AutomationProperties.AutomationId="HelloTextBlock"
Text="Hello Uno Platform"
HorizontalAlignment="Center" />
<Border Background="AliceBlue">
<graphics:GraphicsCanvas Draw="GraphicsCanvas_OnDraw"/>
</Border>
</StackPanel>
</Page>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Uno.UI.Extensions;
using Microsoft.Maui.Graphics;

namespace KefalurcilaybelJallbuderenajel;

Expand All @@ -7,7 +7,12 @@ public sealed partial class MainPage : Page
public MainPage()
{
this.InitializeComponent();
}

StackPanel.Children.Add(HackHelper.Hack.Create());
private void GraphicsCanvas_OnDraw(object? sender, ICanvas e)
{
e.StrokeSize = 5;
e.StrokeColor = Colors.Red;
e.DrawRectangle(0, 0, 100, 100);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;

namespace Microsoft.Maui.Graphics.UnoAbstract;

public class GraphicsCanvas : Canvas, IDrawableNotify
{
public GraphicsCanvas()
{
SizeChanged += OnSizeChanged;
var frameworkElement = HackHelper.Hack?.Create();

if (frameworkElement != null)
{
IDrawableNotify drawableNotify = (IDrawableNotify) frameworkElement;
drawableNotify.Draw += OnDraw;
Children.Add(frameworkElement);
FrameworkElement = frameworkElement;
}
else
{
var textBlock = new TextBlock()
{
Text = "Not Supported"
};

FrameworkElement = textBlock;
}
}

private FrameworkElement FrameworkElement { get; }

private void OnDraw(object? sender, ICanvas e)
{
Draw?.Invoke(this, e);
}

private void OnSizeChanged(object sender, SizeChangedEventArgs e)
{
FrameworkElement.Width = e.NewSize.Width;
FrameworkElement.Height = e.NewSize.Height;
}

public event EventHandler<ICanvas>? Draw;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Microsoft.Maui.Graphics.UnoAbstract;

public static class HackHelper
{
public static IHack? Hack { set; get; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Microsoft.Maui.Graphics.UnoAbstract;

public interface IDrawableNotify
{
event EventHandler<ICanvas>? Draw;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Microsoft.UI.Xaml;

namespace Microsoft.Maui.Graphics.UnoAbstract;

public interface IHack
{
FrameworkElement Create();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows')) or '$(EnableWindowsTargeting)' == 'true'">$(TargetFrameworks);$(DotNetVersion)-windows10.0.19041</TargetFrameworks>
<TargetFrameworks>$(TargetFrameworks);$(DotNetVersion);</TargetFrameworks>
<TargetFrameworks Condition="'$(OverrideTargetFramework)'!=''">$(OverrideTargetFramework)</TargetFrameworks>
<!-- Ensures the .xr.xml files are generated in a proper layout folder -->
<GenerateLibraryLayout>true</GenerateLibraryLayout>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Uno.WinUI" />
<PackageReference Include="Microsoft.Maui.Graphics" />
</ItemGroup>
<Choose>
<When Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">
<ItemGroup>
<PackageReference Include="Microsoft.WindowsAppSDK" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" />
</ItemGroup>
<ItemGroup>
<!--
If you encounter this error message:
error NETSDK1148: A referenced assembly was compiled using a newer version of Microsoft.Windows.SDK.NET.dll.
Please update to a newer .NET SDK in order to reference this assembly.
This means that the two packages below must be aligned with the "build" version number of
the "Microsoft.Windows.SDK.BuildTools" package above, and the "revision" version number
must be the highest found in https://www.nuget.org/packages/Microsoft.Windows.SDK.NET.Ref.
-->
<!-- <FrameworkReference Update="Microsoft.Windows.SDK.NET.Ref" RuntimeFrameworkVersion="10.0.22621.28" />
<FrameworkReference Update="Microsoft.Windows.SDK.NET.Ref" TargetingPackVersion="10.0.22621.28" /> -->
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<Content Include="Assets\**" />
<Page Include="**\*.xaml" Exclude="bin\**\*.xaml;obj\**\*.xaml" />
<Compile Update="**\*.xaml.cs">
<DependentUpon>%(Filename)</DependentUpon>
</Compile>
<PriResource Include="**\*.resw" />
</ItemGroup>
</Otherwise>
</Choose>
<ItemGroup>
<UpToDateCheckInput Include="**\*.xaml" Exclude="bin\**\*.xaml;obj\**\*.xaml" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
using System.Linq;
using System.Text;
using Windows.Foundation;
using Microsoft.Maui.Graphics.Skia;
using Microsoft.UI;
using Microsoft.UI.Composition;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Input;
using SkiaSharp;
using Uno.UI.Composition;
using Microsoft.Maui.Graphics;

namespace SamplesApp;

Expand All @@ -19,6 +21,13 @@ public GraphicsCanvasElement()
Visual.Children.InsertAtBottom(new GraphicsCanvasVisual(Visual.Compositor, this));
}

public event EventHandler<ICanvas>? Draw;

internal void InvokeDraw(ICanvas canvas)
{
Draw?.Invoke(this, canvas);
}

class GraphicsCanvasVisual : Visual
{
public GraphicsCanvasVisual(Compositor compositor, GraphicsCanvasElement owner) : base(compositor)
Expand All @@ -32,13 +41,9 @@ internal override void Draw(in DrawingSession session)
{
if (_owner.TryGetTarget(out var graphicsCanvasElement))
{
var canvas = session.Surface.Canvas;
canvas.DrawRect(0, 0, 100, 100, new SKPaint()
{
Color = new SKColor(0xF1, 0x56, 0x56, 0xFF),
IsStroke = true,
StrokeWidth = 1,
});
using var skiaCanvas = new SkiaCanvas();
skiaCanvas.Canvas = session.Surface.Canvas;
graphicsCanvasElement.InvokeDraw(skiaCanvas);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
<PropertyGroup>
<TargetFrameworks>net8.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Maui.Graphics" />
<PackageReference Include="Microsoft.Maui.Graphics.Skia" />
</ItemGroup>

<ItemGroup>
<Reference Include="SkiaSharp">
Expand Down

0 comments on commit daf3e44

Please sign in to comment.