Class | Limelight::Prop |
In: |
lib/limelight/prop.rb
|
Parent: | Object |
Prop is the fundamental building block of a scene. A prop represents a rectangular area in the scene, of almost any dimension. It may have borders, backgrounds, margin, padding, and it may contain other props or text. However it is the props’ Styles that determine their size and appearance.
A Prop may have one parent and many children. Hense, when put together, they form a tree structure. The Scene is the root Prop of a tree.
children | [R] | |
hover_style | [RW] | |
id | [R] | |
name | [R] | |
parent | [R] | |
players | [R] | |
style | [RW] |
# File lib/limelight/prop.rb, line 22 22: def event(event_symbol) 23: @events ||= [] 24: @events << event_symbol unless @events.include?(event_symbol) 25: define_method(event_symbol) { |event| } # do nothing by default 26: end
# File lib/limelight/prop.rb, line 32 32: def event2(event_symbol) 33: @events ||= [] 34: @events << event_symbol unless @events.include?(event_symbol) 35: define_method("accepts_#{event_symbol}".to_sym) { return self.respond_to?(event_symbol) } 36: end
When creating a Prop, an optional Hash is accepted. These are called initialization options. The key/value pairs in the initialiaztion options will be used to set properties on the Prop, it Style, or included Player properties. These properties are not set until the prop is added to a Prop tree with a Scene.
# File lib/limelight/prop.rb, line 52 52: def initialize(hash = {}) 53: @options = hash || {} 54: @children = [] 55: @style = Styles::ScreenableStyle.new 56: @panel = UI::Model::Panel.new(self) 57: end
Allows the addition of extra initialization options. Will raise an exception if the Prop has already been illuminated (added to a scene).
# File lib/limelight/prop.rb, line 201 201: def add_options(more_options) 202: raise "Too late to add options" if illuminated? 203: @options.merge!(more_options) 204: end
Initiate an animation loop. Options may include :name (string), :updates_per_second (int: defaults to 60) An Animation object is returned. The provided block will be invoked :updates_per_second times per second until the Animation is stopped.
@animation = prop.animate(:updates_per_second => 20) do prop.style.border_width = (prop.style.top_border_width.to_i + 1).to_s @animation.stop if prop.style.top_border_width.to_i > 60 end
This above example will cause the Prop‘s border to grow until it is 60 pixels wide.
# File lib/limelight/prop.rb, line 247 247: def animate(options={}, &block) 248: animation = Animation.new(self, block, options) 249: animation.start 250: return animation 251: end
Returns a Box representing the relative bounds of the Prop. Is useful with usign the Pen.
box = prop.area box.x, box.y # represents the Prop's location within its parent Prop box.width, box.height # represents the Prop's dimensions
# File lib/limelight/prop.rb, line 212 212: def area 213: return panel.get_bounding_box.clone 214: end
Allows the adding of child Props using the PropBuilder DSL.
prop.build do child1 do grand_child end child2 end
# File lib/limelight/prop.rb, line 85 85: def build(options = {}, &block) 86: require 'limelight/dsl/prop_builder' 87: builder = Limelight::DSL::PropBuilder.new(self) 88: builder.__install_instance_variables(options) 89: builder.__loader__ = scene.loader 90: builder.instance_eval(&block) 91: end
Searches all descendant of the Prop (including itself) for Props with the specified name. Returns an Array of matching Props. Returns an empty Array if none are found.
# File lib/limelight/prop.rb, line 144 144: def find_by_name(name, results = []) 145: results << self if @name == name 146: @children.each { |child| child.find_by_name(name, results) } 147: return results 148: end
Injects the behavior of the specified Player into the Prop. The Player must be a Module.
# File lib/limelight/prop.rb, line 112 112: def include_player(player_module) 113: unless self.is_a?(player_module) 114: extend player_module 115: self.casted if player_module.instance_methods.include?("casted") 116: end 117: end
Luanches the spcified URL using the OS‘s default handlers. For example, opening a URL in a browser:
launch('http://www.google.com')
To create a link prop add an accessor on the player (say url) and use that in the prop definition Ex:
link :text => "I am a link", :url => "http://www.8thlight.com"
# File lib/limelight/prop.rb, line 268 268: def launch(url) 269: Context.instance.os.launch(url) 270: end
Plays a sound on the computers audio output. The parameter is the filename of a .au sound file. This filename should relative to the root directory of the current Production, or an absolute path.
# File lib/limelight/prop.rb, line 256 256: def play_sound(filename) 257: @panel.play_sound(scene.loader.path_to(filename)) 258: end
Returns the current Production this Prop lives in.
# File lib/limelight/prop.rb, line 178 178: def production 179: return scene.production 180: end
Removes all child Props.
# File lib/limelight/prop.rb, line 104 104: def remove_all 105: @panel.remove_all 106: @children.each { |child| scene.unindex_prop(child) } if scene 107: @children = [] 108: end