From ebda41a737ea16814382efbc7bdc69415bb98421 Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Thu, 7 Jun 2018 17:06:36 -0700 Subject: [PATCH] Better HL support, HelloWorld running in software --- lime/_backend/native/NativeApplication.hx | 24 +- lime/_backend/native/NativeCFFI.hx | 168 ++++++++-- project/Build.xml | 1 + project/include/app/ApplicationEvent.h | 5 +- project/include/graphics/RenderEvent.h | 5 +- project/include/graphics/Renderer.h | 2 +- project/include/system/ClipboardEvent.h | 5 +- project/include/system/SensorEvent.h | 5 +- project/include/system/ValuePointer.h | 47 +++ project/include/ui/DropEvent.h | 5 +- project/include/ui/GamepadEvent.h | 5 +- project/include/ui/JoystickEvent.h | 5 +- project/include/ui/KeyEvent.h | 5 +- project/include/ui/MouseEvent.h | 5 +- project/include/ui/TextEvent.h | 5 +- project/include/ui/TouchEvent.h | 5 +- project/include/ui/WindowEvent.h | 5 +- project/src/ExternalInterface.cpp | 320 +++++++++++++------ project/src/app/ApplicationEvent.cpp | 35 +- project/src/backend/sdl/SDLApplication.cpp | 1 - project/src/backend/sdl/SDLRenderer.cpp | 49 ++- project/src/backend/sdl/SDLRenderer.h | 2 +- project/src/graphics/RenderEvent.cpp | 34 +- project/src/graphics/cairo/CairoBindings.cpp | 79 +++++ project/src/system/ClipboardEvent.cpp | 30 +- project/src/system/SensorEvent.cpp | 50 +-- project/src/system/ValuePointer.cpp | 160 ++++++++++ project/src/ui/DropEvent.cpp | 36 ++- project/src/ui/GamepadEvent.cpp | 50 +-- project/src/ui/JoystickEvent.cpp | 55 ++-- project/src/ui/KeyEvent.cpp | 45 ++- project/src/ui/MouseEvent.cpp | 69 ++-- project/src/ui/TextEvent.cpp | 66 ++-- project/src/ui/TouchEvent.cpp | 65 ++-- project/src/ui/WindowEvent.cpp | 97 ++++-- 35 files changed, 1152 insertions(+), 393 deletions(-) create mode 100644 project/include/system/ValuePointer.h create mode 100644 project/src/system/ValuePointer.cpp diff --git a/lime/_backend/native/NativeApplication.hx b/lime/_backend/native/NativeApplication.hx index f59212c37..b88b704f4 100644 --- a/lime/_backend/native/NativeApplication.hx +++ b/lime/_backend/native/NativeApplication.hx @@ -741,7 +741,7 @@ class NativeApplication { } -private class ApplicationEventInfo { +/*private*/ class ApplicationEventInfo { public var deltaTime:Int; @@ -774,7 +774,7 @@ private class ApplicationEventInfo { } -private class ClipboardEventInfo { +/*private*/ class ClipboardEventInfo { public var type:ClipboardEventType; @@ -804,7 +804,7 @@ private class ClipboardEventInfo { } -private class DropEventInfo { +/*private*/ class DropEventInfo { public var file:String; @@ -836,7 +836,7 @@ private class DropEventInfo { } -private class GamepadEventInfo { +/*private*/ class GamepadEventInfo { public var axis:Int; @@ -878,7 +878,7 @@ private class GamepadEventInfo { } -private class JoystickEventInfo { +/*private*/ class JoystickEventInfo { public var id:Int; @@ -924,7 +924,7 @@ private class JoystickEventInfo { } -private class KeyEventInfo { +/*private*/ class KeyEventInfo { public var keyCode:Int; @@ -961,7 +961,7 @@ private class KeyEventInfo { } -private class MouseEventInfo { +/*private*/ class MouseEventInfo { public var button:Int; @@ -1007,7 +1007,7 @@ private class MouseEventInfo { } -private class RenderEventInfo { +/*private*/ class RenderEventInfo { public var context:RenderContext; @@ -1041,7 +1041,7 @@ private class RenderEventInfo { } -private class SensorEventInfo { +/*private*/ class SensorEventInfo { public var id:Int; @@ -1079,7 +1079,7 @@ private class SensorEventInfo { } -private class TextEventInfo { +/*private*/ class TextEventInfo { public var id:Int; @@ -1119,7 +1119,7 @@ private class TextEventInfo { } -private class TouchEventInfo { +/*private*/ class TouchEventInfo { public var device:Int; @@ -1165,7 +1165,7 @@ private class TouchEventInfo { } -private class WindowEventInfo { +/*private*/ class WindowEventInfo { public var height:Int; diff --git a/lime/_backend/native/NativeCFFI.hx b/lime/_backend/native/NativeCFFI.hx index 71f5b0a02..6501e1165 100644 --- a/lime/_backend/native/NativeCFFI.hx +++ b/lime/_backend/native/NativeCFFI.hx @@ -13,6 +13,10 @@ import lime.media.openal.ALAuxiliaryEffectSlot; import lime.system.CFFIPointer; import lime.utils.DataPointer; +#if hl +import lime._backend.native.NativeApplication; +#end + #if cpp import cpp.Float32; #else @@ -188,7 +192,7 @@ class NativeCFFI { #if hl @:hlNative("lime", "lime_application_create") private static function lime_application_create ():CFFIPointer { return null; } - @:cffi private static function lime_application_event_manager_register (callback:Dynamic, eventObject:Dynamic):Void; + @:hlNative("lime", "lime_application_event_manager_register") private static function lime_application_event_manager_register (callback:Void->Void, eventObject:ApplicationEventInfo):Void {} @:hlNative("lime", "lime_application_exec") private static function lime_application_exec (handle:CFFIPointer):Int { return 0; } @:hlNative("lime", "lime_application_init") private static function lime_application_init (handle:CFFIPointer):Void {} @:hlNative("lime", "lime_application_quit") private static function lime_application_quit (handle:CFFIPointer):Int { return 0; } @@ -200,13 +204,13 @@ class NativeCFFI { @:cffi private static function lime_bytes_get_data_pointer_offset (data:Dynamic, offset:Int):Float; @:cffi private static function lime_bytes_read_file (path:String, bytes:Dynamic):Dynamic; @:cffi private static function lime_cffi_get_native_pointer (ptr:Dynamic):Float; - @:cffi private static function lime_clipboard_event_manager_register (callback:Dynamic, eventObject:Dynamic):Void; + @:hlNative("lime", "lime_clipboard_event_manager_register") private static function lime_clipboard_event_manager_register (callback:Void->Void, eventObject:ClipboardEventInfo):Void {} @:cffi private static function lime_clipboard_get_text ():Dynamic; @:cffi private static function lime_clipboard_set_text (text:String):Void; @:cffi private static function lime_data_pointer_offset (dataPointer:DataPointer, offset:Int):Float; @:cffi private static function lime_deflate_compress (data:Dynamic, bytes:Dynamic):Dynamic; @:cffi private static function lime_deflate_decompress (data:Dynamic, bytes:Dynamic):Dynamic; - @:cffi private static function lime_drop_event_manager_register (callback:Dynamic, eventObject:Dynamic):Void; + @:hlNative("lime", "lime_drop_event_manager_register") private static function lime_drop_event_manager_register (callback:Void->Void, eventObject:DropEventInfo):Void {} @:cffi private static function lime_file_dialog_open_directory (title:String, filter:String, defaultPath:String):Dynamic; @:cffi private static function lime_file_dialog_open_file (title:String, filter:String, defaultPath:String):Dynamic; @:cffi private static function lime_file_dialog_open_files (title:String, filter:String, defaultPath:String):Dynamic; @@ -234,7 +238,7 @@ class NativeCFFI { @:cffi private static function lime_gamepad_add_mappings (mappings:Dynamic):Void; @:cffi private static function lime_gamepad_get_device_guid (id:Int):Dynamic; @:cffi private static function lime_gamepad_get_device_name (id:Int):Dynamic; - @:cffi private static function lime_gamepad_event_manager_register (callback:Dynamic, eventObject:Dynamic):Void; + @:hlNative("lime", "lime_gamepad_event_manager_register") private static function lime_gamepad_event_manager_register (callback:Void->Void, eventObject:GamepadEventInfo):Void {} @:cffi private static function lime_gzip_compress (data:Dynamic, bytes:Dynamic):Dynamic; @:cffi private static function lime_gzip_decompress (data:Dynamic, bytes:Dynamic):Dynamic; @:cffi private static function lime_haptic_vibrate (period:Int, duration:Int):Void; @@ -259,12 +263,12 @@ class NativeCFFI { @:cffi private static function lime_joystick_get_num_buttons (id:Int):Int; @:cffi private static function lime_joystick_get_num_hats (id:Int):Int; @:cffi private static function lime_joystick_get_num_trackballs (id:Int):Int; - @:cffi private static function lime_joystick_event_manager_register (callback:Dynamic, eventObject:Dynamic):Void; + @:hlNative("lime", "lime_joystick_event_manager_register") private static function lime_joystick_event_manager_register (callback:Void->Void, eventObject:JoystickEventInfo):Void {} @:cffi private static function lime_jpeg_decode_bytes (data:Dynamic, decodeData:Bool, buffer:Dynamic):Dynamic; @:cffi private static function lime_jpeg_decode_file (path:String, decodeData:Bool, buffer:Dynamic):Dynamic; @:cffi private static function lime_key_code_from_scan_code (scanCode:Float32):Float32; @:cffi private static function lime_key_code_to_scan_code (keyCode:Float32):Float32; - @:cffi private static function lime_key_event_manager_register (callback:Dynamic, eventObject:Dynamic):Void; + @:hlNative("lime", "lime_key_event_manager_register") private static function lime_key_event_manager_register (callback:Void->Void, eventObject:KeyEventInfo):Void {} @:cffi private static function lime_lzma_compress (data:Dynamic, bytes:Dynamic):Dynamic; @:cffi private static function lime_lzma_decompress (data:Dynamic, bytes:Dynamic):Dynamic; @:cffi private static function lime_mouse_hide ():Void; @@ -272,21 +276,21 @@ class NativeCFFI { @:cffi private static function lime_mouse_set_lock (lock:Bool):Void; @:cffi private static function lime_mouse_show ():Void; @:cffi private static function lime_mouse_warp (x:Int, y:Int, window:Dynamic):Void; - @:cffi private static function lime_mouse_event_manager_register (callback:Dynamic, eventObject:Dynamic):Void; + @:hlNative("lime", "lime_mouse_event_manager_register") private static function lime_mouse_event_manager_register (callback:Void->Void, eventObject:MouseEventInfo):Void {} @:cffi private static function lime_neko_execute (module:String):Void; @:cffi private static function lime_png_decode_bytes (data:Dynamic, decodeData:Bool, buffer:Dynamic):Dynamic; @:cffi private static function lime_png_decode_file (path:String, decodeData:Bool, buffer:Dynamic):Dynamic; - @:cffi private static function lime_renderer_create (window:Dynamic):Dynamic; - @:cffi private static function lime_renderer_flip (handle:Dynamic):Void; - @:cffi private static function lime_renderer_get_context (handle:Dynamic):Float; - @:cffi private static function lime_renderer_get_scale (handle:Dynamic):Float; - @:cffi private static function lime_renderer_get_type (handle:Dynamic):Dynamic; - @:cffi private static function lime_renderer_lock (handle:Dynamic):Dynamic; - @:cffi private static function lime_renderer_make_current (handle:Dynamic):Void; - @:cffi private static function lime_renderer_read_pixels (handle:Dynamic, rect:Dynamic, imageBuffer:Dynamic):Dynamic; - @:cffi private static function lime_renderer_unlock (handle:Dynamic):Void; - @:cffi private static function lime_render_event_manager_register (callback:Dynamic, eventObject:Dynamic):Void; - @:cffi private static function lime_sensor_event_manager_register (callback:Dynamic, eventObject:Dynamic):Void; + @:hlNative("lime", "lime_renderer_create") private static function lime_renderer_create (window:CFFIPointer):CFFIPointer { return null; } + @:hlNative("lime", "lime_renderer_flip") private static function lime_renderer_flip (handle:CFFIPointer):Void {} + @:hlNative("lime", "lime_renderer_get_context") private static function lime_renderer_get_context (handle:CFFIPointer):Float { return 0; } + @:hlNative("lime", "lime_renderer_get_scale") private static function lime_renderer_get_scale (handle:CFFIPointer):Float { return 0; } + @:hlNative("lime", "lime_renderer_get_type") private static function lime_renderer_get_type (handle:CFFIPointer):hl.Bytes { return null; } + @:hlNative("lime", "lime_renderer_lock") private static function lime_renderer_lock (handle:CFFIPointer):Dynamic { return null; } + @:hlNative("lime", "lime_renderer_make_current") private static function lime_renderer_make_current (handle:CFFIPointer):Void {} + @:hlNative("lime", "lime_renderer_read_pixels") private static function lime_renderer_read_pixels (handle:CFFIPointer, rect:Rectangle, imageBuffer:ImageBuffer):Dynamic { return null; } + @:hlNative("lime", "lime_renderer_unlock") private static function lime_renderer_unlock (handle:CFFIPointer):Void {} + @:hlNative("lime", "lime_render_event_manager_register") private static function lime_render_event_manager_register (callback:Void->Void, eventObject:RenderEventInfo):Void {} + @:hlNative("lime", "lime_sensor_event_manager_register") private static function lime_sensor_event_manager_register (callback:Void->Void, eventObject:SensorEventInfo):Void {} @:cffi private static function lime_system_get_allow_screen_timeout ():Bool; @:cffi private static function lime_system_set_allow_screen_timeout (value:Bool):Bool; @:cffi private static function lime_system_get_device_model ():Dynamic; @@ -301,13 +305,13 @@ class NativeCFFI { @:cffi private static function lime_system_get_timer ():Float; @:cffi private static function lime_system_open_file (path:String):Void; @:cffi private static function lime_system_open_url (url:String, target:String):Void; - @:cffi private static function lime_text_event_manager_register (callback:Dynamic, eventObject:Dynamic):Void; + @:hlNative("lime", "lime_text_event_manager_register") private static function lime_text_event_manager_register (callback:Void->Void, eventObject:TextEventInfo):Void {} @:cffi private static function lime_text_layout_create (direction:Int, script:String, language:String):Dynamic; @:cffi private static function lime_text_layout_position (textHandle:Dynamic, fontHandle:Dynamic, size:Int, textString:String, data:Dynamic):Dynamic; @:cffi private static function lime_text_layout_set_direction (textHandle:Dynamic, direction:Int):Void; @:cffi private static function lime_text_layout_set_language (textHandle:Dynamic, language:String):Void; @:cffi private static function lime_text_layout_set_script (textHandle:Dynamic, script:String):Void; - @:cffi private static function lime_touch_event_manager_register (callback:Dynamic, eventObject:Dynamic):Void; + @:hlNative("lime", "lime_touch_event_manager_register") private static function lime_touch_event_manager_register (callback:Void->Void, eventObject:TouchEventInfo):Void {} @:cffi private static function lime_window_alert (handle:Dynamic, message:String, title:String):Void; @:cffi private static function lime_window_close (handle:Dynamic):Void; @:cffi private static function lime_window_create (application:Dynamic, width:Int, height:Int, flags:Int, title:String):Dynamic; @@ -331,7 +335,7 @@ class NativeCFFI { @:cffi private static function lime_window_set_minimized (handle:Dynamic, minimized:Bool):Bool; @:cffi private static function lime_window_set_resizable (handle:Dynamic, resizable:Bool):Bool; @:cffi private static function lime_window_set_title (handle:Dynamic, title:String):Dynamic; - @:cffi private static function lime_window_event_manager_register (callback:Dynamic, eventObject:Dynamic):Void; + @:hlNative("lime", "lime_window_event_manager_register") private static function lime_window_event_manager_register (callback:Void->Void, eventObject:WindowEventInfo):Void {} @:cffi private static function lime_zlib_compress (data:Dynamic, bytes:Dynamic):Dynamic; @:cffi private static function lime_zlib_decompress (data:Dynamic, bytes:Dynamic):Dynamic; #end @@ -468,6 +472,7 @@ class NativeCFFI { #end #if (lime_cffi && !macro && lime_cairo) + #if !hl @:cffi private static function lime_cairo_arc (handle:CFFIPointer, xc:Float, yc:Float, radius:Float, angle1:Float, angle2:Float):Void; @:cffi private static function lime_cairo_arc_negative (handle:CFFIPointer, xc:Float, yc:Float, radius:Float, angle1:Float, angle2:Float):Void; @:cffi private static function lime_cairo_clip (handle:CFFIPointer):Void; @@ -587,6 +592,127 @@ class NativeCFFI { @:cffi private static function lime_cairo_surface_flush (surface:CFFIPointer):Void; #end + #if hl + @:cffi private static function lime_cairo_arc (handle:CFFIPointer, xc:Float, yc:Float, radius:Float, angle1:Float, angle2:Float):Void; + @:cffi private static function lime_cairo_arc_negative (handle:CFFIPointer, xc:Float, yc:Float, radius:Float, angle1:Float, angle2:Float):Void; + @:cffi private static function lime_cairo_clip (handle:CFFIPointer):Void; + @:cffi private static function lime_cairo_clip_preserve (handle:CFFIPointer):Void; + @:cffi private static function lime_cairo_clip_extents (handle:CFFIPointer, x1:Float, y1:Float, x2:Float, y2:Float):Void; + @:cffi private static function lime_cairo_close_path (handle:CFFIPointer):Void; + @:cffi private static function lime_cairo_copy_page (handle:CFFIPointer):Void; + @:hlNative("lime", "lime_cairo_create") private static function lime_cairo_create (handle:CFFIPointer):CFFIPointer { return null; } + @:cffi private static function lime_cairo_curve_to (handle:CFFIPointer, x1:Float, y1:Float, x2:Float, y2:Float, x3:Float, y3:Float):Void; + @:cffi private static function lime_cairo_fill (handle:CFFIPointer):Void; + @:cffi private static function lime_cairo_fill_extents (handle:CFFIPointer, x1:Float, y1:Float, x2:Float, y2:Float):Void; + @:cffi private static function lime_cairo_fill_preserve (handle:CFFIPointer):Void; + @:cffi private static function lime_cairo_get_antialias (handle:CFFIPointer):Int; + @:cffi private static function lime_cairo_get_current_point (handle:CFFIPointer):Dynamic; + @:cffi private static function lime_cairo_get_dash (handle:CFFIPointer):Dynamic; + @:cffi private static function lime_cairo_get_dash_count (handle:CFFIPointer):Int; + @:cffi private static function lime_cairo_get_fill_rule (handle:CFFIPointer):Int; + @:cffi private static function lime_cairo_get_font_face (handle:CFFIPointer):CFFIPointer; + @:cffi private static function lime_cairo_get_font_options (handle:CFFIPointer):CFFIPointer; + @:cffi private static function lime_cairo_get_group_target (handle:CFFIPointer):CFFIPointer; + @:cffi private static function lime_cairo_get_line_cap (handle:CFFIPointer):Int; + @:cffi private static function lime_cairo_get_line_join (handle:CFFIPointer):Int; + @:cffi private static function lime_cairo_get_line_width (handle:CFFIPointer):Float; + @:cffi private static function lime_cairo_get_matrix (handle:CFFIPointer):Dynamic; + @:cffi private static function lime_cairo_get_miter_limit (handle:CFFIPointer):Float; + @:cffi private static function lime_cairo_get_operator (handle:CFFIPointer):Int; + @:cffi private static function lime_cairo_get_source (handle:CFFIPointer):CFFIPointer; + @:cffi private static function lime_cairo_get_target (handle:CFFIPointer):CFFIPointer; + @:cffi private static function lime_cairo_get_tolerance (handle:CFFIPointer):Float; + @:cffi private static function lime_cairo_has_current_point (handle:CFFIPointer):Bool; + @:cffi private static function lime_cairo_identity_matrix (handle:CFFIPointer):Void; + @:cffi private static function lime_cairo_in_clip (handle:CFFIPointer, x:Float, y:Float):Bool; + @:cffi private static function lime_cairo_in_fill (handle:CFFIPointer, x:Float, y:Float):Bool; + @:cffi private static function lime_cairo_in_stroke (handle:CFFIPointer, x:Float, y:Float):Bool; + @:cffi private static function lime_cairo_line_to (handle:CFFIPointer, x:Float, y:Float):Void; + @:cffi private static function lime_cairo_mask (handle:CFFIPointer, pattern:CFFIPointer):Void; + @:cffi private static function lime_cairo_mask_surface (handle:CFFIPointer, surface:CFFIPointer, x:Float, y:Float):Void; + @:cffi private static function lime_cairo_move_to (handle:CFFIPointer, x:Float, y:Float):Void; + @:cffi private static function lime_cairo_new_path (handle:CFFIPointer):Void; + @:hlNative("lime", "lime_cairo_paint") private static function lime_cairo_paint (handle:CFFIPointer):Void {} + @:cffi private static function lime_cairo_paint_with_alpha (handle:CFFIPointer, alpha:Float):Void; + @:cffi private static function lime_cairo_pop_group (handle:CFFIPointer):CFFIPointer; + @:cffi private static function lime_cairo_pop_group_to_source (handle:CFFIPointer):Void; + @:cffi private static function lime_cairo_push_group (handle:CFFIPointer):Void; + @:cffi private static function lime_cairo_push_group_with_content (handle:CFFIPointer, content:Int):Void; + @:cffi private static function lime_cairo_rectangle (handle:CFFIPointer, x:Float, y:Float, width:Float, height:Float):Void; + @:cffi private static function lime_cairo_rel_curve_to (handle:CFFIPointer, dx1:Float, dy1:Float, dx2:Float, dy2:Float, dx3:Float, dy3:Float):Void; + @:cffi private static function lime_cairo_rel_line_to (handle:CFFIPointer, dx:Float, dy:Float):Void; + @:cffi private static function lime_cairo_rel_move_to (handle:CFFIPointer, dx:Float, dy:Float):Void; + @:cffi private static function lime_cairo_reset_clip (handle:CFFIPointer):Void; + @:cffi private static function lime_cairo_restore (handle:CFFIPointer):Void; + @:cffi private static function lime_cairo_rotate (handle:CFFIPointer, amount:Float):Void; + @:cffi private static function lime_cairo_save (handle:CFFIPointer):Void; + @:cffi private static function lime_cairo_scale (handle:CFFIPointer, x:Float, y:Float):Void; + @:cffi private static function lime_cairo_set_antialias (handle:CFFIPointer, cap:Int):Void; + @:cffi private static function lime_cairo_set_dash (handle:CFFIPointer, dash:Dynamic):Void; + @:cffi private static function lime_cairo_set_fill_rule (handle:CFFIPointer, cap:Int):Void; + @:cffi private static function lime_cairo_set_font_face (handle:CFFIPointer, face:CFFIPointer):Void; + @:cffi private static function lime_cairo_set_font_options (handle:CFFIPointer, options:CFFIPointer):Void; + @:cffi private static function lime_cairo_set_font_size (handle:CFFIPointer, size:Float):Void; + @:cffi private static function lime_cairo_set_line_cap (handle:CFFIPointer, cap:Int):Void; + @:cffi private static function lime_cairo_set_line_join (handle:CFFIPointer, join:Int):Void; + @:cffi private static function lime_cairo_set_line_width (handle:CFFIPointer, width:Float):Void; + @:cffi private static function lime_cairo_set_matrix (handle:CFFIPointer, a:Float, b:Float, c:Float, d:Float, tx:Float, ty:Float):Void; + //@:cffi private static function lime_cairo_set_matrix (handle:CFFIPointer, matrix:Dynamic):Void; + @:cffi private static function lime_cairo_set_miter_limit (handle:CFFIPointer, miterLimit:Float):Void; + @:cffi private static function lime_cairo_set_operator (handle:CFFIPointer, op:Int):Void; + @:cffi private static function lime_cairo_set_source (handle:CFFIPointer, pattern:CFFIPointer):Void; + @:hlNative("lime", "lime_cairo_set_source_rgb") private static function lime_cairo_set_source_rgb (handle:CFFIPointer, r:Float, g:Float, b:Float):Void {} + @:cffi private static function lime_cairo_set_source_rgba (handle:CFFIPointer, r:Float, g:Float, b:Float, a:Float):Void; + @:cffi private static function lime_cairo_set_source_surface (handle:CFFIPointer, surface:CFFIPointer, x:Float, y:Float):Void; + @:cffi private static function lime_cairo_set_tolerance (handle:CFFIPointer, tolerance:Float):Void; + @:cffi private static function lime_cairo_show_glyphs (handle:CFFIPointer, glyphs:Dynamic):Void; + @:cffi private static function lime_cairo_show_page (handle:CFFIPointer):Void; + @:cffi private static function lime_cairo_show_text (handle:CFFIPointer, text:String):Void; + @:cffi private static function lime_cairo_status (handle:CFFIPointer):Int; + @:cffi private static function lime_cairo_stroke (handle:CFFIPointer):Void; + @:cffi private static function lime_cairo_stroke_extents (handle:CFFIPointer, x1:Float, y1:Float, x2:Float, y2:Float):Void; + @:cffi private static function lime_cairo_stroke_preserve (handle:CFFIPointer):Void; + @:cffi private static function lime_cairo_text_path (handle:CFFIPointer, text:String):Void; + @:cffi private static function lime_cairo_transform (handle:CFFIPointer, matrix:Dynamic):Void; + @:cffi private static function lime_cairo_translate (handle:CFFIPointer, x:Float, y:Float):Void; + @:cffi private static function lime_cairo_version ():Int; + @:cffi private static function lime_cairo_version_string ():String; + @:cffi private static function lime_cairo_font_face_status (handle:CFFIPointer):Int; + @:cffi private static function lime_cairo_font_options_create ():CFFIPointer; + @:cffi private static function lime_cairo_font_options_get_antialias (handle:CFFIPointer):Int; + @:cffi private static function lime_cairo_font_options_get_hint_metrics (handle:CFFIPointer):Int; + @:cffi private static function lime_cairo_font_options_get_hint_style (handle:CFFIPointer):Int; + @:cffi private static function lime_cairo_font_options_get_subpixel_order (handle:CFFIPointer):Int; + @:cffi private static function lime_cairo_font_options_set_antialias (handle:CFFIPointer, v:Int):Void; + @:cffi private static function lime_cairo_font_options_set_hint_metrics (handle:CFFIPointer, v:Int):Void; + @:cffi private static function lime_cairo_font_options_set_hint_style (handle:CFFIPointer, v:Int):Void; + @:cffi private static function lime_cairo_font_options_set_subpixel_order (handle:CFFIPointer, v:Int):Void; + @:cffi private static function lime_cairo_ft_font_face_create (face:CFFIPointer, flags:Int):CFFIPointer; + @:cffi private static function lime_cairo_image_surface_create (format:Int, width:Int, height:Int):CFFIPointer; + @:hlNative("lime", "lime_cairo_image_surface_create_for_data") private static function lime_cairo_image_surface_create_for_data (data:DataPointer, format:Int, width:Int, height:Int, stride:Int):CFFIPointer { return null; } + @:cffi private static function lime_cairo_image_surface_get_data (handle:CFFIPointer):DataPointer; + @:cffi private static function lime_cairo_image_surface_get_format (handle:CFFIPointer):Int; + @:cffi private static function lime_cairo_image_surface_get_height (handle:CFFIPointer):Int; + @:cffi private static function lime_cairo_image_surface_get_stride (handle:CFFIPointer):Int; + @:cffi private static function lime_cairo_image_surface_get_width (handle:CFFIPointer):Int; + @:cffi private static function lime_cairo_pattern_add_color_stop_rgb (handle:CFFIPointer, offset:Float, red:Float, green:Float, blue:Float):Void; + @:cffi private static function lime_cairo_pattern_add_color_stop_rgba (handle:CFFIPointer, offset:Float, red:Float, green:Float, blue:Float, alpha:Float):Void; + @:cffi private static function lime_cairo_pattern_create_for_surface (surface:CFFIPointer):CFFIPointer; + @:cffi private static function lime_cairo_pattern_create_linear (x0:Float, y0:Float, x1:Float, y1:Float):CFFIPointer; + @:cffi private static function lime_cairo_pattern_create_radial (cx0:Float, cy0:Float, radius0:Float, cx1:Float, cy1:Float, radius1:Float):CFFIPointer; + @:cffi private static function lime_cairo_pattern_create_rgb (r:Float, g:Float, b:Float):CFFIPointer; + @:cffi private static function lime_cairo_pattern_create_rgba (r:Float, g:Float, b:Float, a:Float):CFFIPointer; + @:cffi private static function lime_cairo_pattern_get_color_stop_count (handle:CFFIPointer):Int; + @:cffi private static function lime_cairo_pattern_get_extend (handle:CFFIPointer):Int; + @:cffi private static function lime_cairo_pattern_get_filter (handle:CFFIPointer):Int; + @:cffi private static function lime_cairo_pattern_get_matrix (handle:CFFIPointer):Dynamic; + @:cffi private static function lime_cairo_pattern_set_extend (handle:CFFIPointer, extend:Int):Void; + @:cffi private static function lime_cairo_pattern_set_filter (handle:CFFIPointer, filter:Int):Void; + @:cffi private static function lime_cairo_pattern_set_matrix (handle:CFFIPointer, matrix:Dynamic):Void; + @:hlNative("lime", "lime_cairo_surface_flush") private static function lime_cairo_surface_flush (surface:CFFIPointer):Void {} + #end + #end + #if (lime_cffi && !macro && lime_curl) @:cffi private static function lime_curl_getdate (date:String, now:Float):Float; @:cffi private static function lime_curl_global_cleanup ():Void; diff --git a/project/Build.xml b/project/Build.xml index ea73796ca..aeb0b8657 100644 --- a/project/Build.xml +++ b/project/Build.xml @@ -296,6 +296,7 @@ + diff --git a/project/include/app/ApplicationEvent.h b/project/include/app/ApplicationEvent.h index 57eeaf122..32b49b36e 100644 --- a/project/include/app/ApplicationEvent.h +++ b/project/include/app/ApplicationEvent.h @@ -4,6 +4,7 @@ #include #include +#include namespace lime { @@ -30,8 +31,8 @@ namespace lime { public: - static AutoGCRoot* callback; - static AutoGCRoot* eventObject; + static ValuePointer* callback; + static ValuePointer* eventObject; ApplicationEvent (); diff --git a/project/include/graphics/RenderEvent.h b/project/include/graphics/RenderEvent.h index 70591bdab..ca1a2566d 100644 --- a/project/include/graphics/RenderEvent.h +++ b/project/include/graphics/RenderEvent.h @@ -4,6 +4,7 @@ #include #include +#include namespace lime { @@ -30,8 +31,8 @@ namespace lime { public: - static AutoGCRoot* callback; - static AutoGCRoot* eventObject; + static ValuePointer* callback; + static ValuePointer* eventObject; RenderEvent (); diff --git a/project/include/graphics/Renderer.h b/project/include/graphics/Renderer.h index c964e8086..f7199fd04 100644 --- a/project/include/graphics/Renderer.h +++ b/project/include/graphics/Renderer.h @@ -21,7 +21,7 @@ namespace lime { virtual void Flip () = 0; virtual void* GetContext () = 0; virtual double GetScale () = 0; - virtual value Lock () = 0; + virtual void* Lock (bool useCFFIValue) = 0; virtual void MakeCurrent () = 0; virtual void ReadPixels (ImageBuffer *buffer, Rectangle *rect) = 0; virtual const char* Type () = 0; diff --git a/project/include/system/ClipboardEvent.h b/project/include/system/ClipboardEvent.h index 531356218..91664b4da 100644 --- a/project/include/system/ClipboardEvent.h +++ b/project/include/system/ClipboardEvent.h @@ -4,6 +4,7 @@ #include #include +#include namespace lime { @@ -28,8 +29,8 @@ namespace lime { public: - static AutoGCRoot* callback; - static AutoGCRoot* eventObject; + static ValuePointer* callback; + static ValuePointer* eventObject; ClipboardEvent (); diff --git a/project/include/system/SensorEvent.h b/project/include/system/SensorEvent.h index 602612d4c..a92cefaa1 100644 --- a/project/include/system/SensorEvent.h +++ b/project/include/system/SensorEvent.h @@ -4,6 +4,7 @@ #include #include +#include namespace lime { @@ -32,8 +33,8 @@ namespace lime { public: - static AutoGCRoot* callback; - static AutoGCRoot* eventObject; + static ValuePointer* callback; + static ValuePointer* eventObject; SensorEvent (); diff --git a/project/include/system/ValuePointer.h b/project/include/system/ValuePointer.h new file mode 100644 index 000000000..f52312426 --- /dev/null +++ b/project/include/system/ValuePointer.h @@ -0,0 +1,47 @@ +#ifndef LIME_SYSTEM_VALUE_POINTER_H +#define LIME_SYSTEM_VALUE_POINTER_H + + +#include +#include + + +namespace lime { + + + class ValuePointer { + + + public: + + ValuePointer (vobj* handle); + ValuePointer (vdynamic* handle); + ValuePointer (vclosure* handle); + ValuePointer (value handle); + ~ValuePointer (); + + void* Call (); + void* Call (void* arg0); + void* Call (void* arg0, void* arg1); + void* Call (void* arg0, void* arg1, void* arg2); + void* Call (void* arg0, void* arg1, void* arg2, void* arg3); + void* Call (void* arg0, void* arg1, void* arg2, void* arg3, void* arg4); + void* Get () const; + bool IsCFFIValue (); + bool IsHLValue (); + void Set (vobj* handle); + void Set (value handle); + + private: + + gcroot cffiRoot; + value* cffiValue; + vobj* hlValue; + + }; + + +} + + +#endif \ No newline at end of file diff --git a/project/include/ui/DropEvent.h b/project/include/ui/DropEvent.h index 3fcaa629a..0b044e453 100644 --- a/project/include/ui/DropEvent.h +++ b/project/include/ui/DropEvent.h @@ -4,6 +4,7 @@ #include #include +#include namespace lime { @@ -29,8 +30,8 @@ namespace lime { public: - static AutoGCRoot* callback; - static AutoGCRoot* eventObject; + static ValuePointer* callback; + static ValuePointer* eventObject; DropEvent (); diff --git a/project/include/ui/GamepadEvent.h b/project/include/ui/GamepadEvent.h index 82979fcc8..a83cde5f4 100644 --- a/project/include/ui/GamepadEvent.h +++ b/project/include/ui/GamepadEvent.h @@ -4,6 +4,7 @@ #include #include +#include namespace lime { @@ -36,8 +37,8 @@ namespace lime { public: - static AutoGCRoot* callback; - static AutoGCRoot* eventObject; + static ValuePointer* callback; + static ValuePointer* eventObject; GamepadEvent (); diff --git a/project/include/ui/JoystickEvent.h b/project/include/ui/JoystickEvent.h index acd60576c..d6a8ab534 100644 --- a/project/include/ui/JoystickEvent.h +++ b/project/include/ui/JoystickEvent.h @@ -4,6 +4,7 @@ #include #include +#include namespace lime { @@ -39,8 +40,8 @@ namespace lime { public: - static AutoGCRoot* callback; - static AutoGCRoot* eventObject; + static ValuePointer* callback; + static ValuePointer* eventObject; JoystickEvent (); diff --git a/project/include/ui/KeyEvent.h b/project/include/ui/KeyEvent.h index 7ea7b96cc..b3d892285 100644 --- a/project/include/ui/KeyEvent.h +++ b/project/include/ui/KeyEvent.h @@ -4,6 +4,7 @@ #include #include +#include #include @@ -33,8 +34,8 @@ namespace lime { public: - static AutoGCRoot* callback; - static AutoGCRoot* eventObject; + static ValuePointer* callback; + static ValuePointer* eventObject; KeyEvent (); diff --git a/project/include/ui/MouseEvent.h b/project/include/ui/MouseEvent.h index 097405d20..f182912fc 100644 --- a/project/include/ui/MouseEvent.h +++ b/project/include/ui/MouseEvent.h @@ -4,6 +4,7 @@ #include #include +#include #include @@ -38,8 +39,8 @@ namespace lime { public: - static AutoGCRoot* callback; - static AutoGCRoot* eventObject; + static ValuePointer* callback; + static ValuePointer* eventObject; MouseEvent (); diff --git a/project/include/ui/TextEvent.h b/project/include/ui/TextEvent.h index 4a55dc1c7..8ff496248 100644 --- a/project/include/ui/TextEvent.h +++ b/project/include/ui/TextEvent.h @@ -4,6 +4,7 @@ #include #include +#include #include @@ -35,8 +36,8 @@ namespace lime { public: - static AutoGCRoot* callback; - static AutoGCRoot* eventObject; + static ValuePointer* callback; + static ValuePointer* eventObject; TextEvent (); diff --git a/project/include/ui/TouchEvent.h b/project/include/ui/TouchEvent.h index 6374f2889..1a8bb9e57 100644 --- a/project/include/ui/TouchEvent.h +++ b/project/include/ui/TouchEvent.h @@ -4,6 +4,7 @@ #include #include +#include #include @@ -38,8 +39,8 @@ namespace lime { public: - static AutoGCRoot* callback; - static AutoGCRoot* eventObject; + static ValuePointer* callback; + static ValuePointer* eventObject; TouchEvent (); diff --git a/project/include/ui/WindowEvent.h b/project/include/ui/WindowEvent.h index 77fd552bb..02862b9e2 100644 --- a/project/include/ui/WindowEvent.h +++ b/project/include/ui/WindowEvent.h @@ -4,6 +4,7 @@ #include #include +#include #include @@ -45,8 +46,8 @@ namespace lime { public: - static AutoGCRoot* callback; - static AutoGCRoot* eventObject; + static ValuePointer* callback; + static ValuePointer* eventObject; WindowEvent (); diff --git a/project/src/ExternalInterface.cpp b/project/src/ExternalInterface.cpp index ef793732e..632fcb3bd 100644 --- a/project/src/ExternalInterface.cpp +++ b/project/src/ExternalInterface.cpp @@ -182,7 +182,6 @@ namespace lime { value lime_application_create () { Application* application = CreateApplication (); - // Application::callback = new ValuePointer (callback); return CFFIPointer (application, gc_application); } @@ -191,7 +190,6 @@ namespace lime { HL_PRIM HL_CFFIPointer* hl_lime_application_create () { Application* application = CreateApplication (); - // Application::callback = new ValuePointer (callback); return HLCFFIPointer (application, (hl_finalizer)hl_gc_application); } @@ -199,16 +197,16 @@ namespace lime { void lime_application_event_manager_register (value callback, value eventObject) { - ApplicationEvent::callback = new AutoGCRoot (callback); - ApplicationEvent::eventObject = new AutoGCRoot (eventObject); + ApplicationEvent::callback = new ValuePointer (callback); + ApplicationEvent::eventObject = new ValuePointer (eventObject); } HL_PRIM void hl_lime_application_event_manager_register (vclosure* callback, HL_ApplicationEvent* eventObject) { - // ApplicationEvent::callback = new AutoGCRoot (callback); - // ApplicationEvent::eventObject = new AutoGCRoot (eventObject); + ApplicationEvent::callback = new ValuePointer (callback); + ApplicationEvent::eventObject = new ValuePointer ((vobj*)eventObject); } @@ -488,16 +486,16 @@ namespace lime { void lime_clipboard_event_manager_register (value callback, value eventObject) { - ClipboardEvent::callback = new AutoGCRoot (callback); - ClipboardEvent::eventObject = new AutoGCRoot (eventObject); + ClipboardEvent::callback = new ValuePointer (callback); + ClipboardEvent::eventObject = new ValuePointer (eventObject); } HL_PRIM void hl_lime_clipboard_event_manager_register (vclosure* callback, HL_ClipboardEvent* eventObject) { - // ClipboardEvent::callback = new AutoGCRoot (callback); - // ClipboardEvent::eventObject = new AutoGCRoot (eventObject); + ClipboardEvent::callback = new ValuePointer (callback); + ClipboardEvent::eventObject = new ValuePointer ((vobj*)eventObject); } @@ -634,16 +632,16 @@ namespace lime { void lime_drop_event_manager_register (value callback, value eventObject) { - DropEvent::callback = new AutoGCRoot (callback); - DropEvent::eventObject = new AutoGCRoot (eventObject); + DropEvent::callback = new ValuePointer (callback); + DropEvent::eventObject = new ValuePointer (eventObject); } HL_PRIM void hl_lime_drop_event_manager_register (vclosure* callback, HL_DropEvent* eventObject) { - // DropEvent::callback = new AutoGCRoot (callback); - // DropEvent::eventObject = new AutoGCRoot (eventObject); + DropEvent::callback = new ValuePointer (callback); + DropEvent::eventObject = new ValuePointer ((vobj*)eventObject); } @@ -1536,16 +1534,16 @@ namespace lime { void lime_gamepad_event_manager_register (value callback, value eventObject) { - GamepadEvent::callback = new AutoGCRoot (callback); - GamepadEvent::eventObject = new AutoGCRoot (eventObject); + GamepadEvent::callback = new ValuePointer (callback); + GamepadEvent::eventObject = new ValuePointer (eventObject); } HL_PRIM void hl_lime_gamepad_event_manager_register (vclosure* callback, HL_GamepadEvent* eventObject) { - // GamepadEvent::callback = new AutoGCRoot (callback); - // GamepadEvent::eventObject = new AutoGCRoot (eventObject); + GamepadEvent::callback = new ValuePointer (callback); + GamepadEvent::eventObject = new ValuePointer ((vobj*)eventObject); } @@ -2214,16 +2212,16 @@ namespace lime { void lime_joystick_event_manager_register (value callback, value eventObject) { - JoystickEvent::callback = new AutoGCRoot (callback); - JoystickEvent::eventObject = new AutoGCRoot (eventObject); + JoystickEvent::callback = new ValuePointer (callback); + JoystickEvent::eventObject = new ValuePointer (eventObject); } HL_PRIM void hl_lime_joystick_event_manager_register (vclosure* callback, HL_JoystickEvent* eventObject) { - // JoystickEvent::callback = new AutoGCRoot (callback); - // JoystickEvent::eventObject = new AutoGCRoot (eventObject); + JoystickEvent::callback = new ValuePointer (callback); + JoystickEvent::eventObject = new ValuePointer ((vobj*)eventObject); } @@ -2420,16 +2418,16 @@ namespace lime { void lime_key_event_manager_register (value callback, value eventObject) { - KeyEvent::callback = new AutoGCRoot (callback); - KeyEvent::eventObject = new AutoGCRoot (eventObject); + KeyEvent::callback = new ValuePointer (callback); + KeyEvent::eventObject = new ValuePointer (eventObject); } HL_PRIM void hl_lime_key_event_manager_register (vclosure* callback, HL_KeyEvent* eventObject) { - // KeyEvent::callback = new AutoGCRoot (callback); - // KeyEvent::eventObject = new AutoGCRoot (eventObject); + KeyEvent::callback = new ValuePointer (callback); + KeyEvent::eventObject = new ValuePointer ((vobj*)eventObject); } @@ -2541,16 +2539,16 @@ namespace lime { void lime_mouse_event_manager_register (value callback, value eventObject) { - MouseEvent::callback = new AutoGCRoot (callback); - MouseEvent::eventObject = new AutoGCRoot (eventObject); + MouseEvent::callback = new ValuePointer (callback); + MouseEvent::eventObject = new ValuePointer (eventObject); } HL_PRIM void hl_lime_mouse_event_manager_register (vclosure* callback, HL_MouseEvent* eventObject) { - // MouseEvent::callback = new AutoGCRoot (callback); - // MouseEvent::eventObject = new AutoGCRoot (eventObject); + MouseEvent::callback = new ValuePointer (callback); + MouseEvent::eventObject = new ValuePointer ((vobj*)eventObject); } @@ -2726,16 +2724,16 @@ namespace lime { void lime_render_event_manager_register (value callback, value eventObject) { - RenderEvent::callback = new AutoGCRoot (callback); - RenderEvent::eventObject = new AutoGCRoot (eventObject); + RenderEvent::callback = new ValuePointer (callback); + RenderEvent::eventObject = new ValuePointer (eventObject); } HL_PRIM void hl_lime_render_event_manager_register (vclosure* callback, HL_RenderEvent* eventObject) { - // RenderEvent::callback = new AutoGCRoot (callback); - // RenderEvent::eventObject = new AutoGCRoot (eventObject); + RenderEvent::callback = new ValuePointer (callback); + RenderEvent::eventObject = new ValuePointer ((vobj*)eventObject); } @@ -2821,15 +2819,14 @@ namespace lime { value lime_renderer_lock (value renderer) { - return ((Renderer*)val_data (renderer))->Lock (); + return (value)((Renderer*)val_data (renderer))->Lock (true); } HL_PRIM vdynamic* hl_lime_renderer_lock (HL_CFFIPointer* renderer) { - // return ((Renderer*)renderer->ptr)->Lock (); - return 0; + return (vdynamic*)((Renderer*)renderer->ptr)->Lock (false); } @@ -2907,16 +2904,16 @@ namespace lime { void lime_sensor_event_manager_register (value callback, value eventObject) { - SensorEvent::callback = new AutoGCRoot (callback); - SensorEvent::eventObject = new AutoGCRoot (eventObject); + SensorEvent::callback = new ValuePointer (callback); + SensorEvent::eventObject = new ValuePointer (eventObject); } HL_PRIM void hl_lime_sensor_event_manager_register (vclosure* callback, HL_SensorEvent* eventObject) { - // SensorEvent::callback = new AutoGCRoot (callback); - // SensorEvent::eventObject = new AutoGCRoot (eventObject); + SensorEvent::callback = new ValuePointer (callback); + SensorEvent::eventObject = new ValuePointer ((vobj*)eventObject); } @@ -3342,16 +3339,16 @@ namespace lime { void lime_text_event_manager_register (value callback, value eventObject) { - TextEvent::callback = new AutoGCRoot (callback); - TextEvent::eventObject = new AutoGCRoot (eventObject); + TextEvent::callback = new ValuePointer (callback); + TextEvent::eventObject = new ValuePointer (eventObject); } HL_PRIM void hl_lime_text_event_manager_register (vclosure* callback, HL_TextEvent* eventObject) { - // TextEvent::callback = new AutoGCRoot (callback); - // TextEvent::eventObject = new AutoGCRoot (eventObject); + TextEvent::callback = new ValuePointer (callback); + TextEvent::eventObject = new ValuePointer ((vobj*)eventObject); } @@ -3484,16 +3481,16 @@ namespace lime { void lime_touch_event_manager_register (value callback, value eventObject) { - TouchEvent::callback = new AutoGCRoot (callback); - TouchEvent::eventObject = new AutoGCRoot (eventObject); + TouchEvent::callback = new ValuePointer (callback); + TouchEvent::eventObject = new ValuePointer (eventObject); } HL_PRIM void hl_lime_touch_event_manager_register (vclosure* callback, HL_TouchEvent* eventObject) { - // TouchEvent::callback = new AutoGCRoot (callback); - // TouchEvent::eventObject = new AutoGCRoot (eventObject); + TouchEvent::callback = new ValuePointer (callback); + TouchEvent::eventObject = new ValuePointer ((vobj*)eventObject); } @@ -3548,16 +3545,16 @@ namespace lime { void lime_window_event_manager_register (value callback, value eventObject) { - WindowEvent::callback = new AutoGCRoot (callback); - WindowEvent::eventObject = new AutoGCRoot (eventObject); + WindowEvent::callback = new ValuePointer (callback); + WindowEvent::eventObject = new ValuePointer (eventObject); } HL_PRIM void hl_lime_window_event_manager_register (vclosure* callback, HL_WindowEvent* eventObject) { - // WindowEvent::callback = new AutoGCRoot (callback); - // WindowEvent::eventObject = new AutoGCRoot (eventObject); + WindowEvent::callback = new ValuePointer (callback); + WindowEvent::eventObject = new ValuePointer ((vobj*)eventObject); } @@ -4152,52 +4149,183 @@ namespace lime { #define _ENUM "?" - // #define TCFFIPOINTER _ABSTRACT (HL_CFFIPointer) - #define TCFFIPOINTER _DYN - #define TBYTES _OBJ (_I32 _BYTES) - #define TARRAYBUFFER TBYTES - #define TARRAYBUFFERVIEW _OBJ (_I32 TARRAYBUFFER _I32 _I32 _I32 _I32) - #define TIMAGEBUFFER _OBJ (_I32 TARRAYBUFFERVIEW _I32 _I32 _BOOL _BOOL _I32 _DYN _DYN _DYN _DYN _DYN _DYN) - #define TRECTANGLE _OBJ (_F64 _F64 _F64 _F64) - #define TIMAGE _OBJ (TIMAGEBUFFER _BOOL _I32 _I32 _I32 TRECTANGLE _ENUM _I32 _I32 _F64 _F64) - // #define TNATIVE_APPLICATION _ABSTRACT (Application) + // #define _TCFFIPOINTER _ABSTRACT (HL_CFFIPointer) + #define _TAPPLICATION_EVENT _OBJ (_I32 _I32) + #define _TARRAYBUFFER _TBYTES + #define _TBYTES _OBJ (_I32 _BYTES) + #define _TCFFIPOINTER _DYN + #define _TCLIPBOARD_EVENT _OBJ (_I32) + #define _TDROP_EVENT _OBJ (_STRING _I32) + #define _TGAMEPAD_EVENT _OBJ (_I32 _I32 _I32 _I32 _F64) + #define _TJOYSTICK_EVENT _OBJ (_I32 _I32 _I32 _I32 _F64 _F64) + #define _TKEY_EVENT _OBJ (_I32 _I32 _I32 _I32) + #define _TMOUSE_EVENT _OBJ (_I32 _F64 _F64 _I32 _I32 _F64 _F64) + #define _TRECTANGLE _OBJ (_F64 _F64 _F64 _F64) + #define _TRENDER_EVENT _OBJ (_ENUM _I32) + #define _TSENSOR_EVENT _OBJ (_I32 _F64 _F64 _F64 _I32) + #define _TTEXT_EVENT _OBJ (_I32 _I32 _I32 _STRING _I32 _I32) + #define _TTOUCH_EVENT _OBJ (_I32 _F64 _F64 _I32 _F64 _I32 _F64 _F64) + #define _TWINDOW_EVENT _OBJ (_I32 _I32 _I32 _I32 _I32 _I32) - DEFINE_HL_PRIM (TCFFIPOINTER, lime_application_create, _NO_ARG); - // DEFINE_PRIME2v (lime_application_event_manager_register); - DEFINE_HL_PRIM (_I32, lime_application_exec, TCFFIPOINTER); - DEFINE_HL_PRIM (_VOID, lime_application_init, TCFFIPOINTER); - DEFINE_HL_PRIM (_I32, lime_application_quit, TCFFIPOINTER); - DEFINE_HL_PRIM (_VOID, lime_application_set_frame_rate, TCFFIPOINTER _F64); - DEFINE_HL_PRIM (_BOOL, lime_application_update, TCFFIPOINTER); + #define _TARRAYBUFFERVIEW _OBJ (_I32 _TARRAYBUFFER _I32 _I32 _I32 _I32) + #define _TIMAGEBUFFER _OBJ (_I32 _TARRAYBUFFERVIEW _I32 _I32 _BOOL _BOOL _I32 _DYN _DYN _DYN _DYN _DYN _DYN) + #define _TIMAGE _OBJ (_TIMAGEBUFFER _BOOL _I32 _I32 _I32 _TRECTANGLE _ENUM _I32 _I32 _F64 _F64) + + + DEFINE_HL_PRIM (_TCFFIPOINTER, lime_application_create, _NO_ARG); + DEFINE_HL_PRIM (_VOID, lime_application_event_manager_register, _FUN(_VOID, _NO_ARG) _TAPPLICATION_EVENT); + DEFINE_HL_PRIM (_I32, lime_application_exec, _TCFFIPOINTER); + DEFINE_HL_PRIM (_VOID, lime_application_init, _TCFFIPOINTER); + DEFINE_HL_PRIM (_I32, lime_application_quit, _TCFFIPOINTER); + DEFINE_HL_PRIM (_VOID, lime_application_set_frame_rate, _TCFFIPOINTER _F64); + DEFINE_HL_PRIM (_BOOL, lime_application_update, _TCFFIPOINTER); + // DEFINE_PRIME2 (lime_audio_load); + // DEFINE_PRIME2 (lime_bytes_from_data_pointer); + // DEFINE_PRIME1 (lime_bytes_get_data_pointer); + // DEFINE_PRIME2 (lime_bytes_get_data_pointer_offset); + // DEFINE_PRIME2 (lime_bytes_read_file); + // DEFINE_PRIME1 (lime_cffi_get_native_pointer); + // DEFINE_PRIME1 (lime_cffi_set_finalizer); + DEFINE_HL_PRIM (_VOID, lime_clipboard_event_manager_register, _FUN(_VOID, _NO_ARG) _TCLIPBOARD_EVENT); + // DEFINE_PRIME0 (lime_clipboard_get_text); + // DEFINE_PRIME1v (lime_clipboard_set_text); + // DEFINE_PRIME2 (lime_data_pointer_offset); + // DEFINE_PRIME2 (lime_deflate_compress); + // DEFINE_PRIME2 (lime_deflate_decompress); + DEFINE_HL_PRIM (_VOID, lime_drop_event_manager_register, _FUN(_VOID, _NO_ARG) _TDROP_EVENT); + // DEFINE_PRIME3 (lime_file_dialog_open_directory); + // DEFINE_PRIME3 (lime_file_dialog_open_file); + // DEFINE_PRIME3 (lime_file_dialog_open_files); + // DEFINE_PRIME3 (lime_file_dialog_save_file); + // DEFINE_PRIME1 (lime_file_watcher_create); + // DEFINE_PRIME3 (lime_file_watcher_add_directory); + // DEFINE_PRIME2v (lime_file_watcher_remove_directory); + // DEFINE_PRIME1v (lime_file_watcher_update); + // DEFINE_PRIME1 (lime_font_get_ascender); + // DEFINE_PRIME1 (lime_font_get_descender); + // DEFINE_PRIME1 (lime_font_get_family_name); + // DEFINE_PRIME2 (lime_font_get_glyph_index); + // DEFINE_PRIME2 (lime_font_get_glyph_indices); + // DEFINE_PRIME2 (lime_font_get_glyph_metrics); + // DEFINE_PRIME1 (lime_font_get_height); + // DEFINE_PRIME1 (lime_font_get_num_glyphs); + // DEFINE_PRIME1 (lime_font_get_underline_position); + // DEFINE_PRIME1 (lime_font_get_underline_thickness); + // DEFINE_PRIME1 (lime_font_get_units_per_em); + // DEFINE_PRIME1 (lime_font_load); + // DEFINE_PRIME2 (lime_font_outline_decompose); + // DEFINE_PRIME3 (lime_font_render_glyph); + // DEFINE_PRIME3 (lime_font_render_glyphs); + // DEFINE_PRIME2v (lime_font_set_size); DEFINE_HL_PRIM (_VOID, lime_gamepad_add_mappings, _DYN); - DEFINE_HL_PRIM (_VOID, lime_image_data_util_fill_rect, TIMAGE TRECTANGLE _I32 _I32); - DEFINE_HL_PRIM (TCFFIPOINTER, lime_renderer_create, TCFFIPOINTER); - DEFINE_HL_PRIM (_VOID, lime_renderer_flip, TCFFIPOINTER); - DEFINE_HL_PRIM (_F64, lime_renderer_get_context, TCFFIPOINTER); - DEFINE_HL_PRIM (_F64, lime_renderer_get_scale, TCFFIPOINTER); - DEFINE_HL_PRIM (_BYTES, lime_renderer_get_type, TCFFIPOINTER); - DEFINE_HL_PRIM (_DYN, lime_renderer_lock, TCFFIPOINTER); - DEFINE_HL_PRIM (_VOID, lime_renderer_make_current, TCFFIPOINTER); - DEFINE_HL_PRIM (_DYN, lime_renderer_read_pixels, TCFFIPOINTER TRECTANGLE TIMAGEBUFFER); - DEFINE_HL_PRIM (_VOID, lime_renderer_unlock, TCFFIPOINTER); - DEFINE_HL_PRIM (_VOID, lime_window_alert, TCFFIPOINTER _BYTES _BYTES); - DEFINE_HL_PRIM (_VOID, lime_window_close, TCFFIPOINTER); - DEFINE_HL_PRIM (TCFFIPOINTER, lime_window_create, TCFFIPOINTER _I32 _I32 _I32 _STRING); - // DEFINE_PRIME2v (_VOID, lime_window_event_manager_register, TCFFIPOINTER ); - DEFINE_HL_PRIM (_VOID, lime_window_focus, TCFFIPOINTER); - DEFINE_HL_PRIM (_I32, lime_window_get_display, TCFFIPOINTER); + DEFINE_HL_PRIM (_VOID, lime_gamepad_event_manager_register, _FUN(_VOID, _NO_ARG) _TGAMEPAD_EVENT); + // DEFINE_PRIME1 (lime_gamepad_get_device_guid); + // DEFINE_PRIME1 (lime_gamepad_get_device_name); + // DEFINE_PRIME2 (lime_gzip_compress); + // DEFINE_PRIME2 (lime_gzip_decompress); + // DEFINE_PRIME2v (lime_haptic_vibrate); + // DEFINE_PRIME3v (lime_image_data_util_color_transform); + // DEFINE_PRIME6v (lime_image_data_util_copy_channel); + // DEFINE_PRIME7v (lime_image_data_util_copy_pixels); + DEFINE_HL_PRIM (_VOID, lime_image_data_util_fill_rect, _TIMAGE _TRECTANGLE _I32 _I32); + // DEFINE_PRIME5v (lime_image_data_util_flood_fill); + // DEFINE_PRIME4v (lime_image_data_util_get_pixels); + // DEFINE_PRIME8v (lime_image_data_util_merge); + // DEFINE_PRIME1v (lime_image_data_util_multiply_alpha); + // DEFINE_PRIME4v (lime_image_data_util_resize); + // DEFINE_PRIME2v (lime_image_data_util_set_format); + // DEFINE_PRIME6v (lime_image_data_util_set_pixels); + // DEFINE_PRIME12 (lime_image_data_util_threshold); + // DEFINE_PRIME1v (lime_image_data_util_unmultiply_alpha); + // DEFINE_PRIME4 (lime_image_encode); + // DEFINE_PRIME2 (lime_image_load); + // DEFINE_PRIME0 (lime_jni_getenv); + DEFINE_HL_PRIM (_VOID, lime_joystick_event_manager_register, _FUN(_VOID, _NO_ARG) _TJOYSTICK_EVENT); + // DEFINE_PRIME1 (lime_joystick_get_device_guid); + // DEFINE_PRIME1 (lime_joystick_get_device_name); + // DEFINE_PRIME1 (lime_joystick_get_num_axes); + // DEFINE_PRIME1 (lime_joystick_get_num_buttons); + // DEFINE_PRIME1 (lime_joystick_get_num_hats); + // DEFINE_PRIME1 (lime_joystick_get_num_trackballs); + // DEFINE_PRIME3 (lime_jpeg_decode_bytes); + // DEFINE_PRIME3 (lime_jpeg_decode_file); + // DEFINE_PRIME1 (lime_key_code_from_scan_code); + // DEFINE_PRIME1 (lime_key_code_to_scan_code); + DEFINE_HL_PRIM (_VOID, lime_key_event_manager_register, _FUN (_VOID, _NO_ARG) _TKEY_EVENT); + // DEFINE_PRIME0 (lime_locale_get_system_locale); + // DEFINE_PRIME2 (lime_lzma_compress); + // DEFINE_PRIME2 (lime_lzma_decompress); + DEFINE_HL_PRIM (_VOID, lime_mouse_event_manager_register, _FUN (_VOID, _NO_ARG) _TMOUSE_EVENT); + // DEFINE_PRIME0v (lime_mouse_hide); + // DEFINE_PRIME1v (lime_mouse_set_cursor); + // DEFINE_PRIME1v (lime_mouse_set_lock); + // DEFINE_PRIME0v (lime_mouse_show); + // DEFINE_PRIME3v (lime_mouse_warp); + // DEFINE_PRIME1v (lime_neko_execute); + // DEFINE_PRIME3 (lime_png_decode_bytes); + // DEFINE_PRIME3 (lime_png_decode_file); + DEFINE_HL_PRIM (_TCFFIPOINTER, lime_renderer_create, _TCFFIPOINTER); + DEFINE_HL_PRIM (_VOID, lime_renderer_flip, _TCFFIPOINTER); + DEFINE_HL_PRIM (_F64, lime_renderer_get_context, _TCFFIPOINTER); + DEFINE_HL_PRIM (_F64, lime_renderer_get_scale, _TCFFIPOINTER); + DEFINE_HL_PRIM (_BYTES, lime_renderer_get_type, _TCFFIPOINTER); + DEFINE_HL_PRIM (_DYN, lime_renderer_lock, _TCFFIPOINTER); + DEFINE_HL_PRIM (_VOID, lime_renderer_make_current, _TCFFIPOINTER); + DEFINE_HL_PRIM (_DYN, lime_renderer_read_pixels, _TCFFIPOINTER _TRECTANGLE _TIMAGEBUFFER); + DEFINE_HL_PRIM (_VOID, lime_renderer_unlock, _TCFFIPOINTER); + DEFINE_HL_PRIM (_VOID, lime_render_event_manager_register, _FUN (_VOID, _NO_ARG) _TRENDER_EVENT); + DEFINE_HL_PRIM (_VOID, lime_sensor_event_manager_register, _FUN (_VOID, _NO_ARG) _TSENSOR_EVENT); + // DEFINE_PRIME2v (lime_render_event_manager_register); + // DEFINE_PRIME2v (lime_sensor_event_manager_register); + // DEFINE_PRIME0 (lime_system_get_allow_screen_timeout); + // DEFINE_PRIME0 (lime_system_get_device_model); + // DEFINE_PRIME0 (lime_system_get_device_vendor); + // DEFINE_PRIME3 (lime_system_get_directory); + // DEFINE_PRIME1 (lime_system_get_display); + // DEFINE_PRIME0 (lime_system_get_ios_tablet); + // DEFINE_PRIME0 (lime_system_get_num_displays); + // DEFINE_PRIME0 (lime_system_get_platform_label); + // DEFINE_PRIME0 (lime_system_get_platform_name); + // DEFINE_PRIME0 (lime_system_get_platform_version); + // DEFINE_PRIME0 (lime_system_get_timer); + // DEFINE_PRIME1 (lime_system_get_windows_console_mode); + // DEFINE_PRIME1v (lime_system_open_file); + // DEFINE_PRIME2v (lime_system_open_url); + // DEFINE_PRIME1 (lime_system_set_allow_screen_timeout); + // DEFINE_PRIME2 (lime_system_set_windows_console_mode); + DEFINE_HL_PRIM (_VOID, lime_text_event_manager_register, _FUN (_VOID, _NO_ARG) _TTEXT_EVENT); + // DEFINE_PRIME3 (lime_text_layout_create); + // DEFINE_PRIME5 (lime_text_layout_position); + // DEFINE_PRIME2v (lime_text_layout_set_direction); + // DEFINE_PRIME2v (lime_text_layout_set_language); + // DEFINE_PRIME2v (lime_text_layout_set_script); + DEFINE_HL_PRIM (_VOID, lime_touch_event_manager_register, _FUN (_VOID, _NO_ARG) _TTOUCH_EVENT); + DEFINE_HL_PRIM (_VOID, lime_window_alert, _TCFFIPOINTER _BYTES _BYTES); + DEFINE_HL_PRIM (_VOID, lime_window_close, _TCFFIPOINTER); + DEFINE_HL_PRIM (_TCFFIPOINTER, lime_window_create, _TCFFIPOINTER _I32 _I32 _I32 _STRING); + DEFINE_HL_PRIM (_VOID, lime_window_event_manager_register, _FUN (_VOID, _NO_ARG) _TWINDOW_EVENT); + DEFINE_HL_PRIM (_VOID, lime_window_focus, _TCFFIPOINTER); + DEFINE_HL_PRIM (_I32, lime_window_get_display, _TCFFIPOINTER); // DEFINE_PRIME1 (lime_window_get_display_mode); - DEFINE_HL_PRIM (_BOOL, lime_window_get_enable_text_events, TCFFIPOINTER); - DEFINE_HL_PRIM (_I32, lime_window_get_height, TCFFIPOINTER); - DEFINE_HL_PRIM (_I32, lime_window_get_id, TCFFIPOINTER); - DEFINE_HL_PRIM (_I32, lime_window_get_width, TCFFIPOINTER); - DEFINE_HL_PRIM (_I32, lime_window_get_x, TCFFIPOINTER); - DEFINE_HL_PRIM (_I32, lime_window_get_y, TCFFIPOINTER); - DEFINE_HL_PRIM (_VOID, lime_window_move, TCFFIPOINTER _I32); - DEFINE_HL_PRIM (_VOID, lime_window_resize, TCFFIPOINTER _I32); - DEFINE_HL_PRIM (_BOOL, lime_window_set_borderless, TCFFIPOINTER _BOOL); - // DEFINE_PRIME2 (lime_window_set_display_mode, TCFFIPOINTER ); - DEFINE_HL_PRIM (_VOID, lime_window_set_enable_text_events, TCFFIPOINTER _BOOL); + DEFINE_HL_PRIM (_BOOL, lime_window_get_enable_text_events, _TCFFIPOINTER); + DEFINE_HL_PRIM (_I32, lime_window_get_height, _TCFFIPOINTER); + DEFINE_HL_PRIM (_I32, lime_window_get_id, _TCFFIPOINTER); + DEFINE_HL_PRIM (_I32, lime_window_get_width, _TCFFIPOINTER); + DEFINE_HL_PRIM (_I32, lime_window_get_x, _TCFFIPOINTER); + DEFINE_HL_PRIM (_I32, lime_window_get_y, _TCFFIPOINTER); + DEFINE_HL_PRIM (_VOID, lime_window_move, _TCFFIPOINTER _I32); + DEFINE_HL_PRIM (_VOID, lime_window_resize, _TCFFIPOINTER _I32); + DEFINE_HL_PRIM (_BOOL, lime_window_set_borderless, _TCFFIPOINTER _BOOL); + // DEFINE_PRIME2 (lime_window_set_display_mode, _TCFFIPOINTER ); + DEFINE_HL_PRIM (_VOID, lime_window_set_enable_text_events, _TCFFIPOINTER _BOOL); + // DEFINE_PRIME2 (lime_window_set_fullscreen); + // DEFINE_PRIME2v (lime_window_set_icon); + // DEFINE_PRIME2 (lime_window_set_maximized); + // DEFINE_PRIME2 (lime_window_set_minimized); + // DEFINE_PRIME2 (lime_window_set_resizable); + // DEFINE_PRIME2 (lime_window_set_title); + // DEFINE_PRIME2 (lime_zlib_compress); + // DEFINE_PRIME2 (lime_zlib_decompress); } diff --git a/project/src/app/ApplicationEvent.cpp b/project/src/app/ApplicationEvent.cpp index 1eacd0dd4..200b9049e 100644 --- a/project/src/app/ApplicationEvent.cpp +++ b/project/src/app/ApplicationEvent.cpp @@ -5,8 +5,8 @@ namespace lime { - AutoGCRoot* ApplicationEvent::callback = 0; - AutoGCRoot* ApplicationEvent::eventObject = 0; + ValuePointer* ApplicationEvent::callback = 0; + ValuePointer* ApplicationEvent::eventObject = 0; static int id_deltaTime; static int id_type; @@ -25,20 +25,31 @@ namespace lime { if (ApplicationEvent::callback) { - if (!init) { + if (ApplicationEvent::eventObject->IsCFFIValue ()) { - id_deltaTime = val_id ("deltaTime"); - id_type = val_id ("type"); - init = true; + if (!init) { + + id_deltaTime = val_id ("deltaTime"); + id_type = val_id ("type"); + init = true; + + } + + value object = (value)ApplicationEvent::eventObject->Get (); + + alloc_field (object, id_deltaTime, alloc_int (event->deltaTime)); + alloc_field (object, id_type, alloc_int (event->type)); + + } else { + + HL_ApplicationEvent* eventObject = (HL_ApplicationEvent*)ApplicationEvent::eventObject->Get (); + + eventObject->deltaTime = event->deltaTime; + eventObject->type = event->type; } - value object = (ApplicationEvent::eventObject ? ApplicationEvent::eventObject->get () : alloc_empty_object ()); - - alloc_field (object, id_deltaTime, alloc_int (event->deltaTime)); - alloc_field (object, id_type, alloc_int (event->type)); - - val_call0 (ApplicationEvent::callback->get ()); + ApplicationEvent::callback->Call (); } diff --git a/project/src/backend/sdl/SDLApplication.cpp b/project/src/backend/sdl/SDLApplication.cpp index 35a0e739d..2d8090c5d 100644 --- a/project/src/backend/sdl/SDLApplication.cpp +++ b/project/src/backend/sdl/SDLApplication.cpp @@ -17,7 +17,6 @@ namespace lime { AutoGCRoot* Application::callback = 0; SDLApplication* SDLApplication::currentApplication = 0; - const int analogAxisDeadZone = 1000; std::map > gamepadsAxisMap; bool inBackground = false; diff --git a/project/src/backend/sdl/SDLRenderer.cpp b/project/src/backend/sdl/SDLRenderer.cpp index 47351b37d..5a9bd6d54 100644 --- a/project/src/backend/sdl/SDLRenderer.cpp +++ b/project/src/backend/sdl/SDLRenderer.cpp @@ -191,7 +191,7 @@ namespace lime { } - value SDLRenderer::Lock () { + void* SDLRenderer::Lock (bool useCFFIValue) { if (sdlRenderer) { @@ -212,25 +212,52 @@ namespace lime { } - value result = alloc_empty_object (); - void *pixels; int pitch; - if (SDL_LockTexture (sdlTexture, NULL, &pixels, &pitch) == 0) { + if (useCFFIValue) { - alloc_field (result, val_id ("width"), alloc_int (width)); - alloc_field (result, val_id ("height"), alloc_int (height)); - alloc_field (result, val_id ("pixels"), alloc_float ((uintptr_t)pixels)); - alloc_field (result, val_id ("pitch"), alloc_int (pitch)); + value result = alloc_empty_object (); + + if (SDL_LockTexture (sdlTexture, NULL, &pixels, &pitch) == 0) { + + alloc_field (result, val_id ("width"), alloc_int (width)); + alloc_field (result, val_id ("height"), alloc_int (height)); + alloc_field (result, val_id ("pixels"), alloc_float ((uintptr_t)pixels)); + alloc_field (result, val_id ("pitch"), alloc_int (pitch)); + + } + + return result; + + } else { + + vdynamic* result = (vdynamic*)hl_alloc_dynobj (); + + if (SDL_LockTexture (sdlTexture, NULL, &pixels, &pitch) == 0) { + + hl_dyn_seti (result, hl_hash_utf8 ("width"), &hlt_i32, width); + hl_dyn_seti (result, hl_hash_utf8 ("height"), &hlt_i32, height); + hl_dyn_setd (result, hl_hash_utf8 ("pixels"), (uintptr_t)pixels); + hl_dyn_seti (result, hl_hash_utf8 ("pitch"), &hlt_i32, pitch); + + } + + return result; } - return result; - } else { - return alloc_null (); + if (useCFFIValue) { + + return alloc_null (); + + } else { + + return 0; + + } } diff --git a/project/src/backend/sdl/SDLRenderer.h b/project/src/backend/sdl/SDLRenderer.h index 735bdc916..b94dbd459 100644 --- a/project/src/backend/sdl/SDLRenderer.h +++ b/project/src/backend/sdl/SDLRenderer.h @@ -19,7 +19,7 @@ namespace lime { virtual void Flip (); virtual void* GetContext (); virtual double GetScale (); - virtual value Lock (); + virtual void* Lock (bool useCFFIValue); virtual void MakeCurrent (); virtual void ReadPixels (ImageBuffer *buffer, Rectangle *rect); virtual const char* Type (); diff --git a/project/src/graphics/RenderEvent.cpp b/project/src/graphics/RenderEvent.cpp index 37d42a59a..2658ae9fc 100644 --- a/project/src/graphics/RenderEvent.cpp +++ b/project/src/graphics/RenderEvent.cpp @@ -5,11 +5,11 @@ namespace lime { - AutoGCRoot* RenderEvent::callback = 0; - AutoGCRoot* RenderEvent::eventObject = 0; + ValuePointer* RenderEvent::callback = 0; + ValuePointer* RenderEvent::eventObject = 0; - //static int id_type; - //static bool init = false; + static int id_type; + static bool init = false; RenderEvent::RenderEvent () { @@ -23,17 +23,27 @@ namespace lime { if (RenderEvent::callback) { - //if (!init) { + if (RenderEvent::eventObject->IsCFFIValue ()) { - //id_type = val_id ("type"); + if (!init) { + + id_type = val_id ("type"); + + } - //} + value object = (value)RenderEvent::eventObject->Get (); + + alloc_field (object, id_type, alloc_int (event->type)); + + } else { + + HL_RenderEvent* eventObject = (HL_RenderEvent*)RenderEvent::eventObject->Get (); + + eventObject->type = event->type; + + } - value object = (RenderEvent::eventObject ? RenderEvent::eventObject->get () : alloc_empty_object ()); - - //alloc_field (object, id_type, alloc_int (event->type)); - - val_call0 (RenderEvent::callback->get ()); + RenderEvent::callback->Call (); } diff --git a/project/src/graphics/cairo/CairoBindings.cpp b/project/src/graphics/cairo/CairoBindings.cpp index 65e6445f2..f14f68887 100644 --- a/project/src/graphics/cairo/CairoBindings.cpp +++ b/project/src/graphics/cairo/CairoBindings.cpp @@ -1,3 +1,6 @@ +#define HL_NAME(n) hl_##n +#include + #include #include #include @@ -36,6 +39,16 @@ namespace lime { } + void hl_gc_cairo (cairo_t* cairo) { + + // cairoObjects_Mutex.Lock (); + // cairoObjects.erase (cairo); + // cairoObjects_Mutex.Unlock (); + cairo_destroy (cairo); + + } + + void gc_cairo_font_face (value handle) { if (!val_is_null (handle)) { @@ -93,6 +106,16 @@ namespace lime { } + void hl_gc_cairo_surface (cairo_surface_t* surface) { + + // cairoObjects_Mutex.Lock (); + // cairoObjects.erase (surface); + // cairoObjects_Mutex.Unlock (); + cairo_surface_destroy (surface); + + } + + void gc_user_data (void* data) { AutoGCRoot* reference = (AutoGCRoot*)data; @@ -163,6 +186,19 @@ namespace lime { } + HL_PRIM HL_CFFIPointer* hl_lime_cairo_create (HL_CFFIPointer* surface) { + + cairo_t* cairo = cairo_create ((cairo_surface_t*)surface->ptr); + + HL_CFFIPointer* object = HLCFFIPointer (cairo, (hl_finalizer)hl_gc_cairo); + // cairoObjects_Mutex.Lock (); + // cairoObjects[cairo] = object; + // cairoObjects_Mutex.Unlock (); + return object; + + } + + void lime_cairo_curve_to (value handle, double x1, double y1, double x2, double y2, double x3, double y3) { cairo_curve_to ((cairo_t*)val_data (handle), x1, y1, x2, y2, x3, y3); @@ -530,6 +566,19 @@ namespace lime { } + HL_PRIM HL_CFFIPointer* hl_lime_cairo_image_surface_create_for_data (double data, int format, int width, int height, int stride) { + + cairo_surface_t* surface = cairo_image_surface_create_for_data ((unsigned char*)(uintptr_t)data, (cairo_format_t)format, width, height, stride); + + HL_CFFIPointer* object = HLCFFIPointer (surface, (hl_finalizer)hl_gc_cairo_surface); + // cairoObjects_Mutex.Lock (); + // cairoObjects[surface] = object; + // cairoObjects_Mutex.Unlock (); + return object; + + } + + double lime_cairo_image_surface_get_data (value handle) { return (uintptr_t)cairo_image_surface_get_data ((cairo_surface_t*)val_data (handle)); @@ -628,6 +677,13 @@ namespace lime { } + HL_PRIM void hl_lime_cairo_paint (HL_CFFIPointer* handle) { + + cairo_paint ((cairo_t*)handle->ptr); + + } + + void lime_cairo_paint_with_alpha (value handle, double alpha) { cairo_paint_with_alpha ((cairo_t*)val_data (handle), alpha); @@ -1025,6 +1081,13 @@ namespace lime { } + HL_PRIM void hl_lime_cairo_set_source_rgb (HL_CFFIPointer* handle, double r, double g, double b) { + + cairo_set_source_rgb ((cairo_t*)handle->ptr, r, g, b); + + } + + void lime_cairo_set_source_rgba (value handle, double r, double g, double b, double a) { cairo_set_source_rgba ((cairo_t*)val_data (handle), r, g, b, a); @@ -1125,6 +1188,13 @@ namespace lime { } + HL_PRIM void hl_lime_cairo_surface_flush (HL_CFFIPointer* handle) { + + cairo_surface_flush ((cairo_surface_t*)handle->ptr); + + } + + void lime_cairo_text_path (value handle, HxString text) { cairo_text_path ((cairo_t*)val_data (handle), (char*)text.__s); @@ -1285,6 +1355,15 @@ namespace lime { DEFINE_PRIME0 (lime_cairo_version_string); + #define _TCFFIPOINTER _DYN + + DEFINE_HL_PRIM (_TCFFIPOINTER, lime_cairo_create, _TCFFIPOINTER); + DEFINE_HL_PRIM (_TCFFIPOINTER, lime_cairo_image_surface_create_for_data, _F64 _I32 _I32 _I32 _I32); + DEFINE_HL_PRIM (_VOID, lime_cairo_set_source_rgb, _TCFFIPOINTER _F64 _F64 _F64); + DEFINE_HL_PRIM (_VOID, lime_cairo_surface_flush, _TCFFIPOINTER); + DEFINE_HL_PRIM (_VOID, lime_cairo_paint, _TCFFIPOINTER); + + } diff --git a/project/src/system/ClipboardEvent.cpp b/project/src/system/ClipboardEvent.cpp index 5003ffd8d..9c090ba0a 100644 --- a/project/src/system/ClipboardEvent.cpp +++ b/project/src/system/ClipboardEvent.cpp @@ -5,8 +5,8 @@ namespace lime { - AutoGCRoot* ClipboardEvent::callback = 0; - AutoGCRoot* ClipboardEvent::eventObject = 0; + ValuePointer* ClipboardEvent::callback = 0; + ValuePointer* ClipboardEvent::eventObject = 0; static int id_type; static bool init = false; @@ -23,18 +23,28 @@ namespace lime { if (ClipboardEvent::callback) { - if (!init) { + if (ClipboardEvent::eventObject->IsCFFIValue ()) { - id_type = val_id ("type"); - init = true; + if (!init) { + + id_type = val_id ("type"); + init = true; + + } + + value object = (value)ClipboardEvent::eventObject->Get (); + + alloc_field (object, id_type, alloc_int (event->type)); + + } else { + + HL_ClipboardEvent* eventObject = (HL_ClipboardEvent*)ClipboardEvent::eventObject->Get (); + + eventObject->type = event->type; } - value object = (ClipboardEvent::eventObject ? ClipboardEvent::eventObject->get () : alloc_empty_object ()); - - alloc_field (object, id_type, alloc_int (event->type)); - - val_call0 (ClipboardEvent::callback->get ()); + ClipboardEvent::callback->Call (); } diff --git a/project/src/system/SensorEvent.cpp b/project/src/system/SensorEvent.cpp index 3327135f0..232497b7d 100644 --- a/project/src/system/SensorEvent.cpp +++ b/project/src/system/SensorEvent.cpp @@ -5,8 +5,8 @@ namespace lime { - AutoGCRoot* SensorEvent::callback = 0; - AutoGCRoot* SensorEvent::eventObject = 0; + ValuePointer* SensorEvent::callback = 0; + ValuePointer* SensorEvent::eventObject = 0; static int id_id; static int id_type; @@ -31,26 +31,40 @@ namespace lime { if (SensorEvent::callback) { - if (!init) { + if (SensorEvent::eventObject->IsCFFIValue ()) { - id_id = val_id ("id"); - id_type = val_id ("type"); - id_x = val_id ("x"); - id_y = val_id ("y"); - id_z = val_id ("z"); - init = true; + if (!init) { + + id_id = val_id ("id"); + id_type = val_id ("type"); + id_x = val_id ("x"); + id_y = val_id ("y"); + id_z = val_id ("z"); + init = true; + + } + + value object = (value)SensorEvent::eventObject->Get (); + + alloc_field (object, id_id, alloc_int (event->id)); + alloc_field (object, id_type, alloc_int (event->type)); + alloc_field (object, id_x, alloc_float (event->x)); + alloc_field (object, id_y, alloc_float (event->y)); + alloc_field (object, id_z, alloc_float (event->z)); + + } else { + + HL_SensorEvent* eventObject = (HL_SensorEvent*)SensorEvent::eventObject->Get (); + + eventObject->id = event->id; + eventObject->type = event->type; + eventObject->x = event->x; + eventObject->y = event->y; + eventObject->z = event->z; } - value object = (SensorEvent::eventObject ? SensorEvent::eventObject->get () : alloc_empty_object ()); - - alloc_field (object, id_id, alloc_int (event->id)); - alloc_field (object, id_type, alloc_int (event->type)); - alloc_field (object, id_x, alloc_float (event->x)); - alloc_field (object, id_y, alloc_float (event->y)); - alloc_field (object, id_z, alloc_float (event->z)); - - val_call0 (SensorEvent::callback->get ()); + SensorEvent::callback->Call (); } diff --git a/project/src/system/ValuePointer.cpp b/project/src/system/ValuePointer.cpp new file mode 100644 index 000000000..775847230 --- /dev/null +++ b/project/src/system/ValuePointer.cpp @@ -0,0 +1,160 @@ +#include +#include + + +namespace lime { + + + ValuePointer::ValuePointer (value handle) { + + cffiRoot = 0; + cffiValue = alloc_root (); + + if (cffiValue) { + + *cffiValue = handle; + + } else { + + cffiRoot = create_root (handle); + + } + + hlValue = 0; + + } + + + ValuePointer::ValuePointer (vobj* handle) { + + hlValue = handle; + hl_add_root (&hlValue); + + cffiRoot = 0; + cffiValue = 0; + + } + + + ValuePointer::ValuePointer (vdynamic* handle) { + + hlValue = (vobj*)handle; + hl_add_root (&hlValue); + + cffiRoot = 0; + cffiValue = 0; + + } + + + ValuePointer::ValuePointer (vclosure* callback) { + + hlValue = (vobj*)callback; + hl_add_root (&hlValue); + + cffiRoot = 0; + cffiValue = 0; + + } + + + ValuePointer::~ValuePointer () { + + if (cffiValue) { + + free_root (cffiValue); + + } else if (cffiRoot) { + + destroy_root (cffiRoot); + + } else if (hlValue) { + + hl_remove_root (&hlValue); + + } + + } + + + void* ValuePointer::Call () { + + if (!hlValue) { + + return val_call0 ((value)Get ()); + + } else { + + return hl_dyn_call ((vclosure*)hlValue, 0, 0); + + } + + } + + + void* ValuePointer::Call (void* arg0) { return 0; } + void* ValuePointer::Call (void* arg0, void* arg1) { return 0; } + void* ValuePointer::Call (void* arg0, void* arg1, void* arg2) { return 0; } + void* ValuePointer::Call (void* arg0, void* arg1, void* arg2, void* arg3) { return 0; } + void* ValuePointer::Call (void* arg0, void* arg1, void* arg2, void* arg3, void* arg4) { return 0; } + + + void* ValuePointer::Get () const { + + if (cffiValue) { + + return *cffiValue; + + } else if (cffiRoot) { + + return query_root (cffiRoot); + + } else if (hlValue) { + + return hlValue; + + } + + return 0; + + } + + + bool ValuePointer::IsCFFIValue () { + + return hlValue == 0; + + } + + + bool ValuePointer::IsHLValue () { + + return hlValue != 0; + + } + + + void ValuePointer::Set (value handle) { + + if (cffiValue) { + + *cffiValue = handle; + + } else { + + if (cffiRoot) destroy_root (cffiRoot); + cffiRoot = create_root (handle); + + } + + } + + + void ValuePointer::Set (vobj* handle) { + + hlValue = handle; + + } + + +} \ No newline at end of file diff --git a/project/src/ui/DropEvent.cpp b/project/src/ui/DropEvent.cpp index 7204f80c7..0039f3def 100644 --- a/project/src/ui/DropEvent.cpp +++ b/project/src/ui/DropEvent.cpp @@ -5,8 +5,8 @@ namespace lime { - AutoGCRoot* DropEvent::callback = 0; - AutoGCRoot* DropEvent::eventObject = 0; + ValuePointer* DropEvent::callback = 0; + ValuePointer* DropEvent::eventObject = 0; static int id_file; static int id_type; @@ -25,20 +25,32 @@ namespace lime { if (DropEvent::callback) { - if (!init) { + if (DropEvent::eventObject->IsCFFIValue ()) { - id_file = val_id ("file"); - id_type = val_id ("type"); - init = true; + if (!init) { + + id_file = val_id ("file"); + id_type = val_id ("type"); + init = true; + + } + + value object = (value)DropEvent::eventObject->Get (); + + alloc_field (object, id_file, alloc_string (event->file)); + alloc_field (object, id_type, alloc_int (event->type)); + + } else { + + HL_DropEvent* eventObject = (HL_DropEvent*)DropEvent::eventObject->Get (); + + // TODO + // eventObject->file = event->file; + eventObject->type = event->type; } - value object = (DropEvent::eventObject ? DropEvent::eventObject->get () : alloc_empty_object ()); - - alloc_field (object, id_file, alloc_string (event->file)); - alloc_field (object, id_type, alloc_int (event->type)); - - val_call0 (DropEvent::callback->get ()); + DropEvent::callback->Call (); } diff --git a/project/src/ui/GamepadEvent.cpp b/project/src/ui/GamepadEvent.cpp index 60e0999b1..ea1f1000b 100644 --- a/project/src/ui/GamepadEvent.cpp +++ b/project/src/ui/GamepadEvent.cpp @@ -5,8 +5,8 @@ namespace lime { - AutoGCRoot* GamepadEvent::callback = 0; - AutoGCRoot* GamepadEvent::eventObject = 0; + ValuePointer* GamepadEvent::callback = 0; + ValuePointer* GamepadEvent::eventObject = 0; static double id_axis; static int id_button; @@ -31,26 +31,40 @@ namespace lime { if (GamepadEvent::callback) { - if (!init) { + if (GamepadEvent::eventObject->IsCFFIValue ()) { - id_axis = val_id ("axis"); - id_button = val_id ("button"); - id_id = val_id ("id"); - id_type = val_id ("type"); - id_value = val_id ("value"); - init = true; + if (!init) { + + id_axis = val_id ("axis"); + id_button = val_id ("button"); + id_id = val_id ("id"); + id_type = val_id ("type"); + id_value = val_id ("value"); + init = true; + + } + + value object = (value)GamepadEvent::eventObject->Get (); + + alloc_field (object, id_axis, alloc_int (event->axis)); + alloc_field (object, id_button, alloc_int (event->button)); + alloc_field (object, id_id, alloc_int (event->id)); + alloc_field (object, id_type, alloc_int (event->type)); + alloc_field (object, id_value, alloc_float (event->axisValue)); + + } else { + + HL_GamepadEvent* eventObject = (HL_GamepadEvent*)GamepadEvent::eventObject->Get (); + + eventObject->axis = event->axis; + eventObject->button = event->button; + eventObject->id = event->id; + eventObject->type = event->type; + eventObject->value = event->axisValue; } - value object = (GamepadEvent::eventObject ? GamepadEvent::eventObject->get () : alloc_empty_object ()); - - alloc_field (object, id_axis, alloc_int (event->axis)); - alloc_field (object, id_button, alloc_int (event->button)); - alloc_field (object, id_id, alloc_int (event->id)); - alloc_field (object, id_type, alloc_int (event->type)); - alloc_field (object, id_value, alloc_float (event->axisValue)); - - val_call0 (GamepadEvent::callback->get ()); + GamepadEvent::callback->Call (); } diff --git a/project/src/ui/JoystickEvent.cpp b/project/src/ui/JoystickEvent.cpp index d61201afa..89aec6075 100644 --- a/project/src/ui/JoystickEvent.cpp +++ b/project/src/ui/JoystickEvent.cpp @@ -5,8 +5,8 @@ namespace lime { - AutoGCRoot* JoystickEvent::callback = 0; - AutoGCRoot* JoystickEvent::eventObject = 0; + ValuePointer* JoystickEvent::callback = 0; + ValuePointer* JoystickEvent::eventObject = 0; static int id_id; static int id_index; @@ -33,28 +33,43 @@ namespace lime { if (JoystickEvent::callback) { - if (!init) { + if (JoystickEvent::eventObject->IsCFFIValue ()) { - id_id = val_id ("id"); - id_index = val_id ("index"); - id_type = val_id ("type"); - id_value = val_id ("value"); - id_x = val_id ("x"); - id_y = val_id ("y"); - init = true; + if (!init) { + + id_id = val_id ("id"); + id_index = val_id ("index"); + id_type = val_id ("type"); + id_value = val_id ("value"); + id_x = val_id ("x"); + id_y = val_id ("y"); + init = true; + + } + + value object = (value)JoystickEvent::eventObject->Get (); + + alloc_field (object, id_id, alloc_int (event->id)); + alloc_field (object, id_index, alloc_int (event->index)); + alloc_field (object, id_type, alloc_int (event->type)); + alloc_field (object, id_value, alloc_int (event->eventValue)); + alloc_field (object, id_x, alloc_float (event->x)); + alloc_field (object, id_y, alloc_float (event->y)); + + } else { + + HL_JoystickEvent* eventObject = (HL_JoystickEvent*)JoystickEvent::eventObject->Get (); + + eventObject->id = event->id; + eventObject->index = event->index; + eventObject->type = event->type; + eventObject->value = event->eventValue; + eventObject->x = event->x; + eventObject->y = event->y; } - value object = (JoystickEvent::eventObject ? JoystickEvent::eventObject->get () : alloc_empty_object ()); - - alloc_field (object, id_id, alloc_int (event->id)); - alloc_field (object, id_index, alloc_int (event->index)); - alloc_field (object, id_type, alloc_int (event->type)); - alloc_field (object, id_value, alloc_int (event->eventValue)); - alloc_field (object, id_x, alloc_float (event->x)); - alloc_field (object, id_y, alloc_float (event->y)); - - val_call0 (JoystickEvent::callback->get ()); + JoystickEvent::callback->Call (); } diff --git a/project/src/ui/KeyEvent.cpp b/project/src/ui/KeyEvent.cpp index 4804f1023..12839e009 100644 --- a/project/src/ui/KeyEvent.cpp +++ b/project/src/ui/KeyEvent.cpp @@ -5,8 +5,8 @@ namespace lime { - AutoGCRoot* KeyEvent::callback = 0; - AutoGCRoot* KeyEvent::eventObject = 0; + ValuePointer* KeyEvent::callback = 0; + ValuePointer* KeyEvent::eventObject = 0; static double id_keyCode; static int id_modifier; @@ -29,24 +29,37 @@ namespace lime { if (KeyEvent::callback) { - if (!init) { + if (KeyEvent::eventObject->IsCFFIValue ()) { - id_keyCode = val_id ("keyCode"); - id_modifier = val_id ("modifier"); - id_type = val_id ("type"); - id_windowID = val_id ("windowID"); - init = true; + if (!init) { + + id_keyCode = val_id ("keyCode"); + id_modifier = val_id ("modifier"); + id_type = val_id ("type"); + id_windowID = val_id ("windowID"); + init = true; + + } + + value object = (value)KeyEvent::eventObject->Get (); + + alloc_field (object, id_keyCode, alloc_float (event->keyCode)); + alloc_field (object, id_modifier, alloc_int (event->modifier)); + alloc_field (object, id_type, alloc_int (event->type)); + alloc_field (object, id_windowID, alloc_int (event->windowID)); + + } else { + + HL_KeyEvent* eventObject = (HL_KeyEvent*)KeyEvent::eventObject->Get (); + + eventObject->keyCode = event->keyCode; + eventObject->modifier = event->modifier; + eventObject->type = event->type; + eventObject->windowID = event->windowID; } - value object = (KeyEvent::eventObject ? KeyEvent::eventObject->get () : alloc_empty_object ()); - - alloc_field (object, id_keyCode, alloc_float (event->keyCode)); - alloc_field (object, id_modifier, alloc_int (event->modifier)); - alloc_field (object, id_type, alloc_int (event->type)); - alloc_field (object, id_windowID, alloc_int (event->windowID)); - - val_call0 (KeyEvent::callback->get ()); + KeyEvent::callback->Call (); } diff --git a/project/src/ui/MouseEvent.cpp b/project/src/ui/MouseEvent.cpp index 0ee8a1b60..9cd2ada43 100644 --- a/project/src/ui/MouseEvent.cpp +++ b/project/src/ui/MouseEvent.cpp @@ -5,8 +5,8 @@ namespace lime { - AutoGCRoot* MouseEvent::callback = 0; - AutoGCRoot* MouseEvent::eventObject = 0; + ValuePointer* MouseEvent::callback = 0; + ValuePointer* MouseEvent::eventObject = 0; static int id_button; static int id_movementX; @@ -35,35 +35,50 @@ namespace lime { if (MouseEvent::callback) { - if (!init) { + if (MouseEvent::eventObject->IsCFFIValue ()) { - id_button = val_id ("button"); - id_movementX = val_id ("movementX"); - id_movementY = val_id ("movementY"); - id_type = val_id ("type"); - id_windowID = val_id ("windowID"); - id_x = val_id ("x"); - id_y = val_id ("y"); - init = true; + if (!init) { + + id_button = val_id ("button"); + id_movementX = val_id ("movementX"); + id_movementY = val_id ("movementY"); + id_type = val_id ("type"); + id_windowID = val_id ("windowID"); + id_x = val_id ("x"); + id_y = val_id ("y"); + init = true; + + } + + value object = (value)MouseEvent::eventObject->Get (); + + if (event->type != MOUSE_WHEEL) { + + alloc_field (object, id_button, alloc_int (event->button)); + + } + + alloc_field (object, id_movementX, alloc_float (event->movementX)); + alloc_field (object, id_movementY, alloc_float (event->movementY)); + alloc_field (object, id_type, alloc_int (event->type)); + alloc_field (object, id_windowID, alloc_int (event->windowID)); + alloc_field (object, id_x, alloc_float (event->x)); + alloc_field (object, id_y, alloc_float (event->y)); + + } else { + + HL_MouseEvent* eventObject = (HL_MouseEvent*)MouseEvent::eventObject->Get (); + + eventObject->movementX = event->movementX; + eventObject->movementY = event->movementY; + eventObject->type = event->type; + eventObject->windowID = event->windowID; + eventObject->x = event->x; + eventObject->y = event->y; } - value object = (MouseEvent::eventObject ? MouseEvent::eventObject->get () : alloc_empty_object ()); - - if (event->type != MOUSE_WHEEL) { - - alloc_field (object, id_button, alloc_int (event->button)); - - } - - alloc_field (object, id_movementX, alloc_float (event->movementX)); - alloc_field (object, id_movementY, alloc_float (event->movementY)); - alloc_field (object, id_type, alloc_int (event->type)); - alloc_field (object, id_windowID, alloc_int (event->windowID)); - alloc_field (object, id_x, alloc_float (event->x)); - alloc_field (object, id_y, alloc_float (event->y)); - - val_call0 (MouseEvent::callback->get ()); + MouseEvent::callback->Call (); } diff --git a/project/src/ui/TextEvent.cpp b/project/src/ui/TextEvent.cpp index 5aa0af221..cb4fb62ca 100644 --- a/project/src/ui/TextEvent.cpp +++ b/project/src/ui/TextEvent.cpp @@ -5,8 +5,8 @@ namespace lime { - AutoGCRoot* TextEvent::callback = 0; - AutoGCRoot* TextEvent::eventObject = 0; + ValuePointer* TextEvent::callback = 0; + ValuePointer* TextEvent::eventObject = 0; static int id_length; static int id_start; @@ -29,31 +29,51 @@ namespace lime { if (TextEvent::callback) { - if (!init) { + if (TextEvent::eventObject->IsCFFIValue ()) { - id_length = val_id ("length"); - id_start = val_id ("start"); - id_text = val_id ("text"); - id_type = val_id ("type"); - id_windowID = val_id ("windowID"); - init = true; + if (!init) { + + id_length = val_id ("length"); + id_start = val_id ("start"); + id_text = val_id ("text"); + id_type = val_id ("type"); + id_windowID = val_id ("windowID"); + init = true; + + } + + value object = (value)TextEvent::eventObject->Get (); + + 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)); + alloc_field (object, id_windowID, alloc_int (event->windowID)); + + } else { + + HL_TextEvent* eventObject = (HL_TextEvent*)TextEvent::eventObject->Get (); + + if (event->type != TEXT_INPUT) { + + eventObject->length = event->length; + eventObject->start = event->start; + + } + + // TODO + //eventObject->text = event->text; + eventObject->type = event->type; + eventObject->windowID = event->windowID; } - 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)); - alloc_field (object, id_windowID, alloc_int (event->windowID)); - - val_call0 (TextEvent::callback->get ()); + TextEvent::callback->Call (); } diff --git a/project/src/ui/TouchEvent.cpp b/project/src/ui/TouchEvent.cpp index 23bac483b..639a05180 100644 --- a/project/src/ui/TouchEvent.cpp +++ b/project/src/ui/TouchEvent.cpp @@ -5,8 +5,8 @@ namespace lime { - AutoGCRoot* TouchEvent::callback = 0; - AutoGCRoot* TouchEvent::eventObject = 0; + ValuePointer* TouchEvent::callback = 0; + ValuePointer* TouchEvent::eventObject = 0; static int id_device; static int id_dx; @@ -37,32 +37,49 @@ namespace lime { if (TouchEvent::callback) { - if (!init) { + if (TouchEvent::eventObject->IsCFFIValue ()) { - id_device = val_id ("device"); - id_dx = val_id ("dx"); - id_dy = val_id ("dy"); - id_id = val_id ("id"); - id_pressure = val_id ("pressure"); - id_type = val_id ("type"); - id_x = val_id ("x"); - id_y = val_id ("y"); - init = true; + if (!init) { + + id_device = val_id ("device"); + id_dx = val_id ("dx"); + id_dy = val_id ("dy"); + id_id = val_id ("id"); + id_pressure = val_id ("pressure"); + id_type = val_id ("type"); + id_x = val_id ("x"); + id_y = val_id ("y"); + init = true; + + } + + value object = (value)TouchEvent::eventObject->Get (); + + alloc_field (object, id_device, alloc_int (event->device)); + alloc_field (object, id_dx, alloc_float (event->dx)); + alloc_field (object, id_dy, alloc_float (event->dy)); + alloc_field (object, id_id, alloc_int (event->id)); + alloc_field (object, id_pressure, alloc_float (event->pressure)); + alloc_field (object, id_type, alloc_int (event->type)); + alloc_field (object, id_x, alloc_float (event->x)); + alloc_field (object, id_y, alloc_float (event->y)); + + } else { + + HL_TouchEvent* eventObject = (HL_TouchEvent*)TouchEvent::eventObject->Get (); + + eventObject->device = event->device; + eventObject->dx = event->dx; + eventObject->dy = event->dy; + eventObject->id = event->id; + eventObject->pressure = event->pressure; + eventObject->type = event->type; + eventObject->x = event->x; + eventObject->y = event->y; } - value object = (TouchEvent::eventObject ? TouchEvent::eventObject->get () : alloc_empty_object ()); - - alloc_field (object, id_device, alloc_int (event->device)); - alloc_field (object, id_dx, alloc_float (event->dx)); - alloc_field (object, id_dy, alloc_float (event->dy)); - alloc_field (object, id_id, alloc_int (event->id)); - alloc_field (object, id_pressure, alloc_float (event->pressure)); - alloc_field (object, id_type, alloc_int (event->type)); - alloc_field (object, id_x, alloc_float (event->x)); - alloc_field (object, id_y, alloc_float (event->y)); - - val_call0 (TouchEvent::callback->get ()); + TouchEvent::callback->Call (); } diff --git a/project/src/ui/WindowEvent.cpp b/project/src/ui/WindowEvent.cpp index befa0994a..6bde2e862 100644 --- a/project/src/ui/WindowEvent.cpp +++ b/project/src/ui/WindowEvent.cpp @@ -5,8 +5,8 @@ namespace lime { - AutoGCRoot* WindowEvent::callback = 0; - AutoGCRoot* WindowEvent::eventObject = 0; + ValuePointer* WindowEvent::callback = 0; + ValuePointer* WindowEvent::eventObject = 0; static int id_height; static int id_type; @@ -34,42 +34,71 @@ namespace lime { if (WindowEvent::callback) { - if (!init) { + if (WindowEvent::eventObject->IsCFFIValue ()) { - id_height = val_id ("height"); - id_type = val_id ("type"); - id_width = val_id ("width"); - id_windowID = val_id ("windowID"); - id_x = val_id ("x"); - id_y = val_id ("y"); - init = true; + if (!init) { + + id_height = val_id ("height"); + id_type = val_id ("type"); + id_width = val_id ("width"); + id_windowID = val_id ("windowID"); + id_x = val_id ("x"); + id_y = val_id ("y"); + init = true; + + } + + value object = (value)WindowEvent::eventObject->Get (); + + alloc_field (object, id_type, alloc_int (event->type)); + alloc_field (object, id_windowID, alloc_int (event->windowID)); + + switch (event->type) { + + case WINDOW_MOVE: + + alloc_field (object, id_x, alloc_int (event->x)); + alloc_field (object, id_y, alloc_int (event->y)); + break; + + case WINDOW_RESIZE: + + alloc_field (object, id_width, alloc_int (event->width)); + alloc_field (object, id_height, alloc_int (event->height)); + break; + + default: break; + + } + + } else { + + HL_WindowEvent* eventObject = (HL_WindowEvent*)WindowEvent::eventObject->Get (); + + eventObject->type = event->type; + eventObject->windowID = event->windowID; + + switch (event->type) { + + case WINDOW_MOVE: + + eventObject->x = event->x; + eventObject->y = event->y; + break; + + case WINDOW_RESIZE: + + eventObject->width = event->width; + eventObject->height = event->height; + break; + + default: break; + + } } - value object = (WindowEvent::eventObject ? WindowEvent::eventObject->get () : alloc_empty_object ()); - - alloc_field (object, id_type, alloc_int (event->type)); - alloc_field (object, id_windowID, alloc_int (event->windowID)); - - switch (event->type) { - - case WINDOW_MOVE: - - alloc_field (object, id_x, alloc_int (event->x)); - alloc_field (object, id_y, alloc_int (event->y)); - break; - - case WINDOW_RESIZE: - - alloc_field (object, id_width, alloc_int (event->width)); - alloc_field (object, id_height, alloc_int (event->height)); - break; - - default: break; - - } - - val_call0 (WindowEvent::callback->get ()); + WindowEvent::callback->Call (); }