Class: Dedalus::Elements::Image

Inherits:
Atom show all
Defined in:
lib/dedalus/elements/image.rb

Direct Known Subclasses

Icon, Sprite

Instance Attribute Summary collapse

Attributes inherited from Dedalus::Element

#background_color, #color, #height_percent, #margin, #position, #width_percent

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Dedalus::Element

#big_font, #code_font, #draw_bounding_box, #font, #huge_font, #initialize, #tiny_font, #view, #window

Constructor Details

This class inherits a constructor from Dedalus::Element

Instance Attribute Details

#paddingObject

Returns the value of attribute padding.



4
5
6
# File 'lib/dedalus/elements/image.rb', line 4

def padding
  @padding
end

#pathObject

Returns the value of attribute path.



4
5
6
# File 'lib/dedalus/elements/image.rb', line 4

def path
  @path
end

#z_orderObject

Returns the value of attribute z_order.



4
5
6
# File 'lib/dedalus/elements/image.rb', line 4

def z_order
  @z_order
end

Class Method Details

.descriptionObject



39
40
41
# File 'lib/dedalus/elements/image.rb', line 39

def self.description
  "an image"
end

.example_dataObject



35
36
37
# File 'lib/dedalus/elements/image.rb', line 35

def self.example_data
  { path: "media/images/cosmos.jpg", scale: 0.2 }
end

Instance Method Details

#assetObject



43
44
45
# File 'lib/dedalus/elements/image.rb', line 43

def asset
  @asset ||= Dedalus::ImageRepository.lookup(path)
end

#dimensionsObject



23
24
25
# File 'lib/dedalus/elements/image.rb', line 23

def dimensions
  [ width, height ]
end

#heightObject



19
20
21
# File 'lib/dedalus/elements/image.rb', line 19

def height
  2*padding + (asset.height * scale)
end

#renderObject



6
7
8
9
# File 'lib/dedalus/elements/image.rb', line 6

def render
  x,y = *position
  asset.draw(x + padding, y + padding, z_order, scale, scale)
end

#scaleObject



31
32
33
# File 'lib/dedalus/elements/image.rb', line 31

def scale
  @scale ||= 1.0
end

#widthObject



15
16
17
# File 'lib/dedalus/elements/image.rb', line 15

def width
  2*padding + (asset.width * scale)
end