class Castaway::Scene

Attributes

_timeline[R]
duration[R]
finish[R]
production[R]
title[R]

Public Class Methods

new(title, production) click to toggle source
# File lib/castaway/scene.rb, line 19
def initialize(title, production)
  @title = title
  @production = production
end

Public Instance Methods

_still(filename, full) click to toggle source
# File lib/castaway/scene.rb, line 129
def _still(filename, full)
  Element::Still.new(production, self, filename, full: full).
    tap do |element|
      _timeline.add(element)
    end
end
_strip(text) click to toggle source
# File lib/castaway/scene.rb, line 136
def _strip(text)
  if text =~ /^(\s+)\S/
    indent = Regexp.last_match(1)
    text.gsub(/^#{indent}/, '')
  else
    text
  end
end
configure(&block) click to toggle source
# File lib/castaway/scene.rb, line 24
def configure(&block)
  instance_eval(&block)
  self
end
construct(timeline) click to toggle source
# File lib/castaway/scene.rb, line 73
def construct(timeline)
  @_timeline = timeline
  instance_eval(&@plan) if @plan
ensure
  remove_instance_variable :@_timeline
end
matte(color) click to toggle source

Returns a new Castaway::Element::Matte element with the given color, and adds it to the timeline.

# File lib/castaway/scene.rb, line 82
def matte(color)
  Element::Matte.new(production, self, color).tap do |element|
    _timeline.add(element)
  end
end
plan(&block) click to toggle source

Declare the plan to be used for constructing the scene. Within the plan, scene elements are declared and configured.

plan do
  matte(:black).enter(-0.5).in(:dissolve, speed: 0.5)
end

See matte, still, text, sprite, and pointer.

# File lib/castaway/scene.rb, line 69
def plan(&block)
  @plan = block
end
pointer(id = :default) click to toggle source

Returns a new Castaway::Element::Pointer element and adds it to the timeline. If an `id` is given, the pointer declared with that `id` is used.

# File lib/castaway/scene.rb, line 103
def pointer(id = :default)
  Element::Pointer.new(production, self, id).tap do |pointer|
    _timeline.add(pointer)
  end
end
relative_position(x, y) click to toggle source

Returns a Castaway::Point with the given coordinates multiplied by the resolution. This let's you declare coordinates as fractions of the frame size, so that they work regardless of the final rendered resolution.

# File lib/castaway/scene.rb, line 120
def relative_position(x, y)
  Castaway::Point.new(x, y) * production.resolution
end
relative_to_image(name) click to toggle source

Returns a new Castaway::RelativeTo instance for the resource with the given file name. This is useful for positioning pointers in a resolution-independent way.

# File lib/castaway/scene.rb, line 45
def relative_to_image(name)
  RelativeTo.new(name, production)
end
script(*args) click to toggle source

Sets (or returns) the script corresponding to the current scene. This is not used, except informationally.

# File lib/castaway/scene.rb, line 51
def script(*args)
  if args.empty?
    @script
  elsif args.length == 1
    @script = _strip(args.first)
  else
    raise ArgumentError, 'script expects 0 or 1 argument'
  end
end
sprite(filename) click to toggle source

Returns a new Castaway::Element::Still element for the given filename, and adds it to the timeline. It's native dimensions will be preserved.

# File lib/castaway/scene.rb, line 96
def sprite(filename)
  _still(filename, false)
end
start(value = nil) click to toggle source

Declares (or returns) the time value (in seconds) for the start of this scene. Any value parsable by Castaway::Times will be accepted.

# File lib/castaway/scene.rb, line 31
def start(value = nil)
  return @start unless value
  @start = _parse_time(value)
end
still(filename) click to toggle source

Returns a new Castaway::Element::Still element for the given filename, and adds it to the timeline. It will be forced to fill the entire frame.

# File lib/castaway/scene.rb, line 90
def still(filename)
  _still(filename, true)
end
text(string) click to toggle source

Returns a new Castaway::Element::Text element with the given text, and adds it to the timeline.

# File lib/castaway/scene.rb, line 111
def text(string)
  Element::Text.new(production, self, string).tap do |text|
    _timeline.add(text)
  end
end
time(value) click to toggle source

Parses and returns the seconds corresponding to the given value. See Castaway::Times.

# File lib/castaway/scene.rb, line 38
def time(value)
  _parse_time(value)
end
update_from_next(neighbor) click to toggle source
# File lib/castaway/scene.rb, line 124
def update_from_next(neighbor)
  @finish = neighbor.nil? ? @start : neighbor.start
  @duration = @finish - @start
end