Sha256: 5220e93fdce538a1c005a4126c0df1a9bfb899ecb2455c399d13e664be2689c7

Contents?: true

Size: 942 Bytes

Versions: 2

Compression:

Stored size: 942 Bytes

Contents

#
#
class Background
  
  #
  #
  attr_reader :window, :draw_function
  
  #
  #
  def initialize window
    @window        = window
    @draw_function = functionify window.background_options
  end
  
  def functionify path_or_color
    Gosu::Color === path_or_color ? color_draw_function(path_or_color) : image_draw_function(path_or_color)
  end
  
  #
  #
  def color_draw_function color
    lambda do
      window.draw_quad(0,            0,             color,
                       window.width, 0,             color,
                       window.width, window.height, color,
                       0,            window.height, color,
                       0, :default)
    end
  end
  
  #
  #
  def image_draw_function path
    image = Gosu::Image.new window, File.join(Resources.root, path), true
    lambda do
      image.draw 0, 0, Layer::Background, 1.0, 1.0
    end
  end
  
  #
  #
  def draw
    draw_function.call
  end
  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
gosu_extensions-0.2.9 lib/core/background.rb
gosu_extensions-0.2.8 lib/core/background.rb