Add Cairo currentPoint/hasCurrentPoint

This commit is contained in:
Joshua Granick
2015-05-06 00:22:45 -07:00
parent a523803595
commit 2ec0f7c4b2
4 changed files with 77 additions and 0 deletions

View File

@@ -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<Float>;
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<Float> {
#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);

View File

@@ -14,8 +14,11 @@ namespace lime {
public:
Vector2 ();
Vector2 (double x, double y);
Vector2 (value vec);
value Value ();
double x;
double y;

View File

@@ -1,5 +1,6 @@
#include <cairo.h>
#include <math/Matrix3.h>
#include <math/Vector2.h>
#include <hx/CFFI.h>
@@ -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);

View File

@@ -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;
}
}