Module: Rabbit::Element::Base

Includes:
DrawHook, GetText, Utils
Included in:
ContainerElement, Image, IndexThumbnail, PopplerPage, TextRenderer, Video, WaitTag
Defined in:
lib/rabbit/element/base.rb,
lib/rabbit/element/base/draw-hook.rb

Defined Under Namespace

Modules: DrawHook

Constant Summary

Constants included from GetText

GetText::DOMAIN

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DrawHook

#clear_draw_procs, def_draw_hook, def_draw_hooks

Methods included from Utils

arg_list, collect_classes_under_module, collect_modules_under_module, collect_under_module, combination, compute_bottom_y, compute_left_x, compute_right_x, compute_top_y, corresponding_class_under_module, corresponding_module_under_module, corresponding_objects, drawable_to_pixbuf, ensure_time, events_pending_available?, extract_four_way, find_path_in_load_path, init_by_constants_as_default_value, move_to, move_to_bottom_left, move_to_bottom_right, move_to_top_left, move_to_top_right, parse_four_way, process_pending_events, process_pending_events_proc, quartz?, require_files_under_directory_in_load_path, require_safe, split_number_to_minute_and_second, stringify_hash_key, support_console_input?, support_console_output?, syntax_highlighting_debug?, time, to_class_name, unescape_title, windows?

Methods included from GetText

included

Instance Attribute Details

#base_hObject (readonly)

Returns the value of attribute base_h.



19
20
21
# File 'lib/rabbit/element/base.rb', line 19

def base_h
  @base_h
end

#base_wObject (readonly)

Returns the value of attribute base_w.



19
20
21
# File 'lib/rabbit/element/base.rb', line 19

def base_w
  @base_w
end

#base_xObject (readonly)

Returns the value of attribute base_x.



19
20
21
# File 'lib/rabbit/element/base.rb', line 19

def base_x
  @base_x
end

#base_yObject (readonly)

Returns the value of attribute base_y.



19
20
21
# File 'lib/rabbit/element/base.rb', line 19

def base_y
  @base_y
end

#default_margin_bottomObject

Returns the value of attribute default_margin_bottom.



31
32
33
# File 'lib/rabbit/element/base.rb', line 31

def default_margin_bottom
  @default_margin_bottom
end

#default_margin_leftObject

Returns the value of attribute default_margin_left.



30
31
32
# File 'lib/rabbit/element/base.rb', line 30

def default_margin_left
  @default_margin_left
end

#default_margin_rightObject

Returns the value of attribute default_margin_right.



30
31
32
# File 'lib/rabbit/element/base.rb', line 30

def default_margin_right
  @default_margin_right
end

#default_margin_topObject

Returns the value of attribute default_margin_top.



31
32
33
# File 'lib/rabbit/element/base.rb', line 31

def default_margin_top
  @default_margin_top
end

#default_padding_bottomObject

Returns the value of attribute default_padding_bottom.



34
35
36
# File 'lib/rabbit/element/base.rb', line 34

def default_padding_bottom
  @default_padding_bottom
end

#default_padding_leftObject

Returns the value of attribute default_padding_left.



33
34
35
# File 'lib/rabbit/element/base.rb', line 33

def default_padding_left
  @default_padding_left
end

#default_padding_rightObject

Returns the value of attribute default_padding_right.



33
34
35
# File 'lib/rabbit/element/base.rb', line 33

def default_padding_right
  @default_padding_right
end

#default_padding_topObject

Returns the value of attribute default_padding_top.



34
35
36
# File 'lib/rabbit/element/base.rb', line 34

def default_padding_top
  @default_padding_top
end

#default_visibleObject

Returns the value of attribute default_visible.



36
37
38
# File 'lib/rabbit/element/base.rb', line 36

def default_visible
  @default_visible
end

#hObject (readonly)

Returns the value of attribute h.



16
17
18
# File 'lib/rabbit/element/base.rb', line 16

def h
  @h
end

#horizontal_centeringObject

Returns the value of attribute horizontal_centering.



20
21
22
# File 'lib/rabbit/element/base.rb', line 20

def horizontal_centering
  @horizontal_centering
end

#margin_bottomObject

Returns the value of attribute margin_bottom.



25
26
27
# File 'lib/rabbit/element/base.rb', line 25

