module Scruffy::Helpers::Canvas

Scruffy::Helpers::Canvas

Author

Brasten Sager

Date

August 16th, 2006

Provides common methods for canvas objects. Primarily used for providing spacial-type calculations where necessary.

Attributes

components[RW]

Public Instance Methods

component(id, components=self.components) click to toggle source
# File lib/scruffy/helpers/canvas.rb, line 17
def component(id, components=self.components)
  components.find {|elem| elem.id == id}
end
remove(id, components=self.components) click to toggle source
# File lib/scruffy/helpers/canvas.rb, line 21
def remove(id, components=self.components)
  components.delete(component(id))
end
reset_settings!() click to toggle source
# File lib/scruffy/helpers/canvas.rb, line 13
def reset_settings!
  self.options = {}
end

Protected Instance Methods

bounds_for(canvas_size, position, size) click to toggle source

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