class Rabbit::Element::Video

Attributes

filename[R]
relative_height[R]
relative_margin_bottom[R]
relative_margin_left[R]
relative_margin_right[R]
relative_margin_top[R]
relative_padding_bottom[R]
relative_padding_left[R]
relative_padding_right[R]
relative_padding_top[R]
relative_width[R]

Public Class Methods

new(filename, prop) click to toggle source
Calls superclass method Rabbit::Element::TextRenderer::new
# File lib/rabbit/element/video.rb, line 23
def initialize(filename, prop)
  @filename = filename
  prop = Utils.stringify_hash_key(prop)
  super()
  normalized_prop = {}
  prop.each do |name, value|
    normalized_prop[name.gsub(/-/, '_')] = value
  end
  prop = normalized_prop
  %w(as_large_as_possible).each do |name|
    instance_variable_set("@#{name}", true_value?(prop[name]))
  end
  %w(width height
     relative_width relative_height
     relative_margin_top relative_margin_bottom
     relative_margin_left relative_margin_right
     relative_padding_top relative_padding_bottom
     relative_padding_left relative_padding_right
    ).each do |name|
    begin
      instance_variable_set("@#{name}", prop[name] && Integer(prop[name]))
    rescue ArgumentError
      raise InvalidSizeError.new(filename, name, prop[name])
    end
  end

  resize(@width, @height)
end

Public Instance Methods

_compile(canvas, x, y, w, h)
Alias for: compile
as_large_as_possible?() click to toggle source
# File lib/rabbit/element/video.rb, line 70
def as_large_as_possible?
  @as_large_as_possible
end
compile(canvas, x, y, w, h) click to toggle source
Calls superclass method Rabbit::Element::TextRenderer#compile
# File lib/rabbit/element/video.rb, line 57
def compile(canvas, x, y, w, h)
  super
  adjust_size(canvas, @x, @y, @w, @h)
end
Also aliased as: _compile
compile_for_horizontal_centering(canvas, x, y, w, h) click to toggle source
# File lib/rabbit/element/video.rb, line 53
def compile_for_horizontal_centering(canvas, x, y, w, h)
  _compile(canvas, x, y, w, h)
end
draw_element(canvas, x, y, w, h, simulation) click to toggle source
# File lib/rabbit/element/video.rb, line 74
def draw_element(canvas, x, y, w, h, simulation)
  unless simulation
    if canvas.display?
      require "rabbit/video-window"
      VideoWindow.show(canvas.window, self)
    else
      draw_layout(canvas, x, y)
    end
  end
  [x, y + height, w, h - height]
end
height() click to toggle source
# File lib/rabbit/element/video.rb, line 66
def height
  @height.to_i + @padding_top + @padding_bottom
end
text() click to toggle source
# File lib/rabbit/element/video.rb, line 86
def text
  "video : #{File.basename(@filename)}"
end
to_rd() click to toggle source
# File lib/rabbit/element/video.rb, line 90
def to_rd
  text
end
width() click to toggle source
# File lib/rabbit/element/video.rb, line 62
def width
  @width.to_i + @padding_left + @padding_right
end

Private Instance Methods

adjust_margin(w, h) click to toggle source
# File lib/rabbit/element/video.rb, line 95
def adjust_margin(w, h)
  @margin_top =
    make_relative_size(@relative_margin_top, h) || @margin_top
  @margin_bottom =
    make_relative_size(@relative_margin_bottom, h) || @margin_bottom
  @margin_left =
    make_relative_size(@relative_margin_left, w) || @margin_left
  @margin_right =
    make_relative_size(@relative_margin_right, w) || @margin_right
end
adjust_padding(w, h) click to toggle source
# File lib/rabbit/element/video.rb, line 106
def adjust_padding(w, h)
  @padding_top =
    make_relative_size(@relative_padding_top, h) || @padding_top
  @padding_bottom =
    make_relative_size(@relative_padding_bottom, h) || @padding_bottom
  @padding_left =
    make_relative_size(@relative_padding_left, w) || @padding_left
  @padding_right =
    make_relative_size(@relative_padding_right, w) || @padding_right
end
adjust_size(canvas, x, y, w, h) click to toggle source
# File lib/rabbit/element/video.rb, line 117
def adjust_size(canvas, x, y, w, h)
  base_w = w
  base_h = h
  adjust_margin(base_w, base_h)
  adjust_padding(base_w, base_h)
  base_h = base_h - @padding_top - @padding_bottom
  if @as_large_as_possible
    iw = base_w
    ih = base_h
  else
    rw = make_relative_size(@relative_width, base_w)
    rh = make_relative_size(@relative_height, base_h)
    iw = rw || base_w
    ih = rh || base_h
  end
  resize(iw, ih)
end
make_relative_size(size, parent_size) click to toggle source
# File lib/rabbit/element/video.rb, line 150
def make_relative_size(size, parent_size)
  size && parent_size && ((size / 100.0) * parent_size).ceil
end
resize(w, h) click to toggle source
# File lib/rabbit/element/video.rb, line 135
def resize(w, h)
  if w.nil? and h.nil?
    return
  else
    w ||= width
    h ||= height
  end
  w = w.ceil if w
  h = h.ceil if h
  if w and w > 0 and h and h > 0 and [w, h] != [width, height]
    @width = w
    @height = h
  end
end
true_value?(value) click to toggle source
# File lib/rabbit/element/video.rb, line 154
def true_value?(value)
  value == true or value == "true"
end