Class: Metro::Model::ScaleProperty

Inherits:
Property
  • Object
show all
Defined in:
lib/metro/models/properties/scale_property.rb

Overview

A scale property maintains an x and y scaling factor.

A scale property also defines a ‘x_factor` property and a `y_factor` property which allows a more direct interface. Changing these values will update the scale the next time that it is used.

A scale is stored in the properties as a string representation and is converted into a Scale when it is retrieved within the system.

Examples:

Defining a scale property


class Scoreboard < Metro::Model
  property :font
  property :color
  property :scale

  def draw
    image.draw text, x, y, z_order, x_factor, y_factor, color
  end

end

Defining a scale property providing a default


class Hero < Metro::Model
  property :image, path: 'hero.jpg'
  property :scale, default: "1.0,1.0"
end

Using a scale property with a different property name


class Hero < Metro::Model
  property :image, path: 'hero.jpg'
  property :enraged_scale, type: :scale, default: "4.0,4.0"
  property :angle
  property :color

  def draw
    image.draw_rot x, y, z_order, angle.to_f, 0.5, 0.5, 
      enraged_scale_factor_x, enraged_scale_factor_y, color
  end
end

Constant Summary

Constants included from Units

Units::Bounds

Instance Attribute Summary

Attributes inherited from Property

#block, #model, #options

Instance Method Summary collapse

Methods inherited from Property

define_property, defined_properties, get, #get, get_or_set, gets, hash_with_default_to_nil, inherited, #initialize, properties, properties_hash, property, #set, set, sets

Constructor Details

This class inherits a constructor from Metro::Model::Property

Instance Method Details

#default_scaleObject



73
74
75
# File 'lib/metro/models/properties/scale_property.rb', line 73

def default_scale
  (options[:default] and options[:default].is_a? Scale) ? options[:default] : Scale.one
end