plutovg/paint
paint-create-color
(paint-create-color [r :float g :float b :float a :float] :ptr<void>)
create a paint with a solid RGBA color.
| r | red in [0.0, 1.0] | |
| g | green in [0.0, 1.0] | |
| b | blue in [0.0, 1.0] | |
| a | alpha in [0.0, 1.0] |
(ok paint-handle) on success; (err 0) on allocation failure.
(paint-create-color 1.0 0.0 0.0 1.0) ; opaque red
Since: PV3
paint-create-color-hex
(paint-create-color-hex [hex :cstr] :ptr<void>)
create a paint from a CSS-style color string.
| hex | color string, e.g. "#ff0000", "#ff0000ff", "red", "rgba(...)" |
(ok paint-handle) on success; (err 0) if plutovg cannot parse the string.
(paint-create-color-hex "#ff0000")
Since: PV3
paint-destroy
(paint-destroy [paint :int] :void)
release a paint allocated by any paint-create-* call.
| paint | paint handle |
void
Since: PV3
gradient-stops-create
(gradient-stops-create :ptr<void>)
allocate an empty stops buffer.
(ok stops-handle) on success; (err 0) on allocation failure.
(let [s (gradient-stops-create)]
(when (ok? s) (gradient-stops-destroy (ok-val s))))
Since: PV3
gradient-stops-add
(gradient-stops-add [stops :int offset :float r :float g :float b :float a :float] :void)
append a stop to a stops buffer.
| stops | stops buffer handle | |
| offset | stop offset in [0.0, 1.0] | |
| r/g/b | color components in [0.0, 1.0] | |
| a | alpha in [0.0, 1.0] |
void (the buffer is grown in place if capacity is exceeded; the handle stays valid, but callers must hold the result of any earlier gradient-stops-* call rather than caching the underlying pointer).
(gradient-stops-add s 0.0 1.0 0.0 0.0 1.0) (gradient-stops-add s 1.0 0.0 0.0 1.0 1.0)
Since: PV3
gradient-stops-count
(gradient-stops-count [stops :int] :int)
return how many stops have been added.
Since: PV3
gradient-stops-destroy
(gradient-stops-destroy [stops :int] :void)
release a stops buffer.
Since: PV3
paint-create-linear-gradient
(paint-create-linear-gradient [x1 :float y1 :float x2 :float y2 :float spread :cstr stops :int] :ptr<void>)
create a linear-gradient paint.
| x1 | gradient start x | |
| y1 | gradient start y | |
| x2 | gradient end x | |
| y2 | gradient end y | |
| spread | spread keyword ":pad" / ":reflect" / ":repeat" | |
| stops | gradient-stops buffer (must contain at least 2 stops) |
(ok paint-handle) on success; (err 0) on allocation failure. The buffer can be freed immediately after the call -- plutovg copies its stops internally.
(let [stops (ok-val (gradient-stops-create))]
(gradient-stops-add stops 0.0 1.0 0.0 0.0 1.0)
(gradient-stops-add stops 1.0 0.0 0.0 1.0 1.0)
(let [p (ok-val (paint-create-linear-gradient 0.0 0.0 100.0 0.0 ":pad" stops))]
(canvas-set-source c p)
(gradient-stops-destroy stops)
(paint-destroy p)))
Since: PV3
paint-create-radial-gradient
(paint-create-radial-gradient [cx :float cy :float cr :float fx :float fy :float fr :float spread :cstr stops :int] :ptr<void>)
create a radial-gradient paint.
| cx | gradient center x | |
| cy | gradient center y | |
| cr | center-circle radius | |
| fx | focal point x | |
| fy | focal point y | |
| fr | focal-circle radius | |
| spread | ":pad" / ":reflect" / ":repeat" | |
| stops | gradient-stops buffer |
(ok paint-handle) on success; (err 0) on allocation failure.
Since: PV3
paint-create-texture
(paint-create-texture [surface :int tex-type :cstr opacity :float] :ptr<void>)
create a paint backed by a surface.
| surface | surface handle (from plutovg/surface) | |
| tex-type | ":plain" (clamp / one-shot) or ":tiled" (repeat) | |
| opacity | :float in [0.0, 1.0] |
(ok paint-handle) on success; (err 0) on allocation failure. The surface must outlive the paint.
(paint-create-texture s ":plain" 1.0)
Since: PV3
canvas-set-source
(canvas-set-source [c :int paint :int] :void)
set the canvas's current paint.
| c | canvas handle | |
| paint | paint handle (any flavour) |
void
(canvas-set-source c my-paint)
Since: PV3
Internal definitions
__ok-- create an ok result wrapping integer value v.__err-- create an err result wrapping integer error value e.