Skip to content

DimensionscapeOrg/nanovg-openfl

Repository files navigation

nanovg-openfl

nanovg-openfl is an OpenFL extension that adds NanoVG-backed display objects and overlays to the openfl.* package tree on native desktop targets.

The primary public API now lives under real openfl.* packages, so it reads like a normal OpenFL extension instead of a parallel mini-framework:

  • openfl.display.NVGShape
  • openfl.display.NVGCacheMode
  • openfl.display.NVGOverlay
  • openfl.render.NVGDrawContext

Status

This is an early library pass focused on a small but useful compatibility layer.

Currently supported by the NanoVG replay path:

  • solid fills
  • beginBitmapFill
  • beginGradientFill
  • line styles
  • lineBitmapStyle
  • lineGradientStyle
  • moveTo, lineTo
  • curveTo, cubicCurveTo
  • drawRect, drawRoundRect
  • drawCircle, drawEllipse

Commands outside that subset fall back to normal OpenFL rendering.

Gradient notes:

  • linear gradients support PAD, REFLECT, and REPEAT
  • radial gradients support focal points and PAD
  • radial REFLECT and REPEAT are approximated with an extended texture domain, which is close in practice but not mathematically identical to Flash/AIR for arbitrarily large shapes

Bitmap notes:

  • bitmap fills and strokes support matrix, repeat, and smooth
  • non-repeating bitmap fills clamp to the edge pixels, matching the Flash/AIR-style padded behavior
  • bitmap replay currently requires readable BitmapData so the pixels can be uploaded into NanoVG

Install

haxelib dev nanovg-openfl .

For a published package later:

haxelib install nanovg-openfl

include.xml is included at the library root for OpenFL extension metadata. Native NanoVG bridge sources are compiled from the haxelib folder path (project/nanovg and dependencies/nanovg/src) and are not copied into Lime.

Git Checkout

The upstream NanoVG source is tracked as a git submodule at dependencies/nanovg.

Clone with submodules:

git clone --recurse-submodules https://github.com/Dimensionscape/haxe-nanovg.git

If you already cloned the repo without them:

git submodule update --init --recursive

The haxe --run Run package command bundles the checked-out submodule contents into the haxelib zip, so release packaging still works as long as the submodule is initialized locally.

Use

import openfl.display.NVGShape;

var shape = new NVGShape();
addChild(shape);

shape.graphics.lineStyle(4, 0x1E120C);
shape.graphics.beginFill(0xE98624);
shape.graphics.drawCircle(0, 0, 80);
shape.graphics.endFill();

You can disable the NanoVG path per object:

shape.useNVG = false;

Overlay example:

import openfl.display.NVGOverlay;

var overlay = NVGOverlay.attach(stage);
overlay.onDraw = function(ctx) {
	ctx.beginPath();
	ctx.circle(80, 80, 30);
	ctx.fillRGBA(255, 80, 40, 220);
	ctx.fill();
};

API Docs

Generated API docs are written to docs/.

The main pages to care about are:

  • docs/openfl/display/NVGShape.html
  • docs/openfl/display/NVGOverlay.html
  • docs/openfl/display/NVGCacheMode.html
  • docs/openfl/render/NVGDrawContext.html
  • docs/nanovg/NanoVGDrawContext.html

Rebuild them with:

haxe --run Run docs

If this checkout is registered with haxelib dev, you can also run:

haxelib run nanovg-openfl docs

The doc build now filters the output down to the library's own public API instead of mirroring the entire std/OpenFL surface.

Packaging

Create a clean release archive for haxelib with:

haxe --run Run package

That writes dist/nanovg-openfl-<version>.zip, containing the library sources, native bridge files, and sample project without generated Export/ output or repo-only tooling. Submit that zip with:

haxelib submit dist/nanovg-openfl-<version>.zip

Target Notes

  • cpp desktop: NVGShape can render through NanoVG.
  • AIR and other non-desktop targets: the class falls back to ordinary OpenFL Shape behavior.

Demo

The repo root project uses the side-by-side OpenFL vs NVGShape sample in samples/openfl-comparison/Source/Main.hx. There is also a standalone sample project at samples/openfl-comparison/project.xml.

Run it with:

openfl test windows -debug

Or run the sample project directly:

openfl test samples/openfl-comparison/project.xml windows -debug

About

NanoVG extension for OpenFL

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors