Sha256: 2d097554b830595a26d24c12f56949b79d2711d6b3e7ee520db2c3e704023fca

Contents?: true

Size: 749 Bytes

Versions: 3

Compression:

Stored size: 749 Bytes

Contents

# image.rb

module Ruby2D
  class Image
    include Renderable

    attr_accessor :x, :y, :width, :height, :data
    attr_reader :path, :color

    def initialize(opts = {})
      @path = opts[:path]

      unless RUBY_ENGINE == 'opal'
        unless File.exists? @path
          raise Error, "Cannot find image file `#{@path}`"
        end
      end

      @x = opts[:x] || 0
      @y = opts[:y] || 0
      @z = opts[:z] || 0
      @width  = opts[:width]  || nil
      @height = opts[:height] || nil

      self.color = opts[:color] || 'white'

      ext_init(@path)
      add
    end

    def color=(c)
      @color = Color.new(c)
    end

    def contains?(x, y)
      @x < x and @x + @width > x and @y < y and @y + @height > y
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ruby2d-0.5.1 lib/ruby2d/image.rb
ruby2d-0.5.0 lib/ruby2d/image.rb
ruby2d-0.4.2 lib/ruby2d/image.rb