summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2012-02-27 11:37:06 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2012-02-27 11:37:06 +0100
commit7603f4c0902bf5845c7e7654c3745f5519347c8b (patch)
treebd381bf3a7f04d2ee7ddd92111c35a03472c7ecf
parent8c013976d73850718e75bbc93a03f3f016fc3ae8 (diff)
downloadffi-efl-7603f4c0902bf5845c7e7654c3745f5519347c8b.zip
ffi-efl-7603f4c0902bf5845c7e7654c3745f5519347c8b.tar.gz
use instance_eval instead of yield self.
- simplify and highlights initialization code - but shadows external scope variables
-rw-r--r--lib/efl/ecore_evas.rb4
-rw-r--r--lib/efl/evas.rb12
-rw-r--r--spec/ecore_evas_spec.rb17
-rw-r--r--spec/evas_spec.rb5
-rw-r--r--spec/helper.rb9
-rw-r--r--test/test_evas.rb24
6 files changed, 37 insertions, 34 deletions
diff --git a/lib/efl/ecore_evas.rb b/lib/efl/ecore_evas.rb
index d5e01b0..a2043a1 100644
--- a/lib/efl/ecore_evas.rb
+++ b/lib/efl/ecore_evas.rb
@@ -19,7 +19,7 @@ module Efl
class REcoreEvas
include Efl::ClassHelper
search_prefixes 'ecore_evas_'
- def initialize o=nil
+ def initialize o=nil, &block
@ptr = (
case o
when NilClass
@@ -32,7 +32,7 @@ module Efl
raise ArgumentError.new "wrong argument #{o.class.name}"
end
)
- yield self if block_given?
+ instance_eval &block if block
end
def self.release p
Native.ecore_evas_free p
diff --git a/lib/efl/evas.rb b/lib/efl/evas.rb
index 613b72b..e65a710 100644
--- a/lib/efl/evas.rb
+++ b/lib/efl/evas.rb
@@ -58,7 +58,7 @@ module Efl
include Efl::ClassHelper
search_prefixes 'evas_'
#
- def initialize o=nil
+ def initialize o=nil, &block
@ptr = (
case o
when NilClass
@@ -69,7 +69,7 @@ module Efl
raise ArgumentError.new "wrong argument #{o.class.name}"
end
)
- yield self if block_given?
+ instance_eval &block if block
end
def self.release p
Native.evas_free p
@@ -133,7 +133,7 @@ module Efl
include Efl::ClassHelper
search_prefixes 'evas_object_', 'evas_'
#
- def initialize a, *args
+ def initialize a, *args, &block
@ptr = (
case a
when FFI::Pointer
@@ -144,7 +144,7 @@ module Efl
raise ArgumentError.new "wrong argument #{a.class.name}"
end
)
- yield self if block_given?
+ instance_eval &block if block
end
def self.release p
Native.evas_object_del p unless p.nil?
@@ -161,9 +161,9 @@ module Efl
REvasObject.release @ptr
@ptr=nil
end
- def object_box_add
+ def object_box_add &block
o = Evas::REvasBox.new FFI::AutoPointer.new Native.evas_object_box_add_to(@ptr), REvasObject.method(:release)
- yield o if block_given?
+ o.instance_eval &block if block
o
end
def evas_name
diff --git a/spec/ecore_evas_spec.rb b/spec/ecore_evas_spec.rb
index 17ab9ea..859e282 100644
--- a/spec/ecore_evas_spec.rb
+++ b/spec/ecore_evas_spec.rb
@@ -52,16 +52,17 @@ describe 'Efl::EcoreEvas' do
EcoreEvas.init.should == 2
end
before(:each) do
- @e = EcoreEvas::REcoreEvas.new :engine_name=>"software_x11", :x=>10, :y=>10, :w=>100, :h=>120
+ @e = EcoreEvas::REcoreEvas.new :engine_name=>"software_x11", :x=>10, :y=>10, :w=>100, :h=>120 do
+ move 10, 10
+ show
+ end
@canvas = @e.evas
- @bg = @canvas.object_rectangle_add { |o|
- o.color = 100, 100, 255, 255
- o.size = @e.size
- }
- @bg.show
+ @bg = @canvas.object_rectangle_add do
+ color_set 100, 100, 255, 255
+ show
+ end
+ @bg.size = @e.size
@e.object_associate @bg, :ecore_evas_object_associate_base
- @e.move 10, 10
- @e.show
end
after(:each) do
@e.free
diff --git a/spec/evas_spec.rb b/spec/evas_spec.rb
index f5f5859..e7dbdf9 100644
--- a/spec/evas_spec.rb
+++ b/spec/evas_spec.rb
@@ -73,8 +73,9 @@ describe "Efl::Evas #{Efl::Evas.version.full}" do
end
#
it "should be able to create and destroy evas" do
- e1 = Evas::REvas.new
- e1.address.should_not == 0
+ e1 = Evas::REvas.new do
+ address.should_not == 0
+ end
e2 = Evas::REvas.new e1.to_ptr
e1.address.should == e2.address
(e1==e2).should be_false
diff --git a/spec/helper.rb b/spec/helper.rb
index e641c92..9bfab78 100644
--- a/spec/helper.rb
+++ b/spec/helper.rb
@@ -9,10 +9,11 @@ def realize_evas
width = 300
height = 200
@pixels = FFI::MemoryPointer.new :int, width*height
- @e = Efl::Evas::REvas.new
- @e.output_method_set Efl::Evas::render_method_lookup("buffer")
- @e.output_viewport_set 0, 0, width, height
- @e.output_size_set width, height
+ @e = Efl::Evas::REvas.new do
+ output_method_set Efl::Evas::render_method_lookup("buffer")
+ output_viewport_set 0, 0, width, height
+ output_size_set width, height
+ end
einfo = Efl::Native::EngineInfoBufferStruct.new @e.engine_info
einfo[:info][:depth_type] = Efl::Evas::EVAS_ENGINE_BUFFER_DEPTH_ARGB32
einfo[:info][:dest_buffer] = @pixels
diff --git a/test/test_evas.rb b/test/test_evas.rb
index c3eadf7..c70f4d9 100644
--- a/test/test_evas.rb
+++ b/test/test_evas.rb
@@ -59,19 +59,19 @@ h = 240
#
canvas, pixels = create_canvas w, h
#
-bg = canvas.object_rectangle_add do |b|
- b.color = 255, 255, 255, 255
- b.move 0, 0
- b.resize w, h
+bg = canvas.object_rectangle_add do
+ color_set 255, 255, 255, 255
+ move 0, 0
+ resize w, h
end
bg.show
#
draw_scene canvas
#
-r1 = canvas.object_rectangle_add do |r|
- r.color = 255, 0, 0, 255
- r.move 10, 10
- r.resize 100, 100
+r1 = canvas.object_rectangle_add do
+ color_set 0, 0, 0, 255
+ move 10, 10
+ resize 100, 100
end
r1.show
#
@@ -82,10 +82,10 @@ r2 = canvas.object_rectangle_add do |r|
end
r2.show
#
-r3 = canvas.object_rectangle_add do |r|
- r.color = 0, 128, 0, 255
- r.move 60, 60
- r.resize 50, 50
+r3 = canvas.object_rectangle_add do
+ color_set 0, 128, 0, 255
+ move 60, 60
+ resize 50, 50
end
r3.show
#