From 2ec0f7c4b28a7d10793e042d7cdf2f07c41381e5 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Wed, 6 May 2015 00:22:45 -0700 Subject: [PATCH] Add Cairo currentPoint/hasCurrentPoint --- lime/graphics/cairo/Cairo.hx | 28 ++++++++++++++++++++ project/include/math/Vector2.h | 3 +++ project/src/graphics/cairo/CairoBindings.cpp | 20 ++++++++++++++ project/src/math/Vector2.cpp | 26 ++++++++++++++++++ 4 files changed, 77 insertions(+) diff --git a/lime/graphics/cairo/Cairo.hx b/lime/graphics/cairo/Cairo.hx index 21a9f125f..0fef27230 100644 --- a/lime/graphics/cairo/Cairo.hx +++ b/lime/graphics/cairo/Cairo.hx @@ -2,6 +2,7 @@ package lime.graphics.cairo; import lime.math.Matrix3; +import lime.math.Vector2; import lime.system.System; @@ -12,10 +13,12 @@ class Cairo { public static var versionString (get, null):String; public var antialias (get, set):CairoAntialias; + public var currentPoint (get, never):Vector2; public var dash (get, set):Array; public var dashCount (get, never):Int; public var fillRule (get, set):CairoFillRule; public var groupTarget (get, never):CairoSurface; + public var hasCurrentPoint (get, never):Bool; public var lineCap (get, set):CairoLineCap; public var lineJoin (get, set):CairoLineJoin; public var lineWidth (get, set):Float; @@ -488,6 +491,18 @@ class Cairo { } + private function get_currentPoint ():Vector2 { + + #if lime_cairo + var vec = lime_cairo_get_current_point (handle); + return new Vector2 (vec.x, vec.y); + #end + + return null; + + } + + private function get_dash ():Array { #if lime_cairo @@ -554,6 +569,17 @@ class Cairo { } + private function get_hasCurrentPoint ():Bool { + + #if lime_cairo + return lime_cairo_has_current_point (handle); + #end + + return false; + + } + + private function get_lineCap ():CairoLineCap { #if lime_cairo @@ -797,6 +823,7 @@ class Cairo { private static var lime_cairo_fill_extents = System.load ("lime", "lime_cairo_fill_extents", 5); private static var lime_cairo_fill_preserve = System.load ("lime", "lime_cairo_fill_preserve", 1); private static var lime_cairo_get_antialias = System.load ("lime", "lime_cairo_get_antialias", 1); + private static var lime_cairo_get_current_point = System.load ("lime", "lime_cairo_get_current_point", 1); private static var lime_cairo_get_dash = System.load ("lime", "lime_cairo_get_dash", 1); private static var lime_cairo_get_dash_count = System.load ("lime", "lime_cairo_get_dash_count", 1); private static var lime_cairo_get_fill_rule = System.load ("lime", "lime_cairo_get_fill_rule", 1); @@ -811,6 +838,7 @@ class Cairo { private static var lime_cairo_get_source = System.load ("lime", "lime_cairo_get_source", 1); private static var lime_cairo_get_target = System.load ("lime", "lime_cairo_get_target", 1); private static var lime_cairo_get_tolerance = System.load ("lime", "lime_cairo_get_tolerance", 1); + private static var lime_cairo_has_current_point = System.load ("lime", "lime_cairo_has_current_point", 1); private static var lime_cairo_identity_matrix = System.load ("lime", "lime_cairo_identity_matrix", 1); private static var lime_cairo_in_clip = System.load ("lime", "lime_cairo_in_clip", 3); private static var lime_cairo_in_fill = System.load ("lime", "lime_cairo_in_fill", 3); diff --git a/project/include/math/Vector2.h b/project/include/math/Vector2.h index 374cbf8af..4f2beb4ed 100644 --- a/project/include/math/Vector2.h +++ b/project/include/math/Vector2.h @@ -14,8 +14,11 @@ namespace lime { public: Vector2 (); + Vector2 (double x, double y); Vector2 (value vec); + value Value (); + double x; double y; diff --git a/project/src/graphics/cairo/CairoBindings.cpp b/project/src/graphics/cairo/CairoBindings.cpp index 551fa392b..6b1645e96 100644 --- a/project/src/graphics/cairo/CairoBindings.cpp +++ b/project/src/graphics/cairo/CairoBindings.cpp @@ -1,5 +1,6 @@ #include #include +#include #include @@ -126,6 +127,16 @@ namespace lime { } + value lime_cairo_get_current_point (value handle) { + + double x, y; + cairo_get_current_point ((cairo_t*)(intptr_t)val_float (handle), &x, &y); + Vector2 vec2 = Vector2 (x, y); + return vec2.Value (); + + } + + value lime_cairo_get_dash (value handle) { int length = cairo_get_dash_count ((cairo_t*)(intptr_t)val_float (handle)); @@ -243,6 +254,13 @@ namespace lime { } + value lime_cairo_has_current_point (value handle) { + + return alloc_bool (cairo_has_current_point ((cairo_t*)(intptr_t)val_float (handle))); + + } + + value lime_cairo_identity_matrix (value handle) { cairo_identity_matrix ((cairo_t*)(intptr_t)val_float (handle)); @@ -770,6 +788,7 @@ namespace lime { DEFINE_PRIM (lime_cairo_fill_extents, 5); DEFINE_PRIM (lime_cairo_fill_preserve, 1); DEFINE_PRIM (lime_cairo_get_antialias, 1); + DEFINE_PRIM (lime_cairo_get_current_point, 1); DEFINE_PRIM (lime_cairo_get_dash, 1); DEFINE_PRIM (lime_cairo_get_dash_count, 1); DEFINE_PRIM (lime_cairo_get_fill_rule, 1); @@ -784,6 +803,7 @@ namespace lime { DEFINE_PRIM (lime_cairo_get_source, 1); DEFINE_PRIM (lime_cairo_get_target, 1); DEFINE_PRIM (lime_cairo_get_tolerance, 1); + DEFINE_PRIM (lime_cairo_has_current_point, 1); DEFINE_PRIM (lime_cairo_identity_matrix, 1); DEFINE_PRIM (lime_cairo_image_surface_create, 3); DEFINE_PRIM (lime_cairo_image_surface_create_for_data, 5); diff --git a/project/src/math/Vector2.cpp b/project/src/math/Vector2.cpp index 6fd56d6f9..96bbcb955 100644 --- a/project/src/math/Vector2.cpp +++ b/project/src/math/Vector2.cpp @@ -17,6 +17,14 @@ namespace lime { } + Vector2::Vector2 (double x, double y) { + + this->x = x; + this->y = y; + + } + + Vector2::Vector2 (value vec) { if (!init) { @@ -33,4 +41,22 @@ namespace lime { } + value Vector2::Value () { + + if (!init) { + + id_x = val_id ("x"); + id_y = val_id ("y"); + init = true; + + } + + value result = alloc_empty_object (); + alloc_field (result, id_x, alloc_float (x)); + alloc_field (result, id_y, alloc_float (y)); + return result; + + } + + } \ No newline at end of file