HTLLeonding.Utility.SimpleDrawing 2.0.0

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package HTLLeonding.Utility.SimpleDrawing --version 2.0.0
NuGet\Install-Package HTLLeonding.Utility.SimpleDrawing -Version 2.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="HTLLeonding.Utility.SimpleDrawing" Version="2.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add HTLLeonding.Utility.SimpleDrawing --version 2.0.0
#r "nuget: HTLLeonding.Utility.SimpleDrawing, 2.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install HTLLeonding.Utility.SimpleDrawing as a Cake Addin
#addin nuget:?package=HTLLeonding.Utility.SimpleDrawing&version=2.0.0

// Install HTLLeonding.Utility.SimpleDrawing as a Cake Tool
#tool nuget:?package=HTLLeonding.Utility.SimpleDrawing&version=2.0.0

SimpleDrawing - Cross Platform

  • Allows for the simple drawing of basic shapes on a canvas
  • Renders the canvas in a window
  • Works on multiple platforms (tested Windows, Linux; should also work on Mac)
  • Based on SkiaSharp
  • User click events are registered

This library is meant for simple applications so only basic functions are available to keep the API easy to use.

Sample Usage

using Avalonia.Input;
using Avalonia.Media;
using SimpleDrawing;
using SimpleDrawing.Core;

await LeoCanvas.Init(400, 400, clickAction: DrawCircleOnClick);

LeoCanvas.DrawLine(new(100, 100), new(300, 300));
LeoCanvas.DrawLine(new(300, 100), new(100, 300), thickness: 4, color: Brushes.Green);
LeoCanvas.DrawRectangle(new(50, 50), new(100, 80), lineColor: Brushes.Red);
LeoCanvas.DrawRectangle(new(325, 325), new(375, 375), fillColor: Brushes.Azure);
LeoCanvas.DrawEllipse(new(200, 300), 50, 75, 
                   lineColor: Brushes.Firebrick, fillColor: Brushes.Firebrick);
LeoCanvas.DrawCircle(new(350, 75), 40, lineThickness: 2.5D, 
                  lineColor: Brushes.BlueViolet, fillColor: Brushes.Gold);
LeoCanvas.DrawText(new(25, 350), "Hello World", 24, Brushes.Lime);

LeoCanvas.Render();

LeoCanvas.DrawLine(new(200, 25), new(200, 375), 8);
LeoCanvas.Render();

await Task.Delay(TimeSpan.FromSeconds(2));
LeoCanvas.Clear();
var x = 50;
for (var i = 0; i < 10; i++)
{
    LeoCanvas.DrawLine(new(x, 25), new(x, 375), 8);
    x += 25;
    LeoCanvas.Render();
    await Task.Delay(TimeSpan.FromSeconds(1));
}

var imagePath = Path.Combine(Directory.GetCurrentDirectory(), "Data/logo.png");
LeoCanvas.DrawImageAtLocation(imagePath, new(50, 100), new (350, 175));
LeoCanvas.Render();

Console.Write("Press any key to exit...");
Console.ReadKey();

static void DrawCircleOnClick(ClickEvent @event)
{
    var radius = @event.Button switch
    {
        MouseButton.Left => 25,
        MouseButton.Right => 50,
        _ => 10
    };
    LeoCanvas.DrawCircle(@event.ClickedPoint, radius);
    LeoCanvas.Render();
}

Click Events

An Action can be passed to the Init function to register a click handler which will receive the location the user clicked within the canvas as well as information if the left or right mouse button was used.

await LeoCanvas.Init(600, 600, clickAction: DrawCircleOnClick);

static void DrawCircleOnClick(ClickEvent @event)
{
    var radius = @event.Button switch
    {
        MouseButton.Left => 25,
        MouseButton.Right => 50,
        _ => 10
    };
    LeoCanvas.DrawCircle(@event.ClickedPoint, radius);
    LeoCanvas.Render();
}

Rendering Images

Images can be rendered on the canvas using the DrawImageAtLocation function. The image path should be passed as the first parameter and the location as the second parameter.

It is also possible to directly pass an IImage to an overload. Images can be (pre)loaded via the TryLoadImage method to avoid loading them from the disk every time.

This library should support all image formats handled by SkiaSharp (e.g., PNG, JPEG, BMP).

var imagePath = Path.Combine(Directory.GetCurrentDirectory(), "Data/logo.png");
LeoCanvas.DrawImageAtLocation(imagePath, new(50, 100), new (350, 175));

Scale of the images is not checked, make sure to use a proper target rectangle.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.0.1 86 4/30/2024
3.0.0 81 4/30/2024
2.0.0 81 4/26/2024
1.0.0 84 4/26/2024
1.0.0-preview9 67 4/26/2024
1.0.0-preview8 74 4/26/2024
1.0.0-preview7 188 3/9/2023
1.0.0-preview6 97 3/9/2023
1.0.0-preview5 97 3/9/2023
1.0.0-preview4 112 3/9/2023
1.0.0-preview3 112 3/8/2023
1.0.0-preview2 108 3/8/2023
1.0.0-preview1 114 3/5/2023