Brasten Sager
August 16th, 2006
Provides common methods for canvas objects. Primarily used for providing spacial-type calculations where necessary.
# File lib/scruffy/helpers/canvas.rb, line 17 def component(id, components=self.components) components.find {|elem| elem.id == id} end
# File lib/scruffy/helpers/canvas.rb, line 21 def remove(id, components=self.components) components.delete(component(id)) end
# File lib/scruffy/helpers/canvas.rb, line 13 def reset_settings! self.options = {} end
Converts percentage values into actual pixel values based on the known render size.
Returns a hash consisting of :x, :y, :width, and :height elements.
# File lib/scruffy/helpers/canvas.rb, line 30 def bounds_for(canvas_size, position, size) return nil if (position.nil? || size.nil?) bounds = {} bounds[:x] = canvas_size.first * (position.first / 100.to_f) bounds[:y] = canvas_size.last * (position.last / 100.to_f) bounds[:width] = canvas_size.first * (size.first / 100.to_f) bounds[:height] = canvas_size.last * (size.last / 100.to_f) bounds end