Class: Castaway::Scene
Instance Attribute Summary collapse
-
#_timeline ⇒ Object
readonly
Returns the value of attribute _timeline.
-
#duration ⇒ Object
readonly
Returns the value of attribute duration.
-
#finish ⇒ Object
readonly
Returns the value of attribute finish.
-
#production ⇒ Object
readonly
Returns the value of attribute production.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
- #_still(filename, full) ⇒ Object
- #_strip(text) ⇒ Object
- #configure(&block) ⇒ Object
- #construct(timeline) ⇒ Object
-
#initialize(title, production) ⇒ Scene
constructor
A new instance of Scene.
-
#matte(color) ⇒ Object
Returns a new Castaway::Element::Matte element with the given color, and adds it to the timeline.
-
#plan(&block) ⇒ Object
Declare the plan to be used for constructing the scene.
-
#pointer(id = :default) ⇒ Object
Returns a new Castaway::Element::Pointer element and adds it to the timeline.
-
#relative_position(x, y) ⇒ Object
Returns a Castaway::Point with the given coordinates multiplied by the resolution.
-
#relative_to_image(name) ⇒ Object
Returns a new Castaway::RelativeTo instance for the resource with the given file name.
-
#script(*args) ⇒ Object
Sets (or returns) the script corresponding to the current scene.
-
#sprite(filename) ⇒ Object
Returns a new Castaway::Element::Still element for the given filename, and adds it to the timeline.
-
#start(value = nil) ⇒ Object
Declares (or returns) the time value (in seconds) for the start of this scene.
-
#still(filename) ⇒ Object
Returns a new Castaway::Element::Still element for the given filename, and adds it to the timeline.
-
#text(string) ⇒ Object
Returns a new Castaway::Element::Text element with the given text, and adds it to the timeline.
-
#time(value) ⇒ Object
Parses and returns the seconds corresponding to the given value.
- #update_from_next(neighbor) ⇒ Object
Methods included from Times
#_parse_numeric_time, #_parse_time, #_parse_timespec_time
Constructor Details
#initialize(title, production) ⇒ Scene
Returns a new instance of Scene.
19 20 21 22 |
# File 'lib/castaway/scene.rb', line 19 def initialize(title, production) @title = title @production = production end |
Instance Attribute Details
#_timeline ⇒ Object (readonly)
Returns the value of attribute _timeline.
17 18 19 |
# File 'lib/castaway/scene.rb', line 17 def _timeline @_timeline end |
#duration ⇒ Object (readonly)
Returns the value of attribute duration.
15 16 17 |
# File 'lib/castaway/scene.rb', line 15 def duration @duration end |
#finish ⇒ Object (readonly)
Returns the value of attribute finish.
15 16 17 |
# File 'lib/castaway/scene.rb', line 15 def finish @finish end |
#production ⇒ Object (readonly)
Returns the value of attribute production.
13 14 15 |
# File 'lib/castaway/scene.rb', line 13 def production @production end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
12 13 14 |
# File 'lib/castaway/scene.rb', line 12 def title @title end |
Instance Method Details
#_still(filename, full) ⇒ Object
129 130 131 132 133 134 |
# 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) ⇒ Object
136 137 138 139 140 141 142 143 |
# 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) ⇒ Object
24 25 26 27 |
# File 'lib/castaway/scene.rb', line 24 def configure(&block) instance_eval(&block) self end |
#construct(timeline) ⇒ Object
73 74 75 76 77 78 |
# 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) ⇒ Object
Returns a new Castaway::Element::Matte element with the given color, and adds it to the timeline.
82 83 84 85 86 |
# 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) ⇒ Object
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.
69 70 71 |
# File 'lib/castaway/scene.rb', line 69 def plan(&block) @plan = block end |
#pointer(id = :default) ⇒ Object
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.
103 104 105 106 107 |
# 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) ⇒ Object
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.
120 121 122 |
# File 'lib/castaway/scene.rb', line 120 def relative_position(x, y) Castaway::Point.new(x, y) * production.resolution end |
#relative_to_image(name) ⇒ Object
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.
45 46 47 |
# File 'lib/castaway/scene.rb', line 45 def relative_to_image(name) RelativeTo.new(name, production) end |
#script(*args) ⇒ Object
Sets (or returns) the script corresponding to the current scene. This is not used, except informationally.
51 52 53 54 55 56 57 58 59 |
# 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) ⇒ Object
Returns a new Castaway::Element::Still element for the given filename, and adds it to the timeline. It’s native dimensions will be preserved.
96 97 98 |
# File 'lib/castaway/scene.rb', line 96 def sprite(filename) _still(filename, false) end |
#start(value = nil) ⇒ Object
Declares (or returns) the time value (in seconds) for the start of this scene. Any value parsable by Castaway::Times will be accepted.
31 32 33 34 |
# File 'lib/castaway/scene.rb', line 31 def start(value = nil) return @start unless value @start = _parse_time(value) end |
#still(filename) ⇒ Object
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.
90 91 92 |
# File 'lib/castaway/scene.rb', line 90 def still(filename) _still(filename, true) end |
#text(string) ⇒ Object
Returns a new Castaway::Element::Text element with the given text, and adds it to the timeline.
111 112 113 114 115 |
# 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) ⇒ Object
Parses and returns the seconds corresponding to the given value. See Castaway::Times.
38 39 40 |
# File 'lib/castaway/scene.rb', line 38 def time(value) _parse_time(value) end |
#update_from_next(neighbor) ⇒ Object
124 125 126 127 |
# File 'lib/castaway/scene.rb', line 124 def update_from_next(neighbor) @finish = neighbor.nil? ? @start : neighbor.start @duration = @finish - @start end |