def margin_bottom
  @margin_bottom
end

#margin_leftObject

Returns the value of attribute margin_left.



24
25
26
# File 'lib/rabbit/element/base.rb', line 24

def margin_left
  @margin_left
end

#margin_rightObject

Returns the value of attribute margin_right.



24
25
26
# File 'lib/rabbit/element/base.rb', line 24

def margin_right
  @margin_right
end

#margin_topObject

Returns the value of attribute margin_top.



25
26
27
# File 'lib/rabbit/element/base.rb', line 25

def margin_top
  @margin_top
end

#padding_bottomObject

Returns the value of attribute padding_bottom.



28
29
30
# File 'lib/rabbit/element/base.rb', line 28

def padding_bottom
  @padding_bottom
end

#padding_leftObject

Returns the value of attribute padding_left.



27
28
29
# File 'lib/rabbit/element/base.rb', line 27

def padding_left
  @padding_left
end

#padding_rightObject

Returns the value of attribute padding_right.



27
28
29
# File 'lib/rabbit/element/base.rb', line 27

def padding_right
  @padding_right
end

#padding_topObject

Returns the value of attribute padding_top.



28
29
30
# File 'lib/rabbit/element/base.rb', line 28

def padding_top
  @padding_top
end

#parentObject

Returns the value of attribute parent.



38
39
40
# File 'lib/rabbit/element/base.rb', line 38

def parent
  @parent
end

#phObject (readonly)

Returns the value of attribute ph.



17
18
19
# File 'lib/rabbit/element/base.rb', line 17

def ph
  @ph
end

#pwObject (readonly)

Returns the value of attribute pw.



17
18
19
# File 'lib/rabbit/element/base.rb', line 17

def pw
  @pw
end

#pxObject (readonly)

Returns the value of attribute px.



17
18
19
# File 'lib/rabbit/element/base.rb', line 17

def px
  @px
end

#pyObject (readonly)

Returns the value of attribute py.



17
18
19
# File 'lib/rabbit/element/base.rb', line 17

def py
  @py
end

#real_simulationObject (readonly)

Returns the value of attribute real_simulation.



38
39
40
# File 'lib/rabbit/element/base.rb', line 38

def real_simulation
  @real_simulation
end

#user_propertyObject

Returns the value of attribute user_property.



22
23
24
# File 'lib/rabbit/element/base.rb', line 22

def user_property
  @user_property
end

#vertical_centeringObject

Returns the value of attribute vertical_centering.



20
21
22
# File 'lib/rabbit/element/base.rb', line 20

def vertical_centering
  @vertical_centering
end

#wObject (readonly)

Returns the value of attribute w.



16
17
18
# File 'lib/rabbit/element/base.rb', line 16

def w
  @w
end

#xObject (readonly)

Returns the value of attribute x.



16
17
18
# File 'lib/rabbit/element/base.rb', line 16

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y.



16
17
18
# File 'lib/rabbit/element/base.rb', line 16

def y
  @y
end

Instance Method Details

#[](name) ⇒ Object



393
394
395
# File 'lib/rabbit/element/base.rb', line 393

def [](name)
  @user_property[name]
end

#[]=(name, value) ⇒ Object



397
398
399
# File 'lib/rabbit/element/base.rb', line 397

def []=(name, value)
  @user_property[name] = value
end

#add_default_prop(name, value) ⇒ Object



148
149
150
151
# File 'lib/rabbit/element/base.rb', line 148

def add_default_prop(name, value)
  name = normalize_property_name(name)
  @default_prop[name] = make_prop_value(name, value)
end

#adjust_x_centering(x, w) ⇒ Object



217
218
219
220
221
# File 'lib/rabbit/element/base.rb', line 217

def adjust_x_centering(x, w)
  x -= centering_adjusted_width
  w += centering_adjusted_width
  [x, w]
end

#adjust_y_margin(y, h) ⇒ Object



237
238
239
240
241
# File 'lib/rabbit/element/base.rb', line 237

def adjust_y_margin(y, h)
  y += @margin_bottom
  h -= @margin_bottom
  [y, h]
end

#adjust_y_padding(y, h) ⇒ Object



223
224
225
226
227
# File 'lib/rabbit/element/base.rb', line 223

