Class: Dedalus::Elements::Image
- Inherits:
-
Atom
show all
- Defined in:
- lib/dedalus/elements/image.rb
Instance Attribute Summary collapse
#background_color, #color, #height_percent, #margin, #position, #width_percent
Class Method Summary
collapse
Instance Method Summary
collapse
#big_font, #code_font, #draw_bounding_box, #font, #huge_font, #initialize, #tiny_font, #view, #window
Instance Attribute Details
#invert_x ⇒ Object
Returns the value of attribute invert_x.
4
5
6
|
# File 'lib/dedalus/elements/image.rb', line 4
def invert_x
@invert_x
end
|
#invert_y ⇒ Object
Returns the value of attribute invert_y.
4
5
6
|
# File 'lib/dedalus/elements/image.rb', line 4
def invert_y
@invert_y
end
|
#overlay_color ⇒ Object
Returns the value of attribute overlay_color.
4
5
6
|
# File 'lib/dedalus/elements/image.rb', line 4
def overlay_color
@overlay_color
end
|
#padding ⇒ Object
Returns the value of attribute padding.
4
5
6
|
# File 'lib/dedalus/elements/image.rb', line 4
def padding
@padding
end
|
#path ⇒ Object
Returns the value of attribute path.
4
5
6
|
# File 'lib/dedalus/elements/image.rb', line 4
def path
@path
end
|
#z_order ⇒ Object
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
.description ⇒ Object
64
65
66
|
# File 'lib/dedalus/elements/image.rb', line 64
def self.description
"an image"
end
|
.example_data ⇒ Object
60
61
62
|
# File 'lib/dedalus/elements/image.rb', line 60
def self.example_data
{ path: "media/images/cosmos.jpg", scale: 0.2, invert_y: true }
end
|
Instance Method Details
#asset ⇒ Object
68
69
70
|
# File 'lib/dedalus/elements/image.rb', line 68
def asset
@asset ||= Dedalus::ImageRepository.lookup(path)
end
|
#dimensions ⇒ Object
48
49
50
|
# File 'lib/dedalus/elements/image.rb', line 48
def dimensions
[ width, height ]
end
|
#height ⇒ Object
44
45
46
|
# File 'lib/dedalus/elements/image.rb', line 44
def height
2*padding + (asset.height * scale)
end
|
#offset ⇒ Object
26
27
28
29
30
31
32
33
34
|
# File 'lib/dedalus/elements/image.rb', line 26
def offset
if invert_x
[ width, 0 ]
elsif invert_y
[ 0, height ]
else
[ 0, 0 ]
end
end
|
#overlay_gosu_color ⇒ Object
20
21
22
23
24
|
# File 'lib/dedalus/elements/image.rb', line 20
def overlay_gosu_color
clr = Palette.decode_color(overlay_color).to_gosu
clr.alpha = 255
clr
end
|
#render ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/dedalus/elements/image.rb', line 6
def render
x,y = *position
x_scale = invert_x ? -scale : scale
y_scale = invert_y ? -scale : scale
ox,oy = *offset
if overlay_color
asset.draw(x + padding + ox, y + padding + oy, z_order, x_scale, y_scale, overlay_gosu_color)
else
asset.draw(x + padding + ox, y + padding + oy, z_order, x_scale, y_scale)
end
end
|
#scale ⇒ Object
56
57
58
|
# File 'lib/dedalus/elements/image.rb', line 56
def scale
@scale ||= 1.0
end
|
#width ⇒ Object
40
41
42
|
# File 'lib/dedalus/elements/image.rb', line 40
def width
2*padding + (asset.width * scale)
end
|