summaryrefslogtreecommitdiffstats
path: root/lib/efl/evas.rb
blob: c4dcbb7accec5fed02ae034ca8efa12ba015c67f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#! /usr/bin/env ruby
# -*- coding: UTF-8 -*-
#
require 'efl/ffi/evas'
#
module Efl
    module FFI
        #
        EVAS_ENGINE_BUFFER_DEPTH_ARGB32 = 0
        EVAS_ENGINE_BUFFER_DEPTH_BGRA32 = 1
        EVAS_ENGINE_BUFFER_DEPTH_RGB24  = 2
        EVAS_ENGINE_BUFFER_DEPTH_BGR24  = 3
        EVAS_ENGINE_BUFFER_DEPTH_RGB32  = 4
        #
        class EvasEngineInfo < ::FFI::Struct
            layout  :magic,         :int
        end
        callback :new_update_region_cb, [:int, :int, :int, :int, :int_p], :pointer
        callback :free_update_region_cb, [:int, :int, :int, :int, :pointer], :void
        class EvasEngineInfoBufferFunc < ::FFI::Struct
            layout  :new_update_region,     :new_update_region_cb,
                    :free_update_region,    :free_update_region_cb
        end
        class EvasEngineInfoBufferInfo < ::FFI::Struct
            layout  :depth_type,            :int,
                    :dest_buffer,           :pointer,
                    :dest_buffer_row_bytes, :int,
                    :use_color_key,         :char,
                    :alpha_threshold,       :int,
                    :color_key_r,           :int,
                    :color_key_g,           :int,
                    :color_key_b,           :int,
                    :func,          EvasEngineInfoBufferFunc,
        end
        class EvasEngineInfoBuffer < ::FFI::Struct
            layout  :magic,         EvasEngineInfo,
                    :info,          EvasEngineInfoBufferInfo,
#                    :func,          EvasEngineInfoBufferFunc,
                    :mode,          :evas_engine_render_mode,
        end
        #
    end
    #
    module Evas
        #
        class Evas
            include Efl::Helper
            @func_prefixes = [ 'evas_' ].freeze
            def initialize o=nil
                @ptr = (
                    case o
                    when NilClass
                        ::FFI::AutoPointer.new Efl::FFI.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::FFI.evas_free @ptr
                @ptr=nil
            end
            def object_add t
                Efl::Evas::EvasObject.new Efl::FFI.send "evas_object_#{t}_add", @ptr
            end
            def output_size_get
                x = ::FFI::MemoryPointer.new :int
                y = ::FFI::MemoryPointer.new :int
                Efl::FFI.evas_output_size_get @ptr, x, y
                [ x.read_int, y.read_int ]
            end
            def output_viewport_get
                x = ::FFI::MemoryPointer.new :int
                y = ::FFI::MemoryPointer.new :int
                w = ::FFI::MemoryPointer.new :int
                h = ::FFI::MemoryPointer.new :int
                Efl::FFI.evas_output_viewport_get @ptr, x, y, w, h
                [ x.read_int, y.read_int, w.read_int, h.read_int ]
            end
            def pointer_output_xy_get
                x = ::FFI::MemoryPointer.new :int
                y = ::FFI::MemoryPointer.new :int
                Efl::FFI.evas_pointer_output_xy_get @ptr, x, y
                [ x.read_int, y.read_int ]
            end
            def pointer_canvas_xy_get
                x = ::FFI::MemoryPointer.new :int
                y = ::FFI::MemoryPointer.new :int
                Efl::FFI.evas_pointer_canvas_xy_get @ptr, x, y
                [ x.read_int, y.read_int ]
            end
        end
        #
        class EvasObject
            include Efl::Helper
            @func_prefixes = [ 'evas_object_', 'evas_' ].freeze
            def initialize o=nil
                @ptr = (
                    case o
                    when NilClass
                        ::FFI::AutoPointer.new Efl::FFI.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::FFI.evas_object_del @ptr
                @ptr=nil
            end
            def geometry_get
                x = ::FFI::MemoryPointer.new :int
                y = ::FFI::MemoryPointer.new :int
                w = ::FFI::MemoryPointer.new :int
                h = ::FFI::MemoryPointer.new :int
                Efl::FFI.evas_object_geometry_get @evas, x, y, w, h
                [ x.read_int, y.read_int, w.read_int, h.read_int ]
            end
            def color_get
                r = ::FFI::MemoryPointer.new :int
                g = ::FFI::MemoryPointer.new :int
                b = ::FFI::MemoryPointer.new :int
                a = ::FFI::MemoryPointer.new :int
                Efl::FFI.evas_object_color_get @evas, r, g, b, a
                [ r.read_int, g.read_int, b.read_int, a.read_int ]
            end
        end
    end
end
#
# EOF