def adjust_y_padding(y, h)
  y -= @padding_top
  h += @padding_top + @padding_bottom
  [y, h]
end

#available_wObject



318
319
320
# File 'lib/rabbit/element/base.rb', line 318

def available_w
  @w - @padding_left - @padding_right
end

#centering_adjusted_heightObject



334
335
336
# File 'lib/rabbit/element/base.rb', line 334

def centering_adjusted_height
  @centering_adjusted_height || 0
end

#centering_adjusted_widthObject



330
331
332
# File 'lib/rabbit/element/base.rb', line 330

def centering_adjusted_width
  @centering_adjusted_width || 0
end

#clear_marginObject



268
269
270
271
272
273
# File 'lib/rabbit/element/base.rb', line 268

def clear_margin
  @margin_left = @default_margin_left
  @margin_right = @default_margin_right
  @margin_top = @default_margin_top
  @margin_bottom = @default_margin_bottom
end

#clear_paddingObject



261
262
263
264
265
266
# File 'lib/rabbit/element/base.rb', line 261

def clear_padding
  @padding_left = @default_padding_left
  @padding_right = @default_padding_right
  @padding_top = @default_padding_top
  @padding_bottom = @default_padding_bottom
end

#clear_themeObject



182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/rabbit/element/base.rb', line 182

def clear_theme
  @slide = nil
  @visible = @default_visible
  @real_simulation = true
  @width = @height = nil
  @centering_adjusted_width = nil
  @centering_adjusted_height = nil
  @horizontal_centering = @vertical_centering = false
  @prop = default_prop
  clear_margin
  clear_padding
  clear_draw_procs
  dirty!
end

#cloneObject



346
347
348
349
350
351
# File 'lib/rabbit/element/base.rb', line 346

def clone
  obj = super
  obj.user_property = @user_property.clone
  obj.prop = @prop.clone
  obj
end

#compile(canvas, x, y, w, h) ⇒ Object



95
96
97
# File 'lib/rabbit/element/base.rb', line 95

def compile(canvas, x, y, w, h)
  compile_element(canvas, x, y, w, h)
end

#compile_element(canvas, x, y, w, h) ⇒ Object



99
100
101
102
103
104
105
106
107
# File 'lib/rabbit/element/base.rb', line 99

def compile_element(canvas, x, y, w, h)
  @base_x, @base_y, @base_w, @base_h = x, y, w, h
  @px, @py, @pw, @ph = @x, @y, @w, @h
  x, y, w, h = setup_margin(x, y, w, h)
  @canvas, @x, @y, @w, @h = canvas, x, y, w, h
  if [@px, @py, @pw, @ph] != [@x, @y, @w, @h]
    dirty!
  end
end

#compile_for_horizontal_centering(canvas, x, y, w, h) ⇒ Object



109
110
111
# File 'lib/rabbit/element/base.rb', line 109

def compile_for_horizontal_centering(canvas, x, y, w, h)
  compile(canvas, x, y, w, h)
end

#compile_horizontal(canvas, x, y, w, h) ⇒ Object



113
114
115
116
117
118
119
# File 'lib/rabbit/element/base.rb', line 113

def compile_horizontal(canvas, x, y, w, h)
  if do_horizontal_centering?
    do_horizontal_centering(canvas, x, y, w, h)
  else
    reset_horizontal_centering(canvas, x, y, w, h)
  end
end

#default_propObject



353
354
355
# File 'lib/rabbit/element/base.rb', line 353

def default_prop
  @default_prop.dup
end

#dirty!Object



75
76
77
# File 'lib/rabbit/element/base.rb', line 75

def dirty!
  @dirty = true
end

#dirty?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/rabbit/element/base.rb', line 79

def dirty?
  @dirty
end

#do_horizontal_centering(canvas, x, y, w, h) ⇒ Object



304
305
# File 'lib/rabbit/element/base.rb', line 304

def do_horizontal_centering(canvas, x, y, w, h)
end

#do_horizontal_centering?Boolean

Returns:

  • (Boolean)


282
283
284
285
# File 'lib/rabbit/element/base.rb', line 282

def do_horizontal_centering?
  @horizontal_centering or
    (parent and parent.do_horizontal_centering?)
end

#do_vertical_centering?Boolean

Returns:

  • (Boolean)


