summaryrefslogtreecommitdiffstats
path: root/lib/efl/evas.rb
blob: fbf52837c6bb9cb8efa0e3c5f56b65b882d8b631 (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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
#! /usr/bin/env ruby
# -*- coding: UTF-8 -*-
#
require 'efl'
require 'efl/native/evas'
#
module Efl
    #
    module Native
        #
        callback :new_update_region_cb, [:int, :int, :int, :int, :pointer], :pointer
        callback :free_update_region_cb, [:int, :int, :int, :int, :pointer], :void
        #
        class EngineInfoStruct < FFI::Struct
            layout  :magic,                 :int
        end
        class EngineInfoBufferFuncStruct < FFI::Struct
            layout  :new_update_region,     :new_update_region_cb,
                    :free_update_region,    :free_update_region_cb
        end
        class EngineInfoBufferInfoStruct < 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,                  EngineInfoBufferFuncStruct
        end
        class EngineInfoBufferStruct < FFI::Struct
            layout  :magic,                 EngineInfoStruct,
                    :info,                  EngineInfoBufferInfoStruct,
#                    :func,                  EvasEngineInfoBufferFunc,
                    :mode,                  :evas_engine_render_mode
        end
        #
    end
    #
    module Evas
        #
        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
        #
        EVAS_HINT_FILL = -1.0
        EVAS_HINT_EXPAND = 1.0
        #
        def self.version
            Native::VersionStruct.new(Native.evas_version)
        end
        #
        class REvas
            #
            include Efl::ClassHelper
            search_prefixes 'evas_'
            #
            def initialize o=nil, &block
                @ptr = (
                    case o
                    when NilClass
                        FFI::AutoPointer.new Native.evas_new, REvas.method(:release)
                    when FFI::Pointer
                        o
                    else
                        raise ArgumentError.new "wrong argument #{o.class.name}"
                    end
                )
                instance_eval &block if block
            end
            def self.release p
                Native.evas_free p
            end
            def free
                @ptr.autorelease=false if @ptr.is_a? FFI::AutoPointer
                REvas.release @ptr
                @ptr=nil
            end
            def object_rectangle_add &block
                 REvasRectangle.new Native.method(:evas_object_rectangle_add), @ptr, &block
            end
            def object_line_add &block
                Evas::REvasLine.new Native.method(:evas_object_line_add), @ptr, &block
            end
            def object_polygon_add &block
                Evas::REvasPolygon.new Native.method(:evas_object_polygon_add), @ptr, &block
            end
            def object_text_add &block
                Evas::REvasText.new Native.method(:evas_object_text_add), @ptr, &block
            end
            def object_box_add &block
                Evas::REvasBox.new Native.method(:evas_object_box_add), @ptr, &block
            end
            def output_size_get
                @ri0 ||= FFI::MemoryPointer.new :int
                @ri1 ||= FFI::MemoryPointer.new :int
                Native.evas_output_size_get @ptr, @ri0, @ri1
                [ @ri0.read_int, @ri1.read_int ]
            end
            alias :output_size :output_size_get
            alias :size :output_size_get
            def output_viewport_get
                @ri0 ||= FFI::MemoryPointer.new :int
                @ri1 ||= FFI::MemoryPointer.new :int
                @ri2 ||= FFI::MemoryPointer.new :int
                @ri3 ||= FFI::MemoryPointer.new :int
                Native.evas_output_viewport_get @ptr, @ri0, @ri1, @ri2, @ri3
                [ @ri0.read_int, @ri1.read_int, @ri2.read_int, @ri3.read_int ]
            end
            alias :output_viewport :output_viewport_get
            alias :viewport :output_viewport_get
            def pointer_output_xy_get
                @ri0 ||= FFI::MemoryPointer.new :int
                @ri1 ||= FFI::MemoryPointer.new :int
                Native.evas_pointer_output_xy_get @ptr, @ri0, @ri1
                [ @ri0.read_int, @ri1.read_int ]
            end
            alias :pointer_output :pointer_output_xy_get
            def pointer_canvas_xy_get
                @ri0 ||= FFI::MemoryPointer.new :int
                @ri1 ||= FFI::MemoryPointer.new :int
                Native.evas_pointer_canvas_xy_get @ptr, @ri0, @ri1
                [ @ri0.read_int, @ri1.read_int ]
            end
            alias :pointer_canvas :pointer_canvas_xy_get
        end
        #
        class REvasObject
            #
            include Efl::ClassHelper
            search_prefixes 'evas_object_', 'evas_'
            #
            def initialize a, *args, &block
                @ptr = (
                    case a
                    when FFI::Pointer
                        a
                    when Method
                        a.call(*args)
                    else
                        raise ArgumentError.new "wrong argument #{a.class.name}"
                    end
                )
                instance_eval &block if block
            end
            def self.release p
                Native.evas_object_del p unless p.nil?
                @ri0.free if @ri0
                @ri1.free if @ri1
                @ri2.free if @ri2
                @ri3.free if @ri3
                @rd0.free if @rd0
                @rd1.free if @rd1
                @rs0.free if @rs0
            end
            def free
                @ptr.autorelease=false if @ptr.is_a? FFI::AutoPointer
                REvasObject.release @ptr
                @ptr=nil
            end
            def object_box_add &block
                o = Evas::REvasBox.new FFI::AutoPointer.new Native.evas_object_box_add_to(@ptr), REvasObject.method(:release)
                o.instance_eval &block if block
                o
            end
            def evas_name
                Native.evas_object_name_get @ptr
            end
            def evas_type
                Native.evas_object_type_get @ptr
            end
            def geometry_get
                @ri0 ||= FFI::MemoryPointer.new :int
                @ri1 ||= FFI::MemoryPointer.new :int
                @ri2 ||= FFI::MemoryPointer.new :int
                @ri3 ||= FFI::MemoryPointer.new :int
                Native.evas_object_geometry_get @ptr, @ri0, @ri1, @ri2, @ri3
                [ @ri0.read_int, @ri1.read_int, @ri2.read_int, @ri3.read_int ]
            end
            alias :geometry :geometry_get
            def center_get
                g = geometry_get
                [ g[0]+(g[2]/2.0), g[1]+(g[3]/2.0) ]
            end
            alias :center :center_get
            def center_set x, y
                g = geometry_get
                move (x-(g[2]/2.0)).to_i, (y-(g[3]/2.0)).to_i
            end
            alias :center= :center_set
            def size
                geometry_get[2..-1]
            end
            def size= wh
                Native.evas_object_resize @ptr, *wh
            end
            def color_get
                @ri0 ||= FFI::MemoryPointer.new :int
                @ri1 ||= FFI::MemoryPointer.new :int
                @ri2 ||= FFI::MemoryPointer.new :int
                @ri3 ||= FFI::MemoryPointer.new :int
                Native.evas_object_color_get @ptr, @ri0, @ri1, @ri2, @ri3
                [ @ri0.read_int, @ri1.read_int, @ri2.read_int, @ri3.read_int ]
            end
            alias :color :color_get
            def evas_get
                REvas.new Native.evas_object_evas_get @ptr
            end
            alias :evas :evas_get
            def above_get
                REvasObject.new Native.evas_object_above_get @ptr
            end
            alias :above :above_get
            def below_get
                REvasObject.new Native.evas_object_below_get @ptr
            end
            alias :below :below_get
            def size_hint_min_get
                @ri0 ||= FFI::MemoryPointer.new :int
                @ri1 ||= FFI::MemoryPointer.new :int
                Native.evas_object_size_hint_min_get @ptr, @ri0, @ri1
                [ @ri0.read_int, @ri1.read_int ]
            end
            alias :size_hint_min :size_hint_min_get
            def size_hint_max_get
                @ri0 ||= FFI::MemoryPointer.new :int
                @ri1 ||= FFI::MemoryPointer.new :int
                Native.evas_object_size_hint_max_get @ptr, @ri0, @ri1
                [ @ri0.read_int, @ri1.read_int ]
            end
            alias :size_hint_max :size_hint_max_get
            def size_hint_request_get
                @ri0 ||= FFI::MemoryPointer.new :int
                @ri1 ||= FFI::MemoryPointer.new :int
                Native.evas_object_size_hint_request_get @ptr, @ri0, @ri1
                [ @ri0.read_int, @ri1.read_int ]
            end
            alias :size_hint_request :size_hint_request_get
            def size_hint_aspect_get
                @ri0 ||= FFI::MemoryPointer.new :int
                @ri1 ||= FFI::MemoryPointer.new :int
                @ri2 ||= FFI::MemoryPointer.new :int
                Native.evas_object_size_hint_aspect_get @ptr, @ri0, @ri1, @ri2
                [ Native.enum_type(:evas_aspect_control)[@ri0.read_int], @ri1.read_int, @ri2.read_int ]
            end
            alias :size_hint_aspect :size_hint_aspect_get
            def size_hint_align_set_fill
                Native.evas_object_size_hint_align_set @ptr, EVAS_HINT_FILL, EVAS_HINT_FILL
            end
            alias :size_hint_align_fill :size_hint_align_set_fill
            def size_hint_align_get
                @rd0 ||= FFI::MemoryPointer.new :double
                @rd1 ||= FFI::MemoryPointer.new :double
                Native.evas_object_size_hint_align_get @ptr, @rd0, @rd1
                [ @rd0.read_double, @rd1.read_double ]
            end
            alias :size_hint_align :size_hint_align_get
            def size_hint_weight_set_expand
                Native.evas_object_size_hint_weight_set @ptr, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND
            end
            alias :size_hint_weight_expand :size_hint_weight_set_expand
            def size_hint_weight_set_expand_fill
                Native.evas_object_size_hint_weight_set @ptr, EVAS_HINT_EXPAND, EVAS_HINT_FILL
            end
            alias :size_hint_weight_expand_fill :size_hint_weight_set_expand_fill
            def size_hint_weight_get
                @rd0 ||= FFI::MemoryPointer.new :double
                @rd1 ||= FFI::MemoryPointer.new :double
                Native.evas_object_size_hint_weight_get @ptr, @rd0, @rd1
                [ @rd0.read_double, @rd1.read_double ]
            end
            alias :size_hint_weight :size_hint_weight_get
            def size_hint_padding_get
                @ri0 ||= FFI::MemoryPointer.new :int
                @ri1 ||= FFI::MemoryPointer.new :int
                @ri2 ||= FFI::MemoryPointer.new :int
                @ri3 ||= FFI::MemoryPointer.new :int
                Native.evas_object_size_hint_padding_get @ptr, @ri0, @ri1, @ri2, @ri3
                [ @ri0.read_int, @ri1.read_int, @ri2.read_int, @ri3.read_int ]
            end
            alias :size_hint_padding :size_hint_padding_get
            def data_get k
                r = Native.evas_object_data_get @ptr, k
                return nil if r==FFI::Pointer::NULL
                r.read_string
            end
            alias :data :data_get
        end
        #
        class REvasRectangle < REvasObject
            #
        end
        #
        class REvasLine < REvasObject
            #
            search_prefixes 'evas_object_line_'
            #
            def line_xy_get
                @ri0 ||= FFI::MemoryPointer.new :int
                @ri1 ||= FFI::MemoryPointer.new :int
                @ri2 ||= FFI::MemoryPointer.new :int
                @ri3 ||= FFI::MemoryPointer.new :int
                Native.evas_object_line_xy_get @ptr, @ri0, @ri1, @ri2, @ri3
                [ @ri0.read_int, @ri1.read_int, @ri2.read_int, @ri3.read_int ]
            end
        end
        #
        class REvasPolygon < REvasObject
            #
            search_prefixes 'evas_object_polygon_'
            #
            def point_add *args
                Native.evas_object_polygon_point_add @ptr, *args
            end
            alias :<< :point_add
        end
        #
        class REvasText < REvasObject
            #
            search_prefixes 'evas_object_text_'
            #
            def font_get
                @rs0 ||= FFI::MemoryPointer.new :string
                @ri0 ||= FFI::MemoryPointer.new :int
                Native.evas_object_text_font_get @ptr, @rs0, @ri0
                [ @rs0.read_pointer.read_string, @ri0.read_int ]
            end
            alias :font :font_get
            def char_pos_get pos
                @ri0 ||= FFI::MemoryPointer.new :int
                @ri1 ||= FFI::MemoryPointer.new :int
                @ri2 ||= FFI::MemoryPointer.new :int
                @ri3 ||= FFI::MemoryPointer.new :int
                Native.evas_object_text_char_pos_get @ptr, pos, @ri0, @ri1, @ri2, @ri3
                return [ @ri0.read_int, @ri1.read_int, @ri2.read_int, @ri3.read_int ]
            end
            alias :char_pos :char_pos_get
            def char_coords_get x, y
                @ri0 ||= FFI::MemoryPointer.new :int
                @ri1 ||= FFI::MemoryPointer.new :int
                @ri2 ||= FFI::MemoryPointer.new :int
                @ri3 ||= FFI::MemoryPointer.new :int
                r = Native.evas_object_text_char_coords_get @ptr, x, y, @ri0, @ri1, @ri2, @ri3
                return [ r, @ri0.read_int, @ri1.read_int, @ri2.read_int, @ri3.read_int ]
            end
            alias :char_coords :char_coords_get
            def style_pad_get
                @ri0 ||= FFI::MemoryPointer.new :int
                @ri1 ||= FFI::MemoryPointer.new :int
                @ri2 ||= FFI::MemoryPointer.new :int
                @ri3 ||= FFI::MemoryPointer.new :int
                Native.evas_object_text_shadow_color_get @ptr, @ri0, @ri1, @ri2, @ri3
                return [ @ri0.read_int, @ri1.read_int, @ri2.read_int, @ri3.read_int ]
            end
            alias :style_pad :style_pad_get
            def shadow_color_get
                @ri0 ||= FFI::MemoryPointer.new :int
                @ri1 ||= FFI::MemoryPointer.new :int
                @ri2 ||= FFI::MemoryPointer.new :int
                @ri3 ||= FFI::MemoryPointer.new :int
                Native.evas_object_text_shadow_color_get @ptr, @ri0, @ri1, @ri2, @ri3
                return [ @ri0.read_int, @ri1.read_int, @ri2.read_int, @ri3.read_int ]
            end
            alias :shadow_color :shadow_color_get
            def glow_color_get
                @ri0 ||= FFI::MemoryPointer.new :int
                @ri1 ||= FFI::MemoryPointer.new :int
                @ri2 ||= FFI::MemoryPointer.new :int
                @ri3 ||= FFI::MemoryPointer.new :int
                Native.evas_object_text_glow_color_get @ptr, @ri0, @ri1, @ri2, @ri3
                return [ @ri0.read_int, @ri1.read_int, @ri2.read_int, @ri3.read_int ]
            end
            alias :glow_color :glow_color_get
            def glow2_color_get
                @ri0 ||= FFI::MemoryPointer.new :int
                @ri1 ||= FFI::MemoryPointer.new :int
                @ri2 ||= FFI::MemoryPointer.new :int
                @ri3 ||= FFI::MemoryPointer.new :int
                Native.evas_object_text_glow2_color_get @ptr, @ri0, @ri1, @ri2, @ri3
                return [ @ri0.read_int, @ri1.read_int, @ri2.read_int, @ri3.read_int ]
            end
            alias :glow2_color :glow2_color_get
            def outline_color_get
                @ri0 ||= FFI::MemoryPointer.new :int
                @ri1 ||= FFI::MemoryPointer.new :int
                @ri2 ||= FFI::MemoryPointer.new :int
                @ri3 ||= FFI::MemoryPointer.new :int
                Native.evas_object_text_outline_color_get @ptr, @ri0, @ri1, @ri2, @ri3
                return [ @ri0.read_int, @ri1.read_int, @ri2.read_int, @ri3.read_int ]
            end
            alias :outline_color :outline_color_get
        end
        #
        class REvasBox < REvasObject
            #
            search_prefixes 'evas_object_box_'
            #
            def children_get
                EinaList::REinaList.new Native.evas_object_box_children_get @ptr
            end
            alias :children :children_get
            def align_get
                @rd0 ||= FFI::MemoryPointer.new :double
                @rd1 ||= FFI::MemoryPointer.new :double
                Native.evas_object_box_align_get @ptr, @rd0, @rd1
                [ @rd0.read_double, @rd1.read_double ]
            end
            alias :align :align_get
            def padding_get
                @ri0 ||= FFI::MemoryPointer.new :int
                @ri1 ||= FFI::MemoryPointer.new :int
                Native.evas_object_box_padding_get @ptr, @ri0, @ri1
                [ @ri0.read_int, @ri1.read_int ]
            end
            alias :padding :padding_get
        end
    end
end
#
# EOF