default obj constructors

This commit is contained in:
Ryan Oldenburg 2021-08-31 11:51:22 -05:00
parent a526c255f0
commit 7ea042647d
4 changed files with 28 additions and 28 deletions

View file

@ -16,9 +16,6 @@ type
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)
@ -63,7 +60,7 @@ exportProcs:
bindings.takeError
exportObject Vector2:
discard vector2(0, 0)
discard
exportObject Matrix3:
discard matrix3()
@ -75,7 +72,7 @@ exportObject Color:
discard
exportObject ColorStop:
discard colorStop(Color(), 0)
discard
exportObject TextMetrics:
discard

View file

@ -4,15 +4,9 @@ proc pixie_check_error*(): bool {.raises: [], cdecl, exportc, dynlib.} =
proc pixie_take_error*(): cstring {.raises: [], cdecl, exportc, dynlib.} =
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()
proc pixie_color_stop*(color: Color, position: float32): ColorStop {.raises: [], cdecl, exportc, dynlib.} =
colorStop(color, position)
type SeqFloat32* = ref object
s: seq[float32]

View file

@ -87,9 +87,16 @@ type ColorStop* = object
color*: Color
position*: float32
proc colorStop*(color: Color, position: float32): ColorStop =
result.color = color
result.position = position
type TextMetrics* = object
width*: float32
proc textMetrics*(width: float32): TextMetrics =
result.width = width
type SeqFloat32Obj = object
reference: pointer
@ -210,11 +217,6 @@ proc pixie_take_error(): cstring {.importc: "pixie_take_error", cdecl.}
proc takeError*(): cstring {.inline.} =
result = pixie_take_error()
proc pixie_color_stop(color: Color, position: float32): ColorStop {.importc: "pixie_color_stop", cdecl.}
proc colorStop*(color: Color, position: float32): ColorStop {.inline.} =
result = pixie_color_stop(color, position)
proc pixie_seq_float_32_len(s: SeqFloat32): int {.importc: "pixie_seq_float_32_len", cdecl.}
proc len*(s: SeqFloat32): int =

View file

@ -101,9 +101,8 @@ class Vector2(Structure):
]
def __init__(self, x, y):
tmp = dll.pixie_vector_2(x, y)
self.x = tmp.x
self.y = tmp.y
self.x = x
self.y = y
def __eq__(self, obj):
self.x == obj.x and self.y == obj.y
@ -144,6 +143,12 @@ class Rect(Structure):
("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):
self.x == obj.x and self.y == obj.y and self.w == obj.w and self.h == obj.h
@ -155,6 +160,12 @@ class Color(Structure):
("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):
self.r == obj.r and self.g == obj.g and self.b == obj.b and self.a == obj.a
@ -165,9 +176,8 @@ class ColorStop(Structure):
]
def __init__(self, color, position):
tmp = dll.pixie_color_stop(color, position)
self.color = tmp.color
self.position = tmp.position
self.color = color
self.position = position
def __eq__(self, obj):
self.color == obj.color and self.position == obj.position
@ -177,6 +187,9 @@ class TextMetrics(Structure):
("width", c_float)
]
def __init__(self, width):
self.width = width
def __eq__(self, obj):
self.width == obj.width
@ -1339,15 +1352,9 @@ dll.pixie_check_error.restype = c_bool
dll.pixie_take_error.argtypes = []
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_color_stop.argtypes = [Color, c_float]
dll.pixie_color_stop.restype = ColorStop
dll.pixie_seq_float_32_unref.argtypes = [SeqFloat32]
dll.pixie_seq_float_32_unref.restype = None