287
288
289
290
# File 'lib/rabbit/element/base.rb', line 287

def do_vertical_centering?
  @vertical_centering or
    (parent and parent.do_horizontal_centering?)
end

#draw(simulation = false) ⇒ Object



64
65
66
67
68
69
70
71
72
73
# File 'lib/rabbit/element/base.rb', line 64

def draw(simulation=false)
  x, y, w, h = setup_padding(@x, @y, @w, @h)
  x, y, w, h = _draw(@canvas, x, y, w, h, simulation)
  x, w = restore_x_padding(x, w)
  x, w = restore_x_margin(x, w)
  x, w = adjust_x_centering(x, w)
  y, h = adjust_y_padding(y, h)
  y, h = adjust_y_margin(y, h)
  [x, y, w, h]
end

#font(props) ⇒ Object



153
154
155
156
157
158
159
160
161
162
# File 'lib/rabbit/element/base.rb', line 153

def font(props)
  props.each do |key, value|
    key, value = normalize_font_property(key, value)
    if value
      prop_set(key, value)
    else
      prop_delete(key)
    end
  end
end

#have_tag?(name) ⇒ Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/rabbit/element/base.rb', line 87

def have_tag?(name)
  false
end

#have_wait_tag?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/rabbit/element/base.rb', line 91

def have_wait_tag?
  false
end

#heightObject



326
327
328
# File 'lib/rabbit/element/base.rb', line 326

def height
  @height + @padding_top + @padding_bottom
end

#hide(&block) ⇒ Object



389
390
391
# File 'lib/rabbit/element/base.rb', line 389

def hide(&block)
  change_visible(false, &block)
end

#if_dirtyObject



275
276
277
278
279
280
# File 'lib/rabbit/element/base.rb', line 275

def if_dirty
  if dirty?
    yield
    @dirty = false
  end
end

#init_default_marginObject



250
251
252
253
254
255
# File 'lib/rabbit/element/base.rb', line 250

def init_default_margin
  @default_margin_left = 0
  @default_margin_right = 0
  @default_margin_top = 0
  @default_margin_bottom = 0
end

#init_default_paddingObject



243
244
245
246
247
248
# File 'lib/rabbit/element/base.rb', line 243

def init_default_padding
  @default_padding_left = 0
  @default_padding_right = 0
  @default_padding_top = 0
  @default_padding_bottom = 0
end

#init_default_visibleObject



257
258
259
# File 'lib/rabbit/element/base.rb', line 257

def init_default_visible
  @default_visible = !have_wait_tag?
end

#initializeObject



40
41
42
43
44
45
46
47
48
49
# File 'lib/rabbit/element/base.rb', line 40

def initialize
  @x = @y = @w = @h = nil
  @parent = nil
  @user_property = {}
  @default_prop = {}
  init_default_padding
  init_default_margin
  init_default_visible
  clear_theme
end

#inline_element?Boolean

Returns:

  • (Boolean)


164
165
166
# File 'lib/rabbit/element/base.rb', line 164

def inline_element?
  true
end

#inspect(verbose = false) ⇒ Object



338
339
340
341
342
343
344
# File 'lib/rabbit/element/base.rb', line 338

def inspect(verbose=false)
  if verbose
    super()
  else
    "<#{self.class.name}>"
  end
end

#margin_set(*values) ⇒ Object



361
362
363
364
365
366
367
# File 'lib/rabbit/element/base.rb', line 361

def margin_set(*values)
  top, right, bottom, left = parse_four_way(*values)
  @margin_top = top if top
  @margin_right = right if right
  @margin_bottom = bottom if bottom
  @margin_left = left if left
end

#margin_with(params) ⇒ Object



369
370
371
# File 'lib/rabbit/element/base.rb', line 369

def margin_with(params)
  margin_set(params)
end

#match?(pattern) ⇒ Boolean

Returns:

  • (Boolean)


357
358
359
# File 'lib/rabbit/element/base.rb', line 357

def match?(pattern)
  pattern === text
end

#next_elementObject



314
315
316
# File 'lib/rabbit/element/base.rb', line 314

def next_element
  sibling_element(1)
end

#padding_set(*values) ⇒ Object



373
374
375
376
377
378
379
# File 'lib/rabbit/element/base.rb', line 373

