CrossPlatformDrawer 1.1.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package CrossPlatformDrawer --version 1.1.2
                    
NuGet\Install-Package CrossPlatformDrawer -Version 1.1.2
                    
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="CrossPlatformDrawer" Version="1.1.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CrossPlatformDrawer" Version="1.1.2" />
                    
Directory.Packages.props
<PackageReference Include="CrossPlatformDrawer" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CrossPlatformDrawer --version 1.1.2
                    
#r "nuget: CrossPlatformDrawer, 1.1.2"
                    
#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.
#:package CrossPlatformDrawer@1.1.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CrossPlatformDrawer&version=1.1.2
                    
Install as a Cake Addin
#tool nuget:?package=CrossPlatformDrawer&version=1.1.2
                    
Install as a Cake Tool

CrossPlatformDrawer

NuGet License: MIT .NET

A powerful, cross-platform educational graphics library for .NET 8.0+ with enhanced drawing primitives, text rendering, and color utilities. Perfect for educational environments, creative coding, and rapid prototyping.

Features

Core Drawing Capabilities

  • Basic Shapes: Rectangles, ellipses, lines, triangles, polygons
  • Advanced Shapes (v1.1.0):
    • Arcs and pie slices
    • Cubic Bezier curves
    • Rounded rectangles
    • Regular polygons (3-12+ sides)
    • Stars and complex polygons

Enhanced Text Rendering (v1.1.0)

  • Text alignment (left, center, right, top, middle, bottom)
  • Automatic word wrapping
  • Custom font loading support
  • Multi-line text with adjustable line spacing

Color Utilities (v1.1.0)

  • Color interpolation (Lerp) for smooth gradients
  • Complementary colors for contrast

Interactive Features

  • Mouse event handling (click, move, release)
  • Keyboard input support
  • Scaled mouse coordinates for pixel-perfect drawing
  • Real-time rendering with continuous mode

Advanced Rendering

  • Shadow effects with customizable blur and offset
  • Background color management
  • Coordinate grid overlay for debugging
  • FPS display for performance monitoring
  • Animation support with continuous rendering mode

Installation

Via NuGet Package Manager

Install-Package CrossPlatformDrawer -Version 1.1.0

Via .NET CLI

dotnet add package CrossPlatformDrawer --version 1.1.0

Via PackageReference

<PackageReference Include="CrossPlatformDrawer" Version="1.1.0" />

Quick Start

using CrossPlatformDrawer;
using SkiaSharp;

// Create a drawing window
var drawer = new CPDrawer(800, 600, false);
drawer.BackgroundColor = SKColors.DarkSlateGray;

// Draw basic shapes
drawer.AddRectangle(50, 50, 150, 100, SKColors.CornflowerBlue, 3, SKColors.White);
drawer.AddEllipse(250, 50, 150, 100, SKColors.Coral);
drawer.AddLine(50, 200, 400, 200, SKColors.LimeGreen, 5);

// Draw advanced shapes
drawer.AddArc(100, 300, 80, 0, 90, SKColors.Red, 3);
drawer.AddPie(250, 300, 100, 100, 45, 270, SKColors.Orange, 2, SKColors.Black);
drawer.AddRoundedRectangle(400, 300, 150, 100, 20, SKColors.SteelBlue);

// Add text
drawer.AddText("CrossPlatformDrawer", 24, 300, 500, SKColors.White);

// Render the scene
drawer.Render();

// Keep window open
System.Threading.Thread.Sleep(5000);
drawer.Dispose();

Documentation

Creating a Drawer

// Basic constructor
CPDrawer drawer = new CPDrawer(width, height);

// With continuous rendering for animation
CPDrawer drawer = new CPDrawer(width, height, false, true);

// Control the scale for pixel art
drawer.Scale = 10; // Each logical pixel becomes 10x10 screen pixels

Drawing Shapes

Basic Shapes
// Rectangle with border
drawer.AddRectangle(x, y, width, height, fillColor, borderThickness, borderColor);

// Filled ellipse
drawer.AddEllipse(x, y, width, height, fillColor);

// Line with thickness
drawer.AddLine(x1, y1, x2, y2, color, thickness);

// Triangle
drawer.AddTriangle(x1, y1, x2, y2, x3, y3, fillColor, borderThickness, borderColor);
Advanced Shapes (v1.1.0)
// Arc - portion of circle outline
drawer.AddArc(centerX, centerY, radius, startAngle, sweepAngle, color, thickness);

// Pie slice - filled sector
drawer.AddPie(x, y, width, height, startAngle, sweepAngle, fillColor, borderThickness, borderColor);

// Cubic Bezier curve
drawer.AddBezier(x1, y1, cx1, cy1, cx2, cy2, x2, y2, color, thickness);

// Rounded rectangle
drawer.AddRoundedRectangle(x, y, width, height, cornerRadius, fillColor, borderThickness, borderColor);

// Regular polygon (pentagon, hexagon, etc.)
drawer.AddRegularPolygon(centerX, centerY, sides, radius, rotation, fillColor, borderThickness, borderColor);

// Star
drawer.AddStar(centerX, centerY, points, outerRadius, innerRadius, rotation, fillColor);

Text Rendering

// Simple text
drawer.AddText("Hello World", fontSize, x, y, color);

