Class: CyberarmEngine::BackgroundImage

Inherits:
Object
  • Object
show all
Includes:
Common
Defined in:
lib/cyberarm_engine/background_image.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#colorObject

Returns the value of attribute color.



5
6
7
# File 'lib/cyberarm_engine/background_image.rb', line 5

def color
  @color
end

#heightObject

Returns the value of attribute height.



5
6
7
# File 'lib/cyberarm_engine/background_image.rb', line 5

def height
  @height
end

#imageObject

Returns the value of attribute image.



5
6
7
# File 'lib/cyberarm_engine/background_image.rb', line 5

def image
  @image
end

#modeObject

Returns the value of attribute mode.



4
5
6
# File 'lib/cyberarm_engine/background_image.rb', line 4

def mode
  @mode
end

#widthObject

Returns the value of attribute width.



5
6
7
# File 'lib/cyberarm_engine/background_image.rb', line 5

def width
  @width
end

#xObject

Returns the value of attribute x.



4
5
6
# File 'lib/cyberarm_engine/background_image.rb', line 4

def x
  @x
end

#yObject

Returns the value of attribute y.



4
5
6
# File 'lib/cyberarm_engine/background_image.rb', line 4

def y
  @y
end

#zObject

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

#drawObject



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_fillObject



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_heightObject



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_widthObject



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_stretchObject



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_tiledObject



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_scaleObject



49
50
51
# File 'lib/cyberarm_engine/background_image.rb', line 49

def height_scale
  (@height.to_f / @image.height).abs
end

#width_scaleObject



45
46
47
# File 'lib/cyberarm_engine/background_image.rb', line 45

def width_scale
  (@width.to_f / @image.width).abs
end