more changes for bindings

This commit is contained in:
Ryan Oldenburg 2021-08-12 21:32:41 -05:00
parent ed4a8692bb
commit abbe4f63ea
5 changed files with 54 additions and 168 deletions

View file

@ -308,8 +308,11 @@ image.draw(polygonImage)
### Blur
[examples/blur.nim](examples/blur.nim)
```nim
let path = newPath()
path.polygon(vec2(100, 100), 70, sides = 6)
let mask = newMask(200, 200)
mask.fillPolygon(vec2(100, 100), 70, sides = 6)
mask.fillPath(path)
blur.blur(20)
blur.draw(mask, blendMode = bmMask)

View file

@ -7,8 +7,11 @@ let
image.fill(rgba(255, 255, 255, 255))
let path = newPath()
path.polygon(vec2(100, 100), 70, sides = 6)
let mask = newMask(200, 200)
mask.fillPolygon(vec2(100, 100), 70, sides = 6)
mask.fillPath(path)
blur.blur(20)
blur.draw(mask, blendMode = bmMask)

View file

@ -88,153 +88,3 @@ proc writeFile*(mask: Mask, filePath: string) =
else:
raise newException(PixieError, "Unsupported file extension")
writeFile(filePath, mask.encodeMask(fileFormat))
proc fillRect*(
mask: Mask,
rect: Rect,
transform: Vec2 | Mat3 = vec2(0, 0)
) =
## Fills a rectangle.
let path = newPath()
path.rect(rect)
mask.fillPath(path, transform)
proc strokeRect*(
mask: Mask,
rect: Rect,
transform: Vec2 | Mat3 = vec2(0, 0),
strokeWidth = 1.0
) =
## Strokes a rectangle.
let path = newPath()
path.rect(rect)
mask.strokePath(path, transform, strokeWidth)
proc fillRoundedRect*(
mask: Mask,
rect: Rect,
nw, ne, se, sw: float32,
transform: Vec2 | Mat3 = vec2(0, 0)
) =
## Fills a rounded rectangle.
let path = newPath()
path.roundedRect(rect, nw, ne, se, sw)
mask.fillPath(path, transform)
proc fillRoundedRect*(
mask: Mask,
rect: Rect,
radius: float32,
transform: Vec2 | Mat3 = vec2(0, 0)
) =
## Fills a rounded rectangle.
let path = newPath()
path.roundedRect(rect, radius, radius, radius, radius)
mask.fillPath(path, transform)
proc strokeRoundedRect*(
mask: Mask,
rect: Rect,
nw, ne, se, sw: float32,
transform: Vec2 | Mat3 = vec2(0, 0),
strokeWidth = 1.0
) =
## Strokes a rounded rectangle.
let path = newPath()
path.roundedRect(rect, nw, ne, se, sw)
mask.strokePath(path, transform, strokeWidth)
proc strokeRoundedRect*(
mask: Mask,
rect: Rect,
radius: float32,
transform: Vec2 | Mat3 = vec2(0, 0),
strokeWidth = 1.0
) =
## Strokes a rounded rectangle.
let path = newPath()
path.roundedRect(rect, radius, radius, radius, radius)
mask.strokePath(path, transform, strokeWidth)
proc strokeSegment*(
mask: Mask,
segment: Segment,
transform: Vec2 | Mat3 = vec2(0, 0),
strokeWidth = 1.0
) =
## Strokes a segment (draws a line from segment.at to segment.to).
let path = newPath()
path.moveTo(segment.at)
path.lineTo(segment.to)
mask.strokePath(path, transform, strokeWidth)
proc fillEllipse*(
mask: Mask,
center: Vec2,
rx, ry: float32,
transform: Vec2 | Mat3 = vec2(0, 0)
) =
## Fills an ellipse.
let path = newPath()
path.ellipse(center, rx, ry)
mask.fillPath(path, transform)
proc strokeEllipse*(
mask: Mask,
center: Vec2,
rx, ry: float32,
transform: Vec2 | Mat3 = vec2(0, 0),
strokeWidth = 1.0
) =
## Strokes an ellipse.
let path = newPath()
path.ellipse(center, rx, ry)
mask.strokePath(path, transform, strokeWidth)
proc fillCircle*(
mask: Mask,
center: Vec2,
radius: float32,
transform: Vec2 | Mat3 = vec2(0, 0)
) =
## Fills a circle.
let path = newPath()
path.ellipse(center, radius, radius)
mask.fillPath(path, transform)
proc strokeCircle*(
mask: Mask,
center: Vec2,
radius: float32,
transform: Vec2 | Mat3 = vec2(0, 0),
strokeWidth = 1.0
) =
## Strokes a circle.
let path = newPath()
path.ellipse(center, radius, radius)
mask.fillPath(path, transform, strokeWidth)
proc fillPolygon*(
mask: Mask,
pos: Vec2,
size: float32,
sides: int,
transform: Vec2 | Mat3 = vec2(0, 0)
) =
## Fills a polygon.
let path = newPath()
path.polygon(pos, size, sides)
mask.fillPath(path, transform)
proc strokePolygon*(
mask: Mask,
pos: Vec2,
size: float32,
sides: int,
transform: Vec2 | Mat3 = vec2(0, 0),
strokeWidth = 1.0
) =
## Strokes a polygon.
let path = newPath()
path.polygon(pos, size, sides)
mask.strokePath(path, transform, strokeWidth)

View file

@ -1,7 +1,7 @@
## Load SVG files.
import chroma, pixie/common, pixie/images, pixie/internal, pixie/paints,
pixie/paths, strutils, tables, vmath, xmlparser, xmltree
import chroma, pixie/common, pixie/images, pixie/paints, pixie/paths, strutils,
tables, vmath, xmlparser, xmltree
when defined(pixieDebugSvg):
import strtabs

View file

@ -98,62 +98,92 @@ block:
writeFile("tests/images/masks/circleMaskSharpened.png", mask.encodePng())
block:
let path = newPath()
path.rect(rect(vec2(10, 10), vec2(30, 30)))
let mask = newMask(100, 100)
mask.fillRect(rect(vec2(10, 10), vec2(30, 30)))
mask.fillPath(path)
writeFile("tests/images/masks/drawRect.png", mask.encodePng())
block:
let path = newPath()
path.rect(rect(vec2(10, 10), vec2(30, 30)))
let mask = newMask(100, 100)
mask.strokeRect(rect(vec2(10, 10), vec2(30, 30)), strokeWidth = 10)
mask.strokePath(path, strokeWidth = 10)
writeFile("tests/images/masks/strokeRect.png", mask.encodePng())
block:
let path = newPath()
path.roundedRect(rect(vec2(10, 10), vec2(30, 30)), 10, 10, 10, 10)
let mask = newMask(100, 100)
mask.fillRoundedRect(rect(vec2(10, 10), vec2(30, 30)), 10)
mask.fillPath(path)
writeFile("tests/images/masks/drawRoundedRect.png", mask.encodePng())
block:
let path = newPath()
path.roundedRect(rect(vec2(10, 10), vec2(30, 30)), 10, 10, 10, 10)
let mask = newMask(100, 100)
mask.strokeRoundedRect(rect(vec2(10, 10), vec2(30, 30)), 10, strokeWidth = 10)
mask.strokePath(path, strokeWidth = 10)
writeFile("tests/images/masks/strokeRoundedRect.png", mask.encodePng())
block:
let path = newPath()
path.moveTo(vec2(10, 10))
path.lineTo(vec2(90, 90))
let mask = newMask(100, 100)
mask.strokeSegment(
segment(vec2(10, 10), vec2(90, 90)),
strokeWidth = 10
)
mask.strokePath(path, strokeWidth = 10)
writeFile("tests/images/masks/drawSegment.png", mask.encodePng())
block:
let path = newPath()
path.ellipse(vec2(50, 50), 20, 10)
let mask = newMask(100, 100)
mask.fillEllipse(vec2(50, 50), 20, 10)
mask.fillPath(path)
writeFile("tests/images/masks/drawEllipse.png", mask.encodePng())
block:
let path = newPath()
path.ellipse(vec2(50, 50), 20, 10)
let mask = newMask(100, 100)
mask.strokeEllipse(vec2(50, 50), 20, 10, strokeWidth = 10)
mask.strokePath(path, strokeWidth = 10)
writeFile("tests/images/masks/strokeEllipse.png", mask.encodePng())
block:
let path = newPath()
path.polygon(vec2(50, 50), 30, 6)
let mask = newMask(100, 100)
mask.fillPolygon(vec2(50, 50), 30, 6)
mask.fillPath(path)
writeFile("tests/images/masks/drawPolygon.png", mask.encodePng())
block:
let path = newPath()
path.polygon(vec2(50, 50), 30, 6)
let mask = newMask(100, 100)
mask.strokePolygon(vec2(50, 50), 30, 6, strokeWidth = 10)
mask.strokepath(path, strokeWidth = 10)
writeFile("tests/images/masks/strokePolygon.png", mask.encodePng())
block:
let path = newPath()
path.rect(rect(25, 25, 50, 50))
let mask = newMask(100, 100)
mask.fillRect(rect(25, 25, 50, 50))
mask.fillpath(path)
mask.blur(20)
writeFile("tests/images/maskblur20.png", mask.encodePng())
block:
let path = newPath()
path.rect(rect(25, 25, 150, 150))
let mask = newMask(200, 200)
mask.fillRect(rect(25, 25, 150, 150))
mask.fillPath(path)
mask.blur(25)
let minified = mask.minifyBy2()