// Aligned text (v1.1.0)
drawer.AddTextAligned("Centered Text", x, y, fontSize, color, 
    CPDrawer.TextAlignment.Center, CPDrawer.VerticalAlignment.Middle, "Arial");

// Word-wrapped text (v1.1.0)
drawer.AddTextWrapped(longText, x, y, maxWidth, fontSize, color, lineSpacing, "Arial");

// Load custom font (v1.1.0)
drawer.LoadFont("MyFont", "path/to/font.ttf");

Color Utilities (v1.1.0)

// Color interpolation for gradients
for (int i = 0; i < steps; i++)
{
    float t = i / (float)(steps - 1);
    SKColor gradientColor = ColorUtils.Lerp(SKColors.Red, SKColors.Blue, t);
    drawer.AddRectangle(x + i * width, y, width, height, gradientColor);
}

// Get complementary color for contrast
SKColor baseColor = SKColors.Orange;
SKColor complement = ColorUtils.GetComplementary(baseColor);

Interactive Features

// Mouse events
drawer.MouseLeftClick += (point, drawer) =>
{
    drawer.AddEllipse(point.X - 10, point.Y - 10, 20, 20, SKColors.Red);
};

drawer.MouseMove += (point, drawer) =>
{
    Console.WriteLine($"Mouse at: {point.X}, {point.Y}");
};

// Keyboard events
drawer.KeyboardEvent += (isDown, key, drawer) =>
{
    if (isDown && key == "Space")
    {
        drawer.Clear();
    }
};

// Get mouse position for pixel drawing
if (drawer.GetLastMouseLeftClick(out Point clickPoint))
{
    drawer.SetBBPixel(clickPoint.X, clickPoint.Y, SKColors.White);
}

Shadow Effects

// Enable shadows for depth
drawer.ShadowEnabled = true;
drawer.ShadowColor = SKColors.Black.WithAlpha(100);
drawer.ShadowOffsetX = 5;
drawer.ShadowOffsetY = 5;
drawer.ShadowBlur = 10;

// Draw shapes - they'll have shadows
drawer.AddRectangle(50, 50, 100, 100, SKColors.White);

Animation

// Create drawer in continuous mode
var drawer = new CPDrawer(800, 600, false, true);

// Animation loop
for (int frame = 0; frame < 300; frame++)
{
    drawer.Clear();
    
    // Draw animated content
    double angle = frame * 2;
    int x = 400 + (int)(150 * Math.Cos(angle * Math.PI / 180));
    int y = 300 + (int)(150 * Math.Sin(angle * Math.PI / 180));
    drawer.AddEllipse(x - 20, y - 20, 40, 40, SKColors.Yellow);
    
    drawer.Render();
    Thread.Sleep(33); // ~30 FPS
}

Use Cases

Educational Programming

  • Teaching graphics programming concepts
  • Visual algorithm demonstrations
  • Interactive coding exercises
  • Student project presentations

Creative Coding

  • Generative art creation
  • Data visualization
  • Interactive sketches
  • Rapid prototyping

Game Development

  • 2D game prototypes
  • Sprite rendering
  • Simple physics simulations
  • UI mockups

Migration from GDIDrawer

CrossPlatformDrawer is designed as a modern replacement for the legacy GDIDrawer library:

// Old GDIDrawer code
using GDIDrawer;
CDrawer drawer = new CDrawer();
drawer.AddText("Hello", 12, Color.Red);

// New CrossPlatformDrawer code
using CrossPlatformDrawer;
using SkiaSharp;
CPDrawer drawer = new CPDrawer();
drawer.AddText("Hello", 12, 100, 100, SKColors.Red);

Key differences:

  • Cross-platform support (Windows, Linux, macOS)
  • Uses SKColor instead of System.Drawing.Color
  • Enhanced features and better performance
  • Modern .NET 8.0+ support

Requirements

  • .NET 8.0 or higher
  • Dependencies (automatically installed):
    • Avalonia 11.0.7
    • Avalonia.Desktop 11.0.7
    • Avalonia.Skia 11.0.7
    • SkiaSharp 2.88.7

Version History

v1.1.0 (Latest)

  • Added new drawing primitives (Arc, Pie, Bezier, Rounded rectangles, Regular polygons)
  • Enhanced text rendering with alignment and word wrapping
  • Custom font loading support
  • Color utility methods (Lerp, complementary colors)
  • Comprehensive XML documentation for IntelliSense

v1.0.0

  • Initial release with basic drawing capabilities
  • Mouse and keyboard event handling
  • Cross-platform support via Avalonia

Acknowledgments

  • Built with Avalonia UI for cross-platform support
  • Graphics rendering powered by SkiaSharp
  • Designed for educational use in computer science courses

Made for educators and students by the Digital Creators Suite team

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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
1.1.3 30 9/29/2025
1.1.2 48 9/26/2025
1.1.1 46 9/26/2025
1.1.0 54 9/26/2025
1.0.2 132 5/30/2025
1.0.1 165 5/29/2025
1.0.0 160 5/28/2025

Version 1.1.2:
- Added new drawing primitives: Arc, Pie, Bezier curves, Rounded rectangles, Regular polygons
- Enhanced text rendering with alignment and word wrapping
- Custom font loading support
- Color utility methods (Lerp, complementary, triadic, analogous)
- Comprehensive XML documentation for IntelliSense