class DXRubySDL::Image
Attributes
_surface[R]
Public Class Methods
load(filename, x = nil, y = nil, width = nil, height = nil)
click to toggle source
# File lib/dxruby_sdl/image.rb, line 8 def self.load(filename, x = nil, y = nil, width = nil, height = nil) image = new(0, 0) surface = SDL::Surface.load(filename) image.instance_variable_set('@_surface', surface) return image end
load_tiles(filename, xcount, ycount)
click to toggle source
# File lib/dxruby_sdl/image.rb, line 15 def self.load_tiles(filename, xcount, ycount) surface = SDL::Surface.load(filename) width = surface.w / xcount height = surface.h / ycount images = [] ycount.times do |y| xcount.times do |x| image = new(0, 0) s = surface.copy_rect(x * width, y * height, width, height) image.instance_variable_set('@_surface', s) images << image end end return images end
Also aliased as: loadTiles, load_to_array
new(width, height, color = [0, 0, 0, 0])
click to toggle source
# File lib/dxruby_sdl/image.rb, line 31 def initialize(width, height, color = [0, 0, 0, 0]) @color = to_sdl_rgba(color) if width == 0 && height == 0 return end @_surface = SDL::Surface.new(SDL::SWSURFACE, width, height, Window.send(:screen)) @_surface.fill_rect(0, 0, width, height, @color) end
Public Instance Methods
[](x, y)
click to toggle source
# File lib/dxruby_sdl/image.rb, line 43 def [](x, y) pixel = lock { @_surface.get_pixel(x, y) } Color.to_dxruby_argb(@_surface.format.get_rgba(pixel)) end
[]=(x, y, color)
click to toggle source
# File lib/dxruby_sdl/image.rb, line 48 def []=(x, y, color) sdl_rgba = Color.to_sdl_rgba(color) lock { @_surface[x, y] = sdl_rgba } end
box(x1, y1, x2, y2, color)
click to toggle source
# File lib/dxruby_sdl/image.rb, line 102 def box(x1, y1, x2, y2, color) x = x1 < x2 ? x1 : x2 w = (x2 - x1).abs y = y1 < y2 ? y1 : y2 h = (y2 - y1).abs lock do @_surface.draw_rect(x, y, w, h, to_sdl_color(color), false, to_sdl_alpha(color)) end return self end
box_fill(x1, y1, x2, y2, color)
click to toggle source
# File lib/dxruby_sdl/image.rb, line 114 def box_fill(x1, y1, x2, y2, color) x = x1 < x2 ? x1 : x2 w = (x2 - x1).abs y = y1 < y2 ? y1 : y2 h = (y2 - y1).abs lock do @_surface.draw_rect(x, y, w, h, to_sdl_color(color), true, to_sdl_alpha(color)) end return self end
Also aliased as: boxFill
circle(x, y, r, color)
click to toggle source
# File lib/dxruby_sdl/image.rb, line 86 def circle(x, y, r, color) lock do @_surface.draw_circle(x, y, r, to_sdl_color(color), false, true, to_sdl_alpha(color)) end return self end
circle_fill(x, y, r, color)
click to toggle source
# File lib/dxruby_sdl/image.rb, line 94 def circle_fill(x, y, r, color) lock do @_surface.draw_circle(x, y, r, to_sdl_color(color), true, false, to_sdl_alpha(color)) end return self end
Also aliased as: circleFill
compare(x, y, color)
click to toggle source
# File lib/dxruby_sdl/image.rb, line 67 def compare(x, y, color) self[x, y] == Color.normalize_dxruby(color) end
draw(x, y, image, x1 = 0, y1 = 0, width = image.width, height = image.height)
click to toggle source
# File lib/dxruby_sdl/image.rb, line 126 def draw(x, y, image, x1 = 0, y1 = 0, width = image.width, height = image.height) SDL.blitSurface(image._surface, x1, y1, width, height, self._surface, x, y) end
draw_font(x, y, string, font, color = [255, 255, 255])
click to toggle source
# File lib/dxruby_sdl/image.rb, line 130 def draw_font(x, y, string, font, color = [255, 255, 255]) if string.empty? return end r, g, b = *to_sdl_color(color) h = font._ttf.height + 1 string.lines.each.with_index do |line, i| line.chomp! if line.empty? next end font._ttf.draw_blended_utf8(@_surface, line, x, y + i * h, r, g, b) end return self end
Also aliased as: drawFont
height()
click to toggle source
# File lib/dxruby_sdl/image.rb, line 59 def height return @_surface.h end
line(x1, y1, x2, y2, color)
click to toggle source
# File lib/dxruby_sdl/image.rb, line 78 def line(x1, y1, x2, y2, color) lock do @_surface.draw_line(x1, y1, x2, y2, to_sdl_color(color), true, to_sdl_alpha(color)) end return self end
set_color_key(color)
click to toggle source
# File lib/dxruby_sdl/image.rb, line 63 def set_color_key(color) @_surface.set_color_key(SDL::SRCCOLORKEY | SDL::RLEACCEL, to_sdl_color(color)) end
Also aliased as: setColorKey
slice(x, y, width, height)
click to toggle source
# File lib/dxruby_sdl/image.rb, line 71 def slice(x, y, width, height) s = @_surface.copy_rect(x, y, width, height) image = Image.new(0, 0) image.instance_variable_set('@_surface', s) return image end
width()
click to toggle source
# File lib/dxruby_sdl/image.rb, line 55 def width return @_surface.w end
Private Instance Methods
lock() { || ... }
click to toggle source
# File lib/dxruby_sdl/image.rb, line 158 def lock(&block) if SDL::Surface.auto_lock? yield else begin @_surface.lock return yield ensure @_surface.unlock end end end