Module: Rabbit::Element::Base

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

Defined Under Namespace

Modules: DrawHook

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?

Instance Attribute Details

#base_hObject (readonly)

Returns the value of attribute base_h.



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

def base_h
  @base_h
end

#base_wObject (readonly)

Returns the value of attribute base_w.



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

def base_w
  @base_w
end

#base_xObject (readonly)

Returns the value of attribute base_x.



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

def base_x
  @base_x
end

#base_yObject (readonly)

Returns the value of attribute base_y.



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

def base_y
  @base_y
end

#default_margin_bottomObject

Returns the value of attribute default_margin_bottom.



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

def default_margin_bottom
  @default_margin_bottom
end

#default_margin_leftObject

Returns the value of attribute default_margin_left.



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

def default_margin_left
  @default_margin_left
end

#default_margin_rightObject

Returns the value of attribute default_margin_right.



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

def default_margin_right
  @default_margin_right
end

#default_margin_topObject

Returns the value of attribute default_margin_top.



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

def default_margin_top
  @default_margin_top
end

#default_padding_bottomObject

Returns the value of attribute default_padding_bottom.



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

def default_padding_bottom
  @default_padding_bottom
end

#default_padding_leftObject

Returns the value of attribute default_padding_left.



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

def default_padding_left
  @default_padding_left
end

#default_padding_rightObject

Returns the value of attribute default_padding_right.



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

def default_padding_right
  @default_padding_right
end

#default_padding_topObject

Returns the value of attribute default_padding_top.



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

def default_padding_top
  @default_padding_top
end

#default_visibleObject

Returns the value of attribute default_visible.



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

def default_visible
  @default_visible
end

#hObject (readonly)

Returns the value of attribute h.



14
15
16
# File 'lib/rabbit/element/base.rb', line 14

def h
  @h
end

#horizontal_centeringObject

Returns the value of attribute horizontal_centering.



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

def horizontal_centering
  @horizontal_centering
end

#margin_bottomObject

Returns the value of attribute margin_bottom.



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

def margin_bottom
  @margin_bottom
end

#margin_leftObject

Returns the value of attribute margin_left.



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

def margin_left
  @margin_left
end

#margin_rightObject

Returns the value of attribute margin_right.



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

def margin_right
  @margin_right
end

#margin_topObject

Returns the value of attribute margin_top.



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

def margin_top
  @margin_top
end

#padding_bottomObject

Returns the value of attribute padding_bottom.



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

def padding_bottom
  @padding_bottom
end

#padding_leftObject

Returns the value of attribute padding_left.



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

def padding_left
  @padding_left
end

#padding_rightObject

Returns the value of attribute padding_right.



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

def padding_right
  @padding_right
end

#padding_topObject

Returns the value of attribute padding_top.



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

def padding_top
  @padding_top
end

#parentObject

Returns the value of attribute parent.



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

def parent
  @parent
end

#phObject (readonly)

Returns the value of attribute ph.



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

def ph
  @ph
end

#pwObject (readonly)

Returns the value of attribute pw.



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

def pw
  @pw
end

#pxObject (readonly)

Returns the value of attribute px.



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

def px
  @px
end

#pyObject (readonly)

Returns the value of attribute py.



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

def py
  @py
end

#real_simulationObject (readonly)

Returns the value of attribute real_simulation.



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

def real_simulation
  @real_simulation
end

#user_propertyObject

Returns the value of attribute user_property.



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

def user_property
  @user_property
end

#vertical_centeringObject

Returns the value of attribute vertical_centering.



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

def vertical_centering
  @vertical_centering
end

#wObject (readonly)

Returns the value of attribute w.



14
15
16
# File 'lib/rabbit/element/base.rb', line 14

def w
  @w
end

#xObject (readonly)

Returns the value of attribute x.



14
15
16
# File 'lib/rabbit/element/base.rb', line 14

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y.



14
15
16
# File 'lib/rabbit/element/base.rb', line 14

def y
  @y
end

Instance Method Details

#[](name) ⇒ Object



377
378
379
# File 'lib/rabbit/element/base.rb', line 377

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

#[]=(name, value) ⇒ Object



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

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

#add_default_prop(name, value) ⇒ Object



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

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



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

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

#adjust_y_margin(y, h) ⇒ Object



225
226
227
228
229
# File 'lib/rabbit/element/base.rb', line 225

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

