Rename PaintKind enum.
This commit is contained in:
parent
95886c4861
commit
5074e33efc
|
@ -235,7 +235,7 @@ image.draw(lines)
|
|||
### Gradient
|
||||
nim c -r [examples/gradient.nim](examples/gradient.nim)
|
||||
```nim
|
||||
let paint = newPaint(pkGradientRadial)
|
||||
let paint = newPaint(PaintGradientRadial)
|
||||
paint.gradientHandlePositions = @[
|
||||
vec2(100, 100),
|
||||
vec2(200, 100),
|
||||
|
@ -270,7 +270,7 @@ path.polygon(
|
|||
sides = 8
|
||||
)
|
||||
|
||||
let paint = newPaint(pkImageTiled)
|
||||
let paint = newPaint(PaintImageTiled)
|
||||
paint.image = readImage("examples/data/mandrill.png")
|
||||
paint.imageMat = scale(vec2(0.08, 0.08))
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ import pixie
|
|||
let image = newImage(200, 200)
|
||||
image.fill(rgba(255, 255, 255, 255))
|
||||
|
||||
let paint = newPaint(pkGradientRadial)
|
||||
let paint = newPaint(PaintGradientRadial)
|
||||
paint.gradientHandlePositions = @[
|
||||
vec2(100, 100),
|
||||
vec2(200, 100),
|
||||
|
|
|
@ -10,7 +10,7 @@ path.polygon(
|
|||
sides = 8
|
||||
)
|
||||
|
||||
let paint = newPaint(pkImageTiled)
|
||||
let paint = newPaint(PaintImageTiled)
|
||||
paint.image = readImage("examples/data/mandrill.png")
|
||||
paint.imageMat = scale(vec2(0.08, 0.08))
|
||||
|
||||
|
|
|
@ -358,7 +358,7 @@ block:
|
|||
# doDiff(readImage("cairo4.png"), a, "4")
|
||||
|
||||
var b: Image
|
||||
let paint = newPaint(pkSolid)
|
||||
let paint = newPaint(PaintSolid)
|
||||
paint.color = color(1, 0, 0, 0.5)
|
||||
paint.blendMode = BlendOverwrite
|
||||
|
||||
|
|
|
@ -192,7 +192,7 @@ proc decodeCtxInternal(inherited: Ctx, node: XmlNode): Ctx =
|
|||
let id = fill[5 .. ^2]
|
||||
if id in result.linearGradients:
|
||||
let linearGradient = result.linearGradients[id]
|
||||
result.fill = newPaint(pkGradientLinear)
|
||||
result.fill = newPaint(PaintGradientLinear)
|
||||
result.fill.gradientHandlePositions = @[
|
||||
result.transform * vec2(linearGradient.x1, linearGradient.y1),
|
||||
result.transform * vec2(linearGradient.x2, linearGradient.y2)
|
||||
|
|
|
@ -53,9 +53,9 @@ proc newContext*(image: Image): Context {.raises: [].} =
|
|||
result.globalAlpha = 1
|
||||
result.lineWidth = 1
|
||||
result.miterLimit = 10
|
||||
result.fillStyle = newPaint(pkSolid)
|
||||
result.fillStyle = newPaint(PaintSolid)
|
||||
result.fillStyle.color = color(0, 0, 0, 1)
|
||||
result.strokeStyle = newPaint(pkSolid)
|
||||
result.strokeStyle = newPaint(PaintSolid)
|
||||
result.strokeStyle.color = color(0, 0, 0, 1)
|
||||
result.fontSize = 12
|
||||
|
||||
|
@ -397,7 +397,7 @@ proc stroke*(ctx: Context) {.inline, raises: [PixieError].} =
|
|||
|
||||
proc clearRect*(ctx: Context, rect: Rect) {.raises: [PixieError].} =
|
||||
## Erases the pixels in a rectangular area.
|
||||
let paint = newPaint(pkSolid)
|
||||
let paint = newPaint(PaintSolid)
|
||||
paint.blendMode = BlendOverwrite
|
||||
|
||||
let path = newPath()
|
||||
|
@ -541,7 +541,7 @@ proc drawImage*(
|
|||
))
|
||||
savedFillStyle = ctx.fillStyle
|
||||
|
||||
ctx.fillStyle = newPaint(pkImage)
|
||||
ctx.fillStyle = newPaint(PaintImage)
|
||||
ctx.fillStyle.image = image
|
||||
ctx.fillStyle.imageMat = imageMat
|
||||
|
||||
|
|
|
@ -169,7 +169,7 @@ proc decodeCtxInternal(inherited: Ctx, node: XmlNode): Ctx =
|
|||
let id = fill[5 .. ^2]
|
||||
if id in result.linearGradients:
|
||||
let linearGradient = result.linearGradients[id]
|
||||
result.fill = newPaint(pkGradientLinear)
|
||||
result.fill = newPaint(PaintGradientLinear)
|
||||
result.fill.gradientHandlePositions = @[
|
||||
result.transform * vec2(linearGradient.x1, linearGradient.y1),
|
||||
result.transform * vec2(linearGradient.x2, linearGradient.y2)
|
||||
|
|
|
@ -197,7 +197,7 @@ proc newFont*(typeface: Typeface): Font {.raises: [].} =
|
|||
result.typeface = typeface
|
||||
result.size = 12
|
||||
result.lineHeight = autoLineHeight
|
||||
result.paint = newPaint(pkSolid)
|
||||
result.paint = newPaint(PaintSolid)
|
||||
result.paint.color = color(0, 0, 0, 1)
|
||||
|
||||
proc newSpan*(text: string, font: Font): Span {.raises: [].} =
|
||||
|
|
|
@ -5,24 +5,24 @@ when defined(amd64) and not defined(pixieNoSimd):
|
|||
|
||||
type
|
||||
PaintKind* = enum
|
||||
pkSolid
|
||||
pkImage
|
||||
pkImageTiled
|
||||
pkGradientLinear
|
||||
pkGradientRadial
|
||||
pkGradientAngular
|
||||
PaintSolid
|
||||
PaintImage
|
||||
PaintImageTiled
|
||||
PaintGradientLinear
|
||||
PaintGradientRadial
|
||||
PaintGradientAngular
|
||||
|
||||
Paint* = ref object
|
||||
## Paint used to fill paths.
|
||||
kind*: PaintKind
|
||||
blendMode*: BlendMode ## Blend mode.
|
||||
opacity*: float32
|
||||
# pkSolid
|
||||
# PaintSolid
|
||||
color*: Color ## Color to fill with.
|
||||
# pkImage, pkImageTiled:
|
||||
# PaintImage, PaintImageTiled:
|
||||
image*: Image ## Image to fill with.
|
||||
imageMat*: Mat3 ## Matrix of the filled image.
|
||||
# pkGradientLinear, pkGradientRadial, pkGradientAngular:
|
||||
# PaintGradientLinear, PaintGradientRadial, PaintGradientAngular:
|
||||
gradientHandlePositions*: seq[Vec2] ## Gradient positions (image space).
|
||||
gradientStops*: seq[ColorStop] ## Color stops (gradient space).
|
||||
|
||||
|
@ -51,13 +51,13 @@ proc newPaint*(paint: Paint): Paint {.raises: [].} =
|
|||
converter parseSomePaint*(paint: SomePaint): Paint {.inline.} =
|
||||
## Given SomePaint, parse it in different ways.
|
||||
when type(paint) is string:
|
||||
result = newPaint(pkSolid)
|
||||
result = newPaint(PaintSolid)
|
||||
try:
|
||||
result.color = parseHtmlColor(paint)
|
||||
except:
|
||||
raise newException(PixieError, "Unable to parse color " & paint)
|
||||
elif type(paint) is SomeColor:
|
||||
result = newPaint(pkSolid)
|
||||
result = newPaint(PaintSolid)
|
||||
when type(paint) is Color:
|
||||
result.color = paint
|
||||
else:
|
||||
|
@ -229,11 +229,11 @@ proc fillGradient*(image: Image, paint: Paint) {.raises: [PixieError].} =
|
|||
## Fills with the Paint gradient.
|
||||
|
||||
case paint.kind:
|
||||
of pkGradientLinear:
|
||||
of PaintGradientLinear:
|
||||
image.fillGradientLinear(paint)
|
||||
of pkGradientRadial:
|
||||
of PaintGradientRadial:
|
||||
image.fillGradientRadial(paint)
|
||||
of pkGradientAngular:
|
||||
of PaintGradientAngular:
|
||||
image.fillGradientAngular(paint)
|
||||
else:
|
||||
raise newException(PixieError, "Paint must be a gradient")
|
||||
|
|
|
@ -1901,7 +1901,7 @@ proc fillPath*(
|
|||
if paint.opacity == 0:
|
||||
return
|
||||
|
||||
if paint.kind == pkSolid:
|
||||
if paint.kind == PaintSolid:
|
||||
if paint.color.a > 0 or paint.blendMode == BlendOverwrite:
|
||||
var shapes = parseSomePath(path, true, transform.pixelScale())
|
||||
shapes.transform(transform)
|
||||
|
@ -1922,13 +1922,13 @@ proc fillPath*(
|
|||
paint.opacity = 1
|
||||
|
||||
case paint.kind:
|
||||
of pkSolid:
|
||||
of PaintSolid:
|
||||
discard # Handled above
|
||||
of pkImage:
|
||||
of PaintImage:
|
||||
fill.draw(paint.image, paint.imageMat)
|
||||
of pkImageTiled:
|
||||
of PaintImageTiled:
|
||||
fill.drawTiled(paint.image, paint.imageMat)
|
||||
of pkGradientLinear, pkGradientRadial, pkGradientAngular:
|
||||
of PaintGradientLinear, PaintGradientRadial, PaintGradientAngular:
|
||||
fill.fillGradient(paint)
|
||||
|
||||
paint.opacity = savedOpacity
|
||||
|
@ -1979,7 +1979,7 @@ proc strokePath*(
|
|||
if paint.opacity == 0:
|
||||
return
|
||||
|
||||
if paint.kind == pkSolid:
|
||||
if paint.kind == PaintSolid:
|
||||
if paint.color.a > 0 or paint.blendMode == BlendOverwrite:
|
||||
var strokeShapes = strokeShapes(
|
||||
parseSomePath(path, false, transform.pixelScale()),
|
||||
|
@ -2016,13 +2016,13 @@ proc strokePath*(
|
|||
paint.opacity = 1
|
||||
|
||||
case paint.kind:
|
||||
of pkSolid:
|
||||
of PaintSolid:
|
||||
discard # Handled above
|
||||
of pkImage:
|
||||
of PaintImage:
|
||||
fill.draw(paint.image, paint.imageMat)
|
||||
of pkImageTiled:
|
||||
of PaintImageTiled:
|
||||
fill.drawTiled(paint.image, paint.imageMat)
|
||||
of pkGradientLinear, pkGradientRadial, pkGradientAngular:
|
||||
of PaintGradientLinear, PaintGradientRadial, PaintGradientAngular:
|
||||
fill.fillGradient(paint)
|
||||
|
||||
paint.opacity = savedOpacity
|
||||
|
|
|
@ -3,7 +3,7 @@ import benchy, pixie
|
|||
let image = newImage(1000, 1000)
|
||||
|
||||
timeIt "GradientLinear vertical":
|
||||
let paint = newPaint(pkGradientLinear)
|
||||
let paint = newPaint(PaintGradientLinear)
|
||||
paint.gradientHandlePositions = @[
|
||||
vec2(50, 0),
|
||||
vec2(50, 1000),
|
||||
|
@ -15,7 +15,7 @@ timeIt "GradientLinear vertical":
|
|||
image.fillGradient(paint)
|
||||
|
||||
timeIt "GradientLinear horizontal":
|
||||
let paint = newPaint(pkGradientLinear)
|
||||
let paint = newPaint(PaintGradientLinear)
|
||||
paint.gradientHandlePositions = @[
|
||||
vec2(0, 50),
|
||||
vec2(1000, 50),
|
||||
|
@ -30,7 +30,7 @@ timeIt "GradientLinear horizontal":
|
|||
# discard
|
||||
|
||||
timeIt "GradientLinear angular":
|
||||
let paint = newPaint(pkGradientAngular)
|
||||
let paint = newPaint(PaintGradientAngular)
|
||||
paint.gradientHandlePositions = @[
|
||||
vec2(500, 500),
|
||||
vec2(1000, 500),
|
||||
|
|
|
@ -526,7 +526,7 @@ block:
|
|||
|
||||
image.fill(rgba(255, 255, 255, 255))
|
||||
|
||||
let paint = newPaint(pkSolid)
|
||||
let paint = newPaint(PaintSolid)
|
||||
paint.color = color(0, 0, 1, 1)
|
||||
paint.blendMode = BlendExclusion
|
||||
|
||||
|
|
|
@ -661,7 +661,7 @@ block:
|
|||
block:
|
||||
var font = readFont("tests/fonts/IBMPlexSans-Regular_2.ttf")
|
||||
font.size = 48
|
||||
font.paint = newPaint(pkGradientLinear)
|
||||
font.paint = newPaint(PaintGradientLinear)
|
||||
font.paint.gradientHandlePositions = @[
|
||||
vec2(0, 50),
|
||||
vec2(100, 50),
|
||||
|
|
|
@ -17,7 +17,7 @@ block:
|
|||
image.writeFile("tests/paths/paintSolid.png")
|
||||
|
||||
block:
|
||||
let paint = newPaint(pkImage)
|
||||
let paint = newPaint(PaintImage)
|
||||
paint.image = decodePng(readFile("tests/fileformats/png/mandrill.png"))
|
||||
paint.imageMat = scale(vec2(0.2, 0.2))
|
||||
|
||||
|
@ -26,7 +26,7 @@ block:
|
|||
image.writeFile("tests/paths/paintImage.png")
|
||||
|
||||
block:
|
||||
let paint = newPaint(pkImage)
|
||||
let paint = newPaint(PaintImage)
|
||||
paint.image = decodePng(readFile("tests/fileformats/png/mandrill.png"))
|
||||
paint.imageMat = scale(vec2(0.2, 0.2))
|
||||
paint.opacity = 0.5
|
||||
|
@ -36,7 +36,7 @@ block:
|
|||
image.writeFile("tests/paths/paintImageOpacity.png")
|
||||
|
||||
block:
|
||||
let paint = newPaint(pkImageTiled)
|
||||
let paint = newPaint(PaintImageTiled)
|
||||
paint.image = decodePng(readFile("tests/fileformats/png/mandrill.png"))
|
||||
paint.imageMat = scale(vec2(0.02, 0.02))
|
||||
|
||||
|
@ -45,7 +45,7 @@ block:
|
|||
image.writeFile("tests/paths/paintImageTiled.png")
|
||||
|
||||
block:
|
||||
let paint = newPaint(pkImageTiled)
|
||||
let paint = newPaint(PaintImageTiled)
|
||||
paint.image = decodePng(readFile("tests/fileformats/png/mandrill.png"))
|
||||
paint.imageMat = scale(vec2(0.02, 0.02))
|
||||
paint.opacity = 0.5
|
||||
|
@ -55,7 +55,7 @@ block:
|
|||
image.writeFile("tests/paths/paintImageTiledOpacity.png")
|
||||
|
||||
block:
|
||||
let paint = newPaint(pkGradientLinear)
|
||||
let paint = newPaint(PaintGradientLinear)
|
||||
paint.gradientHandlePositions = @[
|
||||
vec2(0, 50),
|
||||
vec2(100, 50),
|
||||
|
@ -70,7 +70,7 @@ block:
|
|||
image.writeFile("tests/paths/gradientLinear.png")
|
||||
|
||||
block:
|
||||
let paint = newPaint(pkGradientLinear)
|
||||
let paint = newPaint(PaintGradientLinear)
|
||||
paint.gradientHandlePositions = @[
|
||||
vec2(50, 0),
|
||||
vec2(50, 100),
|
||||
|
@ -85,7 +85,7 @@ block:
|
|||
image.writeFile("tests/paths/gradientLinear2.png")
|
||||
|
||||
block:
|
||||
let paint = newPaint(pkGradientRadial)
|
||||
let paint = newPaint(PaintGradientRadial)
|
||||
paint.gradientHandlePositions = @[
|
||||
vec2(50, 50),
|
||||
vec2(100, 50),
|
||||
|
@ -101,7 +101,7 @@ block:
|
|||
image.writeFile("tests/paths/gradientRadial.png")
|
||||
|
||||
block:
|
||||
let paint = newPaint(pkGradientAngular)
|
||||
let paint = newPaint(PaintGradientAngular)
|
||||
paint.gradientHandlePositions = @[
|
||||
vec2(50, 50),
|
||||
vec2(100, 50),
|
||||
|
@ -117,7 +117,7 @@ block:
|
|||
image.writeFile("tests/paths/gradientAngular.png")
|
||||
|
||||
block:
|
||||
let paint = newPaint(pkGradientAngular)
|
||||
let paint = newPaint(PaintGradientAngular)
|
||||
paint.gradientHandlePositions = @[
|
||||
vec2(50, 50),
|
||||
vec2(100, 50),
|
||||
|
|
|
@ -390,7 +390,7 @@ block:
|
|||
rgbx(255, 0, 0, 255)
|
||||
)
|
||||
|
||||
let paint = newPaint(pkSolid)
|
||||
let paint = newPaint(PaintSolid)
|
||||
paint.color = color(0, 1, 0, 1)
|
||||
paint.blendMode = BlendExcludeMask
|
||||
|
||||
|
@ -407,7 +407,7 @@ block:
|
|||
rgbx(255, 0, 0, 255)
|
||||
)
|
||||
|
||||
let paint = newPaint(pkSolid)
|
||||
let paint = newPaint(PaintSolid)
|
||||
paint.color = color(0, 1, 0, 1)
|
||||
paint.blendMode = BlendExcludeMask
|
||||
|
||||
|
@ -424,7 +424,7 @@ block:
|
|||
rgbx(255, 0, 0, 255)
|
||||
)
|
||||
|
||||
let paint = newPaint(pkSolid)
|
||||
let paint = newPaint(PaintSolid)
|
||||
paint.color = color(0, 1, 0, 1)
|
||||
paint.blendMode = BlendMask
|
||||
|
||||
|
@ -441,7 +441,7 @@ block:
|
|||
rgbx(255, 0, 0, 255)
|
||||
)
|
||||
|
||||
let paint = newPaint(pkSolid)
|
||||
let paint = newPaint(PaintSolid)
|
||||
paint.color = color(0, 1, 0, 1)
|
||||
paint.blendMode = BlendMask
|
||||
|
||||
|
@ -613,7 +613,7 @@ block:
|
|||
let path = newPath()
|
||||
path.circle(50, 50, 30)
|
||||
|
||||
let paint = newPaint(pkSolid)
|
||||
let paint = newPaint(PaintSolid)
|
||||
paint.color = color(1, 0, 1, 1)
|
||||
paint.opacity = 0.5
|
||||
|
||||
|
@ -626,7 +626,7 @@ block:
|
|||
let path = newPath()
|
||||
path.circle(50, 50, 30)
|
||||
|
||||
let paint = newPaint(pkSolid)
|
||||
let paint = newPaint(PaintSolid)
|
||||
paint.color = color(1, 0, 1, 1)
|
||||
paint.opacity = 0.5
|
||||
|
||||
|
|
Loading…
Reference in a new issue