Class: CyberarmEngine::BackgroundImage
- Inherits:
-
Object
- Object
- CyberarmEngine::BackgroundImage
- Includes:
- Common
- Defined in:
- lib/cyberarm_engine/background_image.rb
Instance Attribute Summary collapse
-
#color ⇒ Object
Returns the value of attribute color.
-
#height ⇒ Object
Returns the value of attribute height.
-
#image ⇒ Object
Returns the value of attribute image.
-
#mode ⇒ Object
Returns the value of attribute mode.
-
#width ⇒ Object
Returns the value of attribute width.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
-
#z ⇒ Object
Returns the value of attribute z.
Instance Method Summary collapse
- #draw ⇒ Object
- #draw_fill ⇒ Object
- #draw_fill_height ⇒ Object
- #draw_fill_width ⇒ Object
- #draw_stretch ⇒ Object
- #draw_tiled ⇒ Object
- #height_scale ⇒ Object
-
#initialize(image_path: nil, x: 0, y: 0, z: 0, width: 0, height: 0, mode: :fill, color: Gosu::Color::WHITE) ⇒ BackgroundImage
constructor
A new instance of BackgroundImage.
- #width_scale ⇒ Object
Methods included from Common
#alt_down?, #control_down?, #current_state, #darken, #draw_rect, #fill, #find_element_by_tag, #get_asset, #get_image, #get_sample, #get_song, #lighten, #opacity, #pop_state, #previous_state, #push_state, #shift_down?, #shift_state, #show_cursor, #show_cursor=, #window
Constructor Details
#initialize(image_path: nil, x: 0, y: 0, z: 0, width: 0, height: 0, mode: :fill, color: Gosu::Color::WHITE) ⇒ BackgroundImage
Returns a new instance of BackgroundImage.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/cyberarm_engine/background_image.rb', line 7 def initialize(image_path: nil, x: 0, y: 0, z: 0, width: 0, height: 0, mode: :fill, color: Gosu::Color::WHITE) @image_path = image_path @image = get_image(image_path) if image_path @x = x @y = y @z = z @width = width @height = height @mode = mode @color = color @cached_tiling = nil end |
Instance Attribute Details
#color ⇒ Object
Returns the value of attribute color.
5 6 7 |
# File 'lib/cyberarm_engine/background_image.rb', line 5 def color @color end |
#height ⇒ Object
Returns the value of attribute height.
5 6 7 |
# File 'lib/cyberarm_engine/background_image.rb', line 5 def height @height end |
#image ⇒ Object
Returns the value of attribute image.
5 6 7 |
# File 'lib/cyberarm_engine/background_image.rb', line 5 def image @image end |
#mode ⇒ Object
Returns the value of attribute mode.
4 5 6 |
# File 'lib/cyberarm_engine/background_image.rb', line 4 def mode @mode end |
#width ⇒ Object
Returns the value of attribute width.
5 6 7 |
# File 'lib/cyberarm_engine/background_image.rb', line 5 def width @width end |
#x ⇒ Object
Returns the value of attribute x.
4 5 6 |
# File 'lib/cyberarm_engine/background_image.rb', line 4 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
4 5 6 |
# File 'lib/cyberarm_engine/background_image.rb', line 4 def y @y end |
#z ⇒ Object
Returns the value of attribute z.
4 5 6 |
# File 'lib/cyberarm_engine/background_image.rb', line 4 def z @z end |
Instance Method Details
#draw ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/cyberarm_engine/background_image.rb', line 53 def draw return unless @image Gosu.clip_to(@x, @y, @width, @height) do send(:"draw_#{mode}") end end |
#draw_fill ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/cyberarm_engine/background_image.rb', line 77 def draw_fill if (@image.width * width_scale) >= @width && (@image.height * width_scale) >= @height draw_fill_width else draw_fill_height end end |
#draw_fill_height ⇒ Object
89 90 91 |
# File 'lib/cyberarm_engine/background_image.rb', line 89 def draw_fill_height @image.draw(@x, @y, @z, height_scale, height_scale, @color) end |
#draw_fill_width ⇒ Object
85 86 87 |
# File 'lib/cyberarm_engine/background_image.rb', line 85 def draw_fill_width @image.draw(@x, @y, @z, width_scale, width_scale, @color) end |
#draw_stretch ⇒ Object
61 62 63 |
# File 'lib/cyberarm_engine/background_image.rb', line 61 def draw_stretch @image.draw(@x, @y, @z, width_scale, height_scale, @color) end |
#draw_tiled ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/cyberarm_engine/background_image.rb', line 65 def draw_tiled @cached_tiling ||= Gosu.record(@width, @height) do height_scale.ceil.times do |y| width_scale.ceil.times do |x| @image.draw(x * @image.width, y * @image.height, @z, 1, 1, @color) end end end @cached_tiling.draw(@x, @y, @z) end |
#height_scale ⇒ Object
49 50 51 |
# File 'lib/cyberarm_engine/background_image.rb', line 49 def height_scale (@height.to_f / @image.height).abs end |
#width_scale ⇒ Object
45 46 47 |
# File 'lib/cyberarm_engine/background_image.rb', line 45 def width_scale (@width.to_f / @image.width).abs end |