#adjust_y_padding(y, h) ⇒ Object



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

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

#available_wObject



301
302
303
# File 'lib/rabbit/element/base.rb', line 301

def available_w
  @w - @padding_left - @padding_right
end

#centering_adjusted_heightObject



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

def centering_adjusted_height
  @centering_adjusted_height || 0
end

#centering_adjusted_widthObject



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

def centering_adjusted_width
  @centering_adjusted_width || 0
end

#clear_marginObject



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

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



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

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



170
171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/rabbit/element/base.rb', line 170

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



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

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

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



89
90
91
92
93
94
95
96
97
# File 'lib/rabbit/element/base.rb', line 89

def compile(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



99
100
101
# File 'lib/rabbit/element/base.rb', line 99

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



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

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

#default_propObject



337
338
339
# File 'lib/rabbit/element/base.rb', line 337

def default_prop
  @default_prop.dup
end

#dirty!Object



73
74
75
# File 'lib/rabbit/element/base.rb', line 73

def dirty!
  @dirty = true
end

#dirty?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/rabbit/element/base.rb', line 77

def dirty?
  @dirty
end

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



290
291
# File 'lib/rabbit/element/base.rb', line 290

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

#do_horizontal_centering?Boolean

Returns:

  • (Boolean)


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

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

#do_vertical_centering?Boolean

Returns:

  • (Boolean)


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

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

#draw(simulation = false) ⇒ Object



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

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



141
142
143
144
145
146
147
148
149
150
# File 'lib/rabbit/element/base.rb', line 141

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_wait_tag?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/rabbit/element/base.rb', line 85

def have_wait_tag?
  false
end

#heightObject



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

def height
  @height + @padding_top + @padding_bottom
end

#hide(&block) ⇒ Object



373
374
375
# File 'lib/rabbit/element/base.rb', line 373

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

#if_dirtyObject



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

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

#init_default_marginObject



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

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

#init_default_paddingObject



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

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

#init_default_visibleObject



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

def init_default_visible
  @default_visible = !have_wait_tag?
end

#initializeObject



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

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)


152
153
154
# File 'lib/rabbit/element/base.rb', line 152

def inline_element?
  true
end

#inspect(verbose = false) ⇒ Object



321
322
323
324
325
326
327
328
# File 'lib/rabbit/element/base.rb', line 321

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

#margin_set(*values) ⇒ Object



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

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



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

def margin_with(params)
  margin_set(params)
end

#match?(pattern) ⇒ Boolean

Returns:

  • (Boolean)


341
342
343
# File 'lib/rabbit/element/base.rb', line 341

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

#next_elementObject



297
298
299
# File 'lib/rabbit/element/base.rb', line 297

def next_element
  sibling_element(1)
end

#padding_set(*values) ⇒ Object



357
358
359
360
361
362
363
# File 'lib/rabbit/element/base.rb', line 357

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



365
366
367
# File 'lib/rabbit/element/base.rb', line 365

def padding_with(params)
  padding_set(params)
end

#previous_elementObject



293
294
295
# File 'lib/rabbit/element/base.rb', line 293

def previous_element
  sibling_element(-1)
end

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



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

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

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



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

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

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



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

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

#prop_value(name) ⇒ Object



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

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

#restore_x_margin(x, w) ⇒ Object



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

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

#restore_x_padding(x, w) ⇒ Object



193
194
195
196
197
# File 'lib/rabbit/element/base.rb', line 193

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

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



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

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



185
186
187
188
189
190
191
# File 'lib/rabbit/element/base.rb', line 185

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



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

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

#slideObject



58
59
60
# File 'lib/rabbit/element/base.rb', line 58

def slide
  @slide ||= _slide
end

#substitute_newlineObject



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

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

#substitute_textObject



160
161
162
# File 'lib/rabbit/element/base.rb', line 160

def substitute_text
  false
end

#text_renderer?Boolean

Returns:

  • (Boolean)


156
157
158
# File 'lib/rabbit/element/base.rb', line 156

def text_renderer?
  false
end

#visible?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/rabbit/element/base.rb', line 54

def visible?
  @visible
end

#wait(*args, &block) ⇒ Object



81
82
83
# File 'lib/rabbit/element/base.rb', line 81

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

#widthObject



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

def width
  @width + @padding_left + @padding_right
end