diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2011-04-21 11:57:28 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2011-04-21 11:57:28 +0200 |
commit | eca9cca97c1389804e9ad325d4cf878d0dbc9259 (patch) | |
tree | 0de5e0cf267f480d3de7261d308454ce8e61790a /lib/efl | |
parent | a84f1bbae4dd2053f19dc8c82cc54bd5e57553f3 (diff) | |
download | ffi-efl-eca9cca97c1389804e9ad325d4cf878d0dbc9259.zip ffi-efl-eca9cca97c1389804e9ad325d4cf878d0dbc9259.tar.gz |
update Evas and EvasObject classes, start specs
Diffstat (limited to 'lib/efl')
-rw-r--r-- | lib/efl/evas.rb | 129 |
1 files changed, 62 insertions, 67 deletions
diff --git a/lib/efl/evas.rb b/lib/efl/evas.rb index 8999245..b3df675 100644 --- a/lib/efl/evas.rb +++ b/lib/efl/evas.rb @@ -7,38 +7,43 @@ module Efl module Evas # class Evas - def initialize; @ptr = Efl::API.evas_new; end - def free; Efl::API.evas_free @ptr; @ptr=nil; end - def focus_in; Efl::API.evas_focus_in @ptr; end - def focus_out; Efl::API.evas_focus_out @ptr; end - def focus_state_get; Efl::API.evas_focus_state_get @ptr; end - def nochange_push; Efl::API.evas_nochange_push @ptr; end - def nochange_pop; Efl::API.evas_nochange_pop @ptr; end - def data_attach_set data; Efl::API.evas_data_attach_set @ptr, data; end - def data_attach_get; Efl::API.evas_data_attach_get @ptr; end - def damage_rectangle_add x, y, w, h; Efl::API.evas_damage_rectangle_add @ptr, x, y, w, h; end - def obscured_rectangle_add x, y, w, h; Efl::API.evas_obscured_rectangle_add @ptr, x, y, w, h; end - def obscured_clear; Efl::API.evas_obscured_clear @ptr; end - def render_updates; Efl::API.evas_render_updates @ptr; end -# def rendre_updates_free updates; Efl::API.evas_render_updates_free updates; end - def render; Efl::API.evas_render @ptr; end - def norender; Efl::API.evas_norender @ptr; end - def render_idle_flush; Efl::API.evas_render_idle_flush @ptr; end - def render_dump; Efl::API.evas_render_dump @ptr; end - # - def output_method_set method; Efl::API.evas_output_method_set @ptr, method; end - def output_method_get; Efl::API.evas_output_method_get @ptr; end - def engine_info_get; Efl::API.evas_engine_info_get @ptr; end - def engine_info_set info; Efl::API.evas_engine_info_set @ptr, info; end - # - def output_size_set w, h; Efl::API.evas_output_size_set @ptr, w, h; end + attr_reader :ptr + def initialize o=nil + @ptr = ( + case o + when NilClass + FFI::AutoPointer.new Efl::API.evas_new, method(:free) + when self.class + o.ptr + when FFI::AutoPointer + o + when FFI::Pointer + FFI::AutoPointer.new o, method(:free) + else + raise ArgumentError.new "#{ptr.class} valid argument" + end + ) + yield self if block_given? + end + def free + Efl::API.evas_free @ptr + @ptr=nil + end + def === o + @ptr === o.ptr + end + def method_missing m, *args, &block + sym = 'evas_'+m.to_s + Efl::API.send sym if not Efl::API.respond_to? sym + self.class.class_eval "def #{m} *args, █ r =Efl::API.#{sym}(@ptr,*args); yield r if block_given?; r; end" + self.send m, *args, &block + end def output_size_get x = FFI::MemoryPointer.new :int y = FFI::MemoryPointer.new :int Efl::API.evas_output_size_get @ptr, x, y [ x.read_int, y.read_int ] end - def output_viewport_set x, y, w, h; Efl::API.evas_output_viewport_set @ptr, x, y, w, h; end def output_viewport_get x = FFI::MemoryPointer.new :int y = FFI::MemoryPointer.new :int @@ -47,12 +52,6 @@ module Efl Efl::API.evas_output_viewport_get @ptr, x, y, w, h [ x.read_int, y.read_int, w.read_int, h.read_int ] end - # - def coord_screen_x_to_world x; Efl::API.evas_coord_screen_x_to_world @ptr, x; end - def coord_screen_y_to_world y; Efl::API.evas_coord_screen_y_to_world @ptr, y; end - def coord_world_x_to_screen x; Efl::API.evas_coord_world_x_to_screen @ptr, x; end - def coord_world_y_to_screen y; Efl::API.evas_coord_world_y_to_screen @ptr, y; end - # def pointer_output_xy_get x = FFI::MemoryPointer.new :int y = FFI::MemoryPointer.new :int @@ -65,29 +64,40 @@ module Efl Efl::API.evas_pointer_canvas_xy_get @ptr, x, y [ x.read_int, y.read_int ] end - def pointer_button_down_mask_get; Efl::API.evas_pointer_button_down_mask_get @ptr; end - def pointer_inside_get; Efl::API.evas_pointer_inside_get @ptr; end - # end # class EvasObject - def type_get - Efl::API.evas_object_type_get @evas - end - def ref - Efl::API.evas_object_type_ref @evas - end - def unref - Efl::API.evas_object_type_unref @evas - end - def del - Efl::API.evas_object_type_del @evas; @evas = nil - end - def move x, y - Efl::API.evas_object_move @evas, x, y - end - def resize w, h - Efl::API.evas_object_resize @evas, w, h + attr_reader :ptr + def initialize o=nil + @ptr = ( + case o + when NilClass + FFI::AutoPointer.new Efl::API.evas_new, method(:free) + when self.class + o.ptr + when FFI::AutoPointer + o + when FFI::Pointer + FFI::AutoPointer.new o, method(:free) + else + raise ArgumentError.new "#{ptr.class} valid argument" + end + ) + yield self if block_given? + end + def free + Efl::API.evas_object_del @ptr + @ptr=nil + end + def method_missing m, *args, &block + if Efl::API.respond_to? m + self.class.class_eval "def #{m} *args, █ r=Efl::API.#{m}(@ptr,*args); yield r if block_given?; r; end" + return self.send m, *args, &block + end + sym = 'evas_object_'+m.to_s + Efl::API.send sym if not Efl::API.respond_to? sym + self.class.class_eval "def #{m} *args, █ r=Efl::API.#{sym}(@ptr,*args); yield r if block_given?; r; end" + self.send m, *args, &block end def geometry_get x = FFI::MemoryPointer.new :int @@ -97,18 +107,6 @@ module Efl Efl::API.evas_object_geometry_get @evas, x, y, w, h [ x.read_int, y.read_int, w.read_int, h.read_int ] end - def show - Efl::API.evas_object_show @evas - end - def hide - Efl::API.evas_object_hide @evas - end - def visible? - Efl::API.evas_object_visible_get @evas - end - def color_set r, g, b, a - Efl::API.evas_object_color_set @evas, r, g, b, a - end def color_get r = FFI::MemoryPointer.new :int g = FFI::MemoryPointer.new :int @@ -117,9 +115,6 @@ module Efl Efl::API.evas_object_color_get @evas, r, g, b, a [ r.read_int, g.read_int, b.read_int, a.read_int ] end - def evas_get - Efl::API.evas_object_evas_get @evas - end end end end |