def padding_set(*values)
  top, right, bottom, left = parse_four_way(*values)
  @padding_top = top if top
  @padding_right = right if right
  @padding_bottom = bottom if bottom
  @padding_left = left if left
end

#padding_with(params) ⇒ Object



381
382
383
# File 'lib/rabbit/element/base.rb', line 381

def padding_with(params)
  padding_set(params)
end

#previous_elementObject



310
311
312
# File 'lib/rabbit/element/base.rb', line 310

def previous_element
  sibling_element(-1)
end

#prop_delete(name) ⇒ Object Also known as: __prop_delete__



141
142
143
144
145
# File 'lib/rabbit/element/base.rb', line 141

def prop_delete(name)
  name = normalize_property_name(name)
  @prop.delete(name)
  dirty!
end

#prop_get(name) ⇒ Object Also known as: __prop_get__



128
129
130
131
# File 'lib/rabbit/element/base.rb', line 128

def prop_get(name)
  name = normalize_property_name(name)
  @prop[name]
end

#prop_set(name, *values) ⇒ Object Also known as: __prop_set__



121
122
123
124
125
# File 'lib/rabbit/element/base.rb', line 121

def prop_set(name, *values)
  name = normalize_property_name(name)
  @prop[name] = make_prop_value(name, *values)
  dirty!
end

#prop_value(name) ⇒ Object



134
135
136
137
138
139
# File 'lib/rabbit/element/base.rb', line 134

def prop_value(name)
  name = normalize_property_name(name)
  value = @prop[name]
  value = value.value if value.respond_to?(:value)
  value
end

#reset_horizontal_centering(canvas, x, y, w, h) ⇒ Object



307
308
# File 'lib/rabbit/element/base.rb', line 307

def reset_horizontal_centering(canvas, x, y, w, h)
end

#restore_x_margin(x, w) ⇒ Object



211
212
213
214
215
# File 'lib/rabbit/element/base.rb', line 211

def restore_x_margin(x, w)
  x -= @margin_left
  w += @margin_left + @margin_right
  [x, w]
end

#restore_x_padding(x, w) ⇒ Object



205
206
207
208
209
# File 'lib/rabbit/element/base.rb', line 205

def restore_x_padding(x, w)
  x -= @padding_left
  w += @padding_left + @padding_right
  [x, w]
end

#setup_margin(x, y, w, h) ⇒ Object



229
230
231
232
233
234
235
# File 'lib/rabbit/element/base.rb', line 229

def setup_margin(x, y, w, h)
  x += @margin_left
  y += @margin_top
  w -= @margin_left + @margin_right
  h -= @margin_top + @margin_bottom
  [x, y, w, h]
end

#setup_padding(x, y, w, h) ⇒ Object



197
198
199
200
201
202
203
# File 'lib/rabbit/element/base.rb', line 197

def setup_padding(x, y, w, h)
  x += @padding_left
  y += @padding_top
  w -= @padding_left + @padding_right
  h -= @padding_top + @padding_bottom
  [x, y, w, h]
end

#show(&block) ⇒ Object



385
386
387
# File 'lib/rabbit/element/base.rb', line 385

def show(&block)
  change_visible(true, &block)
end

#slideObject



60
61
62
# File 'lib/rabbit/element/base.rb', line 60

def slide
  @slide ||= _slide
end

#substitute_newlineObject



176
177
178
179
180
# File 'lib/rabbit/element/base.rb', line 176

def substitute_newline
  substitute_text do |text|
    text.gsub(/(\\)?\\n/) {$1 ? "\\n" : "\n"}
  end
end

#substitute_textObject



172
173
174
# File 'lib/rabbit/element/base.rb', line 172

def substitute_text
  false
end

#text_renderer?Boolean

Returns:

  • (Boolean)


168
169
170
# File 'lib/rabbit/element/base.rb', line 168

def text_renderer?
  false
end

#visible?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/rabbit/element/base.rb', line 56

def visible?
  @visible
end

#wait(*args, &block) ⇒ Object



83
84
85
# File 'lib/rabbit/element/base.rb', line 83

def wait(*args, &block)
  slide.register_wait_proc(self, *args, &block) if slide
end

#widthObject



322
323
324
# File 'lib/rabbit/element/base.rb', line 322

def width
  @width + @padding_left + @padding_right
end