summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2011-05-05 12:14:03 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2011-05-05 12:14:03 +0200
commit36707e379932a8de7c1940b945ec9ea9d3bbb4c6 (patch)
tree705feef206253a0ddd1b346f6d7a02b7a59d21c1
parent429e5812eab616a3db352b5ae84d1c2bcf9278b4 (diff)
downloadffi-efl-36707e379932a8de7c1940b945ec9ea9d3bbb4c6.zip
ffi-efl-36707e379932a8de7c1940b945ec9ea9d3bbb4c6.tar.gz
add classes : REvasRectangle, REvasLine, REvasPolygon and specs
-rw-r--r--lib/efl/evas.rb43
-rw-r--r--spec/evas_spec.rb91
2 files changed, 100 insertions, 34 deletions
diff --git a/lib/efl/evas.rb b/lib/efl/evas.rb
index a0067e7..ff0f3bc 100644
--- a/lib/efl/evas.rb
+++ b/lib/efl/evas.rb
@@ -72,10 +72,21 @@ module Efl
@ptr=nil
end
def object_add t
- # TODO should return Objects
- r = Evas::REvasObject.new Native.send "evas_object_#{t.to_s}_add", @ptr
- yield r if block_given?
- r
+ ts = t.to_s
+ o = (
+ case ts
+ when 'rectangle'
+ Evas::REvasRectangle.new Native.evas_object_rectangle_add @ptr
+ when 'line'
+ Evas::REvasLine.new Native.evas_object_line_add @ptr
+ when 'polygon'
+ Evas::REvasPolygon.new Native.evas_object_polygon_add @ptr
+ else
+ raise NameError.new "unknown or not implemented yet evas_object type #{ts}"
+ end
+ )
+ yield o if block_given?
+ o
end
def output_size_get
x = FFI::MemoryPointer.new :int
@@ -238,6 +249,30 @@ module Efl
end
alias :data :data_get
end
+ #
+ class REvasRectangle < REvasObject
+ end
+ #
+ class REvasLine < REvasObject
+ #
+ search_prefixes 'evas_object_line_'
+ #
+ def line_xy_get
+ x1 = FFI::MemoryPointer.new :int
+ y1 = FFI::MemoryPointer.new :int
+ x2 = FFI::MemoryPointer.new :int
+ y2 = FFI::MemoryPointer.new :int
+ Native.evas_object_line_xy_get @ptr, x1, y1, x2, y2
+ [ x1.read_int, y1.read_int, x2.read_int, y2.read_int ]
+ end
+ end
+ #
+ class REvasPolygon < REvasObject
+ #
+ search_prefixes 'evas_object_polygon_'
+ #
+ end
+ #
end
end
#
diff --git a/spec/evas_spec.rb b/spec/evas_spec.rb
index d437619..8936cfe 100644
--- a/spec/evas_spec.rb
+++ b/spec/evas_spec.rb
@@ -5,6 +5,24 @@ require 'efl/ecore'
require 'efl/evas'
#
describe Efl::Evas do
+ def realize_evas
+ @width = 800
+ @height = 600
+ @pixels = FFI::MemoryPointer.new :int, @width*@height
+ @e = Evas::REvas.new
+ @e.output_method_set Evas::render_method_lookup("buffer")
+ @e.output_viewport_set 0, 0, @width, @height
+ @e.output_size_set @width, @height
+ einfo = Native::EngineInfoBufferStruct.new @e.engine_info
+ einfo[:info][:depth_type] = Efl::Evas::EVAS_ENGINE_BUFFER_DEPTH_ARGB32
+ einfo[:info][:dest_buffer] = @pixels
+ einfo[:info][:dest_buffer_row_bytes] = @width * FFI::type_size(:int);
+ einfo[:info][:use_color_key] = 0;
+ einfo[:info][:alpha_threshold] = 0;
+ einfo[:info][:func][:new_update_region] = nil #FFI::Pointer::NULL;
+ einfo[:info][:func][:free_update_region] = nil #FFI::Pointer::NULL;
+ @e.engine_info_set einfo
+ end
#
before(:all) {
Evas = Efl::Evas
@@ -59,22 +77,7 @@ describe Efl::Evas do
describe Efl::Evas::REvas do
before(:all) do
Evas.init
- @width = 800
- @height = 600
- @pixels = FFI::MemoryPointer.new :int, @width*@height
- @e = Evas::REvas.new
- @e.output_method_set Evas::render_method_lookup("buffer")
- @e.output_viewport_set 0, 0, @width, @height
- @e.output_size_set @width, @height
- einfo = Native::EngineInfoBufferStruct.new @e.engine_info
- einfo[:info][:depth_type] = Efl::Evas::EVAS_ENGINE_BUFFER_DEPTH_ARGB32
- einfo[:info][:dest_buffer] = @pixels
- einfo[:info][:dest_buffer_row_bytes] = @width * FFI::type_size(:int);
- einfo[:info][:use_color_key] = 0;
- einfo[:info][:alpha_threshold] = 0;
- einfo[:info][:func][:new_update_region] = nil #FFI::Pointer::NULL;
- einfo[:info][:func][:free_update_region] = nil #FFI::Pointer::NULL;
- @e.engine_info_set einfo
+ realize_evas
end
after(:all) do
@e.free
@@ -306,20 +309,7 @@ describe Efl::Evas do
#
before(:all) do
Evas.init
- @pixels = FFI::MemoryPointer.new :int, 100*100
- @e = Evas::REvas.new
- @e.output_method_set Evas.render_method_lookup("buffer")
- @e.output_viewport_set 0, 0, 100, 100
- @e.output_size_set 100, 100
- einfo = Native::EngineInfoBufferStruct.new @e.engine_info
- einfo[:info][:depth_type] = Efl::Evas::EVAS_ENGINE_BUFFER_DEPTH_ARGB32
- einfo[:info][:dest_buffer] = @pixels
- einfo[:info][:dest_buffer_row_bytes] = 100 * FFI::type_size(:int);
- einfo[:info][:use_color_key] = 0;
- einfo[:info][:alpha_threshold] = 0;
- einfo[:info][:func][:new_update_region] = nil #FFI::Pointer::NULL;
- einfo[:info][:func][:free_update_region] = nil #FFI::Pointer::NULL;
- @e.engine_info_set einfo
+ realize_evas
@o = @e.object_add(:rectangle) { |o|
o.color = 200,200,200,200
o.move 0, 0
@@ -567,6 +557,47 @@ describe Efl::Evas do
@o.static_clip?.should be_false
@o.static_clip.should be_false
end
+ #
+ end
+ #
+ describe Efl::Evas::REvasLine do
+ #
+ before(:all) do
+ Evas.init
+ realize_evas
+ @l = @e.object_add 'line'
+ end
+ after(:all) do
+ @e.free
+ Evas.shutdown
+ end
+ it "xy get/set should work" do
+ @l.line_xy_set 10, 20, 30, 40
+ @l.line_xy_get.should == [10, 20, 30, 40]
+ end
+ end
+ #
+ describe Efl::Evas::REvasPolygon do
+ #
+ before(:all) do
+ Evas.init
+ realize_evas
+ @p = @e.object_add 'polygon'
+ end
+ after(:all) do
+ @e.free
+ Evas.shutdown
+ end
+ it "xy point_add should work" do
+ @p.point_add 10, 20
+ @p.point_add 30, 40
+ @p.point_add 50, 60
+ @p.point_add 80, 80
+ end
+ #
+ it "point clear shold work" do
+ @p.points_clear
+ end
end
#
end