diff --git a/bindings/bindings.nim b/bindings/bindings.nim index 04a99a9..b96db68 100644 --- a/bindings/bindings.nim +++ b/bindings/bindings.nim @@ -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 diff --git a/bindings/generated/internal.nim b/bindings/generated/internal.nim index 733a1f5..85ae1c1 100644 --- a/bindings/generated/internal.nim +++ b/bindings/generated/internal.nim @@ -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] diff --git a/bindings/generated/pixie.nim b/bindings/generated/pixie.nim index 05c599c..0a1388e 100644 --- a/bindings/generated/pixie.nim +++ b/bindings/generated/pixie.nim @@ -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 = diff --git a/bindings/generated/pixie.py b/bindings/generated/pixie.py index 06d296d..619d1b9 100644 --- a/bindings/generated/pixie.py +++ b/bindings/generated/pixie.py @@ -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 @@ -246,15 +259,9 @@ class SeqSpan(Structure): def clear(self): dll.pixie_seq_span_clear(self) - def typeset(self, bounds = None, h_align = None, v_align = None, wrap = None): + def typeset(self, bounds = None, h_align = HA_LEFT, v_align = VA_TOP, wrap = True): if bounds is None: bounds = Vector2(0, 0) - if h_align is None: - h_align = HA_LEFT - if v_align is None: - v_align = VA_TOP - if wrap is None: - wrap = True result = dll.pixie_seq_span_typeset(self, bounds, h_align, v_align, wrap) return result @@ -333,17 +340,13 @@ class Image(Structure): raise PixieError(take_error()) return result - def minify_by_2(self, power = None): - if power is None: - power = 1 + def minify_by_2(self, power = 1): result = dll.pixie_image_minify_by_2(self, power) if check_error(): raise PixieError(take_error()) return result - def magnify_by_2(self, power = None): - if power is None: - power = 1 + def magnify_by_2(self, power = 1): result = dll.pixie_image_magnify_by_2(self, power) if check_error(): raise PixieError(take_error()) @@ -386,20 +389,16 @@ class Image(Structure): raise PixieError(take_error()) return result - def mask_draw(self, mask, transform = None, blend_mode = None): + def mask_draw(self, mask, transform = None, blend_mode = BM_MASK): if transform is None: transform = Matrix3() - if blend_mode is None: - blend_mode = BM_MASK dll.pixie_image_mask_draw(self, mask, transform, blend_mode) if check_error(): raise PixieError(take_error()) - def image_draw(self, b, transform = None, blend_mode = None): + def image_draw(self, b, transform = None, blend_mode = BM_NORMAL): if transform is None: transform = Matrix3() - if blend_mode is None: - blend_mode = BM_NORMAL dll.pixie_image_image_draw(self, b, transform, blend_mode) if check_error(): raise PixieError(take_error()) @@ -416,81 +415,41 @@ class Image(Structure): if check_error(): raise PixieError(take_error()) - def font_fill_text(self, font, text, transform = None, bounds = None, h_align = None, v_align = None): + def font_fill_text(self, font, text, transform = None, bounds = None, h_align = HA_LEFT, v_align = VA_TOP): if transform is None: transform = Matrix3() if bounds is None: bounds = Vector2(0, 0) - if h_align is None: - h_align = HA_LEFT - if v_align is None: - v_align = VA_TOP dll.pixie_image_font_fill_text(self, font, text.encode("utf8"), transform, bounds, h_align, v_align) if check_error(): raise PixieError(take_error()) - def arrangement_stroke_text(self, arrangement, transform = None, stroke_width = None, line_cap = None, line_join = None, miter_limit = None, dashes = None): + def arrangement_stroke_text(self, arrangement, transform = None, stroke_width = 1.0, line_cap = LC_BUTT, line_join = LJ_MITER, miter_limit = DEFAULT_MITER_LIMIT, dashes = None): if transform is None: transform = Matrix3() - if stroke_width is None: - stroke_width = 1.0 - if line_cap is None: - line_cap = LC_BUTT - if line_join is None: - line_join = LJ_MITER - if miter_limit is None: - miter_limit = DEFAULT_MITER_LIMIT - if dashes is None: - dashes = SeqFloat32() dll.pixie_image_arrangement_stroke_text(self, arrangement, transform, stroke_width, line_cap, line_join, miter_limit, dashes) if check_error(): raise PixieError(take_error()) - def font_stroke_text(self, font, text, transform = None, stroke_width = None, bounds = None, h_align = None, v_align = None, line_cap = None, line_join = None, miter_limit = None, dashes = None): + def font_stroke_text(self, font, text, transform = None, stroke_width = 1.0, bounds = None, h_align = HA_LEFT, v_align = VA_TOP, line_cap = LC_BUTT, line_join = LJ_MITER, miter_limit = DEFAULT_MITER_LIMIT, dashes = None): if transform is None: transform = Matrix3() - if stroke_width is None: - stroke_width = 1.0 if bounds is None: bounds = Vector2(0, 0) - if h_align is None: - h_align = HA_LEFT - if v_align is None: - v_align = VA_TOP - if line_cap is None: - line_cap = LC_BUTT - if line_join is None: - line_join = LJ_MITER - if miter_limit is None: - miter_limit = DEFAULT_MITER_LIMIT - if dashes is None: - dashes = SeqFloat32() dll.pixie_image_font_stroke_text(self, font, text.encode("utf8"), transform, stroke_width, bounds, h_align, v_align, line_cap, line_join, miter_limit, dashes) if check_error(): raise PixieError(take_error()) - def fill_path(self, path, paint, transform = None, winding_rule = None): + def fill_path(self, path, paint, transform = None, winding_rule = WR_NON_ZERO): if transform is None: transform = Matrix3() - if winding_rule is None: - winding_rule = WR_NON_ZERO dll.pixie_image_fill_path(self, path, paint, transform, winding_rule) if check_error(): raise PixieError(take_error()) - def stroke_path(self, path, paint, transform = None, stroke_width = None, line_cap = None, line_join = None, miter_limit = None, dashes = None): + def stroke_path(self, path, paint, transform = None, stroke_width = 1.0, line_cap = LC_BUTT, line_join = LJ_MITER, miter_limit = DEFAULT_MITER_LIMIT, dashes = None): if transform is None: transform = Matrix3() - if stroke_width is None: - stroke_width = 1.0 - if line_cap is None: - line_cap = LC_BUTT - if line_join is None: - line_join = LJ_MITER - if miter_limit is None: - miter_limit = DEFAULT_MITER_LIMIT - if dashes is None: - dashes = SeqFloat32() dll.pixie_image_stroke_path(self, path, paint, transform, stroke_width, line_cap, line_join, miter_limit, dashes) if check_error(): raise PixieError(take_error()) @@ -558,9 +517,7 @@ class Mask(Structure): def fill(self, value): dll.pixie_mask_fill(self, value) - def minify_by_2(self, power = None): - if power is None: - power = 1 + def minify_by_2(self, power = 1): result = dll.pixie_mask_minify_by_2(self, power) if check_error(): raise PixieError(take_error()) @@ -586,27 +543,21 @@ class Mask(Structure): def invert(self): dll.pixie_mask_invert(self) - def blur(self, radius, out_of_bounds = None): - if out_of_bounds is None: - out_of_bounds = 0 + def blur(self, radius, out_of_bounds = 0): dll.pixie_mask_blur(self, radius, out_of_bounds) if check_error(): raise PixieError(take_error()) - def mask_draw(self, b, transform = None, blend_mode = None): + def mask_draw(self, b, transform = None, blend_mode = BM_MASK): if transform is None: transform = Matrix3() - if blend_mode is None: - blend_mode = BM_MASK dll.pixie_mask_mask_draw(self, b, transform, blend_mode) if check_error(): raise PixieError(take_error()) - def image_draw(self, image, transform = None, blend_mode = None): + def image_draw(self, image, transform = None, blend_mode = BM_MASK): if transform is None: transform = Matrix3() - if blend_mode is None: - blend_mode = BM_MASK dll.pixie_mask_image_draw(self, image, transform, blend_mode) if check_error(): raise PixieError(take_error()) @@ -618,85 +569,41 @@ class Mask(Structure): if check_error(): raise PixieError(take_error()) - def font_fill_text(self, font, text, transform = None, bounds = None, h_align = None, v_align = None): + def font_fill_text(self, font, text, transform = None, bounds = None, h_align = HA_LEFT, v_align = VA_TOP): if transform is None: transform = Matrix3() if bounds is None: bounds = Vector2(0, 0) - if h_align is None: - h_align = HA_LEFT - if v_align is None: - v_align = VA_TOP dll.pixie_mask_font_fill_text(self, font, text.encode("utf8"), transform, bounds, h_align, v_align) if check_error(): raise PixieError(take_error()) - def arrangement_stroke_text(self, arrangement, transform = None, stroke_width = None, line_cap = None, line_join = None, miter_limit = None, dashes = None): + def arrangement_stroke_text(self, arrangement, transform = None, stroke_width = 1.0, line_cap = LC_BUTT, line_join = LJ_MITER, miter_limit = DEFAULT_MITER_LIMIT, dashes = None): if transform is None: transform = Matrix3() - if stroke_width is None: - stroke_width = 1.0 - if line_cap is None: - line_cap = LC_BUTT - if line_join is None: - line_join = LJ_MITER - if miter_limit is None: - miter_limit = DEFAULT_MITER_LIMIT - if dashes is None: - dashes = SeqFloat32() dll.pixie_mask_arrangement_stroke_text(self, arrangement, transform, stroke_width, line_cap, line_join, miter_limit, dashes) if check_error(): raise PixieError(take_error()) - def font_stroke_text(self, font, text, transform = None, stroke_width = None, bounds = None, h_align = None, v_align = None, line_cap = None, line_join = None, miter_limit = None, dashes = None): + def font_stroke_text(self, font, text, transform = None, stroke_width = 1.0, bounds = None, h_align = HA_LEFT, v_align = VA_TOP, line_cap = LC_BUTT, line_join = LJ_MITER, miter_limit = DEFAULT_MITER_LIMIT, dashes = None): if transform is None: transform = Matrix3() - if stroke_width is None: - stroke_width = 1.0 if bounds is None: bounds = Vector2(0, 0) - if h_align is None: - h_align = HA_LEFT - if v_align is None: - v_align = VA_TOP - if line_cap is None: - line_cap = LC_BUTT - if line_join is None: - line_join = LJ_MITER - if miter_limit is None: - miter_limit = DEFAULT_MITER_LIMIT - if dashes is None: - dashes = SeqFloat32() dll.pixie_mask_font_stroke_text(self, font, text.encode("utf8"), transform, stroke_width, bounds, h_align, v_align, line_cap, line_join, miter_limit, dashes) if check_error(): raise PixieError(take_error()) - def fill_path(self, path, transform = None, winding_rule = None, blend_mode = None): + def fill_path(self, path, transform = None, winding_rule = WR_NON_ZERO, blend_mode = BM_NORMAL): if transform is None: transform = Matrix3() - if winding_rule is None: - winding_rule = WR_NON_ZERO - if blend_mode is None: - blend_mode = BM_NORMAL dll.pixie_mask_fill_path(self, path, transform, winding_rule, blend_mode) if check_error(): raise PixieError(take_error()) - def stroke_path(self, path, transform = None, stroke_width = None, line_cap = None, line_join = None, miter_limit = None, dashes = None, blend_mode = None): + def stroke_path(self, path, transform = None, stroke_width = 1.0, line_cap = LC_BUTT, line_join = LJ_MITER, miter_limit = DEFAULT_MITER_LIMIT, dashes = None, blend_mode = BM_NORMAL): if transform is None: transform = Matrix3() - if stroke_width is None: - stroke_width = 1.0 - if line_cap is None: - line_cap = LC_BUTT - if line_join is None: - line_join = LJ_MITER - if miter_limit is None: - miter_limit = DEFAULT_MITER_LIMIT - if dashes is None: - dashes = SeqFloat32() - if blend_mode is None: - blend_mode = BM_NORMAL dll.pixie_mask_stroke_path(self, path, transform, stroke_width, line_cap, line_join, miter_limit, dashes, blend_mode) if check_error(): raise PixieError(take_error()) @@ -856,29 +763,17 @@ class Path(Structure): raise PixieError(take_error()) return result - def fill_overlaps(self, test, transform = None, winding_rule = None): + def fill_overlaps(self, test, transform = None, winding_rule = WR_NON_ZERO): if transform is None: transform = Matrix3() - if winding_rule is None: - winding_rule = WR_NON_ZERO result = dll.pixie_path_fill_overlaps(self, test, transform, winding_rule) if check_error(): raise PixieError(take_error()) return result - def stroke_overlaps(self, test, transform = None, stroke_width = None, line_cap = None, line_join = None, miter_limit = None, dashes = None): + def stroke_overlaps(self, test, transform = None, stroke_width = 1.0, line_cap = LC_BUTT, line_join = LJ_MITER, miter_limit = DEFAULT_MITER_LIMIT, dashes = None): if transform is None: transform = Matrix3() - if stroke_width is None: - stroke_width = 1.0 - if line_cap is None: - line_cap = LC_BUTT - if line_join is None: - line_join = LJ_MITER - if miter_limit is None: - miter_limit = DEFAULT_MITER_LIMIT - if dashes is None: - dashes = SeqFloat32() result = dll.pixie_path_stroke_overlaps(self, test, transform, stroke_width, line_cap, line_join, miter_limit, dashes) if check_error(): raise PixieError(take_error()) @@ -909,14 +804,10 @@ class Path(Structure): if check_error(): raise PixieError(take_error()) - def rect(self, x, y, w, h, clockwise = None): - if clockwise is None: - clockwise = True + def rect(self, x, y, w, h, clockwise = True): dll.pixie_path_rect(self, x, y, w, h, clockwise) - def rounded_rect(self, x, y, w, h, nw, ne, se, sw, clockwise = None): - if clockwise is None: - clockwise = True + def rounded_rect(self, x, y, w, h, nw, ne, se, sw, clockwise = True): dll.pixie_path_rounded_rect(self, x, y, w, h, nw, ne, se, sw, clockwise) def ellipse(self, cx, cy, rx, ry): @@ -1085,15 +976,9 @@ class Font(Structure): result = dll.pixie_font_default_line_height(self) return result - def typeset(self, text, bounds = None, h_align = None, v_align = None, wrap = None): + def typeset(self, text, bounds = None, h_align = HA_LEFT, v_align = VA_TOP, wrap = True): if bounds is None: bounds = Vector2(0, 0) - if h_align is None: - h_align = HA_LEFT - if v_align is None: - v_align = VA_TOP - if wrap is None: - wrap = True result = dll.pixie_font_typeset(self, text.encode("utf8"), bounds, h_align, v_align, wrap) return result @@ -1276,30 +1161,22 @@ class Context(Structure): def close_path(self): dll.pixie_context_close_path(self) - def path_fill(self, path, winding_rule = None): - if winding_rule is None: - winding_rule = WR_NON_ZERO + def path_fill(self, path, winding_rule = WR_NON_ZERO): dll.pixie_context_path_fill(self, path, winding_rule) if check_error(): raise PixieError(take_error()) - def fill(self, winding_rule = None): - if winding_rule is None: - winding_rule = WR_NON_ZERO + def fill(self, winding_rule = WR_NON_ZERO): dll.pixie_context_winding_rule_fill(self, winding_rule) if check_error(): raise PixieError(take_error()) - def path_clip(self, path, winding_rule = None): - if winding_rule is None: - winding_rule = WR_NON_ZERO + def path_clip(self, path, winding_rule = WR_NON_ZERO): dll.pixie_context_path_clip(self, path, winding_rule) if check_error(): raise PixieError(take_error()) - def clip(self, winding_rule = None): - if winding_rule is None: - winding_rule = WR_NON_ZERO + def clip(self, winding_rule = WR_NON_ZERO): dll.pixie_context_winding_rule_clip(self, winding_rule) if check_error(): raise PixieError(take_error()) @@ -1360,9 +1237,7 @@ class Context(Structure): def quadratic_curve_to(self, cpx, cpy, x, y): dll.pixie_context_quadratic_curve_to(self, cpx, cpy, x, y) - def arc(self, x, y, r, a_0, a_1, ccw = None): - if ccw is None: - ccw = False + def arc(self, x, y, r, a_0, a_1, ccw = False): dll.pixie_context_arc(self, x, y, r, a_0, a_1, ccw) if check_error(): raise PixieError(take_error()) @@ -1421,9 +1296,7 @@ class Context(Structure): def rotate(self, angle): dll.pixie_context_rotate(self, angle) - def is_point_in_path(self, x, y, winding_rule = None): - if winding_rule is None: - winding_rule = WR_NON_ZERO + def is_point_in_path(self, x, y, winding_rule = WR_NON_ZERO): result = dll.pixie_context_is_point_in_path(self, x, y, winding_rule) if check_error(): raise PixieError(take_error()) @@ -1479,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