Class: SDL2::Surface
Overview
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.
Constant Summary collapse
- SWSURFACE =
Surface Flags
0
- PREALLOC =
0x00000001
- RLEACCEL =
0x00000002
- DONTFREE =
0x00000004
Class Method Summary collapse
-
.create_rgb(flags, width, height, depth, rmask = 0, gmask = 0, bmask = 0, amask = 0) ⇒ Object
Allocate and free an RGB surface If depth is 4 or 8 bits, an empty palette is allocated for the surface.
- .create_rgb_from(pixels, width, height, depth, pitch, rmask, gmask, bmask, amask) ⇒ Object
- .load_bmp(file) ⇒ Object
- .load_bmp_rw(rwops, freesrc = 0) ⇒ Object
- .release(pointer) ⇒ Object
Instance Method Summary collapse
-
#blit_in(src, src_rect = nil, dst_rect = nil) ⇒ Object
Blit from source to this surface.
-
#blit_out(dest, dst_rect = nil, src_rect = nil) ⇒ Object
Blit from this surface to dest.
-
#convert(surface, flags = 0) ⇒ Object
Convert existing surface into this surface’s format.
- #fill_rect(rect, color) ⇒ Object
- #free ⇒ Object
-
#get_color_key ⇒ Object
(also: #color_key)
Gets the color key for this surface.
- #get_palette ⇒ Object (also: #palette)
- #lock ⇒ Object
-
#mustlock? ⇒ Boolean
Macro, redefined here for use.
-
#rect ⇒ Object
Returns a RECT for the whole surface:.
- #save_bmp(file) ⇒ Object
- #save_bmp_rw(rwops, freedst = 0) ⇒ Object
-
#set_color_key(key) ⇒ Object
(also: #color_key=)
Sets the color key for this surface.
- #set_palette(palette) ⇒ Object (also: #palette=)
- #set_rle(flag) ⇒ Object (also: #rle=)
- #unlock ⇒ Object
Methods inherited from Struct
Methods included from StructHelper
#member_readers, #member_writers
Constructor Details
This class inherits a constructor from SDL2::Struct
Class Method Details
.create_rgb(flags, width, height, depth, rmask = 0, gmask = 0, bmask = 0, amask = 0) ⇒ Object
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.
48 49 50 |
# File 'lib/sdl2/surface.rb', line 48 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) ⇒ Object
52 53 54 |
# File 'lib/sdl2/surface.rb', line 52 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) ⇒ Object
60 61 62 |
# File 'lib/sdl2/surface.rb', line 60 def self.load_bmp(file) SDL2.load_bmp!(file) end |
.load_bmp_rw(rwops, freesrc = 0) ⇒ Object
56 57 58 |
# File 'lib/sdl2/surface.rb', line 56 def self.load_bmp_rw(rwops, freesrc = 0) SDL2.load_bmp_rw!(rwops, freesrc) end |
.release(pointer) ⇒ Object
40 41 42 |
# File 'lib/sdl2/surface.rb', line 40 def self.release(pointer) SDL2.free_surface(pointer) end |
Instance Method Details
#blit_in(src, src_rect = nil, dst_rect = nil) ⇒ Object
Blit from source to this surface
108 109 110 111 112 113 114 115 |
# File 'lib/sdl2/surface.rb', line 108 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) ⇒ Object
Blit from this surface to dest
118 119 120 121 122 |
# File 'lib/sdl2/surface.rb', line 118 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 |
#convert(surface, flags = 0) ⇒ Object
Convert existing surface into this surface’s format
165 166 167 |
# File 'lib/sdl2/surface.rb', line 165 def convert(surface, flags = 0) SDL2.convert_surface!(surface, self.format, flags) end |
#fill_rect(rect, color) ⇒ Object
169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/sdl2/surface.rb', line 169 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 ⇒ Object
72 73 74 |
# File 'lib/sdl2/surface.rb', line 72 def free SDL2.free_surface(self) end |
#get_color_key ⇒ Object Also known as: color_key
Gets the color key for this surface.
150 151 152 153 154 155 156 157 158 159 |
# File 'lib/sdl2/surface.rb', line 150 def get_color_key() key_s = UInt32Struct.new if SDL2.get_color_key?(self, key_s) result = key_s[:value] else result = nil end key_s.free return result end |
#get_palette ⇒ Object Also known as: palette
80 81 82 83 |
# File 'lib/sdl2/surface.rb', line 80 def get_palette() #SDL2.get_surface_palette!(self) format.palette end |
#lock ⇒ Object
88 89 90 |
# File 'lib/sdl2/surface.rb', line 88 def lock() SDL2.lock_surface(self) end |
#mustlock? ⇒ Boolean
Macro, redefined here for use.
103 104 105 |
# File 'lib/sdl2/surface.rb', line 103 def mustlock? self[:flags] & RLEACCEL != 0 end |
#rect ⇒ Object
Returns a RECT for the whole surface:
182 183 184 |
# File 'lib/sdl2/surface.rb', line 182 def rect Rect.cast(x: 0, y: 0, w: self.w, h: self.h) end |
#save_bmp(file) ⇒ Object
68 69 70 |
# File 'lib/sdl2/surface.rb', line 68 def save_bmp(file) SDL2.save_bmp!(self, file) end |
#save_bmp_rw(rwops, freedst = 0) ⇒ Object
64 65 66 |
# File 'lib/sdl2/surface.rb', line 64 def save_bmp_rw(rwops, freedst = 0) SDL2.save_bmp_rw!(self, rwops, freedst) end |
#set_color_key(key) ⇒ Object Also known as: color_key=
Sets the color key for this surface. 2) Anything that Color::cast can handle. 3) Nil, which will disable the color key for this surface.
134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/sdl2/surface.rb', line 134 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 SDL2.set_color_key(self, true, pixel_value) end end |
#set_palette(palette) ⇒ Object Also known as: palette=
76 77 78 |
# File 'lib/sdl2/surface.rb', line 76 def set_palette(palette) SDL2.set_surface_palette!(self, palette) end |
#set_rle(flag) ⇒ Object Also known as: rle=
124 125 126 |
# File 'lib/sdl2/surface.rb', line 124 def set_rle(flag) SDL2.set_surface_rle!(self, flag) end |
#unlock ⇒ Object
92 93 94 |
# File 'lib/sdl2/surface.rb', line 92 def unlock() SDL2.unlock_surface(self) end |