bindings work
This commit is contained in:
parent
163a087366
commit
f64b99c950
|
@ -115,7 +115,7 @@ Here are some examples of using Pixie for realtime rendering with some popular w
|
|||
### Text
|
||||
[examples/text.nim](examples/text.nim)
|
||||
```nim
|
||||
var font = readFont("tests/fonts/Roboto-Regular_1.ttf")
|
||||
var font = readFont("examples/data/Roboto-Regular_1.ttf")
|
||||
font.size = 20
|
||||
|
||||
let text = "Typesetting is the arrangement and composition of text in graphic design and publishing in both digital and traditional medias."
|
||||
|
@ -127,7 +127,7 @@ image.fillText(font.typeset(text, vec2(180, 180)), translate(vec2(10, 10)))
|
|||
### Text spans
|
||||
[examples/text_spans.nim](examples/text_spans.nim)
|
||||
```nim
|
||||
let typeface = readTypeface("tests/fonts/Ubuntu-Regular_1.ttf")
|
||||
let typeface = readTypeface("examples/data/Ubuntu-Regular_1.ttf")
|
||||
|
||||
proc newFont(typeface: Typeface, size: float32, color: Color): Font =
|
||||
result = newFont(typeface)
|
||||
|
@ -272,7 +272,7 @@ path.polygon(
|
|||
)
|
||||
|
||||
let paint = newPaint(pkImageTiled)
|
||||
paint.image = readImage("tests/images/png/baboon.png")
|
||||
paint.image = readImage("examples/data/baboon.png")
|
||||
paint.imageMat = scale(vec2(0.08, 0.08))
|
||||
|
||||
image.fillPath(path, paint)
|
||||
|
|
|
@ -14,15 +14,42 @@ type
|
|||
x*, y*: float32
|
||||
|
||||
Matrix3* = object
|
||||
a*, b*, c*, d*, e*, f*, g*, h*, i*: float32
|
||||
values*: array[9, float32]
|
||||
|
||||
proc matrix3*(): Matrix3 =
|
||||
Matrix3(a: 1, b: 0, c: 0, d: 0, e: 1, f: 0, g: 0, h: 0, i: 1)
|
||||
result.values[0] = 1
|
||||
result.values[4] = 1
|
||||
result.values[8] = 1
|
||||
|
||||
proc drawImage1*(
|
||||
ctx: Context, image: Image, dx, dy: float32
|
||||
) {.raises: [PixieError].} =
|
||||
ctx.drawImage(image, dx, dy)
|
||||
proc mul*(a, b: Matrix3): Matrix3 =
|
||||
cast[Matrix3](cast[Mat3](a) * cast[Mat3](b))
|
||||
|
||||
proc translate*(x, y: float32): Matrix3 =
|
||||
result = matrix3()
|
||||
result.values[6] = x
|
||||
result.values[7] = y
|
||||
|
||||
proc rotate*(angle: float32): Matrix3 =
|
||||
let
|
||||
sin = sin(angle)
|
||||
cos = cos(angle)
|
||||
result = matrix3()
|
||||
result.values[0] = cos
|
||||
result.values[1] = -sin
|
||||
result.values[3] = sin
|
||||
result.values[4] = cos
|
||||
|
||||
proc scale*(x, y: float32): Matrix3 =
|
||||
result = matrix3()
|
||||
result.values[0] = x
|
||||
result.values[4] = y
|
||||
|
||||
proc parseColor*(s: string): Color {.raises: [PixieError]} =
|
||||
try:
|
||||
result = parseHtmlColor(s)
|
||||
except:
|
||||
let e = getCurrentException()
|
||||
raise newException(PixieError, e.msg, e)
|
||||
|
||||
proc drawImage2*(
|
||||
ctx: Context, image: Image, dx, dy, dWidth, dHeight: float32
|
||||
|
@ -62,6 +89,8 @@ exportObject Vector2:
|
|||
exportObject Matrix3:
|
||||
constructor:
|
||||
matrix3
|
||||
procs:
|
||||
mul(Matrix3, Matrix3)
|
||||
|
||||
exportObject Rect:
|
||||
discard
|
||||
|
@ -257,7 +286,7 @@ exportRefObject Context:
|
|||
setTransform
|
||||
transform(Context, Mat3)
|
||||
resetTransform
|
||||
drawImage1
|
||||
drawImage(Context, Image, float32, float32)
|
||||
drawImage2
|
||||
drawImage3
|
||||
moveTo(Context, float32, float32)
|
||||
|
@ -274,6 +303,7 @@ exportRefObject Context:
|
|||
clearRect(Context, float32, float32, float32, float32)
|
||||
fillRect(Context, float32, float32, float32, float32)
|
||||
strokeRect(Context, float32, float32, float32, float32)
|
||||
strokeSegment(Context, float32, float32, float32, float32)
|
||||
fillText(Context, string, float32, float32)
|
||||
strokeText(Context, string, float32, float32)
|
||||
translate(Context, float32, float32)
|
||||
|
@ -292,6 +322,10 @@ exportProcs:
|
|||
parsePath
|
||||
miterLimitToAngle
|
||||
angleToMiterLimit
|
||||
parseColor
|
||||
translate(float32, float32)
|
||||
rotate(float32)
|
||||
scale(float32, float32)
|
||||
|
||||
writeFiles("bindings/generated", "pixie")
|
||||
|
||||
|
|
BIN
examples/data/Roboto-Regular_1.ttf
Normal file
BIN
examples/data/Roboto-Regular_1.ttf
Normal file
Binary file not shown.
BIN
examples/data/Ubuntu-Regular_1.ttf
Normal file
BIN
examples/data/Ubuntu-Regular_1.ttf
Normal file
Binary file not shown.
BIN
examples/data/baboon.png
Normal file
BIN
examples/data/baboon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 636 KiB |
|
@ -11,7 +11,7 @@ path.polygon(
|
|||
)
|
||||
|
||||
let paint = newPaint(pkImageTiled)
|
||||
paint.image = readImage("tests/images/png/baboon.png")
|
||||
paint.image = readImage("examples/data/baboon.png")
|
||||
paint.imageMat = scale(vec2(0.08, 0.08))
|
||||
|
||||
image.fillPath(path, paint)
|
||||
|
|
|
@ -3,7 +3,7 @@ import pixie
|
|||
let image = newImage(200, 200)
|
||||
image.fill(rgba(255, 255, 255, 255))
|
||||
|
||||
var font = readFont("tests/fonts/Roboto-Regular_1.ttf")
|
||||
var font = readFont("examples/data/Roboto-Regular_1.ttf")
|
||||
font.size = 20
|
||||
|
||||
let text = "Typesetting is the arrangement and composition of text in graphic design and publishing in both digital and traditional medias."
|
||||
|
|
|
@ -3,7 +3,7 @@ import pixie
|
|||
let image = newImage(200, 200)
|
||||
image.fill(rgba(255, 255, 255, 255))
|
||||
|
||||
let typeface = readTypeface("tests/fonts/Ubuntu-Regular_1.ttf")
|
||||
let typeface = readTypeface("examples/data/Ubuntu-Regular_1.ttf")
|
||||
|
||||
proc newFont(typeface: Typeface, size: float32, color: Color): Font =
|
||||
result = newFont(typeface)
|
||||
|
|
|
@ -679,6 +679,19 @@ proc polygon*(
|
|||
## Adds an n-sided regular polygon at (x, y) of size to the current path.
|
||||
ctx.path.polygon(pos, size, sides)
|
||||
|
||||
proc strokeSegment*(ctx: Context, segment: Segment) {.raises: [PixieError].} =
|
||||
## Strokes a segment (draws a line from segment.at to segment.to) according
|
||||
## to the current strokeStyle and other context settings.
|
||||
let path = newPath()
|
||||
path.moveTo(segment.at)
|
||||
path.lineTo(segment.to)
|
||||
ctx.stroke(path)
|
||||
|
||||
proc strokeSegment*(ctx: Context, ax, ay, bx, by: float32) {.raises: [PixieError].} =
|
||||
## Strokes a segment (draws a line from ax, ay to bx, by) according
|
||||
## to the current strokeStyle and other context settings.
|
||||
ctx.strokeSegment(segment(vec2(ax, ay), vec2(bx, by)))
|
||||
|
||||
proc fillRoundedRect*(
|
||||
ctx: Context, rect: Rect, nw, ne, se, sw: float32
|
||||
) {.raises: [PixieError].} =
|
||||
|
@ -709,14 +722,6 @@ proc strokeRoundedRect*(
|
|||
## current strokeStyle and other context settings.
|
||||
ctx.strokeRoundedRect(rect, radius, radius, radius, radius)
|
||||
|
||||
proc strokeSegment*(ctx: Context, segment: Segment) {.raises: [PixieError].} =
|
||||
## Strokes a segment (draws a line from segment.at to segment.to) according
|
||||
## to the current strokeStyle and other context settings.
|
||||
let path = newPath()
|
||||
path.moveTo(segment.at)
|
||||
path.lineTo(segment.to)
|
||||
ctx.stroke(path)
|
||||
|
||||
proc fillEllipse*(
|
||||
ctx: Context, center: Vec2, rx, ry: float32
|
||||
) {.raises: [PixieError].} =
|
||||
|
|
Loading…
Reference in a new issue