Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moves Microsoft.Maui.Graphics.Gtk into the Maui repo #9522

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Microsoft.Maui.Graphics.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
"src\\Graphics\\samples\\GraphicsTester.Skia.Windows\\GraphicsTester.Skia.Windows.csproj",
"src\\Graphics\\samples\\GraphicsTester.WinUI.Desktop\\GraphicsTester.WinUI.Desktop.csproj",
"src\\Graphics\\samples\\GraphicsTester.iOS\\GraphicsTester.iOS.csproj",
"src\\Graphics\\samples\\GraphicsTester.Gtk\\GraphicsTester.Gtk.csproj",
"src\\Graphics\\src\\Graphics.Skia.GtkSharp\\Graphics.Skia.GtkSharp.csproj",
"src\\Graphics\\src\\Graphics.Skia.WPF\\Graphics.Skia.WPF.csproj",
"src\\Graphics\\src\\Graphics.Skia\\Graphics.Skia.csproj",
"src\\Graphics\\src\\Graphics.Gtk\\Graphics.Gtk.csproj",
"src\\Graphics\\src\\Graphics.Win2D\\Graphics.Win2D.csproj",
"src\\Graphics\\src\\Graphics\\Graphics.csproj",
"src\\Graphics\\src\\Text.Markdig\\Graphics.Text.Markdig.csproj",
Expand Down
14 changes: 14 additions & 0 deletions Microsoft.Maui.sln
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Graphics.Skia", "src\Graphi
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Graphics.Win2D", "src\Graphics\src\Graphics.Win2D\Graphics.Win2D.csproj", "{291F634A-2D8D-48B6-A1A0-BB9BC265D6E4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Graphics.Gtk", "src\Graphics\src\Graphics.Gtk\Graphics.Gtk.csproj", "{4EDE89FC-7C84-4855-8DD8-D7C8B128A974}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Graphics.Text.Markdig", "src\Graphics\src\Text.Markdig\Graphics.Text.Markdig.csproj", "{375B22F5-9D79-4D17-B759-F8220DFB8B70}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Graphics.Tests", "src\Graphics\tests\Graphics.Tests\Graphics.Tests.csproj", "{56BBFDBD-254F-42B6-9984-46E19C53FB00}"
Expand All @@ -211,6 +213,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GraphicsTester.Mac", "src\G
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GraphicsTester.MacCatalyst", "src\Graphics\samples\GraphicsTester.MacCatalyst\GraphicsTester.MacCatalyst.csproj", "{B3DD0741-2EC3-4A54-82B7-73923DE4CF48}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GraphicsTester.Gtk", "src\Graphics\samples\GraphicsTester.Gtk\GraphicsTester.Gtk.csproj", "{624D161D-762C-45F7-9CBC-9929BA5D13EF}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GraphicsTester.Portable", "src\Graphics\samples\GraphicsTester.Portable\GraphicsTester.Portable.csproj", "{546614BB-07AA-4E8E-B6AE-EBDC183C4DAB}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GraphicsTester.Skia.Console", "src\Graphics\samples\GraphicsTester.Skia.Console\GraphicsTester.Skia.Console.csproj", "{EF6ACA06-D4DF-4C21-9F65-FBFEC6325094}"
Expand Down Expand Up @@ -605,6 +609,14 @@ Global
{34969E49-FA6E-41BB-9813-5689BB14021E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{34969E49-FA6E-41BB-9813-5689BB14021E}.Release|Any CPU.Build.0 = Release|Any CPU
{34969E49-FA6E-41BB-9813-5689BB14021E}.Release|Any CPU.Deploy.0 = Release|Any CPU
{4EDE89FC-7C84-4855-8DD8-D7C8B128A974}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4EDE89FC-7C84-4855-8DD8-D7C8B128A974}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4EDE89FC-7C84-4855-8DD8-D7C8B128A974}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4EDE89FC-7C84-4855-8DD8-D7C8B128A974}.Release|Any CPU.Build.0 = Release|Any CPU
{624D161D-762C-45F7-9CBC-9929BA5D13EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{624D161D-762C-45F7-9CBC-9929BA5D13EF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{624D161D-762C-45F7-9CBC-9929BA5D13EF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{624D161D-762C-45F7-9CBC-9929BA5D13EF}.Release|Any CPU.Build.0 = Release|Any CPU
{A23B108A-AB56-4692-B9DA-0E23602E3955}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A23B108A-AB56-4692-B9DA-0E23602E3955}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A23B108A-AB56-4692-B9DA-0E23602E3955}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -744,6 +756,8 @@ Global
{F26D31D3-CE4C-4F32-A77F-E2905C948674} = {42AB9AE1-631D-4AD4-85B7-910FF0940BDB}
{F351A992-18E4-473C-8ADD-2BA0BAA7B5A2} = {1BA0121E-0B83-4C8F-81BE-C293E7E35DCE}
{F68932B0-81A2-4CC3-A4F7-28091EE91B23} = {25D0D27A-C5FE-443D-8B65-D6C987F4A80E}
{4EDE89FC-7C84-4855-8DD8-D7C8B128A974} = {42AB9AE1-631D-4AD4-85B7-910FF0940BDB}
{624D161D-762C-45F7-9CBC-9929BA5D13EF} = {1BA0121E-0B83-4C8F-81BE-C293E7E35DCE}
{4A6930AE-B67C-4D29-B1A8-ED9EB7F923A7} = {50C758FE-4E10-409A-94F5-A75480960864}
{66CC98E3-6A1A-4C44-A23C-B575E82106EC} = {C564DDD6-DE79-45CD-88EA-3F690481572A}
{34969E49-FA6E-41BB-9813-5689BB14021E} = {936C47A9-A7EA-4FBD-8733-CED1D4100E69}
Expand Down
4 changes: 4 additions & 0 deletions eng/Microsoft.Extensions.targets
Original file line number Diff line number Diff line change
Expand Up @@ -189,5 +189,9 @@
Update="Fizzler"
Version="$(FizzlerPackageVersion)"
/>
<PackageReference
Update="GtkSharp"
Version="$(GtkSharpPackageVersion)"
/>
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
<TizenUIExtensionsVersion>0.9.0</TizenUIExtensionsVersion>
<SvgSkiaPackageVersion>0.5.13</SvgSkiaPackageVersion>
<FizzlerPackageVersion>1.2.0</FizzlerPackageVersion>
<GtkSharpPackageVersion>3.24.24.34</GtkSharpPackageVersion>
</PropertyGroup>
<PropertyGroup>
<DotNetVersionBand Condition=" '$(DotNetVersionBand)' == '' ">7.0.100</DotNetVersionBand>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>$(_MauiDotNetTfm)</TargetFramework>
<RootNamespace>GraphicsTester.Gtk</RootNamespace>

<PackageId>GraphicsTester.Gtk</PackageId>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Graphics.Gtk\Graphics.Gtk.csproj"/>
<ProjectReference Include="..\..\src\Graphics\Graphics.csproj"/>
<ProjectReference Include="..\GraphicsTester.Portable\GraphicsTester.Portable.csproj"/>

</ItemGroup>


</Project>
101 changes: 101 additions & 0 deletions src/Graphics/samples/GraphicsTester.Gtk/MainWindow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// This is free and unencumbered software released into the public domain.
// Happy coding!!! - GtkSharp Team

using System;
using System.Collections.Generic;
using GraphicsTester.Scenarios;
using Gtk;
using Microsoft.Maui.Graphics;
using Microsoft.Maui.Graphics.Platform.Gtk;

namespace GraphicsTester.Gtk;

class MainWindow : Window
{
private TreeView _treeView;
private TreeStore _store;
private Dictionary<string, AbstractScenario> _items;
private GtkGraphicsView _gtkGtkGraphicsView;

public MainWindow() : base(WindowType.Toplevel)
{
// Setup GUI
WindowPosition = WindowPosition.Center;
DefaultSize = new Gdk.Size(800, 600);

var headerBar = new HeaderBar { ShowCloseButton = true, Title = $"{typeof(Point).Namespace} Gtk Sample Application" };

var btnClickMe = new Button { AlwaysShowImage = true, Image = Image.NewFromIconName("document-new-symbolic", IconSize.Button) };

headerBar.PackStart(btnClickMe);

Titlebar = headerBar;

var hpanned = new HPaned { Position = 300 };

_treeView = new TreeView { HeadersVisible = false };

var scroll0 = new ScrolledWindow { Child = _treeView };

hpanned.Pack1(scroll0, true, true);

_gtkGtkGraphicsView = new GtkGraphicsView { BackgroundColor = Colors.White };

var scroll1 = new ScrolledWindow { Child = _gtkGtkGraphicsView };

hpanned.Pack2(scroll1, true, true);

Child = hpanned;

// Fill up data
FillUpTreeView();

// Connect events
_treeView.Selection.Changed += Selection_Changed;
Destroyed += (sender, e) => this.Close();

var scenario = ScenarioList.Scenarios[0];
_gtkGtkGraphicsView.Drawable = scenario;
}

private void Selection_Changed(object sender, EventArgs e)
{
if (!_treeView.Selection.GetSelected(out TreeIter iter)) return;

var s = _store.GetValue(iter, 0).ToString();

if (!_items.TryGetValue(s, out var scenario)) return;

_gtkGtkGraphicsView.Drawable = scenario;
_gtkGtkGraphicsView.HeightRequest = (int)scenario.Height;
_gtkGtkGraphicsView.WidthRequest = (int)scenario.Width;
}

private void FillUpTreeView()
{
// Init cells
var cellName = new CellRendererText();

// Init columns
var columeSections = new TreeViewColumn { Title = "Sections" };

columeSections.PackStart(cellName, true);

columeSections.AddAttribute(cellName, "text", 0);

_treeView.AppendColumn(columeSections);

// Init treeview
_store = new TreeStore(typeof(string));
_treeView.Model = _store;
_items = new Dictionary<string, AbstractScenario>();

foreach (var scenario in ScenarioList.Scenarios)
{
_store.AppendValues(scenario.ToString());
_items[scenario.ToString()] = scenario;
}

_treeView.ExpandAll();
}
}
81 changes: 81 additions & 0 deletions src/Graphics/samples/GraphicsTester.Gtk/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// This is free and unencumbered software released into the public domain.
// Happy coding!!! - GtkSharp Team

using System;
using Gtk;
using Microsoft.Maui.Graphics.Platform.Gtk;

namespace GraphicsTester.Gtk;

class Program
{
public static Application App;
public static Window Win;

[STAThread]
public static void Main(string[] args)
{
Application.Init();

App = new Application("Microsoft.Maui.Graphics.Samples", GLib.ApplicationFlags.None);

App.Startup += (s, e) => StartupTests();

App.Startup += (s, e) =>
{
Win = new MainWindow();
App.AddWindow(Win);

var menu = new GLib.Menu();

menu.AppendItem(new GLib.MenuItem("About", "app.about"));
menu.AppendItem(new GLib.MenuItem("Quit", "app.quit"));
App.AppMenu = menu;

var aboutAction = new GLib.SimpleAction("about", null);
aboutAction.Activated += AboutActivated;
App.AddAction(aboutAction);

var quitAction = new GLib.SimpleAction("quit", null);
quitAction.Activated += QuitActivated;
App.AddAction(quitAction);

Win.ShowAll();
};

App.Activated += (s, e) =>
{
App.Windows[0].Present();
};

((GLib.Application)App).Run();
}

private static void StartupTests()
{
StartupTest.InitTests();
}

private static void AboutActivated(object sender, EventArgs e)
{
var dialog = new AboutDialog
{
TransientFor = Win,
ProgramName = $"{nameof(GtkGraphicsView)} Sample Application",
Version = "1.0.0.0",
Comments = $"A gtk sample application for the {typeof(Microsoft.Maui.Graphics.Point).Namespace} project.",
LogoIconName = "system-run-symbolic",
License = "This sample application is licensed under public domain.",
Website = "https://www.github.com/dotnet/Microsoft.Maui.Graphics",
WebsiteLabel = "Microsoft.Maui.Graphics Website"
};

dialog.Run();
dialog.Hide();
}

private static void QuitActivated(object sender, EventArgs e)
{
((GLib.Application)App).Quit();
}
}
36 changes: 36 additions & 0 deletions src/Graphics/samples/GraphicsTester.Gtk/StartupTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using Microsoft.Maui.Graphics.Platform.Gtk;

namespace GraphicsTester.Gtk;

public class StartupTest
{
public static void InitTests()
{
var canvas = new PlatformCanvas();

Console.WriteLine(FontExtensions.Default);

using var desc = Pango.FontDescription.FromString(FontExtensions.Default.Family);
Console.WriteLine(desc);

var testStr = "123456";
var size = canvas.GetStringSize(testStr, null, -1);
Console.WriteLine($"{testStr} : {size}");

size = canvas.GetStringSize(testStr, null, size.Width / 2);
Console.WriteLine($"{testStr} : {size}");

Console.WriteLine($"ScreenResolution {HardwareInformations.DefaultScreen.Resolution}");
Console.WriteLine($"{nameof(HardwareInformations.CurrentScaleFaktor)} {HardwareInformations.CurrentScaleFaktor}");
}

void Notes()
{
// for context;
var x = typeof(Gdk.CairoHelper);

// for fonts:
var y = typeof(Pango.CairoHelper);
}
}
43 changes: 43 additions & 0 deletions src/Graphics/src/Graphics.Gtk/CanvasExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
namespace Microsoft.Maui.Graphics.Platform.Gtk;

public static class CanvasExtensions {

public static Cairo.LineJoin ToLineJoin(this LineJoin lineJoin) =>
lineJoin switch {
LineJoin.Bevel => Cairo.LineJoin.Bevel,
LineJoin.Round => Cairo.LineJoin.Round,
_ => Cairo.LineJoin.Miter
};

public static Cairo.FillRule ToFillRule(this WindingMode windingMode) =>
windingMode switch {
WindingMode.EvenOdd => Cairo.FillRule.EvenOdd,
_ => Cairo.FillRule.Winding
};

public static Cairo.LineCap ToLineCap(this LineCap lineCap) =>
lineCap switch {
LineCap.Butt => Cairo.LineCap.Butt,
LineCap.Round => Cairo.LineCap.Round,
_ => Cairo.LineCap.Square
};

public static Cairo.Antialias ToAntialias(bool antialias) => antialias ? Cairo.Antialias.Default : Cairo.Antialias.None;

public static Size? GetSize(this Cairo.Surface it) {
if (it is Cairo.ImageSurface i)
return new Size(i.Width, i.Height);

if (it is Cairo.XlibSurface x)
return new Size(x.Width, x.Height);

if (it is Cairo.XcbSurface c)
return null;

if (it is Cairo.SvgSurface s)
return null;

return null;
}

}
22 changes: 22 additions & 0 deletions src/Graphics/src/Graphics.Gtk/ColorExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;

namespace Microsoft.Maui.Graphics.Platform.Gtk;

public static class ColorExtensions {

public static Gdk.RGBA ToGdkRgba(this Color color)
=> color == default ? default : new Gdk.RGBA {Red = color.Red, Green = color.Green, Blue = color.Blue, Alpha = color.Alpha};

public static Color ToColor(this Gdk.RGBA color)
=> new Color((float) color.Red, (float) color.Green, (float) color.Blue, (float) color.Alpha);

public static Cairo.Color ToCairoColor(this Color color)
=> color == default ? default : new Cairo.Color(color.Red, color.Green, color.Blue, color.Alpha);

public static Cairo.Color ToCairoColor(this Gdk.RGBA color)
=> new Cairo.Color(color.Red, color.Green, color.Blue, color.Alpha);

public static Color ToColor(this Cairo.Color color)
=> new Color((float) color.R, (float) color.G, (float) color.B, (float) color.A);

}
Loading