value object constructors
This commit is contained in:
parent
4bee35753f
commit
38b3f3bc03
4 changed files with 68 additions and 61 deletions
|
@ -1,12 +1,5 @@
|
||||||
import bindy, pixie, unicode
|
import bindy, pixie, unicode
|
||||||
|
|
||||||
type
|
|
||||||
Vector2 = object
|
|
||||||
x*, y*: float32
|
|
||||||
|
|
||||||
Matrix3 = object
|
|
||||||
a*, b*, c*, d*, e*, f*, g*, h*, i*: float32
|
|
||||||
|
|
||||||
var lastError*: ref PixieError
|
var lastError*: ref PixieError
|
||||||
|
|
||||||
proc takeError*(): string =
|
proc takeError*(): string =
|
||||||
|
@ -16,6 +9,19 @@ proc takeError*(): string =
|
||||||
proc checkError*(): bool =
|
proc checkError*(): bool =
|
||||||
result = lastError != nil
|
result = lastError != nil
|
||||||
|
|
||||||
|
type
|
||||||
|
Vector2* = object
|
||||||
|
x*, y*: float32
|
||||||
|
|
||||||
|
Matrix3* = object
|
||||||
|
a*, b*, c*, d*, e*, f*, g*, h*, i*: float32
|
||||||
|
|
||||||
|
proc vector2*(x, y: float32): Vector2 =
|
||||||
|
Vector2(x: x, y: y)
|
||||||
|
|
||||||
|
proc matrix3*(): Matrix3 =
|
||||||
|
Matrix3(a: 1, b: 0, c: 0, d: 0, e: 1, f: 0, g: 0, h: 0, i: 1)
|
||||||
|
|
||||||
proc drawImage1*(
|
proc drawImage1*(
|
||||||
ctx: Context, image: Image, dx, dy: float32
|
ctx: Context, image: Image, dx, dy: float32
|
||||||
) {.raises: [PixieError].} =
|
) {.raises: [PixieError].} =
|
||||||
|
@ -51,20 +57,31 @@ exportEnums:
|
||||||
VerticalAlignment,
|
VerticalAlignment,
|
||||||
TextCase
|
TextCase
|
||||||
|
|
||||||
exportObjects:
|
|
||||||
export
|
|
||||||
Vector2,
|
|
||||||
Matrix3,
|
|
||||||
Rect,
|
|
||||||
Color,
|
|
||||||
ColorStop,
|
|
||||||
TextMetrics
|
|
||||||
|
|
||||||
exportProcs:
|
exportProcs:
|
||||||
export
|
export
|
||||||
bindings.checkError,
|
bindings.checkError,
|
||||||
bindings.takeError
|
bindings.takeError
|
||||||
|
|
||||||
|
exportObject Vector2:
|
||||||
|
discard vector2(0, 0)
|
||||||
|
discard
|
||||||
|
|
||||||
|
exportObject Matrix3:
|
||||||
|
discard matrix3()
|
||||||
|
discard
|
||||||
|
|
||||||
|
exportObject Rect:
|
||||||
|
discard
|
||||||
|
|
||||||
|
exportObject Color:
|
||||||
|
discard
|
||||||
|
|
||||||
|
exportObject ColorStop:
|
||||||
|
discard
|
||||||
|
|
||||||
|
exportObject TextMetrics:
|
||||||
|
discard
|
||||||
|
|
||||||
exportSeq seq[float32]:
|
exportSeq seq[float32]:
|
||||||
discard
|
discard
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,12 @@ proc pixie_check_error*(): bool {.raises: [], cdecl, exportc, dynlib.} =
|
||||||
proc pixie_take_error*(): cstring {.raises: [], cdecl, exportc, dynlib.} =
|
proc pixie_take_error*(): cstring {.raises: [], cdecl, exportc, dynlib.} =
|
||||||
takeError().cstring
|
takeError().cstring
|
||||||
|
|
||||||
|
proc pixie_vector_2*(x: float32, y: float32): Vector2 {.raises: [], cdecl, exportc, dynlib.} =
|
||||||
|
vector2(x, y)
|
||||||
|
|
||||||
|
proc pixie_matrix_3*(): Matrix3 {.raises: [], cdecl, exportc, dynlib.} =
|
||||||
|
matrix3()
|
||||||
|
|
||||||
type SeqFloat32* = ref object
|
type SeqFloat32* = ref object
|
||||||
s: seq[float32]
|
s: seq[float32]
|
||||||
|
|
||||||
|
|
|
@ -83,12 +83,6 @@ type TextCase* = enum
|
||||||
tcLower
|
tcLower
|
||||||
tcTitle
|
tcTitle
|
||||||
|
|
||||||
type Rect* = object
|
|
||||||
x*: float32
|
|
||||||
y*: float32
|
|
||||||
w*: float32
|
|
||||||
h*: float32
|
|
||||||
|
|
||||||
type ColorStop* = object
|
type ColorStop* = object
|
||||||
color*: Color
|
color*: Color
|
||||||
position*: float32
|
position*: float32
|
||||||
|
|
|
@ -86,6 +86,14 @@ TC_UPPER = 1
|
||||||
TC_LOWER = 2
|
TC_LOWER = 2
|
||||||
TC_TITLE = 3
|
TC_TITLE = 3
|
||||||
|
|
||||||
|
def check_error():
|
||||||
|
result = dll.pixie_check_error()
|
||||||
|
return result
|
||||||
|
|
||||||
|
def take_error():
|
||||||
|
result = dll.pixie_take_error().decode("utf8")
|
||||||
|
return result
|
||||||
|
|
||||||
class Vector2(Structure):
|
class Vector2(Structure):
|
||||||
_fields_ = [
|
_fields_ = [
|
||||||
("x", c_float),
|
("x", c_float),
|
||||||
|
@ -93,8 +101,9 @@ class Vector2(Structure):
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, x, y):
|
def __init__(self, x, y):
|
||||||
self.x = x
|
tmp = dll.pixie_vector_2(x, y)
|
||||||
self.y = y
|
self.x = tmp.x
|
||||||
|
self.y = tmp.y
|
||||||
|
|
||||||
def __eq__(self, obj):
|
def __eq__(self, obj):
|
||||||
self.x == obj.x and self.y == obj.y
|
self.x == obj.x and self.y == obj.y
|
||||||
|
@ -112,16 +121,17 @@ class Matrix3(Structure):
|
||||||
("i", c_float)
|
("i", c_float)
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, a, b, c, d, e, f, g, h, i):
|
def __init__(self):
|
||||||
self.a = a
|
tmp = dll.pixie_matrix_3()
|
||||||
self.b = b
|
self.a = tmp.a
|
||||||
self.c = c
|
self.b = tmp.b
|
||||||
self.d = d
|
self.c = tmp.c
|
||||||
self.e = e
|
self.d = tmp.d
|
||||||
self.f = f
|
self.e = tmp.e
|
||||||
self.g = g
|
self.f = tmp.f
|
||||||
self.h = h
|
self.g = tmp.g
|
||||||
self.i = i
|
self.h = tmp.h
|
||||||
|
self.i = tmp.i
|
||||||
|
|
||||||
def __eq__(self, obj):
|
def __eq__(self, obj):
|
||||||
self.a == obj.a and self.b == obj.b and self.c == obj.c and self.d == obj.d and self.e == obj.e and self.f == obj.f and self.g == obj.g and self.h == obj.h and self.i == obj.i
|
self.a == obj.a and self.b == obj.b and self.c == obj.c and self.d == obj.d and self.e == obj.e and self.f == obj.f and self.g == obj.g and self.h == obj.h and self.i == obj.i
|
||||||
|
@ -134,12 +144,6 @@ class Rect(Structure):
|
||||||
("h", c_float)
|
("h", c_float)
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, x, y, w, h):
|
|
||||||
self.x = x
|
|
||||||
self.y = y
|
|
||||||
self.w = w
|
|
||||||
self.h = h
|
|
||||||
|
|
||||||
def __eq__(self, obj):
|
def __eq__(self, obj):
|
||||||
self.x == obj.x and self.y == obj.y and self.w == obj.w and self.h == obj.h
|
self.x == obj.x and self.y == obj.y and self.w == obj.w and self.h == obj.h
|
||||||
|
|
||||||
|
@ -151,12 +155,6 @@ class Color(Structure):
|
||||||
("a", c_float)
|
("a", c_float)
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, r, g, b, a):
|
|
||||||
self.r = r
|
|
||||||
self.g = g
|
|
||||||
self.b = b
|
|
||||||
self.a = a
|
|
||||||
|
|
||||||
def __eq__(self, obj):
|
def __eq__(self, obj):
|
||||||
self.r == obj.r and self.g == obj.g and self.b == obj.b and self.a == obj.a
|
self.r == obj.r and self.g == obj.g and self.b == obj.b and self.a == obj.a
|
||||||
|
|
||||||
|
@ -166,10 +164,6 @@ class ColorStop(Structure):
|
||||||
("position", c_float)
|
("position", c_float)
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, color, position):
|
|
||||||
self.color = color
|
|
||||||
self.position = position
|
|
||||||
|
|
||||||
def __eq__(self, obj):
|
def __eq__(self, obj):
|
||||||
self.color == obj.color and self.position == obj.position
|
self.color == obj.color and self.position == obj.position
|
||||||
|
|
||||||
|
@ -178,20 +172,9 @@ class TextMetrics(Structure):
|
||||||
("width", c_float)
|
("width", c_float)
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(self, width):
|
|
||||||
self.width = width
|
|
||||||
|
|
||||||
def __eq__(self, obj):
|
def __eq__(self, obj):
|
||||||
self.width == obj.width
|
self.width == obj.width
|
||||||
|
|
||||||
def check_error():
|
|
||||||
result = dll.pixie_check_error()
|
|
||||||
return result
|
|
||||||
|
|
||||||
def take_error():
|
|
||||||
result = dll.pixie_take_error().decode("utf8")
|
|
||||||
return result
|
|
||||||
|
|
||||||
class SeqFloat32(Structure):
|
class SeqFloat32(Structure):
|
||||||
_fields_ = [("ref", c_ulonglong)]
|
_fields_ = [("ref", c_ulonglong)]
|
||||||
|
|
||||||
|
@ -1299,6 +1282,12 @@ dll.pixie_check_error.restype = c_bool
|
||||||
dll.pixie_take_error.argtypes = []
|
dll.pixie_take_error.argtypes = []
|
||||||
dll.pixie_take_error.restype = c_char_p
|
dll.pixie_take_error.restype = c_char_p
|
||||||
|
|
||||||
|
dll.pixie_vector_2.argtypes = [c_float, c_float]
|
||||||
|
dll.pixie_vector_2.restype = Vector2
|
||||||
|
|
||||||
|
dll.pixie_matrix_3.argtypes = []
|
||||||
|
dll.pixie_matrix_3.restype = Matrix3
|
||||||
|
|
||||||
dll.pixie_seq_float_32_unref.argtypes = [SeqFloat32]
|
dll.pixie_seq_float_32_unref.argtypes = [SeqFloat32]
|
||||||
dll.pixie_seq_float_32_unref.restype = None
|
dll.pixie_seq_float_32_unref.restype = None
|
||||||
|
|
||||||
|
@ -2021,3 +2010,4 @@ dll.pixie_miter_limit_to_angle.restype = c_float
|
||||||
|
|
||||||
dll.pixie_angle_to_miter_limit.argtypes = [c_float]
|
dll.pixie_angle_to_miter_limit.argtypes = [c_float]
|
||||||
dll.pixie_angle_to_miter_limit.restype = c_float
|
dll.pixie_angle_to_miter_limit.restype = c_float
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue