class SDL2::Surface

brief A collection of pixels used in software blitting.

note This structure should be treated as read-only, except for c pixels,

which, if not NULL, contains the raw pixel data for the surface.

Constants

DONTFREE
PREALLOC
RLEACCEL
SWSURFACE

Surface Flags

Public Class Methods

create_rgb(flags, width, height, depth, rmask = 0, gmask = 0, bmask = 0, amask = 0) click to toggle source

Allocate and free an RGB surface If depth is 4 or 8 bits, an empty palette is allocated for the surface. If depth is > 8 bits, the pixel format is set using the flag masks. If the function runs out of memory, it will return NULL.

# File lib/sdl2/surface.rb, line 49
def self.create_rgb(flags, width, height, depth, rmask = 0, gmask = 0, bmask = 0, amask = 0)
  SDL2.create_rgb_surface!(flags, width, height, depth, rmask, gmask, bmask, amask)
end
create_rgb_from(pixels, width, height, depth, pitch, rmask, gmask, bmask, amask) click to toggle source
# File lib/sdl2/surface.rb, line 53
def self.create_rgb_from(pixels, width, height, depth, pitch, rmask, gmask, bmask, amask)
  SDL2.create_rgb_surface_from!(pixels, width, height, depth, pitch, rmask, gmask, bmask, amask)
end
load_bmp(file) click to toggle source
# File lib/sdl2/surface.rb, line 61
def self.load_bmp(file)
  SDL2.load_bmp!(file)
end
load_bmp_rw(rwops, freesrc = 0) click to toggle source
# File lib/sdl2/surface.rb, line 57
def self.load_bmp_rw(rwops, freesrc = 0)
  SDL2.load_bmp_rw!(rwops, freesrc)
end
release(pointer) click to toggle source
# File lib/sdl2/surface.rb, line 41
def self.release(pointer)
  SDL2.free_surface(pointer)
end

Public Instance Methods

blit_in(src, src_rect = nil, dst_rect = nil) click to toggle source

Blit from source to this surface

# File lib/sdl2/surface.rb, line 109
def blit_in(src, src_rect = nil, dst_rect = nil)
  
  
  src_rect = Rect.cast(src_rect)
  dst_rect = Rect.cast(dst_rect)
  
  SDL2.blit_surface!(src, src_rect, self, dst_rect)
end
blit_out(dest, dst_rect = nil, src_rect = nil) click to toggle source

Blit from this surface to dest

# File lib/sdl2/surface.rb, line 119
def blit_out(dest, dst_rect = nil, src_rect = nil)
  src_rect = Rect.cast(src_rect)
  dst_rect = Rect.cast(dst_rect)
  SDL2.blit_surface!(self, src_rect, dest, dst_rect)
end
color_key()
Alias for: get_color_key
color_key=(key)
Alias for: set_color_key
convert(surface, flags = 0) click to toggle source

Convert existing surface into this surface’s format

# File lib/sdl2/surface.rb, line 167
def convert(surface, flags = 0)
  SDL2.convert_surface!(surface, self.format, flags)
end
fill_rect(rect, color) click to toggle source
# File lib/sdl2/surface.rb, line 171
def fill_rect(rect, color)
  
  if color.kind_of? Integer
    pixel_value = color
  else
    
    pixel_value = format.map(Color.cast(color))
  end
  rect = Rect.cast(rect)
  SDL2.fill_rect!(self, rect, pixel_value)
end
free() click to toggle source
# File lib/sdl2/surface.rb, line 73
def free
  SDL2.free_surface(self)
end
get_color_key() click to toggle source

Gets the color key for this surface. @returns Nil, indicating no color keying, or the encoded pixel value used.

# File lib/sdl2/surface.rb, line 152
def get_color_key()
  key_s = TypedPointer::UInt32.new
  if SDL2.get_color_key?(self, key_s)
    result = key_s[:value]
  else
    result = nil
  end
  key_s.free
  return result
end
Also aliased as: color_key
get_palette() click to toggle source
# File lib/sdl2/surface.rb, line 81
def get_palette()
  #SDL2.get_surface_palette!(self)
  format.palette
end
Also aliased as: palette
lock() click to toggle source
# File lib/sdl2/surface.rb, line 89
def lock()
  SDL2.lock_surface(self)
end
mustlock?() click to toggle source

Macro, redefined here for use.

# File lib/sdl2/surface.rb, line 104
def mustlock?
  self[:flags] & RLEACCEL != 0
end
palette()
Alias for: get_palette
palette=(palette)
Alias for: set_palette
rect() click to toggle source

Returns a RECT for the whole surface:

# File lib/sdl2/surface.rb, line 184
def rect
  Rect.cast(x: 0, y: 0, w: self.w, h: self.h)
end
rle=(flag)
Alias for: set_rle
save_bmp(file) click to toggle source
# File lib/sdl2/surface.rb, line 69
def save_bmp(file)
  SDL2.save_bmp!(self, file)
end
save_bmp_rw(rwops, freedst = 0) click to toggle source
# File lib/sdl2/surface.rb, line 65
def save_bmp_rw(rwops, freedst = 0)
  SDL2.save_bmp_rw!(self, rwops, freedst)
end
set_color_key(key) click to toggle source

Sets the color key for this surface.

*  key may be 1) A pixel value encoded for this surface's format

2) Anything that Color::cast can handle. 3) Nil, which will disable the color key for this surface.

# File lib/sdl2/surface.rb, line 135
def set_color_key(key)
  if key.kind_of? Integer
    pixel_value = key
  else
    pixel_value = format.map_rgb(Color.cast(key))
  end

  if key.nil?#then disable color keying
    SDL2.set_color_key(self, false, 0)
  else# Enable color key by value
    #binding.pry
    SDL2.set_color_key(self, true, pixel_value)
  end
end
Also aliased as: color_key=
set_palette(palette) click to toggle source
# File lib/sdl2/surface.rb, line 77
def set_palette(palette)
  SDL2.set_surface_palette!(self, palette)
end
Also aliased as: palette=
set_rle(flag) click to toggle source
# File lib/sdl2/surface.rb, line 125
def set_rle(flag)
  SDL2.set_surface_rle!(self, flag)
end
Also aliased as: rle=
unlock() click to toggle source
# File lib/sdl2/surface.rb, line 93
def unlock()
  SDL2.unlock_surface(self)
end