From efa02a58ca9652a1fa1e27df0fc197c1cbe3cf5f Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Sat, 2 May 2015 17:11:40 -0700 Subject: [PATCH 01/30] Some more Cairo bindings --- lime/graphics/cairo/Cairo.hx | 33 +++++++++++++++ lime/graphics/cairo/CairoSurface.hx | 35 ++++++++++++++++ project/src/graphics/cairo/CairoBindings.cpp | 42 ++++++++++++++++++++ 3 files changed, 110 insertions(+) diff --git a/lime/graphics/cairo/Cairo.hx b/lime/graphics/cairo/Cairo.hx index adade6715..0c0ed3a6f 100644 --- a/lime/graphics/cairo/Cairo.hx +++ b/lime/graphics/cairo/Cairo.hx @@ -18,6 +18,7 @@ class Cairo { public var miterLimit (get, set):Float; public var operator (get, set):CairoOperator; public var source (get, set):CairoPattern; + public var target (get, null):CairoSurface; private var handle:Dynamic; @@ -44,6 +45,15 @@ class Cairo { } + public function arcNegative (xc:Float, yc:Float, radius:Float, angle1:Float, angle2:Float):Void { + + #if lime_cairo + lime_cairo_arc_negative (handle, xc, yc, radius, angle1, angle2); + #end + + } + + public function clip ():Void { #if lime_cairo @@ -271,6 +281,15 @@ class Cairo { } + public function translate (x:Float, y:Float):Void { + + #if lime_cairo + lime_cairo_translate (handle, x, y); + #end + + } + + // Get & Set Methods @@ -433,6 +452,17 @@ class Cairo { } + private function get_target ():CairoSurface { + + #if lime_cairo + return lime_cairo_get_target (handle); + #else + return cast 0; + #end + + } + + private static function get_version ():Int { #if lime_cairo @@ -464,6 +494,7 @@ class Cairo { #if lime_cairo private static var lime_cairo_arc = System.load ("lime", "lime_cairo_arc", -1); + private static var lime_cairo_arc_negative = System.load ("lime", "lime_cairo_arc_negative", -1); private static var lime_cairo_clip = System.load ("lime", "lime_cairo_clip", 1); private static var lime_cairo_close_path = System.load ("lime", "lime_cairo_close_path", 1); private static var lime_cairo_create = System.load ("lime", "lime_cairo_create", 1); @@ -477,6 +508,7 @@ class Cairo { private static var lime_cairo_get_miter_limit = System.load ("lime", "lime_cairo_get_miter_limit", 1); private static var lime_cairo_get_operator = System.load ("lime", "lime_cairo_get_operator", 1); 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_line_to = System.load ("lime", "lime_cairo_line_to", 3); private static var lime_cairo_mask = System.load ("lime", "lime_cairo_mask", 2); private static var lime_cairo_move_to = System.load ("lime", "lime_cairo_move_to", 3); @@ -504,6 +536,7 @@ class Cairo { private static var lime_cairo_stroke = System.load ("lime", "lime_cairo_stroke", 1); private static var lime_cairo_stroke_preserve = System.load ("lime", "lime_cairo_stroke_preserve", 1); private static var lime_cairo_transform = System.load ("lime", "lime_cairo_transform", 2); + private static var lime_cairo_translate = System.load ("lime", "lime_cairo_translate", 3); private static var lime_cairo_version = System.load ("lime", "lime_cairo_version", 0); private static var lime_cairo_version_string = System.load ("lime", "lime_cairo_version_string", 0); #end diff --git a/lime/graphics/cairo/CairoSurface.hx b/lime/graphics/cairo/CairoSurface.hx index 8a78afe99..e3609ae1a 100644 --- a/lime/graphics/cairo/CairoSurface.hx +++ b/lime/graphics/cairo/CairoSurface.hx @@ -7,6 +7,10 @@ import lime.system.System; abstract CairoSurface(Dynamic) { + public var height (get, never):Int; + public var width (get, never):Int; + + public function new (format:CairoFormat, width:Int, height:Int):CairoSurface { #if lime_cairo @@ -49,6 +53,35 @@ abstract CairoSurface(Dynamic) { + // Get & Set Methods + + + + + private function get_height ():Int { + + #if lime_cairo + return lime_cairo_image_surface_get_height (this); + #else + return 0; + #end + + } + + + private function get_width ():Int { + + #if lime_cairo + return lime_cairo_image_surface_get_width (this); + #else + return 0; + #end + + } + + + + // Native Methods @@ -57,6 +90,8 @@ abstract CairoSurface(Dynamic) { #if lime_cairo private static var lime_cairo_image_surface_create = System.load ("lime", "lime_cairo_image_surface_create", 3); private static var lime_cairo_image_surface_create_for_data = System.load ("lime", "lime_cairo_image_surface_create_for_data", 5); + private static var lime_cairo_image_surface_get_height = System.load ("lime", "lime_cairo_image_surface_get_height", 1); + private static var lime_cairo_image_surface_get_width = System.load ("lime", "lime_cairo_image_surface_get_width", 1); private static var lime_cairo_surface_destroy = System.load ("lime", "lime_cairo_surface_destroy", 1); private static var lime_cairo_surface_flush = System.load ("lime", "lime_cairo_surface_flush", 1); #end diff --git a/project/src/graphics/cairo/CairoBindings.cpp b/project/src/graphics/cairo/CairoBindings.cpp index 84ac70e74..8b18df6d9 100644 --- a/project/src/graphics/cairo/CairoBindings.cpp +++ b/project/src/graphics/cairo/CairoBindings.cpp @@ -14,6 +14,14 @@ namespace lime { } + value lime_cairo_arc_negative (value *arg, int argCount) { + + cairo_arc_negative ((cairo_t*)(intptr_t)val_float (arg[0]), val_number (arg[1]), val_number (arg[2]), val_number (arg[3]), val_number (arg[4]), val_number (arg[5])); + return alloc_null (); + + } + + value lime_cairo_clip (value handle) { cairo_clip ((cairo_t*)(intptr_t)val_float (handle)); @@ -113,6 +121,13 @@ namespace lime { } + value lime_cairo_get_target (value handle) { + + return alloc_float ((intptr_t)cairo_get_target ((cairo_t*)(intptr_t)val_float (handle))); + + } + + value lime_cairo_image_surface_create (value format, value width, value height) { return alloc_float ((intptr_t)cairo_image_surface_create ((cairo_format_t)val_int (format), val_int (width), val_int (height))); @@ -127,6 +142,20 @@ namespace lime { } + value lime_cairo_image_surface_get_height (value handle) { + + return alloc_int ((intptr_t)cairo_image_surface_get_height ((cairo_surface_t*)(intptr_t)val_float (handle))); + + } + + + value lime_cairo_image_surface_get_width (value handle) { + + return alloc_int ((intptr_t)cairo_image_surface_get_width ((cairo_surface_t*)(intptr_t)val_float (handle))); + + } + + value lime_cairo_line_to (value handle, value x, value y) { cairo_line_to ((cairo_t*)(intptr_t)val_float (handle), val_number (x), val_number (y)); @@ -436,6 +465,14 @@ namespace lime { } + value lime_cairo_translate (value handle, value x, value y) { + + cairo_translate ((cairo_t*)(intptr_t)val_float (handle), val_number (x), val_number (y)); + return alloc_null (); + + } + + value lime_cairo_version () { return alloc_int (cairo_version ()); @@ -451,6 +488,7 @@ namespace lime { DEFINE_PRIM_MULT (lime_cairo_arc); + DEFINE_PRIM_MULT (lime_cairo_arc_negative); DEFINE_PRIM (lime_cairo_clip, 1); DEFINE_PRIM (lime_cairo_close_path, 1); DEFINE_PRIM (lime_cairo_create, 1); @@ -464,8 +502,11 @@ namespace lime { DEFINE_PRIM (lime_cairo_get_miter_limit, 1); DEFINE_PRIM (lime_cairo_get_operator, 1); DEFINE_PRIM (lime_cairo_get_source, 1); + DEFINE_PRIM (lime_cairo_get_target, 1); DEFINE_PRIM (lime_cairo_image_surface_create, 3); DEFINE_PRIM (lime_cairo_image_surface_create_for_data, 5); + DEFINE_PRIM (lime_cairo_image_surface_get_height, 1); + DEFINE_PRIM (lime_cairo_image_surface_get_width, 1); DEFINE_PRIM (lime_cairo_line_to, 3); DEFINE_PRIM (lime_cairo_mask, 2); DEFINE_PRIM (lime_cairo_move_to, 3); @@ -503,6 +544,7 @@ namespace lime { DEFINE_PRIM (lime_cairo_surface_destroy, 1); DEFINE_PRIM (lime_cairo_surface_flush, 1); DEFINE_PRIM (lime_cairo_transform, 2); + DEFINE_PRIM (lime_cairo_translate, 3); DEFINE_PRIM (lime_cairo_version, 0); DEFINE_PRIM (lime_cairo_version_string, 0); From 2e5438c2d637766ee2a314613e64668290799fad Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Sat, 2 May 2015 22:22:27 -0700 Subject: [PATCH 02/30] Add identityMatrix --- lime/graphics/cairo/Cairo.hx | 10 ++++++++++ project/src/graphics/cairo/CairoBindings.cpp | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/lime/graphics/cairo/Cairo.hx b/lime/graphics/cairo/Cairo.hx index 0c0ed3a6f..2896ab26f 100644 --- a/lime/graphics/cairo/Cairo.hx +++ b/lime/graphics/cairo/Cairo.hx @@ -99,6 +99,15 @@ class Cairo { } + public function identityMatrix ():Void { + + #if lime_cairo + lime_cairo_identity_matrix (handle); + #end + + } + + public function lineTo (x:Float, y:Float):Void { #if lime_cairo @@ -509,6 +518,7 @@ class Cairo { private static var lime_cairo_get_operator = System.load ("lime", "lime_cairo_get_operator", 1); 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_identity_matrix = System.load ("lime", "lime_cairo_identity_matrix", 1); private static var lime_cairo_line_to = System.load ("lime", "lime_cairo_line_to", 3); private static var lime_cairo_mask = System.load ("lime", "lime_cairo_mask", 2); private static var lime_cairo_move_to = System.load ("lime", "lime_cairo_move_to", 3); diff --git a/project/src/graphics/cairo/CairoBindings.cpp b/project/src/graphics/cairo/CairoBindings.cpp index 8b18df6d9..11014259d 100644 --- a/project/src/graphics/cairo/CairoBindings.cpp +++ b/project/src/graphics/cairo/CairoBindings.cpp @@ -128,6 +128,14 @@ namespace lime { } + value lime_cairo_identity_matrix (value handle) { + + cairo_identity_matrix ((cairo_t*)(intptr_t)val_float (handle)); + return alloc_null (); + + } + + value lime_cairo_image_surface_create (value format, value width, value height) { return alloc_float ((intptr_t)cairo_image_surface_create ((cairo_format_t)val_int (format), val_int (width), val_int (height))); @@ -503,6 +511,7 @@ namespace lime { DEFINE_PRIM (lime_cairo_get_operator, 1); DEFINE_PRIM (lime_cairo_get_source, 1); DEFINE_PRIM (lime_cairo_get_target, 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); DEFINE_PRIM (lime_cairo_image_surface_get_height, 1); From 961b1f3e4ce548952ffa30db2ce07fb3629ac386 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Sat, 2 May 2015 22:32:44 -0700 Subject: [PATCH 03/30] Try preserving the Cairo render surface longer --- lime/_backend/native/NativeRenderer.hx | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/lime/_backend/native/NativeRenderer.hx b/lime/_backend/native/NativeRenderer.hx index b6ed816a9..46bb0e7c7 100644 --- a/lime/_backend/native/NativeRenderer.hx +++ b/lime/_backend/native/NativeRenderer.hx @@ -22,6 +22,7 @@ class NativeRenderer { private var useHardware:Bool; #if lime_cairo + private var cacheLock:Dynamic; private var cairo:Cairo; private var primarySurface:CairoSurface; #end @@ -89,17 +90,22 @@ class NativeRenderer { if (!useHardware) { #if lime_cairo - if (cairo != null) { + var lock = lime_renderer_lock (handle); + + if (cacheLock == null || cacheLock.pixels != lock.pixels || cacheLock.width != lock.width || cacheLock.height != lock.height) { - cairo.destroy (); - primarySurface.destroy (); + if (cairo != null) { + + cairo.destroy (); + primarySurface.destroy (); + + } + + primarySurface = CairoSurface.createForData (lock.pixels, CairoFormat.ARGB32, lock.width, lock.height, lock.pitch); + cairo = new Cairo (primarySurface); + parent.context = CAIRO (cairo); } - - var lock = lime_renderer_lock (handle); - primarySurface = CairoSurface.createForData (lock.pixels, CairoFormat.ARGB32, lock.width, lock.height, lock.pitch); - cairo = new Cairo (primarySurface); - parent.context = CAIRO (cairo); #else parent.context = NONE; #end From b02677e05c67cf2ae671edf8d274c5c08ae9c817 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Sat, 2 May 2015 22:34:29 -0700 Subject: [PATCH 04/30] Minor fix --- lime/_backend/native/NativeRenderer.hx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lime/_backend/native/NativeRenderer.hx b/lime/_backend/native/NativeRenderer.hx index 46bb0e7c7..19b3f9e31 100644 --- a/lime/_backend/native/NativeRenderer.hx +++ b/lime/_backend/native/NativeRenderer.hx @@ -106,6 +106,8 @@ class NativeRenderer { parent.context = CAIRO (cairo); } + + cacheLock = lock; #else parent.context = NONE; #end From ddd77134d292f157014b1704293ea99fa63c34a7 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Sun, 3 May 2015 02:29:23 -0700 Subject: [PATCH 05/30] Extend Cairo bindings --- lime/graphics/cairo/Cairo.hx | 268 +++++++++++++++++++ lime/graphics/cairo/CairoAntialias.hx | 14 + lime/graphics/cairo/CairoFillRule.hx | 9 + lime/graphics/cairo/CairoStatus.hx | 46 ++++ project/src/graphics/cairo/CairoBindings.cpp | 238 ++++++++++++++++ 5 files changed, 575 insertions(+) create mode 100644 lime/graphics/cairo/CairoAntialias.hx create mode 100644 lime/graphics/cairo/CairoFillRule.hx create mode 100644 lime/graphics/cairo/CairoStatus.hx diff --git a/lime/graphics/cairo/Cairo.hx b/lime/graphics/cairo/Cairo.hx index 2896ab26f..1826c6ab1 100644 --- a/lime/graphics/cairo/Cairo.hx +++ b/lime/graphics/cairo/Cairo.hx @@ -11,14 +11,22 @@ class Cairo { public static var version (get, null):Int; public static var versionString (get, null):String; + public var antialias (get, set):CairoAntialias; + 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 lineCap (get, set):CairoLineCap; public var lineJoin (get, set):CairoLineJoin; public var lineWidth (get, set):Float; public var matrix (get, set):Matrix3; public var miterLimit (get, set):Float; public var operator (get, set):CairoOperator; + public var referenceCount (get, never):Int; public var source (get, set):CairoPattern; public var target (get, null):CairoSurface; + public var tolerance (get, set):Float; + public var userData:Dynamic; private var handle:Dynamic; @@ -63,6 +71,24 @@ class Cairo { } + public function clipExtents (x1:Float, y1:Float, x2:Float, y2:Float):Void { + + #if lime_cairo + lime_cairo_clip_extents (handle, x1, y1, x2, y2); + #end + + } + + + public function clipPreserve ():Void { + + #if lime_cairo + lime_cairo_clip_preserve (handle); + #end + + } + + public function closePath ():Void { #if lime_cairo @@ -72,6 +98,15 @@ class Cairo { } + public function copyPage ():Void { + + #if lime_cairo + lime_cairo_copy_page (handle); + #end + + } + + public function destroy ():Void { #if lime_cairo @@ -90,6 +125,15 @@ class Cairo { } + public function fillExtents (x1:Float, y1:Float, x2:Float, y2:Float):Void { + + #if lime_cairo + lime_cairo_fill_extents (x1, y1, x2, y2); + #end + + } + + public function fillPreserve ():Void { #if lime_cairo @@ -108,6 +152,39 @@ class Cairo { } + public function inClip (x:Float, y:Float):Bool { + + #if lime_cairo + return lime_cairo_in_clip (x, y); + #else + return false; + #end + + } + + + public function inFill (x:Float, y:Float):Bool { + + #if lime_cairo + return lime_cairo_in_fill (x, y); + #else + return false; + #end + + } + + + public function inStroke (x:Float, y:Float):Bool { + + #if lime_cairo + return lime_cairo_in_stroke (x, y); + #else + return false; + #end + + } + + public function lineTo (x:Float, y:Float):Void { #if lime_cairo @@ -135,6 +212,15 @@ class Cairo { } + public function maskSurface (surface:CairoSurface, x:Float, y:Float):Void { + + #if lime_cairo + lime_cairo_mask_surface (surface, x, y); + #end + + } + + public function newPath ():Void { #if lime_cairo @@ -209,6 +295,15 @@ class Cairo { } + public function reference ():Void { + + #if lime_cairo + lime_cairo_reference (handle); + #end + + } + + public function resetClip ():Void { #if lime_cairo @@ -263,6 +358,26 @@ class Cairo { } + public function showPage ():Void { + + #if lime_cairo + lime_cairo_show_page (handle); + #end + + } + + + public function status ():CairoStatus { + + #if lime_cairo + return lime_cairo_status (handle); + #else + return cast 0; + #end + + } + + public function stroke ():Void { #if lime_cairo @@ -272,6 +387,15 @@ class Cairo { } + public function strokeExtents (x1:Float, y1:Float, x2:Float, y2:Float):Void { + + #if lime_cairo + lime_cairo_stroke_extents (handle, x1, y1, x2, y2); + #end + + } + + public function strokePreserve ():Void { #if lime_cairo @@ -306,6 +430,94 @@ class Cairo { + private function get_antialias ():CairoAntialias { + + #if lime_cairo + return lime_cairo_get_antialias (handle); + #end + + return cast 0; + + } + + + private function set_antialias (value:CairoAntialias):CairoAntialias { + + #if lime_cairo + lime_cairo_set_antialias (handle, value); + #end + + return value; + + } + + + private function get_dash ():Array { + + #if lime_cairo + return lime_cairo_get_dash (handle); + #end + + return []; + + } + + + private function set_dash (value:Array):Array { + + #if lime_cairo + lime_cairo_set_dash (handle, value); + #end + + return value; + + } + + + private function get_dashCount ():Int { + + #if lime_cairo + return lime_cairo_get_dash_count (handle); + #end + + return 0; + + } + + + private function get_fillRule ():CairoFillRule { + + #if lime_cairo + return lime_cairo_get_fill_rule (handle); + #end + + return cast 0; + + } + + + private function set_fillRule (value:CairoFillRule):CairoFillRule { + + #if lime_cairo + lime_cairo_set_fill_rule (handle, value); + #end + + return value; + + } + + + private function get_groupTarget ():CairoSurface { + + #if lime_cairo + return lime_cairo_get_group_target (handle); + #else + return cast 0; + #end + + } + + private function get_lineCap ():CairoLineCap { #if lime_cairo @@ -439,6 +651,17 @@ class Cairo { } + private function get_referenceCount ():Int { + + #if lime_cairo + return lime_cairo_get_reference_count (); + #else + return 0; + #end + + } + + private function get_source ():CairoPattern { #if lime_cairo @@ -472,6 +695,28 @@ class Cairo { } + private function get_tolerance ():Float { + + #if lime_cairo + return lime_cairo_get_tolerance (); + #else + return 0; + #end + + } + + + private function set_tolerance (value:Float):Float { + + #if lime_cairo + lime_cairo_set_tolerance (value); + #end + + return value; + + } + + private static function get_version ():Int { #if lime_cairo @@ -505,22 +750,37 @@ class Cairo { private static var lime_cairo_arc = System.load ("lime", "lime_cairo_arc", -1); private static var lime_cairo_arc_negative = System.load ("lime", "lime_cairo_arc_negative", -1); private static var lime_cairo_clip = System.load ("lime", "lime_cairo_clip", 1); + private static var lime_cairo_clip_preserve = System.load ("lime", "lime_cairo_clip_preserve", 1); + private static var lime_cairo_clip_extents = System.load ("lime", "lime_cairo_clip_extents", 5); private static var lime_cairo_close_path = System.load ("lime", "lime_cairo_close_path", 1); + private static var lime_cairo_copy_page = System.load ("lime", "lime_cairo_copy_page", 1); private static var lime_cairo_create = System.load ("lime", "lime_cairo_create", 1); private static var lime_cairo_destroy = System.load ("lime", "lime_cairo_destroy", 1); private static var lime_cairo_fill = System.load ("lime", "lime_cairo_fill", 1); + 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_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); + private static var lime_cairo_get_group_target = System.load ("lime", "lime_cairo_get_group_target", 1); private static var lime_cairo_get_line_cap = System.load ("lime", "lime_cairo_get_line_cap", 1); private static var lime_cairo_get_line_join = System.load ("lime", "lime_cairo_get_line_join", 1); private static var lime_cairo_get_line_width = System.load ("lime", "lime_cairo_get_line_width", 1); private static var lime_cairo_get_matrix = System.load ("lime", "lime_cairo_get_matrix", 1); private static var lime_cairo_get_miter_limit = System.load ("lime", "lime_cairo_get_miter_limit", 1); private static var lime_cairo_get_operator = System.load ("lime", "lime_cairo_get_operator", 1); + private static var lime_cairo_get_reference_count = System.load ("lime", "lime_cairo_get_reference_count", 1); 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_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); + private static var lime_cairo_in_stroke = System.load ("lime", "lime_cairo_in_stroke", 3); private static var lime_cairo_line_to = System.load ("lime", "lime_cairo_line_to", 3); private static var lime_cairo_mask = System.load ("lime", "lime_cairo_mask", 2); + private static var lime_cairo_mask_surface = System.load ("lime", "lime_cairo_mask_surface", 4); private static var lime_cairo_move_to = System.load ("lime", "lime_cairo_move_to", 3); private static var lime_cairo_new_path = System.load ("lime", "lime_cairo_new_path", 1); private static var lime_cairo_paint = System.load ("lime", "lime_cairo_paint", 1); @@ -530,9 +790,13 @@ class Cairo { private static var lime_cairo_push_group = System.load ("lime", "lime_cairo_push_group", 1); private static var lime_cairo_push_group_with_content = System.load ("lime", "lime_cairo_push_group_with_content", 2); private static var lime_cairo_rectangle = System.load ("lime", "lime_cairo_rectangle", 5); + private static var lime_cairo_reference = System.load ("lime", "lime_cairo_reference", 1); private static var lime_cairo_reset_clip = System.load ("lime", "lime_cairo_reset_clip", 1); private static var lime_cairo_restore = System.load ("lime", "lime_cairo_restore", 1); private static var lime_cairo_save = System.load ("lime", "lime_cairo_save", 1); + private static var lime_cairo_set_antialias = System.load ("lime", "lime_cairo_set_antialias", 2); + private static var lime_cairo_set_dash = System.load ("lime", "lime_cairo_set_dash", 2); + private static var lime_cairo_set_fill_rule = System.load ("lime", "lime_cairo_set_fill_rule", 2); private static var lime_cairo_set_line_cap = System.load ("lime", "lime_cairo_set_line_cap", 2); private static var lime_cairo_set_line_join = System.load ("lime", "lime_cairo_set_line_join", 2); private static var lime_cairo_set_line_width = System.load ("lime", "lime_cairo_set_line_width", 2); @@ -543,7 +807,11 @@ class Cairo { private static var lime_cairo_set_source_rgb = System.load ("lime", "lime_cairo_set_source_rgb", 4); private static var lime_cairo_set_source_rgba = System.load ("lime", "lime_cairo_set_source_rgba", 5); private static var lime_cairo_set_source_surface = System.load ("lime", "lime_cairo_set_source_surface", 4); + private static var lime_cairo_set_tolerance = System.load ("lime", "lime_cairo_set_tolerance", 2); + private static var lime_cairo_show_page = System.load ("lime", "lime_cairo_show_page", 1); + private static var lime_cairo_status = System.load ("lime", "lime_cairo_status", 1); private static var lime_cairo_stroke = System.load ("lime", "lime_cairo_stroke", 1); + private static var lime_cairo_stroke_extents = System.load ("lime", "lime_cairo_stroke_extents", 5); private static var lime_cairo_stroke_preserve = System.load ("lime", "lime_cairo_stroke_preserve", 1); private static var lime_cairo_transform = System.load ("lime", "lime_cairo_transform", 2); private static var lime_cairo_translate = System.load ("lime", "lime_cairo_translate", 3); diff --git a/lime/graphics/cairo/CairoAntialias.hx b/lime/graphics/cairo/CairoAntialias.hx new file mode 100644 index 000000000..1e3b88ca6 --- /dev/null +++ b/lime/graphics/cairo/CairoAntialias.hx @@ -0,0 +1,14 @@ +package lime.graphics.cairo; + + +@:enum abstract CairoAntialias(Int) from Int to Int { + + public var DEFAULT = 0; + public var NONE = 1; + public var GRAY = 2; + public var SUBPIXEL = 3; + public var FAST = 4; + public var GOOD = 5; + public var BEST = 6; + +} \ No newline at end of file diff --git a/lime/graphics/cairo/CairoFillRule.hx b/lime/graphics/cairo/CairoFillRule.hx new file mode 100644 index 000000000..c284b4209 --- /dev/null +++ b/lime/graphics/cairo/CairoFillRule.hx @@ -0,0 +1,9 @@ +package lime.graphics.cairo; + + +@:enum abstract CairoFillRule(Int) from Int to Int { + + public var WINDING = 0; + public var EVEN_ODD = 1; + +} \ No newline at end of file diff --git a/lime/graphics/cairo/CairoStatus.hx b/lime/graphics/cairo/CairoStatus.hx new file mode 100644 index 000000000..d98dfa636 --- /dev/null +++ b/lime/graphics/cairo/CairoStatus.hx @@ -0,0 +1,46 @@ +package lime.graphics.cairo; + + +@:enum abstract CairoStatus(Int) from Int to Int { + + public var SUCCESS = 0; + public var NO_MEMORY = 1; + public var INVALID_RESTORE = 2; + public var INVALID_POP_GROUP = 3; + public var NO_CURRENT_POINT = 4; + public var INVALID_MATRIX = 5; + public var INVALID_STATUS = 6; + public var NULL_POINTER = 7; + public var INVALID_STRING = 8; + public var INVALID_PATH_DATA = 9; + public var READ_ERROR = 10; + public var WRITE_ERROR = 11; + public var SURFACE_FINISHED = 12; + public var SURFACE_TYPE_MISMATCH = 13; + public var PATTERN_TYPE_MISMATCH = 14; + public var INVALID_CONTENT = 15; + public var INVALID_FORMAT = 16; + public var INVALID_VISUAL = 17; + public var FILE_NOT_FOUND = 18; + public var INVALID_DASH = 19; + public var INVALID_DSC_COMMENT = 20; + public var INVALID_INDEX = 21; + public var CLIP_NOT_REPRESENTABLE = 22; + public var TEMP_FILE_ERROR = 23; + public var INVALID_STRIDE = 24; + public var FONT_TYPE_MISMATCH = 25; + public var USER_FONT_IMMUTABLE = 26; + public var USER_FONT_ERROR = 27; + public var NEGATIVE_COUNT = 28; + public var INVALID_CLUSTERS = 29; + public var INVALID_SLANT = 30; + public var INVALID_WEIGHT = 31; + public var INVALID_SIZE = 32; + public var USER_FONT_NOT_IMPLEMENTED = 33; + public var DEVICE_TYPE_MISMATCH = 34; + public var DEVICE_ERROR = 35; + public var INVALID_MESH_CONSTRUCTION = 36; + public var DEVICE_FINISHED = 37; + public var JBIG2_GLOBAL_MISSING = 38; + +} \ No newline at end of file diff --git a/project/src/graphics/cairo/CairoBindings.cpp b/project/src/graphics/cairo/CairoBindings.cpp index 11014259d..c3719745e 100644 --- a/project/src/graphics/cairo/CairoBindings.cpp +++ b/project/src/graphics/cairo/CairoBindings.cpp @@ -30,6 +30,27 @@ namespace lime { } + value lime_cairo_clip_extents (value handle, value x1, value y1, value x2, value y2) { + + double _x1 = val_number (x1); + double _y1 = val_number (y1); + double _x2 = val_number (x2); + double _y2 = val_number (y2); + + cairo_clip_extents ((cairo_t*)(intptr_t)val_float (handle), &_x1, &_y1, &_x2, &_y2); + return alloc_null (); + + } + + + value lime_cairo_clip_preserve (value handle) { + + cairo_clip_preserve ((cairo_t*)(intptr_t)val_float (handle)); + return alloc_null (); + + } + + value lime_cairo_close_path (value handle) { cairo_close_path ((cairo_t*)(intptr_t)val_float (handle)); @@ -38,6 +59,14 @@ namespace lime { } + value lime_cairo_copy_page (value handle) { + + cairo_copy_page ((cairo_t*)(intptr_t)val_float (handle)); + return alloc_null (); + + } + + value lime_cairo_create (value surface) { return alloc_float ((intptr_t)cairo_create ((cairo_surface_t*)(intptr_t)val_float (surface))); @@ -61,6 +90,19 @@ namespace lime { } + value lime_cairo_fill_extents (value handle, value x1, value y1, value x2, value y2) { + + double _x1 = val_number (x1); + double _y1 = val_number (y1); + double _x2 = val_number (x2); + double _y2 = val_number (y2); + + cairo_fill_extents ((cairo_t*)(intptr_t)val_float (handle), &_x1, &_y1, &_x2, &_y2); + return alloc_null (); + + } + + value lime_cairo_fill_preserve (value handle) { cairo_fill_preserve ((cairo_t*)(intptr_t)val_float (handle)); @@ -69,6 +111,57 @@ namespace lime { } + value lime_cairo_get_antialias (value handle) { + + return alloc_int (cairo_get_antialias ((cairo_t*)(intptr_t)val_float (handle))); + + } + + + value lime_cairo_get_dash (value handle) { + + int length = cairo_get_dash_count ((cairo_t*)(intptr_t)val_float (handle)); + + double* dashes = new double[length]; + double offset; + + cairo_get_dash ((cairo_t*)(intptr_t)val_float (handle), dashes, &offset); + + value result = alloc_array (length); + + for (int i = 0; i < length; i++) { + + val_array_set_i (result, i, alloc_float (dashes[i])); + + } + + delete dashes; + return result; + + } + + + value lime_cairo_get_dash_count (value handle) { + + return alloc_int (cairo_get_dash_count ((cairo_t*)(intptr_t)val_float (handle))); + + } + + + value lime_cairo_get_fill_rule (value handle) { + + return alloc_int (cairo_get_fill_rule ((cairo_t*)(intptr_t)val_float (handle))); + + } + + + value lime_cairo_get_group_target (value handle) { + + return alloc_float ((intptr_t)cairo_get_group_target ((cairo_t*)(intptr_t)val_float (handle))); + + } + + value lime_cairo_get_line_cap (value handle) { return alloc_int (cairo_get_line_cap ((cairo_t*)(intptr_t)val_float (handle))); @@ -114,6 +207,13 @@ namespace lime { } + value lime_cairo_get_reference_count (value handle) { + + return alloc_int (cairo_get_reference_count ((cairo_t*)(intptr_t)val_float (handle))); + + } + + value lime_cairo_get_source (value handle) { return alloc_float ((intptr_t)cairo_get_source ((cairo_t*)(intptr_t)val_float (handle))); @@ -128,6 +228,13 @@ namespace lime { } + value lime_cairo_get_tolerance (value handle) { + + return alloc_float (cairo_get_tolerance ((cairo_t*)(intptr_t)val_float (handle))); + + } + + value lime_cairo_identity_matrix (value handle) { cairo_identity_matrix ((cairo_t*)(intptr_t)val_float (handle)); @@ -164,6 +271,27 @@ namespace lime { } + value lime_cairo_in_clip (value handle, value x, value y) { + + return alloc_bool (cairo_in_clip ((cairo_t*)(intptr_t)val_float (handle), val_number (x), val_number (y))); + + } + + + value lime_cairo_in_fill (value handle, value x, value y) { + + return alloc_bool (cairo_in_fill ((cairo_t*)(intptr_t)val_float (handle), val_number (x), val_number (y))); + + } + + + value lime_cairo_in_stroke (value handle, value x, value y) { + + return alloc_bool (cairo_in_stroke ((cairo_t*)(intptr_t)val_float (handle), val_number (x), val_number (y))); + + } + + value lime_cairo_line_to (value handle, value x, value y) { cairo_line_to ((cairo_t*)(intptr_t)val_float (handle), val_number (x), val_number (y)); @@ -180,6 +308,14 @@ namespace lime { } + value lime_cairo_mask_surface (value handle, value surface, value x, value y) { + + cairo_mask_surface ((cairo_t*)(intptr_t)val_float (handle), (cairo_surface_t*)(intptr_t)val_float (surface), val_number (x), val_number (y)); + return alloc_null (); + + } + + value lime_cairo_move_to (value handle, value x, value y) { cairo_move_to ((cairo_t*)(intptr_t)val_float (handle), val_number (x), val_number (y)); @@ -319,6 +455,14 @@ namespace lime { } + value lime_cairo_reference (value handle) { + + cairo_reference ((cairo_t*)(intptr_t)val_float (handle)); + return alloc_null (); + + } + + value lime_cairo_reset_clip (value handle) { cairo_reset_clip ((cairo_t*)(intptr_t)val_float (handle)); @@ -343,6 +487,41 @@ namespace lime { } + value lime_cairo_set_antialias (value handle, value cap) { + + cairo_set_antialias ((cairo_t*)(intptr_t)val_float (handle), (cairo_antialias_t)val_int (cap)); + return alloc_null (); + + } + + + value lime_cairo_set_dash (value handle, value dash) { + + int length = val_array_size (dash); + + double* dashPattern = new double[length]; + + for (int i = 0; i < length; i++) { + + dashPattern[i] = val_number (val_array_i (dash, i)); + + } + + cairo_set_dash ((cairo_t*)(intptr_t)val_float (handle), dashPattern, length, 0); + delete dashPattern; + return alloc_null (); + + } + + + value lime_cairo_set_fill_rule (value handle, value cap) { + + cairo_set_fill_rule ((cairo_t*)(intptr_t)val_float (handle), (cairo_fill_rule_t)val_int (cap)); + return alloc_null (); + + } + + value lime_cairo_set_line_cap (value handle, value cap) { cairo_set_line_cap ((cairo_t*)(intptr_t)val_float (handle), (cairo_line_cap_t)val_int (cap)); @@ -428,6 +607,29 @@ namespace lime { } + value lime_cairo_set_tolerance (value handle, value tolerance) { + + cairo_set_tolerance ((cairo_t*)(intptr_t)val_float (handle), val_number (tolerance)); + return alloc_null (); + + } + + + value lime_cairo_show_page (value handle) { + + cairo_show_page ((cairo_t*)(intptr_t)val_float (handle)); + return alloc_null (); + + } + + + value lime_cairo_status (value handle) { + + return alloc_int (cairo_status ((cairo_t*)(intptr_t)val_float (handle))); + + } + + value lime_cairo_stroke (value handle) { cairo_stroke ((cairo_t*)(intptr_t)val_float (handle)); @@ -436,6 +638,19 @@ namespace lime { } + value lime_cairo_stroke_extents (value handle, value x1, value y1, value x2, value y2) { + + double _x1 = val_number (x1); + double _y1 = val_number (y1); + double _x2 = val_number (x2); + double _y2 = val_number (y2); + + cairo_stroke_extents ((cairo_t*)(intptr_t)val_float (handle), &_x1, &_y1, &_x2, &_y2); + return alloc_null (); + + } + + value lime_cairo_stroke_preserve (value handle) { cairo_stroke_preserve ((cairo_t*)(intptr_t)val_float (handle)); @@ -498,26 +713,41 @@ namespace lime { DEFINE_PRIM_MULT (lime_cairo_arc); DEFINE_PRIM_MULT (lime_cairo_arc_negative); DEFINE_PRIM (lime_cairo_clip, 1); + DEFINE_PRIM (lime_cairo_clip_extents, 5); + DEFINE_PRIM (lime_cairo_clip_preserve, 1); DEFINE_PRIM (lime_cairo_close_path, 1); + DEFINE_PRIM (lime_cairo_copy_page, 1); DEFINE_PRIM (lime_cairo_create, 1); DEFINE_PRIM (lime_cairo_destroy, 1); DEFINE_PRIM (lime_cairo_fill, 1); + 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_dash, 1); + DEFINE_PRIM (lime_cairo_get_dash_count, 1); + DEFINE_PRIM (lime_cairo_get_fill_rule, 1); + DEFINE_PRIM (lime_cairo_get_group_target, 1); DEFINE_PRIM (lime_cairo_get_line_cap, 1); DEFINE_PRIM (lime_cairo_get_line_join, 1); DEFINE_PRIM (lime_cairo_get_line_width, 1); DEFINE_PRIM (lime_cairo_get_matrix, 1); DEFINE_PRIM (lime_cairo_get_miter_limit, 1); DEFINE_PRIM (lime_cairo_get_operator, 1); + DEFINE_PRIM (lime_cairo_get_reference_count, 1); 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_identity_matrix, 1); DEFINE_PRIM (lime_cairo_image_surface_create, 3); DEFINE_PRIM (lime_cairo_image_surface_create_for_data, 5); DEFINE_PRIM (lime_cairo_image_surface_get_height, 1); DEFINE_PRIM (lime_cairo_image_surface_get_width, 1); + DEFINE_PRIM (lime_cairo_in_clip, 3); + DEFINE_PRIM (lime_cairo_in_fill, 3); + DEFINE_PRIM (lime_cairo_in_stroke, 3); DEFINE_PRIM (lime_cairo_line_to, 3); DEFINE_PRIM (lime_cairo_mask, 2); + DEFINE_PRIM (lime_cairo_mask_surface, 4); DEFINE_PRIM (lime_cairo_move_to, 3); DEFINE_PRIM (lime_cairo_new_path, 1); DEFINE_PRIM (lime_cairo_paint, 1); @@ -535,9 +765,13 @@ namespace lime { DEFINE_PRIM (lime_cairo_push_group, 1); DEFINE_PRIM (lime_cairo_push_group_with_content, 2); DEFINE_PRIM (lime_cairo_rectangle, 5); + DEFINE_PRIM (lime_cairo_reference, 1); DEFINE_PRIM (lime_cairo_reset_clip, 1); DEFINE_PRIM (lime_cairo_restore, 1); DEFINE_PRIM (lime_cairo_save, 1); + DEFINE_PRIM (lime_cairo_set_antialias, 2); + DEFINE_PRIM (lime_cairo_set_dash, 2); + DEFINE_PRIM (lime_cairo_set_fill_rule, 2); DEFINE_PRIM (lime_cairo_set_line_cap, 2); DEFINE_PRIM (lime_cairo_set_line_join, 2); DEFINE_PRIM (lime_cairo_set_line_width, 2); @@ -548,7 +782,11 @@ namespace lime { DEFINE_PRIM (lime_cairo_set_source_rgb, 4); DEFINE_PRIM (lime_cairo_set_source_rgba, 5); DEFINE_PRIM (lime_cairo_set_source_surface, 4); + DEFINE_PRIM (lime_cairo_set_tolerance, 2); + DEFINE_PRIM (lime_cairo_show_page, 1); + DEFINE_PRIM (lime_cairo_status, 1); DEFINE_PRIM (lime_cairo_stroke, 1); + DEFINE_PRIM (lime_cairo_stroke_extents, 5); DEFINE_PRIM (lime_cairo_stroke_preserve, 1); DEFINE_PRIM (lime_cairo_surface_destroy, 1); DEFINE_PRIM (lime_cairo_surface_flush, 1); From 2b75564951d99a39b7df2d71b4805ea84f01cbb3 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Mon, 4 May 2015 15:54:50 -0700 Subject: [PATCH 06/30] Some work on pixel formats --- lime/graphics/Image.hx | 29 ++++++ lime/graphics/ImageBuffer.hx | 13 ++- lime/graphics/PixelFormat.hx | 7 +- lime/graphics/cairo/CairoSurface.hx | 14 +++ lime/graphics/utils/ImageDataUtil.hx | 95 ++++++++++++++++++- lime/utils/ByteArray.hx | 10 ++ project/include/graphics/ImageBuffer.h | 2 + project/include/graphics/PixelFormat.h | 3 +- .../include/graphics/utils/ImageDataUtil.h | 1 + project/src/ExternalInterface.cpp | 11 +++ project/src/graphics/ImageBuffer.cpp | 6 ++ project/src/graphics/utils/ImageDataUtil.cpp | 84 ++++++++++++++++ project/src/utils/ByteArray.cpp | 3 +- 13 files changed, 270 insertions(+), 8 deletions(-) diff --git a/lime/graphics/Image.hx b/lime/graphics/Image.hx index 86fb29bd6..93154d336 100644 --- a/lime/graphics/Image.hx +++ b/lime/graphics/Image.hx @@ -58,6 +58,7 @@ class Image { public var buffer:ImageBuffer; public var data (get, set):UInt8Array; public var dirty:Bool; + public var format (get, set):PixelFormat; public var height:Int; public var offsetX:Int; public var offsetY:Int; @@ -1172,6 +1173,34 @@ class Image { } + private function get_format ():PixelFormat { + + return buffer.format; + + } + + + private function set_format (value:PixelFormat):PixelFormat { + + if (buffer.format != value) { + + switch (type) { + + case DATA: + + ImageDataUtil.setFormat (this, value); + + default: + + } + + } + + return buffer.format = value; + + } + + private function get_powerOfTwo ():Bool { return ((buffer.width != 0) && ((buffer.width & (~buffer.width + 1)) == buffer.width)) && ((buffer.height != 0) && ((buffer.height & (~buffer.height + 1)) == buffer.height)); diff --git a/lime/graphics/ImageBuffer.hx b/lime/graphics/ImageBuffer.hx index 0bf554d33..36d276146 100644 --- a/lime/graphics/ImageBuffer.hx +++ b/lime/graphics/ImageBuffer.hx @@ -2,6 +2,7 @@ package lime.graphics; import haxe.io.Bytes; +import lime.graphics.cairo.CairoSurface; import lime.utils.ByteArray; import lime.utils.UInt8Array; @@ -24,9 +25,11 @@ class ImageBuffer { public var bitsPerPixel:Int; public var data:UInt8Array; + public var format:PixelFormat; public var height:Int; public var premultiplied:Bool; public var src (get, set):Dynamic; + public var stride (get, never):Int; public var transparent:Bool; public var width:Int; @@ -38,12 +41,13 @@ class ImageBuffer { @:noCompletion private var __srcImageData:#if (js && html5) ImageData #else Dynamic #end; - public function new (data:UInt8Array = null, width:Int = 0, height:Int = 0, bitsPerPixel:Int = 4) { + public function new (data:UInt8Array = null, width:Int = 0, height:Int = 0, bitsPerPixel:Int = 4, format:PixelFormat = null) { this.data = data; this.width = width; this.height = height; this.bitsPerPixel = bitsPerPixel; + this.format = (format == null ? RGBA : format); transparent = true; } @@ -169,4 +173,11 @@ class ImageBuffer { } + private function get_stride ():Int { + + return width * 4; + + } + + } \ No newline at end of file diff --git a/lime/graphics/PixelFormat.hx b/lime/graphics/PixelFormat.hx index 5981b014b..7b8106948 100644 --- a/lime/graphics/PixelFormat.hx +++ b/lime/graphics/PixelFormat.hx @@ -1,9 +1,10 @@ package lime.graphics; -enum PixelFormat { +@:enum abstract PixelFormat(Int) from Int to Int { - RGBA; - ARGB; + public var RGBA = 0; + public var ARGB = 1; + public var BGRA = 2; } \ No newline at end of file diff --git a/lime/graphics/cairo/CairoSurface.hx b/lime/graphics/cairo/CairoSurface.hx index e3609ae1a..90cf744a0 100644 --- a/lime/graphics/cairo/CairoSurface.hx +++ b/lime/graphics/cairo/CairoSurface.hx @@ -1,8 +1,11 @@ package lime.graphics.cairo; +import lime.graphics.Image; import lime.system.System; +@:access(haxe.io.Bytes) + abstract CairoSurface(Dynamic) { @@ -51,6 +54,17 @@ abstract CairoSurface(Dynamic) { } + public static function fromImage (image:Image):CairoSurface { + + #if lime_cairo + return createForData (image.data.buffer.__getNativePointer (), CairoFormat.ARGB32, image.width, image.height, image.buffer.stride); + #else + return null; + #end + + } + + // Get & Set Methods diff --git a/lime/graphics/utils/ImageDataUtil.hx b/lime/graphics/utils/ImageDataUtil.hx index 94fffae68..f140c1338 100644 --- a/lime/graphics/utils/ImageDataUtil.hx +++ b/lime/graphics/utils/ImageDataUtil.hx @@ -4,6 +4,7 @@ package lime.graphics.utils; import haxe.ds.Vector; import lime.graphics.Image; import lime.graphics.ImageBuffer; +import lime.graphics.PixelFormat; import lime.math.ColorMatrix; import lime.math.Rectangle; import lime.math.Vector2; @@ -675,7 +676,7 @@ class ImageDataUtil { #end #if ((cpp || neko) && !disable_cffi) - if (!System.disableCFFI) byteArray = lime_image_data_util_get_pixels (image, rect, format == ARGB ? 1 : 0); else + if (!System.disableCFFI) byteArray = lime_image_data_util_get_pixels (image, rect, format); else #end { @@ -935,6 +936,95 @@ class ImageDataUtil { } + public static function setFormat (image:Image, format:PixelFormat):Void { + + var data = image.buffer.data; + if (data == null) return; + + #if ((cpp || neko) && !disable_cffi) + if (!System.disableCFFI) lime_image_data_util_set_format (image, format); else + #end + { + + var index, a16; + var length = Std.int (data.length / 4); + var r1, g1, b1, a1, r2, g2, b2, a2; + var r, g, b, a; + + switch (image.format) { + + case RGBA: + + r1 = 0; + g1 = 1; + b1 = 2; + a1 = 3; + + case ARGB: + + r1 = 1; + g1 = 2; + b1 = 3; + a1 = 0; + + case BGRA: + + r1 = 2; + g1 = 1; + b1 = 0; + a1 = 3; + + } + + switch (format) { + + case RGBA: + + r2 = 0; + g2 = 1; + b2 = 2; + a2 = 3; + + case ARGB: + + r2 = 1; + g2 = 2; + b2 = 3; + a2 = 0; + + case BGRA: + + r2 = 2; + g2 = 1; + b2 = 0; + a2 = 3; + + } + + for (i in 0...length) { + + index = i * 4; + + r = data[index + r1]; + g = data[index + g1]; + b = data[index + b1]; + a = data[index + a1]; + + data[index + r2] = r; + data[index + g2] = g; + data[index + b2] = b; + data[index + a2] = a; + + } + + } + + image.buffer.format = format; + image.dirty = true; + + } + + public static function setPixel (image:Image, x:Int, y:Int, color:Int, format:PixelFormat):Void { var data = image.buffer.data; @@ -1000,7 +1090,7 @@ class ImageDataUtil { if (image.buffer.data == null) return; #if ((cpp || neko) && !disable_cffi) - if (!System.disableCFFI) lime_image_data_util_set_pixels (image, rect, byteArray, format == ARGB ? 1 : 0); else + if (!System.disableCFFI) lime_image_data_util_set_pixels (image, rect, byteArray, format); else #end { @@ -1127,6 +1217,7 @@ class ImageDataUtil { private static var lime_image_data_util_merge = System.load ("lime", "lime_image_data_util_merge", -1); private static var lime_image_data_util_multiply_alpha = System.load ("lime", "lime_image_data_util_multiply_alpha", 1); private static var lime_image_data_util_resize = System.load ("lime", "lime_image_data_util_resize", 4); + private static var lime_image_data_util_set_format = System.load ("lime", "lime_image_data_util_set_format", 2); private static var lime_image_data_util_set_pixels = System.load ("lime", "lime_image_data_util_set_pixels", 4); private static var lime_image_data_util_unmultiply_alpha = System.load ("lime", "lime_image_data_util_unmultiply_alpha", 1); #end diff --git a/lime/utils/ByteArray.hx b/lime/utils/ByteArray.hx index 2910fa5b1..b5f2ea86c 100644 --- a/lime/utils/ByteArray.hx +++ b/lime/utils/ByteArray.hx @@ -1002,6 +1002,15 @@ class ByteArray #if !js extends Bytes implements ArrayAccess implements IDa #end + #if (cpp || neko || nodejs) + public function __getNativePointer ():Dynamic { + + return lime_byte_array_get_native_pointer (this); + + } + #end + + #if js private function __getUTFBytesCount (value:String):Int { @@ -1154,6 +1163,7 @@ class ByteArray #if !js extends Bytes implements ArrayAccess implements IDa + private static var lime_byte_array_get_native_pointer = System.load ("lime", "lime_byte_array_get_native_pointer", 1); private static var lime_byte_array_overwrite_file = System.load ("lime", "lime_byte_array_overwrite_file", 2); private static var lime_byte_array_read_file = System.load ("lime", "lime_byte_array_read_file", 1); private static var lime_lzma_decode = System.load ("lime", "lime_lzma_decode", 1); diff --git a/project/include/graphics/ImageBuffer.h b/project/include/graphics/ImageBuffer.h index 6e6e0ecfd..d092f9964 100644 --- a/project/include/graphics/ImageBuffer.h +++ b/project/include/graphics/ImageBuffer.h @@ -3,6 +3,7 @@ #include +#include #include @@ -24,6 +25,7 @@ namespace lime { int bpp; ByteArray *data; + PixelFormat format; int height; int width; bool transparent; diff --git a/project/include/graphics/PixelFormat.h b/project/include/graphics/PixelFormat.h index 101dcdab8..fb35c7cb1 100644 --- a/project/include/graphics/PixelFormat.h +++ b/project/include/graphics/PixelFormat.h @@ -8,7 +8,8 @@ namespace lime { enum PixelFormat { RGBA, - ARGB + ARGB, + BGRA }; diff --git a/project/include/graphics/utils/ImageDataUtil.h b/project/include/graphics/utils/ImageDataUtil.h index 77ddaac6e..1b06ef15b 100644 --- a/project/include/graphics/utils/ImageDataUtil.h +++ b/project/include/graphics/utils/ImageDataUtil.h @@ -29,6 +29,7 @@ namespace lime { static void Merge (Image* image, Image* sourceImage, Rectangle* sourceRect, Vector2* destPoint, int redMultiplier, int greenMultiplier, int blueMultiplier, int alphaMultiplier); static void MultiplyAlpha (Image* image); static void Resize (Image* image, ImageBuffer* buffer, int width, int height); + static void SetFormat (Image* image, PixelFormat format); static void SetPixels (Image* image, Rectangle* rect, ByteArray* bytes, PixelFormat format); static void UnmultiplyAlpha (Image* image); diff --git a/project/src/ExternalInterface.cpp b/project/src/ExternalInterface.cpp index d20b66d7c..913dd9f87 100644 --- a/project/src/ExternalInterface.cpp +++ b/project/src/ExternalInterface.cpp @@ -549,6 +549,16 @@ namespace lime { } + value lime_image_data_util_set_format (value image, value format) { + + Image _image = Image (image); + PixelFormat _format = (PixelFormat)val_int (format); + ImageDataUtil::SetFormat (&_image, _format); + return alloc_null (); + + } + + value lime_image_data_util_set_pixels (value image, value rect, value bytes, value format) { Image _image = Image (image); @@ -985,6 +995,7 @@ namespace lime { DEFINE_PRIM_MULT (lime_image_data_util_merge); DEFINE_PRIM (lime_image_data_util_multiply_alpha, 1); DEFINE_PRIM (lime_image_data_util_resize, 4); + DEFINE_PRIM (lime_image_data_util_set_format, 2); DEFINE_PRIM (lime_image_data_util_set_pixels, 4); DEFINE_PRIM (lime_image_data_util_unmultiply_alpha, 1); DEFINE_PRIM (lime_image_encode, 3); diff --git a/project/src/graphics/ImageBuffer.cpp b/project/src/graphics/ImageBuffer.cpp index 4f6c179ce..87fe3d9d5 100644 --- a/project/src/graphics/ImageBuffer.cpp +++ b/project/src/graphics/ImageBuffer.cpp @@ -8,6 +8,7 @@ namespace lime { static int id_bpp; static int id_buffer; static int id_data; + static int id_format; static int id_height; static int id_width; static int id_transparent; @@ -19,6 +20,7 @@ namespace lime { width = 0; height = 0; bpp = 4; + format = RGBA; data = 0; transparent = false; @@ -36,6 +38,7 @@ namespace lime { id_width = val_id ("width"); id_height = val_id ("height"); id_data = val_id ("data"); + id_format = val_id ("format"); init = true; } @@ -43,6 +46,7 @@ namespace lime { width = val_int (val_field (imageBuffer, id_width)); height = val_int (val_field (imageBuffer, id_height)); bpp = val_int (val_field (imageBuffer, id_bitsPerPixel)); + format = (PixelFormat)val_int (val_field (imageBuffer, id_format)); transparent = val_bool (val_field (imageBuffer, id_transparent)); value data_value = val_field (imageBuffer, id_data); value buffer_value = val_field (data_value, id_buffer); @@ -103,6 +107,7 @@ namespace lime { id_width = val_id ("width"); id_height = val_id ("height"); id_data = val_id ("data"); + id_format = val_id ("format"); init = true; } @@ -113,6 +118,7 @@ namespace lime { alloc_field (mValue, id_bpp, alloc_int (bpp)); alloc_field (mValue, id_transparent, alloc_bool (transparent)); alloc_field (mValue, id_data, data->mValue); + alloc_field (mValue, id_format, alloc_int (format)); return mValue; } diff --git a/project/src/graphics/utils/ImageDataUtil.cpp b/project/src/graphics/utils/ImageDataUtil.cpp index 70863675a..1ced8f2bb 100644 --- a/project/src/graphics/utils/ImageDataUtil.cpp +++ b/project/src/graphics/utils/ImageDataUtil.cpp @@ -478,6 +478,90 @@ namespace lime { } + void ImageDataUtil::SetFormat (Image* image, PixelFormat format) { + + int index, a16; + int length = image->buffer->data->Size () / 4; + int r1, g1, b1, a1, r2, g2, b2, a2; + int r, g, b, a; + + switch (image->buffer->format) { + + case RGBA: + + r1 = 0; + g1 = 1; + b1 = 2; + a1 = 3; + break; + + case ARGB: + + r1 = 1; + g1 = 2; + b1 = 3; + a1 = 0; + break; + + case BGRA: + + r1 = 2; + g1 = 1; + b1 = 0; + a1 = 3; + break; + + } + + switch (format) { + + case RGBA: + + r2 = 0; + g2 = 1; + b2 = 2; + a2 = 3; + break; + + case ARGB: + + r2 = 1; + g2 = 2; + b2 = 3; + a2 = 0; + break; + + case BGRA: + + r2 = 2; + g2 = 1; + b2 = 0; + a2 = 3; + break; + + } + + unsigned char* data = image->buffer->data->Bytes (); + + for (int i = 0; i < length; i++) { + + index = i * 4; + + r = data[index + r1]; + g = data[index + g1]; + b = data[index + b1]; + a = data[index + a1]; + + data[index + r2] = r; + data[index + g2] = g; + data[index + b2] = b; + data[index + a2] = a; + + } + + } + + void ImageDataUtil::SetPixels (Image* image, Rectangle* rect, ByteArray* bytes, PixelFormat format) { if (format == RGBA && rect->width == image->buffer->width && rect->height == image->buffer->height && rect->x == 0 && rect->y == 0) { diff --git a/project/src/utils/ByteArray.cpp b/project/src/utils/ByteArray.cpp index 231fe27de..5bf21a040 100644 --- a/project/src/utils/ByteArray.cpp +++ b/project/src/utils/ByteArray.cpp @@ -138,7 +138,7 @@ namespace lime { if (!val_is_null (bytes.mValue)) { - return alloc_int ((intptr_t)bytes.Bytes ()); + return alloc_float ((intptr_t)bytes.Bytes ()); } @@ -146,6 +146,7 @@ namespace lime { } + value lime_byte_array_init (value inFactory, value inLen, value inResize, value inBytes) { gByteArrayCreate = new AutoGCRoot (inFactory); From a4772cfceee50f36083d53aa5d5e3f7680cb54e5 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Mon, 4 May 2015 16:05:04 -0700 Subject: [PATCH 07/30] Compile fix --- lime/graphics/cairo/CairoSurface.hx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lime/graphics/cairo/CairoSurface.hx b/lime/graphics/cairo/CairoSurface.hx index 90cf744a0..e78b7685f 100644 --- a/lime/graphics/cairo/CairoSurface.hx +++ b/lime/graphics/cairo/CairoSurface.hx @@ -1,4 +1,4 @@ -package lime.graphics.cairo; +package lime.graphics.cairo; #if !macro import lime.graphics.Image; @@ -111,4 +111,7 @@ abstract CairoSurface(Dynamic) { #end -} \ No newline at end of file +} + + +#end \ No newline at end of file From 099e166bff7f8e84cbdb61a28657277cd63c099e Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Mon, 4 May 2015 21:04:16 -0700 Subject: [PATCH 08/30] Flush before unlock --- lime/_backend/native/NativeRenderer.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lime/_backend/native/NativeRenderer.hx b/lime/_backend/native/NativeRenderer.hx index 19b3f9e31..615976bc7 100644 --- a/lime/_backend/native/NativeRenderer.hx +++ b/lime/_backend/native/NativeRenderer.hx @@ -69,7 +69,6 @@ class NativeRenderer { if (!useHardware) { - lime_renderer_unlock (handle); #if lime_cairo if (cairo != null) { @@ -77,6 +76,7 @@ class NativeRenderer { } #end + lime_renderer_unlock (handle); } From 46094c1dc4257d71805adbc92894e9b20c828050 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Mon, 4 May 2015 21:17:49 -0700 Subject: [PATCH 09/30] Minor fix --- lime/graphics/utils/ImageDataUtil.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lime/graphics/utils/ImageDataUtil.hx b/lime/graphics/utils/ImageDataUtil.hx index f140c1338..522aeb5bd 100644 --- a/lime/graphics/utils/ImageDataUtil.hx +++ b/lime/graphics/utils/ImageDataUtil.hx @@ -1029,7 +1029,7 @@ class ImageDataUtil { var data = image.buffer.data; var offset = (4 * (y + image.offsetY) * image.buffer.width + (x + image.offsetX) * 4); - if (format == null || format == RGBA) color = color >> 8; + if (format == RGBA) color = color >> 8; data[offset] = (color & 0xFF0000) >>> 16; data[offset + 1] = (color & 0x00FF00) >>> 8; From 8bab88bcd7e45ccff78d9ac26f73d0f7a2602a30 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Tue, 5 May 2015 18:24:17 -0700 Subject: [PATCH 10/30] Guard against null bytes, use combine for svg.n path --- lime/tools/helpers/IconHelper.hx | 13 ++++++++++--- lime/tools/helpers/ImageHelper.hx | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lime/tools/helpers/IconHelper.hx b/lime/tools/helpers/IconHelper.hx index 6f8e7983d..8e28383c7 100644 --- a/lime/tools/helpers/IconHelper.hx +++ b/lime/tools/helpers/IconHelper.hx @@ -199,17 +199,24 @@ class IconHelper { if (image != null) { + var data = null; + if (size < 256) { - imageData.push (BMP.encode (image, ICO)); + data = BMP.encode (image, ICO); } else { - imageData.push (image.encode ("png")); + data = image.encode ("png"); } - images.push (image); + if (data != null) { + + imageData.push (data); + images.push (image); + + } } diff --git a/lime/tools/helpers/ImageHelper.hx b/lime/tools/helpers/ImageHelper.hx index 1916d8239..3bf5a6424 100644 --- a/lime/tools/helpers/ImageHelper.hx +++ b/lime/tools/helpers/ImageHelper.hx @@ -23,7 +23,7 @@ class ImageHelper { // try using Lime "legacy" to rasterize SVG first, since it is much faster - ProcessHelper.runCommand ("", "neko", [ PathHelper.getHaxelib (new Haxelib ("lime")) + "/svg.n", "process", path, Std.string (width), Std.string (height), temp ], true, true); + ProcessHelper.runCommand ("", "neko", [ PathHelper.combine (PathHelper.getHaxelib (new Haxelib ("lime")), "svg.n"), "process", path, Std.string (width), Std.string (height), temp ], true, true); if (FileSystem.exists (temp)) { From 1043c4e8a588c532a7615d56a017d5600e464bea Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Tue, 5 May 2015 18:28:38 -0700 Subject: [PATCH 11/30] Minor tweak --- lime/tools/platforms/WindowsPlatform.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lime/tools/platforms/WindowsPlatform.hx b/lime/tools/platforms/WindowsPlatform.hx index 74756e1c3..00123a7b0 100644 --- a/lime/tools/platforms/WindowsPlatform.hx +++ b/lime/tools/platforms/WindowsPlatform.hx @@ -50,7 +50,7 @@ class WindowsPlatform extends PlatformTarget { targetDirectory = project.app.path + "/windows/" + targetType; applicationDirectory = targetDirectory + "/bin/"; - executablePath = applicationDirectory + "/" + project.app.file + ".exe"; + executablePath = applicationDirectory + project.app.file + ".exe"; } From aeeaf7023d6a5d7901241fa773c6142cf88dec7e Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Tue, 5 May 2015 22:30:18 -0700 Subject: [PATCH 12/30] A few more bindings --- lime/graphics/cairo/Cairo.hx | 40 ++++++++++++++++++++ project/src/graphics/cairo/CairoBindings.cpp | 36 ++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/lime/graphics/cairo/Cairo.hx b/lime/graphics/cairo/Cairo.hx index 1826c6ab1..21a9f125f 100644 --- a/lime/graphics/cairo/Cairo.hx +++ b/lime/graphics/cairo/Cairo.hx @@ -107,6 +107,15 @@ class Cairo { } + public function curveTo (x1:Float, y1:Float, x2:Float, y2:Float, x3:Float, y3:Float):Void { + + #if lime_cairo + lime_cairo_curve_to (handle, x1, y1, x2, y2, x3, y3); + #end + + } + + public function destroy ():Void { #if lime_cairo @@ -304,6 +313,33 @@ class Cairo { } + public function relCurveTo (dx1:Float, dy1:Float, dx2:Float, dy2:Float, dx3:Float, dy3:Float):Void { + + #if lime_cairo + lime_cairo_rel_curve_to (handle, dx1, dy1, dx2, dy2, dx3, dy3); + #end + + } + + + public function relLineTo (dx:Float, dy:Float):Void { + + #if lime_cairo + lime_cairo_rel_line_to (handle, dx, dy); + #end + + } + + + public function relMoveTo (dx:Float, dy:Float):Void { + + #if lime_cairo + lime_cairo_rel_move_to (handle, dx, dy); + #end + + } + + public function resetClip ():Void { #if lime_cairo @@ -755,6 +791,7 @@ class Cairo { private static var lime_cairo_close_path = System.load ("lime", "lime_cairo_close_path", 1); private static var lime_cairo_copy_page = System.load ("lime", "lime_cairo_copy_page", 1); private static var lime_cairo_create = System.load ("lime", "lime_cairo_create", 1); + private static var lime_cairo_curve_to = System.load ("lime", "lime_cairo_curve_to", -1); private static var lime_cairo_destroy = System.load ("lime", "lime_cairo_destroy", 1); private static var lime_cairo_fill = System.load ("lime", "lime_cairo_fill", 1); private static var lime_cairo_fill_extents = System.load ("lime", "lime_cairo_fill_extents", 5); @@ -791,6 +828,9 @@ class Cairo { private static var lime_cairo_push_group_with_content = System.load ("lime", "lime_cairo_push_group_with_content", 2); private static var lime_cairo_rectangle = System.load ("lime", "lime_cairo_rectangle", 5); private static var lime_cairo_reference = System.load ("lime", "lime_cairo_reference", 1); + private static var lime_cairo_rel_curve_to = System.load ("lime", "lime_cairo_rel_curve_to", -1); + private static var lime_cairo_rel_line_to = System.load ("lime", "lime_cairo_rel_line_to", 3); + private static var lime_cairo_rel_move_to = System.load ("lime", "lime_cairo_rel_move_to", 3); private static var lime_cairo_reset_clip = System.load ("lime", "lime_cairo_reset_clip", 1); private static var lime_cairo_restore = System.load ("lime", "lime_cairo_restore", 1); private static var lime_cairo_save = System.load ("lime", "lime_cairo_save", 1); diff --git a/project/src/graphics/cairo/CairoBindings.cpp b/project/src/graphics/cairo/CairoBindings.cpp index c3719745e..02c28d4ae 100644 --- a/project/src/graphics/cairo/CairoBindings.cpp +++ b/project/src/graphics/cairo/CairoBindings.cpp @@ -74,6 +74,14 @@ namespace lime { } + value lime_cairo_curve_to (value *arg, int argCount) { + + cairo_curve_to ((cairo_t*)(intptr_t)val_float (arg[0]), val_number (arg[1]), val_number (arg[2]), val_number (arg[3]), val_number (arg[4]), val_number (arg[5]), val_number (arg[6])); + return alloc_null (); + + } + + value lime_cairo_destroy (value handle) { cairo_destroy ((cairo_t*)(intptr_t)val_float (handle)); @@ -463,6 +471,30 @@ namespace lime { } + value lime_cairo_rel_curve_to (value *arg, int argCount) { + + cairo_rel_curve_to ((cairo_t*)(intptr_t)val_float (arg[0]), val_number (arg[1]), val_number (arg[2]), val_number (arg[3]), val_number (arg[4]), val_number (arg[5]), val_number (arg[6])); + return alloc_null (); + + } + + + value lime_cairo_rel_line_to (value handle, value dx, value dy) { + + cairo_rel_line_to ((cairo_t*)(intptr_t)val_float (handle), val_number (dx), val_number (dy)); + return alloc_null (); + + } + + + value lime_cairo_rel_move_to (value handle, value dx, value dy) { + + cairo_rel_move_to ((cairo_t*)(intptr_t)val_float (handle), val_number (dx), val_number (dy)); + return alloc_null (); + + } + + value lime_cairo_reset_clip (value handle) { cairo_reset_clip ((cairo_t*)(intptr_t)val_float (handle)); @@ -718,6 +750,7 @@ namespace lime { DEFINE_PRIM (lime_cairo_close_path, 1); DEFINE_PRIM (lime_cairo_copy_page, 1); DEFINE_PRIM (lime_cairo_create, 1); + DEFINE_PRIM_MULT (lime_cairo_curve_to); DEFINE_PRIM (lime_cairo_destroy, 1); DEFINE_PRIM (lime_cairo_fill, 1); DEFINE_PRIM (lime_cairo_fill_extents, 5); @@ -766,6 +799,9 @@ namespace lime { DEFINE_PRIM (lime_cairo_push_group_with_content, 2); DEFINE_PRIM (lime_cairo_rectangle, 5); DEFINE_PRIM (lime_cairo_reference, 1); + DEFINE_PRIM_MULT (lime_cairo_rel_curve_to); + DEFINE_PRIM (lime_cairo_rel_line_to, 3); + DEFINE_PRIM (lime_cairo_rel_move_to, 3); DEFINE_PRIM (lime_cairo_reset_clip, 1); DEFINE_PRIM (lime_cairo_restore, 1); DEFINE_PRIM (lime_cairo_save, 1); From a5238035957a7030f44243a3de0afce0a5783e6f Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Tue, 5 May 2015 23:03:15 -0700 Subject: [PATCH 13/30] Add a few more bindings --- lime/graphics/cairo/CairoPattern.hx | 24 ++++++++++++++++++++ project/src/graphics/cairo/CairoBindings.cpp | 16 +++++++++++++ 2 files changed, 40 insertions(+) diff --git a/lime/graphics/cairo/CairoPattern.hx b/lime/graphics/cairo/CairoPattern.hx index 9c108da64..05d5c2eb2 100644 --- a/lime/graphics/cairo/CairoPattern.hx +++ b/lime/graphics/cairo/CairoPattern.hx @@ -31,6 +31,28 @@ abstract CairoPattern(Dynamic) { } + public static function createRGB (r:Float, g:Float, b:Float):CairoPattern { + + #if lime_cairo + return lime_cairo_pattern_create_rgb (r, g, b); + #else + return cast 0; + #end + + } + + + public static function createRGBA (r:Float, g:Float, b:Float, a:Float):CairoPattern { + + #if lime_cairo + return lime_cairo_pattern_create_rgba (r, g, b, a); + #else + return cast 0; + #end + + } + + public function destroy ():Void { #if lime_cairo @@ -123,6 +145,8 @@ abstract CairoPattern(Dynamic) { #if lime_cairo private static var lime_cairo_pattern_create_for_surface = System.load ("lime", "lime_cairo_pattern_create_for_surface", 1); + private static var lime_cairo_pattern_create_rgb = System.load ("lime", "lime_cairo_pattern_create_rgb", 3); + private static var lime_cairo_pattern_create_rgba = System.load ("lime", "lime_cairo_pattern_create_rgba", 4); private static var lime_cairo_pattern_destroy = System.load ("lime", "lime_cairo_pattern_destroy", 1); private static var lime_cairo_pattern_get_extend = System.load ("lime", "lime_cairo_pattern_get_extend", 1); private static var lime_cairo_pattern_get_filter = System.load ("lime", "lime_cairo_pattern_get_filter", 1); diff --git a/project/src/graphics/cairo/CairoBindings.cpp b/project/src/graphics/cairo/CairoBindings.cpp index 02c28d4ae..551fa392b 100644 --- a/project/src/graphics/cairo/CairoBindings.cpp +++ b/project/src/graphics/cairo/CairoBindings.cpp @@ -363,6 +363,20 @@ namespace lime { } + value lime_cairo_pattern_create_rgb (value r, value g, value b) { + + return alloc_float ((intptr_t)cairo_pattern_create_rgb (val_number (r), val_number (g), val_number (b))); + + } + + + value lime_cairo_pattern_create_rgba (value r, value g, value b, value a) { + + return alloc_float ((intptr_t)cairo_pattern_create_rgba (val_number (r), val_number (g), val_number (b), val_number (a))); + + } + + value lime_cairo_pattern_destroy (value handle) { cairo_pattern_destroy ((cairo_pattern_t*)(intptr_t)val_float (handle)); @@ -786,6 +800,8 @@ namespace lime { DEFINE_PRIM (lime_cairo_paint, 1); DEFINE_PRIM (lime_cairo_paint_with_alpha, 2); DEFINE_PRIM (lime_cairo_pattern_create_for_surface, 1); + DEFINE_PRIM (lime_cairo_pattern_create_rgb, 3); + DEFINE_PRIM (lime_cairo_pattern_create_rgba, 4); DEFINE_PRIM (lime_cairo_pattern_destroy, 1); DEFINE_PRIM (lime_cairo_pattern_get_extend, 1); DEFINE_PRIM (lime_cairo_pattern_get_filter, 1); From 2ec0f7c4b28a7d10793e042d7cdf2f07c41381e5 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Wed, 6 May 2015 00:22:45 -0700 Subject: [PATCH 14/30] 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 From e976f64ce48ff13b53797528140f842f2d5e13df Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Wed, 6 May 2015 01:01:37 -0700 Subject: [PATCH 15/30] Add Cairo bindings for gradient patterns --- lime/graphics/cairo/CairoPattern.hx | 57 ++++++++++++++++++++ project/src/graphics/cairo/CairoBindings.cpp | 44 +++++++++++++++ 2 files changed, 101 insertions(+) diff --git a/lime/graphics/cairo/CairoPattern.hx b/lime/graphics/cairo/CairoPattern.hx index 05d5c2eb2..83a9e14e0 100644 --- a/lime/graphics/cairo/CairoPattern.hx +++ b/lime/graphics/cairo/CairoPattern.hx @@ -8,6 +8,7 @@ import lime.system.System; abstract CairoPattern(Dynamic) { + public var colorStopCount (get, never):Int; public var extend (get, set):CairoExtend; public var filter (get, set):CairoFilter; public var matrix (get, set):Matrix3; @@ -20,6 +21,24 @@ abstract CairoPattern(Dynamic) { } + public function addColorStopRGB (offset:Float, r:Float, g:Float, b:Float):Void { + + #if lime_cairo + lime_cairo_pattern_add_color_stop_rgb (this, offset, r, g, b); + #end + + } + + + public function addColorStopRGBA (offset:Float, r:Float, g:Float, b:Float, a:Float):Void { + + #if lime_cairo + lime_cairo_pattern_add_color_stop_rgba (this, offset, r, g, b, a); + #end + + } + + public static function createForSurface (surface:CairoSurface):CairoPattern { #if lime_cairo @@ -31,6 +50,28 @@ abstract CairoPattern(Dynamic) { } + public static function createLinear (x0:Float, y0:Float, x1:Float, y1:Float):CairoPattern { + + #if lime_cairo + return lime_cairo_pattern_create_linear (x0, y0, x1, y1); + #else + return cast 0; + #end + + } + + + public static function createRadial (cx0:Float, cy0:Float, radius0:Float, cx1:Float, cy1:Float, radius1:Float):CairoPattern { + + #if lime_cairo + return lime_cairo_pattern_create_radial (cx0, cy0, radius0, cx1, cy1, radius1); + #else + return cast 0; + #end + + } + + public static function createRGB (r:Float, g:Float, b:Float):CairoPattern { #if lime_cairo @@ -69,6 +110,17 @@ abstract CairoPattern(Dynamic) { + public function get_colorStopCount ():Int { + + #if lime_cairo + return lime_cairo_pattern_get_color_stop_count (this); + #else + return 0; + #end + + } + + public function get_extend ():CairoExtend { #if lime_cairo @@ -144,10 +196,15 @@ abstract CairoPattern(Dynamic) { #if lime_cairo + private static var lime_cairo_pattern_add_color_stop_rgb = System.load ("lime", "lime_cairo_pattern_add_color_stop_rgb", 5); + private static var lime_cairo_pattern_add_color_stop_rgba = System.load ("lime", "lime_cairo_pattern_add_color_stop_rgba", -1); private static var lime_cairo_pattern_create_for_surface = System.load ("lime", "lime_cairo_pattern_create_for_surface", 1); + private static var lime_cairo_pattern_create_linear = System.load ("lime", "lime_cairo_pattern_create_linear", 4); + private static var lime_cairo_pattern_create_radial = System.load ("lime", "lime_cairo_pattern_create_radial", -1); private static var lime_cairo_pattern_create_rgb = System.load ("lime", "lime_cairo_pattern_create_rgb", 3); private static var lime_cairo_pattern_create_rgba = System.load ("lime", "lime_cairo_pattern_create_rgba", 4); private static var lime_cairo_pattern_destroy = System.load ("lime", "lime_cairo_pattern_destroy", 1); + private static var lime_cairo_pattern_get_color_stop_count = System.load ("lime", "lime_cairo_pattern_get_color_stop_count", 1); private static var lime_cairo_pattern_get_extend = System.load ("lime", "lime_cairo_pattern_get_extend", 1); private static var lime_cairo_pattern_get_filter = System.load ("lime", "lime_cairo_pattern_get_filter", 1); private static var lime_cairo_pattern_get_matrix = System.load ("lime", "lime_cairo_pattern_get_matrix", 1); diff --git a/project/src/graphics/cairo/CairoBindings.cpp b/project/src/graphics/cairo/CairoBindings.cpp index 6b1645e96..8a9791e3a 100644 --- a/project/src/graphics/cairo/CairoBindings.cpp +++ b/project/src/graphics/cairo/CairoBindings.cpp @@ -374,6 +374,22 @@ namespace lime { } + value lime_cairo_pattern_add_color_stop_rgb (value handle, value offset, value red, value green, value blue) { + + cairo_pattern_add_color_stop_rgb ((cairo_pattern_t*)(intptr_t)val_float (handle), val_number (offset), val_number (red), val_number (green), val_number (blue)); + return alloc_null (); + + } + + + value lime_cairo_pattern_add_color_stop_rgba (value *arg, int argCount) { + + cairo_pattern_add_color_stop_rgba ((cairo_pattern_t*)(intptr_t)val_float (arg[0]), val_number (arg[1]), val_number (arg[2]), val_number (arg[3]), val_number (arg[4]), val_number (arg[5])); + return alloc_null (); + + } + + value lime_cairo_pattern_create_for_surface (value surface) { return alloc_float ((intptr_t)cairo_pattern_create_for_surface ((cairo_surface_t*)(intptr_t)val_float (surface))); @@ -381,6 +397,20 @@ namespace lime { } + value lime_cairo_pattern_create_linear (value x0, value y0, value x1, value y1) { + + return alloc_float ((intptr_t)cairo_pattern_create_linear (val_number (x0), val_number (y0), val_number (x1), val_number (y1))); + + } + + + value lime_cairo_pattern_create_radial (value *arg, int argCount) { + + return alloc_float ((intptr_t)cairo_pattern_create_radial (val_number (arg[0]), val_number (arg[1]), val_number (arg[2]), val_number (arg[3]), val_number (arg[4]), val_number (arg[5]))); + + } + + value lime_cairo_pattern_create_rgb (value r, value g, value b) { return alloc_float ((intptr_t)cairo_pattern_create_rgb (val_number (r), val_number (g), val_number (b))); @@ -403,6 +433,15 @@ namespace lime { } + value lime_cairo_pattern_get_color_stop_count (value handle) { + + int count; + cairo_pattern_get_color_stop_count ((cairo_pattern_t*)(intptr_t)val_float (handle), &count); + return alloc_int (count); + + } + + value lime_cairo_pattern_get_extend (value handle) { return alloc_int (cairo_pattern_get_extend ((cairo_pattern_t*)(intptr_t)val_float (handle))); @@ -819,10 +858,15 @@ namespace lime { DEFINE_PRIM (lime_cairo_new_path, 1); DEFINE_PRIM (lime_cairo_paint, 1); DEFINE_PRIM (lime_cairo_paint_with_alpha, 2); + DEFINE_PRIM (lime_cairo_pattern_add_color_stop_rgb, 5); + DEFINE_PRIM_MULT (lime_cairo_pattern_add_color_stop_rgba); DEFINE_PRIM (lime_cairo_pattern_create_for_surface, 1); + DEFINE_PRIM (lime_cairo_pattern_create_linear, 4); + DEFINE_PRIM_MULT (lime_cairo_pattern_create_radial); DEFINE_PRIM (lime_cairo_pattern_create_rgb, 3); DEFINE_PRIM (lime_cairo_pattern_create_rgba, 4); DEFINE_PRIM (lime_cairo_pattern_destroy, 1); + DEFINE_PRIM (lime_cairo_pattern_get_color_stop_count, 1); DEFINE_PRIM (lime_cairo_pattern_get_extend, 1); DEFINE_PRIM (lime_cairo_pattern_get_filter, 1); DEFINE_PRIM (lime_cairo_pattern_get_matrix, 1); From 20d0c19e3a30eeb80b014ab5ee4f32d9dd277c70 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Wed, 6 May 2015 17:32:27 -0700 Subject: [PATCH 16/30] Fix Cairo build for Linux --- project/Build.xml | 4 ++++ project/lib/cairo | 2 +- project/lib/pixman | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/project/Build.xml b/project/Build.xml index 3ca33d05d..2c8a6915b 100644 --- a/project/Build.xml +++ b/project/Build.xml @@ -43,6 +43,10 @@ + + + + diff --git a/project/lib/cairo b/project/lib/cairo index 83548b922..47662d0e4 160000 --- a/project/lib/cairo +++ b/project/lib/cairo @@ -1 +1 @@ -Subproject commit 83548b92275068f3e9cdb9d9893457714a019e67 +Subproject commit 47662d0e4dc7bdefe34953f547f33cfd89c652b0 diff --git a/project/lib/pixman b/project/lib/pixman index 65dced727..95011bab2 160000 --- a/project/lib/pixman +++ b/project/lib/pixman @@ -1 +1 @@ -Subproject commit 65dced727afeba560ab23cf2b313036569f5649d +Subproject commit 95011bab230cdb08839f5696df7031792f371bc2 From 78859413b35be9e0cb3b9dad8f59aff8fc828742 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Wed, 6 May 2015 19:45:16 -0700 Subject: [PATCH 17/30] Improve handling of Cairo build configuration --- project/Build.xml | 9 +++++---- project/lib/cairo | 2 +- project/lib/pixman | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/project/Build.xml b/project/Build.xml index 2c8a6915b..95704e535 100644 --- a/project/Build.xml +++ b/project/Build.xml @@ -42,11 +42,12 @@
+ + + + + - - - - diff --git a/project/lib/cairo b/project/lib/cairo index 47662d0e4..009a03ba0 160000 --- a/project/lib/cairo +++ b/project/lib/cairo @@ -1 +1 @@ -Subproject commit 47662d0e4dc7bdefe34953f547f33cfd89c652b0 +Subproject commit 009a03ba08ba98b3e4d20664efd377f0021eed13 diff --git a/project/lib/pixman b/project/lib/pixman index 95011bab2..12501eb7b 160000 --- a/project/lib/pixman +++ b/project/lib/pixman @@ -1 +1 @@ -Subproject commit 95011bab230cdb08839f5696df7031792f371bc2 +Subproject commit 12501eb7bb72fbcf1841914c81bf88331d6dbf5f From 4fef58d74cb8b6d37facc8ad54366e36668cb4d0 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Wed, 6 May 2015 19:56:11 -0700 Subject: [PATCH 18/30] Fix OS X build for Cairo --- project/lib/cairo | 2 +- project/lib/harfbuzz | 2 +- project/lib/pixman | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/project/lib/cairo b/project/lib/cairo index 009a03ba0..e889c8218 160000 --- a/project/lib/cairo +++ b/project/lib/cairo @@ -1 +1 @@ -Subproject commit 009a03ba08ba98b3e4d20664efd377f0021eed13 +Subproject commit e889c82181cd7bae0332a86862ec422d827e82b6 diff --git a/project/lib/harfbuzz b/project/lib/harfbuzz index e98c90105..395599e25 160000 --- a/project/lib/harfbuzz +++ b/project/lib/harfbuzz @@ -1 +1 @@ -Subproject commit e98c90105dff6ca62beaecd877042f2052a61b1b +Subproject commit 395599e2536e043251e3eedf37ce4ae3b9f445b9 diff --git a/project/lib/pixman b/project/lib/pixman index 12501eb7b..d0404ae11 160000 --- a/project/lib/pixman +++ b/project/lib/pixman @@ -1 +1 @@ -Subproject commit 12501eb7bb72fbcf1841914c81bf88331d6dbf5f +Subproject commit d0404ae1135602ae60f3ff7e11b0543d395a71c9 From f58c53f8f15e9fa9989072ea8e9a6d1a2d234d18 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Wed, 6 May 2015 20:06:13 -0700 Subject: [PATCH 19/30] Include Cairo by default --- include.xml | 2 +- project/Build.xml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include.xml b/include.xml index e81a21dd5..f1dc110e7 100644 --- a/include.xml +++ b/include.xml @@ -51,7 +51,7 @@ - + diff --git a/project/Build.xml b/project/Build.xml index 95704e535..9991f66b9 100644 --- a/project/Build.xml +++ b/project/Build.xml @@ -9,7 +9,7 @@ - + @@ -18,7 +18,7 @@ - + From 5fcd702027e3b61f1256bd31d35e45dcca9e73ce Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Wed, 6 May 2015 20:18:30 -0700 Subject: [PATCH 20/30] Minor update --- project/lib/cairo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/lib/cairo b/project/lib/cairo index e889c8218..888742ef6 160000 --- a/project/lib/cairo +++ b/project/lib/cairo @@ -1 +1 @@ -Subproject commit e889c82181cd7bae0332a86862ec422d827e82b6 +Subproject commit 888742ef63cd54df6d1d167ef136a50da8770282 From 979d5fd1e4ae67c40da28be2cfba0e9cf9e15798 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Wed, 6 May 2015 20:33:00 -0700 Subject: [PATCH 21/30] Minor update --- project/lib/cairo | 2 +- project/lib/pixman | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/project/lib/cairo b/project/lib/cairo index 888742ef6..eb462ba87 160000 --- a/project/lib/cairo +++ b/project/lib/cairo @@ -1 +1 @@ -Subproject commit 888742ef63cd54df6d1d167ef136a50da8770282 +Subproject commit eb462ba875ed3572cf6e83769bc240614f3e183c diff --git a/project/lib/pixman b/project/lib/pixman index d0404ae11..d42fc0b90 160000 --- a/project/lib/pixman +++ b/project/lib/pixman @@ -1 +1 @@ -Subproject commit d0404ae1135602ae60f3ff7e11b0543d395a71c9 +Subproject commit d42fc0b903c7736b057a6daca7a22dc83db69aab From a28e2673196e6edf2f12688597e0737fc6da9f04 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Thu, 7 May 2015 08:59:25 -0700 Subject: [PATCH 22/30] Update for JS error message --- js/Boot.hx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/js/Boot.hx b/js/Boot.hx index 381fecd49..1db6fcb54 100644 --- a/js/Boot.hx +++ b/js/Boot.hx @@ -24,11 +24,12 @@ package js; private class HaxeError extends js.Error { var val:Dynamic; - - public function new(val:Dynamic) { + + public function new(val:Dynamic) untyped { super(); - this.val = untyped __define_feature__("js.Boot.HaxeError", val); - untyped if (js.Error.captureStackTrace) js.Error.captureStackTrace(this, HaxeError); + this.val = __define_feature__("js.Boot.HaxeError", val); + this.message = String(val); + if (js.Error.captureStackTrace) js.Error.captureStackTrace(this, HaxeError); } } From 4deb21be8c26c9a4378c5b12f47f70faadcd723b Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Thu, 7 May 2015 13:16:36 -0700 Subject: [PATCH 23/30] Fix static build (thanks JeriX) --- include.xml | 2 +- project/Build.xml | 2 +- project/src/ExternalInterface.cpp | 2 +- templates/cpp/static/BuildMain.xml | 2 +- templates/cpp/static/Main.cpp | 6 ++++++ 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/include.xml b/include.xml index f1dc110e7..0f18dcbae 100644 --- a/include.xml +++ b/include.xml @@ -41,7 +41,7 @@ - + diff --git a/project/Build.xml b/project/Build.xml index 9991f66b9..805a92a13 100644 --- a/project/Build.xml +++ b/project/Build.xml @@ -176,7 +176,7 @@ - +
diff --git a/project/src/ExternalInterface.cpp b/project/src/ExternalInterface.cpp index 913dd9f87..99f7e719a 100644 --- a/project/src/ExternalInterface.cpp +++ b/project/src/ExternalInterface.cpp @@ -488,7 +488,7 @@ namespace lime { value lime_image_data_util_fill_rect (value image, value rect, value color) { Image _image = Image (image); - Rectangle _rect = Rectangle (rect); + Rectangle _rect = Rectangle (rect); ImageDataUtil::FillRect (&_image, &_rect, val_number (color)); return alloc_null (); diff --git a/templates/cpp/static/BuildMain.xml b/templates/cpp/static/BuildMain.xml index 6771bd076..cbb4c534a 100644 --- a/templates/cpp/static/BuildMain.xml +++ b/templates/cpp/static/BuildMain.xml @@ -78,7 +78,7 @@ - + diff --git a/templates/cpp/static/Main.cpp b/templates/cpp/static/Main.cpp index 5a92451a7..dc71655b3 100644 --- a/templates/cpp/static/Main.cpp +++ b/templates/cpp/static/Main.cpp @@ -7,6 +7,9 @@ extern "C" const char *hxRunLibrary (); extern "C" void hxcpp_set_top_of_stack (); +extern "C" int zlib_register_prims (); +extern "C" int lime_cairo_register_prims (); +extern "C" int lime_openal_register_prims (); ::foreach ndlls::::if (registerStatics):: extern "C" int ::nameSafe::_register_prims ();::end::::end:: @@ -19,6 +22,9 @@ extern "C" int main(int argc, char *argv[]) { hxcpp_set_top_of_stack (); + zlib_register_prims (); + lime_cairo_register_prims (); + lime_openal_register_prims (); ::foreach ndlls::::if (registerStatics):: ::nameSafe::_register_prims ();::end::::end:: From bc0a475c8b648e249ec614ab78d7220b17b8b97f Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Thu, 7 May 2015 13:21:30 -0700 Subject: [PATCH 24/30] Update licenses --- LICENSE.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/LICENSE.md b/LICENSE.md index d5a4c0d15..9c494ec6f 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -25,6 +25,9 @@ THE SOFTWARE. ------- +This product bundles cairo 1.14.2, which is available under an +"MPL 1.1" license. For details, see [project/lib/cairo/](project/lib). + This product bundles libcurl 7.37.1, which is available under an "MIT/X derivate" license. For details, see [project/lib/curl/](project/lib). @@ -47,6 +50,9 @@ an OpenAL-Soft derivative for Android under [project/lib/openal-android/](projec _OpenAL-Soft is only included in dynamically-linked builds, it is excluded from Lime static builds in order to preserve Lime's permissive nature._ +This product bundles pixman 0.32.6, which is available under an +"MIT" license. For details, see [project/lib/pixman/](project/lib). + This product bundles libpng 1.6.12, which is available under a "zlib" (BSD-style) license. For details, see [project/lib/png/](project/lib). From f1c88a86e5edbb23ce26ae9ad308d5ce8a560717 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Thu, 7 May 2015 14:13:56 -0700 Subject: [PATCH 25/30] Fix possible OpenAL crash on Neko --- project/src/audio/openal/OpenALBindings.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/project/src/audio/openal/OpenALBindings.cpp b/project/src/audio/openal/OpenALBindings.cpp index 088670efb..0a1efc851 100644 --- a/project/src/audio/openal/OpenALBindings.cpp +++ b/project/src/audio/openal/OpenALBindings.cpp @@ -29,7 +29,7 @@ namespace lime { value lime_al_buffer3f (value buffer, value param, value value1, value value2, value value3) { - alBuffer3f (val_int (buffer), val_int (param), val_float (value1), val_float (value2), val_float (value3)); + alBuffer3f (val_int (buffer), val_int (param), val_number (value1), val_number (value2), val_number (value3)); return alloc_null (); } @@ -45,7 +45,7 @@ namespace lime { value lime_al_bufferf (value buffer, value param, value value) { - alBufferf (val_int (buffer), val_int (param), val_float (value)); + alBufferf (val_int (buffer), val_int (param), val_number (value)); return alloc_null (); } @@ -169,7 +169,7 @@ namespace lime { value lime_al_distance_model (value distanceModel) { - alDistanceModel (val_float (distanceModel)); + alDistanceModel (val_number (distanceModel)); return alloc_null (); } @@ -177,7 +177,7 @@ namespace lime { value lime_al_doppler_factor (value factor) { - alDopplerFactor (val_float (factor)); + alDopplerFactor (val_number (factor)); return alloc_null (); } @@ -185,7 +185,7 @@ namespace lime { value lime_al_doppler_velocity (value velocity) { - alDopplerVelocity (val_float (velocity)); + alDopplerVelocity (val_number (velocity)); return alloc_null (); } @@ -688,7 +688,7 @@ namespace lime { value lime_al_listener3f (value param, value value1, value value2, value value3) { - alListener3f (val_int (param), val_float (value1), val_float (value2), val_float (value3)); + alListener3f (val_int (param), val_number (value1), val_number (value2), val_number (value3)); return alloc_null (); } @@ -704,7 +704,7 @@ namespace lime { value lime_al_listenerf (value param, value value1) { - alListenerf (val_int (param), val_float (value1)); + alListenerf (val_int (param), val_number (value1)); return alloc_null (); } @@ -878,7 +878,7 @@ namespace lime { value lime_al_source3f (value source, value param, value value1, value value2, value value3) { - alSource3f (val_int (source), val_int (param), val_float (value1), val_float (value2), val_float (value3)); + alSource3f (val_int (source), val_int (param), val_number (value1), val_number (value2), val_number (value3)); return alloc_null (); } @@ -894,7 +894,7 @@ namespace lime { value lime_al_sourcef (value source, value param, value value) { - alSourcef (val_int (source), val_int (param), val_float (value)); + alSourcef (val_int (source), val_int (param), val_number (value)); return alloc_null (); } @@ -940,7 +940,7 @@ namespace lime { value lime_al_speed_of_sound (value speed) { - alSpeedOfSound (val_float (speed)); + alSpeedOfSound (val_number (speed)); return alloc_null (); } From b1a77a57b14f27c4d926974f9628699a23a30416 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Thu, 7 May 2015 15:16:36 -0700 Subject: [PATCH 26/30] Add AudioSource.dispose for now --- lime/audio/AudioSource.hx | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lime/audio/AudioSource.hx b/lime/audio/AudioSource.hx index b0c27fdb1..b85e707ee 100644 --- a/lime/audio/AudioSource.hx +++ b/lime/audio/AudioSource.hx @@ -59,6 +59,25 @@ class AudioSource { } + public function dispose ():Void { + + switch (AudioManager.context) { + + case OPENAL (alc, al): + + if (id != 0) { + + al.deleteSource (id); + + } + + default: + + } + + } + + private function init ():Void { switch (AudioManager.context) { From 2d3f51d2a4413069b221269da3e084c9b905caa6 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Tue, 12 May 2015 07:11:21 -0700 Subject: [PATCH 27/30] Initial support for text input/edit events --- lime/_backend/flash/FlashApplication.hx | 6 +++ lime/_backend/flash/FlashWindow.hx | 15 ++++++ lime/_backend/html5/HTML5Application.hx | 6 +++ lime/_backend/html5/HTML5Window.hx | 15 ++++++ lime/_backend/native/NativeApplication.hx | 60 ++++++++++++++++++++++ lime/_backend/native/NativeWindow.hx | 28 ++++++++++ lime/app/Application.hx | 24 +++++++++ lime/app/IModule.hx | 16 ++++++ lime/app/Module.hx | 16 ++++++ lime/ui/Window.hx | 17 ++++++ project/Build.xml | 1 + project/include/ui/TextEvent.h | 41 +++++++++++++++ project/include/ui/Window.h | 2 + project/src/ExternalInterface.cpp | 30 +++++++++++ project/src/backend/sdl/SDLApplication.cpp | 36 +++++++++++++ project/src/backend/sdl/SDLApplication.h | 3 ++ project/src/backend/sdl/SDLWindow.cpp | 22 ++++++++ project/src/backend/sdl/SDLWindow.h | 2 + project/src/ui/TextEvent.cpp | 59 +++++++++++++++++++++ 19 files changed, 399 insertions(+) create mode 100644 project/include/ui/TextEvent.h create mode 100644 project/src/ui/TextEvent.cpp diff --git a/lime/_backend/flash/FlashApplication.hx b/lime/_backend/flash/FlashApplication.hx index 7488b6795..23c46bb1b 100644 --- a/lime/_backend/flash/FlashApplication.hx +++ b/lime/_backend/flash/FlashApplication.hx @@ -163,6 +163,12 @@ class FlashApplication { parent.window.onKeyDown.dispatch (keyCode, modifier); + if (parent.window.enableTextEvents) { + + parent.window.onTextInput.dispatch (String.fromCharCode (event.charCode)); + + } + } else { parent.window.onKeyUp.dispatch (keyCode, modifier); diff --git a/lime/_backend/flash/FlashWindow.hx b/lime/_backend/flash/FlashWindow.hx index c35ff4f06..4e5a28146 100644 --- a/lime/_backend/flash/FlashWindow.hx +++ b/lime/_backend/flash/FlashWindow.hx @@ -12,6 +12,7 @@ import lime.ui.Window; class FlashWindow { + private var enableTextEvents:Bool; private var parent:Window; @@ -37,6 +38,13 @@ class FlashWindow { } + public function getEnableTextEvents ():Bool { + + return enableTextEvents; + + } + + public function move (x:Int, y:Int):Void { @@ -51,6 +59,13 @@ class FlashWindow { } + public function setEnableTextEvents (value:Bool):Bool { + + return enableTextEvents = value; + + } + + public function setFullscreen (value:Bool):Bool { return value; diff --git a/lime/_backend/html5/HTML5Application.hx b/lime/_backend/html5/HTML5Application.hx index 0af060c6e..7eda98583 100644 --- a/lime/_backend/html5/HTML5Application.hx +++ b/lime/_backend/html5/HTML5Application.hx @@ -169,6 +169,12 @@ class HTML5Application { parent.window.onKeyDown.dispatch (keyCode, modifier); + if (parent.window.enableTextEvents) { + + parent.window.onTextInput.dispatch (String.fromCharCode (event.keyCode)); + + } + } else { parent.window.onKeyUp.dispatch (keyCode, modifier); diff --git a/lime/_backend/html5/HTML5Window.hx b/lime/_backend/html5/HTML5Window.hx index 6cae8c737..3ebde5693 100644 --- a/lime/_backend/html5/HTML5Window.hx +++ b/lime/_backend/html5/HTML5Window.hx @@ -26,6 +26,7 @@ class HTML5Window { public var stats:Dynamic; #end + private var enableTextEvents:Bool; private var parent:Window; private var setHeight:Int; private var setWidth:Int; @@ -166,6 +167,13 @@ class HTML5Window { } + public function getEnableTextEvents ():Bool { + + return enableTextEvents; + + } + + private function handleMouseEvent (event:MouseEvent):Void { var x = 0.0; @@ -380,6 +388,13 @@ class HTML5Window { } + public function setEnableTextEvents (value:Bool):Bool { + + return enableTextEvents = value; + + } + + public function setFullscreen (value:Bool):Bool { return false; diff --git a/lime/_backend/native/NativeApplication.hx b/lime/_backend/native/NativeApplication.hx index a8803d9a3..f51e5c656 100644 --- a/lime/_backend/native/NativeApplication.hx +++ b/lime/_backend/native/NativeApplication.hx @@ -27,6 +27,7 @@ class NativeApplication { private var keyEventInfo = new KeyEventInfo (); private var mouseEventInfo = new MouseEventInfo (); private var renderEventInfo = new RenderEventInfo (RENDER); + private var textEventInfo = new TextEventInfo (); private var touchEventInfo = new TouchEventInfo (); private var updateEventInfo = new UpdateEventInfo (); private var windowEventInfo = new WindowEventInfo (); @@ -70,6 +71,7 @@ class NativeApplication { lime_key_event_manager_register (handleKeyEvent, keyEventInfo); lime_mouse_event_manager_register (handleMouseEvent, mouseEventInfo); lime_render_event_manager_register (handleRenderEvent, renderEventInfo); + lime_text_event_manager_register (handleTextEvent, textEventInfo); lime_touch_event_manager_register (handleTouchEvent, touchEventInfo); lime_update_event_manager_register (handleUpdateEvent, updateEventInfo); lime_window_event_manager_register (handleWindowEvent, windowEventInfo); @@ -239,6 +241,25 @@ class NativeApplication { } + private function handleTextEvent ():Void { + + switch (textEventInfo.type) { + + case TEXT_INPUT: + + parent.window.onTextInput.dispatch (textEventInfo.text); + + case TEXT_EDIT: + + parent.window.onTextEdit.dispatch (textEventInfo.text, textEventInfo.start, textEventInfo.length); + + default: + + } + + } + + private function handleTouchEvent ():Void { if (parent.window != null) { @@ -394,6 +415,7 @@ class NativeApplication { private static var lime_key_event_manager_register = System.load ("lime", "lime_key_event_manager_register", 2); private static var lime_mouse_event_manager_register = System.load ("lime", "lime_mouse_event_manager_register", 2); private static var lime_render_event_manager_register = System.load ("lime", "lime_render_event_manager_register", 2); + private static var lime_text_event_manager_register = System.load ("lime", "lime_text_event_manager_register", 2); private static var lime_touch_event_manager_register = System.load ("lime", "lime_touch_event_manager_register", 2); private static var lime_update_event_manager_register = System.load ("lime", "lime_update_event_manager_register", 2); private static var lime_window_event_manager_register = System.load ("lime", "lime_window_event_manager_register", 2); @@ -557,6 +579,44 @@ private class RenderEventInfo { } +private class TextEventInfo { + + + public var id:Int; + public var length:Int; + public var start:Int; + public var text:String; + public var type:TextEventType; + + + public function new (type:TextEventType = null, text:String = "", start:Int = 0, length:Int = 0) { + + this.type = type; + this.text = text; + this.start = start; + this.length = length; + + } + + + public function clone ():TextEventInfo { + + return new TextEventInfo (type, text, start, length); + + } + + +} + + +@:enum private abstract TextEventType(Int) { + + var TEXT_INPUT = 0; + var TEXT_EDIT = 1; + +} + + private class TouchEventInfo { diff --git a/lime/_backend/native/NativeWindow.hx b/lime/_backend/native/NativeWindow.hx index 72182d52b..e898e6d2c 100644 --- a/lime/_backend/native/NativeWindow.hx +++ b/lime/_backend/native/NativeWindow.hx @@ -89,6 +89,19 @@ class NativeWindow { } + public function getEnableTextEvents ():Bool { + + if (handle != null) { + + return lime_window_get_enable_text_events (handle); + + } + + return false; + + } + + public function move (x:Int, y:Int):Void { if (handle != null) { @@ -111,6 +124,19 @@ class NativeWindow { } + public function setEnableTextEvents (value:Bool):Bool { + + if (handle != null) { + + return lime_window_set_enable_text_events (handle, value); + + } + + return value; + + } + + public function setFullscreen (value:Bool):Bool { if (handle != null) { @@ -156,12 +182,14 @@ class NativeWindow { private static var lime_window_close = System.load ("lime", "lime_window_close", 1); private static var lime_window_create = System.load ("lime", "lime_window_create", 5); + private static var lime_window_get_enable_text_events = System.load ("lime", "lime_window_get_enable_text_events", 1); private static var lime_window_get_height = System.load ("lime", "lime_window_get_height", 1); private static var lime_window_get_width = System.load ("lime", "lime_window_get_width", 1); private static var lime_window_get_x = System.load ("lime", "lime_window_get_x", 1); private static var lime_window_get_y = System.load ("lime", "lime_window_get_y", 1); private static var lime_window_move = System.load ("lime", "lime_window_move", 3); private static var lime_window_resize = System.load ("lime", "lime_window_resize", 3); + private static var lime_window_set_enable_text_events = System.load ("lime", "lime_window_set_enable_text_events", 2); private static var lime_window_set_fullscreen = System.load ("lime", "lime_window_set_fullscreen", 2); private static var lime_window_set_icon = System.load ("lime", "lime_window_set_icon", 2); private static var lime_window_set_minimized = System.load ("lime", "lime_window_set_minimized", 2); diff --git a/lime/app/Application.hx b/lime/app/Application.hx index 9fa4dad85..69e592424 100644 --- a/lime/app/Application.hx +++ b/lime/app/Application.hx @@ -113,6 +113,8 @@ class Application extends Module { window.onMouseMoveRelative.add (onMouseMoveRelative); window.onMouseUp.add (onMouseUp); window.onMouseWheel.add (onMouseWheel); + window.onTextEdit.add (onTextEdit); + window.onTextInput.add (onTextInput); window.onTouchStart.add (onTouchStart); window.onTouchMove.add (onTouchMove); window.onTouchEnd.add (onTouchEnd); @@ -329,6 +331,28 @@ class Application extends Module { } + public override function onTextEdit (text:String, start:Int, length:Int):Void { + + for (module in modules) { + + module.onTextEdit (text, start, length); + + } + + } + + + public override function onTextInput (text:String):Void { + + for (module in modules) { + + module.onTextInput (text); + + } + + } + + public override function onTouchEnd (x:Float, y:Float, id:Int):Void { for (module in modules) { diff --git a/lime/app/IModule.hx b/lime/app/IModule.hx index 4627999ae..9710ea21c 100644 --- a/lime/app/IModule.hx +++ b/lime/app/IModule.hx @@ -133,6 +133,22 @@ interface IModule { public function onRenderContextRestored (context:RenderContext):Void; + /** + * Called when a text edit event is fired + * @param text The current replacement text + * @param start The starting index for the edit + * @param length The length of the edit + */ + public function onTextEdit (text:String, start:Int, length:Int):Void; + + + /** + * Called when a text input event is fired + * @param text The current input text + */ + public function onTextInput (text:String):Void; + + /** * Called when a touch end event is fired * @param x The current x coordinate of the touch point diff --git a/lime/app/Module.hx b/lime/app/Module.hx index 88b469fad..516ac5b1d 100644 --- a/lime/app/Module.hx +++ b/lime/app/Module.hx @@ -108,6 +108,22 @@ class Module implements IModule { public function onRenderContextRestored (context:RenderContext):Void { } + /** + * Called when a text edit event is fired + * @param text The current replacement text + * @param start The starting index for the edit + * @param length The length of the edit + */ + public function onTextEdit (text:String, start:Int, length:Int):Void { } + + + /** + * Called when a text input event is fired + * @param text The current input text + */ + public function onTextInput (text:String):Void { } + + /** * Called when a touch end event is fired * @param x The current x coordinate of the touch point diff --git a/lime/ui/Window.hx b/lime/ui/Window.hx index 637d01871..2dd7b32d1 100644 --- a/lime/ui/Window.hx +++ b/lime/ui/Window.hx @@ -13,6 +13,7 @@ class Window { public var currentRenderer:Renderer; public var config:Config; + public var enableTextEvents (get, set):Bool; public var fullscreen (get, set):Bool; public var height (get, set):Int; public var minimized (get, set):Bool; @@ -28,6 +29,8 @@ class Window { public var onMouseMoveRelative = new EventFloat->Void> (); public var onMouseUp = new EventFloat->Int->Void> (); public var onMouseWheel = new EventFloat->Void> (); + public var onTextEdit = new EventInt->Int->Void> (); + public var onTextInput = new EventVoid> (); public var onTouchEnd = new EventFloat->Int->Void> (); public var onTouchMove = new EventFloat->Int->Void> (); public var onTouchStart = new EventFloat->Int->Void> (); @@ -141,6 +144,20 @@ class Window { + @:noCompletion private inline function get_enableTextEvents ():Bool { + + return backend.getEnableTextEvents (); + + } + + + @:noCompletion private inline function set_enableTextEvents (value:Bool):Bool { + + return backend.setEnableTextEvents (value); + + } + + @:noCompletion private inline function get_fullscreen ():Bool { return __fullscreen; diff --git a/project/Build.xml b/project/Build.xml index 805a92a13..d56b804e1 100644 --- a/project/Build.xml +++ b/project/Build.xml @@ -194,6 +194,7 @@ + diff --git a/project/include/ui/TextEvent.h b/project/include/ui/TextEvent.h new file mode 100644 index 000000000..4ea3d2251 --- /dev/null +++ b/project/include/ui/TextEvent.h @@ -0,0 +1,41 @@ +#ifndef LIME_UI_TEXT_EVENT_H +#define LIME_UI_TEXT_EVENT_H + + +#include + + +namespace lime { + + + enum TextEventType { + + TEXT_INPUT, + TEXT_EDIT + + }; + + + class TextEvent { + + public: + + static AutoGCRoot* callback; + static AutoGCRoot* eventObject; + + TextEvent (); + + static void Dispatch (TextEvent* event); + + long length; + long start; + char text[32]; + TextEventType type; + + }; + + +} + + +#endif \ No newline at end of file diff --git a/project/include/ui/Window.h b/project/include/ui/Window.h index e58d27420..78c983288 100644 --- a/project/include/ui/Window.h +++ b/project/include/ui/Window.h @@ -19,12 +19,14 @@ namespace lime { public: virtual void Close () = 0; + virtual bool GetEnableTextEvents () = 0; virtual int GetHeight () = 0; virtual int GetWidth () = 0; virtual int GetX () = 0; virtual int GetY () = 0; virtual void Move (int x, int y) = 0; virtual void Resize (int width, int height) = 0; + virtual void SetEnableTextEvents (bool enable) = 0; virtual bool SetFullscreen (bool fullscreen) = 0; virtual void SetIcon (ImageBuffer *imageBuffer) = 0; virtual bool SetMinimized (bool minimized) = 0; diff --git a/project/src/ExternalInterface.cpp b/project/src/ExternalInterface.cpp index 99f7e719a..f253ad9be 100644 --- a/project/src/ExternalInterface.cpp +++ b/project/src/ExternalInterface.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -763,6 +764,15 @@ namespace lime { } + value lime_text_event_manager_register (value callback, value eventObject) { + + TextEvent::callback = new AutoGCRoot (callback); + TextEvent::eventObject = new AutoGCRoot (eventObject); + return alloc_null (); + + } + + void lime_text_layout_destroy (value textHandle) { #ifdef LIME_HARFBUZZ @@ -885,6 +895,14 @@ namespace lime { } + value lime_window_get_enable_text_events (value window) { + + Window* targetWindow = (Window*)(intptr_t)val_float (window); + return alloc_bool (targetWindow->GetEnableTextEvents ()); + + } + + value lime_window_get_height (value window) { Window* targetWindow = (Window*)(intptr_t)val_float (window); @@ -935,6 +953,15 @@ namespace lime { } + value lime_window_set_enable_text_events (value window, value enabled) { + + Window* targetWindow = (Window*)(intptr_t)val_float (window); + targetWindow->SetEnableTextEvents (val_bool (enabled)); + return alloc_null (); + + } + + value lime_window_set_fullscreen (value window, value fullscreen) { Window* targetWindow = (Window*)(intptr_t)val_float (window); @@ -1018,6 +1045,7 @@ namespace lime { DEFINE_PRIM (lime_render_event_manager_register, 2); DEFINE_PRIM (lime_system_get_directory, 3); DEFINE_PRIM (lime_system_get_timer, 0); + DEFINE_PRIM (lime_text_event_manager_register, 2); DEFINE_PRIM (lime_text_layout_create, 3); DEFINE_PRIM (lime_text_layout_position, 5); DEFINE_PRIM (lime_text_layout_set_direction, 2); @@ -1028,12 +1056,14 @@ namespace lime { DEFINE_PRIM (lime_window_close, 1); DEFINE_PRIM (lime_window_create, 5); DEFINE_PRIM (lime_window_event_manager_register, 2); + DEFINE_PRIM (lime_window_get_enable_text_events, 1); DEFINE_PRIM (lime_window_get_height, 1); DEFINE_PRIM (lime_window_get_width, 1); DEFINE_PRIM (lime_window_get_x, 1); DEFINE_PRIM (lime_window_get_y, 1); DEFINE_PRIM (lime_window_move, 3); DEFINE_PRIM (lime_window_resize, 3); + DEFINE_PRIM (lime_window_set_enable_text_events, 2); DEFINE_PRIM (lime_window_set_fullscreen, 2); DEFINE_PRIM (lime_window_set_icon, 2); DEFINE_PRIM (lime_window_set_minimized, 2); diff --git a/project/src/backend/sdl/SDLApplication.cpp b/project/src/backend/sdl/SDLApplication.cpp index 25a153bb7..38a765aae 100644 --- a/project/src/backend/sdl/SDLApplication.cpp +++ b/project/src/backend/sdl/SDLApplication.cpp @@ -41,6 +41,7 @@ namespace lime { KeyEvent keyEvent; MouseEvent mouseEvent; RenderEvent renderEvent; + TextEvent textEvent; TouchEvent touchEvent; UpdateEvent updateEvent; WindowEvent windowEvent; @@ -145,6 +146,12 @@ namespace lime { ProcessMouseEvent (event); break; + case SDL_TEXTINPUT: + case SDL_TEXTEDITING: + + ProcessTextEvent (event); + break; + case SDL_WINDOWEVENT: switch (event->window.event) { @@ -337,6 +344,35 @@ namespace lime { } + void SDLApplication::ProcessTextEvent (SDL_Event* event) { + + if (TextEvent::callback) { + + switch (event->type) { + + case SDL_TEXTINPUT: + + textEvent.type = TEXT_INPUT; + break; + + case SDL_TEXTEDITING: + + textEvent.type = TEXT_EDIT; + textEvent.start = event->edit.start; + textEvent.length = event->edit.length; + break; + + } + + strcpy (textEvent.text, event->text.text); + + TextEvent::Dispatch (&textEvent); + + } + + } + + void SDLApplication::ProcessTouchEvent (SDL_Event* event) { diff --git a/project/src/backend/sdl/SDLApplication.h b/project/src/backend/sdl/SDLApplication.h index 9770cc171..de48a7e0f 100644 --- a/project/src/backend/sdl/SDLApplication.h +++ b/project/src/backend/sdl/SDLApplication.h @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include "SDLWindow.h" @@ -37,6 +38,7 @@ namespace lime { void ProcessGamepadEvent (SDL_Event* event); void ProcessKeyEvent (SDL_Event* event); void ProcessMouseEvent (SDL_Event* event); + void ProcessTextEvent (SDL_Event* event); void ProcessTouchEvent (SDL_Event* event); void ProcessWindowEvent (SDL_Event* event); @@ -54,6 +56,7 @@ namespace lime { MouseEvent mouseEvent; double nextUpdate; RenderEvent renderEvent; + TextEvent textEvent; TouchEvent touchEvent; UpdateEvent updateEvent; WindowEvent windowEvent; diff --git a/project/src/backend/sdl/SDLWindow.cpp b/project/src/backend/sdl/SDLWindow.cpp index ab6a7ca10..eea27001e 100644 --- a/project/src/backend/sdl/SDLWindow.cpp +++ b/project/src/backend/sdl/SDLWindow.cpp @@ -115,6 +115,13 @@ namespace lime { } + bool SDLWindow::GetEnableTextEvents () { + + return SDL_IsTextInputActive (); + + } + + int SDLWindow::GetHeight () { int width; @@ -177,6 +184,21 @@ namespace lime { } + void SDLWindow::SetEnableTextEvents (bool enabled) { + + if (enabled) { + + SDL_StartTextInput (); + + } else { + + SDL_StopTextInput (); + + } + + } + + bool SDLWindow::SetFullscreen (bool fullscreen) { if (fullscreen) { diff --git a/project/src/backend/sdl/SDLWindow.h b/project/src/backend/sdl/SDLWindow.h index f26d580c6..4342166df 100644 --- a/project/src/backend/sdl/SDLWindow.h +++ b/project/src/backend/sdl/SDLWindow.h @@ -18,12 +18,14 @@ namespace lime { ~SDLWindow (); virtual void Close (); + virtual bool GetEnableTextEvents (); virtual int GetHeight (); virtual int GetWidth (); virtual int GetX (); virtual int GetY (); virtual void Move (int x, int y); virtual void Resize (int width, int height); + virtual void SetEnableTextEvents (bool enabled); virtual bool SetFullscreen (bool fullscreen); virtual void SetIcon (ImageBuffer *imageBuffer); virtual bool SetMinimized (bool minimized); diff --git a/project/src/ui/TextEvent.cpp b/project/src/ui/TextEvent.cpp new file mode 100644 index 000000000..a90aac52f --- /dev/null +++ b/project/src/ui/TextEvent.cpp @@ -0,0 +1,59 @@ +#include +#include + + +namespace lime { + + + AutoGCRoot* TextEvent::callback = 0; + AutoGCRoot* TextEvent::eventObject = 0; + + static int id_length; + static int id_start; + static int id_text; + static int id_type; + static bool init = false; + + + TextEvent::TextEvent () { + + length = 0; + start = 0; + + } + + + void TextEvent::Dispatch (TextEvent* event) { + + if (TextEvent::callback) { + + if (!init) { + + id_length = val_id ("length"); + id_start = val_id ("start"); + id_text = val_id ("text"); + id_type = val_id ("type"); + init = true; + + } + + value object = (TextEvent::eventObject ? TextEvent::eventObject->get () : alloc_empty_object ()); + + if (event->type != TEXT_INPUT) { + + alloc_field (object, id_length, alloc_int (event->length)); + alloc_field (object, id_start, alloc_int (event->start)); + + } + + alloc_field (object, id_text, alloc_string (event->text)); + alloc_field (object, id_type, alloc_int (event->type)); + + val_call0 (TextEvent::callback->get ()); + + } + + } + + +} \ No newline at end of file From 6304548e44a05155bbaaef871293e1e3e40b1dd2 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Tue, 12 May 2015 12:20:34 -0700 Subject: [PATCH 28/30] Update to 2.4.0 --- haxelib.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/haxelib.json b/haxelib.json index dd81bb5d8..4d1d9c654 100644 --- a/haxelib.json +++ b/haxelib.json @@ -4,7 +4,7 @@ "license": "MIT", "tags": [], "description": "A flexible lightweight layer for Haxe cross-platform developers", - "version": "2.3.3", - "releasenote": "AudioSource improvements, other fixes", + "version": "2.4.0", + "releasenote": "Added Cairo, text input and mouse focus events, other improvements", "contributors": [ "singmajesty" ] } From 99209ac51b6b73f0801b56e13e17036d5dafabe9 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Tue, 12 May 2015 12:20:42 -0700 Subject: [PATCH 29/30] Update CHANGELOG --- CHANGELOG.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 308bab168..875f311e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,19 @@ +2.4.0 (05/12/2015) +------------------ + +* Added Cairo render context and bindings +* Added support for software windows, using Cairo not OpenGL +* Added text input/edit events +* Added onEnter/onLeave events for Window mouse focus +* Added Image getColorBoundsRect +* Added build support for ANGLE +* Removed prevent default for HTML5 arrow and space keys +* Improved Image copyPixels with merge alpha +* Fixed static build support +* Fixed a case where fonts might not be embedded +* Fixed occasional crash with OpenAL on Neko + + 2.3.3 (04/21/2015) ------------------ From ca97897f39b6e5e138d0a2e53f891e4a4fd8f722 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Tue, 12 May 2015 12:30:34 -0700 Subject: [PATCH 30/30] Sync files --- haxe/CallStack.hx | 89 +++++++++++++++++++++++-------------------- haxe/Timer.hx | 9 +---- haxe/crypto/Hmac.hx | 8 +++- haxe/crypto/Sha256.hx | 3 ++ js/Boot.hx | 7 +--- 5 files changed, 62 insertions(+), 54 deletions(-) diff --git a/haxe/CallStack.hx b/haxe/CallStack.hx index 168a3838b..ae931b7ab 100644 --- a/haxe/CallStack.hx +++ b/haxe/CallStack.hx @@ -36,6 +36,40 @@ enum StackItem { Get informations about the call stack. **/ class CallStack { + #if js + static var lastException:js.Error; + + static function getStack(e:js.Error):Array { + if (e == null) return []; + // https://code.google.com/p/v8/wiki/JavaScriptStackTraceApi + var oldValue = (untyped Error).prepareStackTrace; + (untyped Error).prepareStackTrace = function (error, callsites :Array) { + var stack = []; + for (site in callsites) { + if (wrapCallSite != null) site = wrapCallSite(site); + var method = null; + var fullName :String = site.getFunctionName(); + if (fullName != null) { + var idx = fullName.lastIndexOf("."); + if (idx >= 0) { + var className = fullName.substr(0, idx); + var methodName = fullName.substr(idx+1); + method = Method(className, methodName); + } + } + stack.push(FilePos(method, site.getFileName(), site.getLineNumber())); + } + return stack; + } + var a = makeStack(e.stack); + (untyped Error).prepareStackTrace = oldValue; + return a; + } + + // support for source-map-support module + @:noCompletion + public static var wrapCallSite:Dynamic->Dynamic; + #end /** Return the call stack elements, or an empty array if not available. @@ -45,45 +79,24 @@ class CallStack { var a = makeStack(untyped __dollar__callstack()); a.shift(); // remove Stack.callStack() return a; - #elseif flash9 + #elseif flash var a = makeStack( new flash.errors.Error().getStackTrace() ); a.shift(); // remove Stack.callStack() return a; - #elseif flash - return makeStack("$s"); #elseif php return makeStack("%s"); #elseif cpp var s:Array = untyped __global__.__hxcpp_get_call_stack(true); return makeStack(s); #elseif js - // https://code.google.com/p/v8/wiki/JavaScriptStackTraceApi - var oldValue = (untyped Error).prepareStackTrace; - (untyped Error).prepareStackTrace = function (error, callsites :Array) { - var stack = []; - for (site in callsites) { - var method = null; - var fullName :String = site.getFunctionName(); - if (fullName != null) { - var idx = fullName.lastIndexOf("."); - if (idx >= 0) { - var className = fullName.substr(0, idx); - var methodName = fullName.substr(idx+1); - method = Method(className, methodName); - } - } - stack.push(FilePos(method, site.getFileName(), site.getLineNumber())); - } - return stack; - } try { - throw untyped __new__("Error"); + throw new js.Error(); } catch( e : Dynamic ) { - var a = makeStack(e.stack); - if( a != null ) a.shift(); // remove Stack.callStack() - (untyped Error).prepareStackTrace = oldValue; + var a = getStack(e); + a.shift(); // remove Stack.callStack() return a; } + #elseif java var stack = []; for ( el in java.lang.Thread.currentThread().getStackTrace() ) { @@ -129,7 +142,7 @@ class CallStack { return makeStack(untyped __dollar__excstack()); #elseif as3 return new Array(); - #elseif flash9 + #elseif flash var err : flash.errors.Error = untyped flash.Boot.lastError; if( err == null ) return new Array(); var a = makeStack( err.getStackTrace() ); @@ -143,8 +156,6 @@ class CallStack { i--; } return a; - #elseif flash - return makeStack("$e"); #elseif php return makeStack("%e"); #elseif cpp @@ -182,6 +193,8 @@ class CallStack { stack.push(FilePos(null, elem._1, elem._2)); } return stack; + #elseif js + return untyped __define_feature__("haxe.CallStack.exceptionStack", getStack(lastException)); #else return []; // Unsupported #end @@ -245,7 +258,7 @@ class CallStack { a.unshift(FilePos(null,new String(untyped x[0]),untyped x[1])); } return a; - #elseif flash9 + #elseif flash var a = new Array(); var r = ~/at ([^\/]+?)\$?(\/[^\(]+)?\(\)(\[(.*?):([0-9]+)\])?/; var rlambda = ~/^MethodInfo-([0-9]+)$/g; @@ -266,14 +279,6 @@ class CallStack { s = r.matchedRight(); } return a; - #elseif flash - var a : Array = untyped __eval__(s); - var m = new Array(); - for( i in 0...a.length - if(s == "$s") 2 else 0 ) { - var d = a[i].split("::"); - m.unshift(Method(d[0],d[1])); - } - return m; #elseif php if (!untyped __call__("isset", __var__("GLOBALS", s))) return []; @@ -298,10 +303,12 @@ class CallStack { } return m; #elseif js - if ((untyped __js__("typeof"))(s) == "string") { + if (s == null) { + return []; + } else if ((untyped __js__("typeof"))(s) == "string") { // Return the raw lines in browsers that don't support prepareStackTrace var stack : Array = s.split("\n"); - if( stack[0] == "Error" ) stack.shift(); + if( stack[0] == "Error" ) stack.shift(); var m = []; var rie10 = ~/^ at ([A-Za-z0-9_. ]+) \(([^)]+):([0-9]+):([0-9]+)\)$/; for( line in stack ) { @@ -312,7 +319,7 @@ class CallStack { var line = Std.parseInt(rie10.matched(3)); m.push(FilePos( meth == "Anonymous function" ? LocalFunction() : meth == "Global code" ? null : Method(path.join("."),meth), file, line )); } else - m.push(Module(line)); // A little weird, but better than nothing + m.push(Module(StringTools.trim(line))); // A little weird, but better than nothing } return m; } else { diff --git a/haxe/Timer.hx b/haxe/Timer.hx index 4062c9d00..788bf2fef 100644 --- a/haxe/Timer.hx +++ b/haxe/Timer.hx @@ -62,12 +62,9 @@ class Timer { The accuracy of this may be platform-dependent. **/ public function new( time_ms : Int ){ - #if flash9 + #if flash var me = this; id = untyped __global__["flash.utils.setInterval"](function() { me.run(); },time_ms); - #elseif flash - var me = this; - id = untyped _global["setInterval"](function() { me.run(); },time_ms); #elseif js var me = this; id = untyped setInterval(function() me.run(),time_ms); @@ -89,10 +86,8 @@ class Timer { #if (flash || js) if( id == null ) return; - #if flash9 + #if flash untyped __global__["flash.utils.clearInterval"](id); - #elseif flash - untyped _global["clearInterval"](id); #elseif js untyped clearInterval(id); #end diff --git a/haxe/crypto/Hmac.hx b/haxe/crypto/Hmac.hx index 2afc65ec2..9a83f59e2 100644 --- a/haxe/crypto/Hmac.hx +++ b/haxe/crypto/Hmac.hx @@ -21,12 +21,18 @@ */ package haxe.crypto; +/** + Hash methods for Hmac calculation. +*/ enum HashMethod { MD5; SHA1; SHA256; } +/** + Calculates a Hmac of the given Bytes using a HashMethod. +*/ class Hmac { var method : HashMethod; @@ -82,4 +88,4 @@ class Hmac { return doHash(Ko.getBytes()); } -} \ No newline at end of file +} diff --git a/haxe/crypto/Sha256.hx b/haxe/crypto/Sha256.hx index 868bbe523..17292d573 100644 --- a/haxe/crypto/Sha256.hx +++ b/haxe/crypto/Sha256.hx @@ -21,6 +21,9 @@ */ package haxe.crypto; +/** + Creates a Sha256 of a String. +*/ class Sha256 { public static function encode( s:String ) : String { diff --git a/js/Boot.hx b/js/Boot.hx index 1db6fcb54..ef349f969 100644 --- a/js/Boot.hx +++ b/js/Boot.hx @@ -246,12 +246,9 @@ class Boot { return __nativeClassName(o) != null; } - // resolve native JS class (with window or global): + // resolve native JS class in the global scope: static function __resolveNativeClass(name:String) untyped { - if (__js__("typeof window") != "undefined") - return window[name]; - else - return global[name]; + return untyped Function('return typeof $name != "undefined" ? $name : null')(); } }