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
#==, cast, create, #initialize, #to_s, #update_members
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.
49 50 51 |
# 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) ⇒ Object
53 54 55 |
# 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) ⇒ Object
61 62 63 |
# File 'lib/sdl2/surface.rb', line 61 def self.load_bmp(file) SDL2.load_bmp!(file) end |
.load_bmp_rw(rwops, freesrc = 0) ⇒ Object
57 58 59 |
# File 'lib/sdl2/surface.rb', line 57 def self.load_bmp_rw(rwops, freesrc = 0) SDL2.load_bmp_rw!(rwops, freesrc) end |
.release(pointer) ⇒ Object
41 42 43 |
# File 'lib/sdl2/surface.rb', line 41 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
109 110 111 112 113 114 115 116 |
# 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) ⇒ Object
Blit from this surface to dest
119 120 121 122 123 |
# 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 |
#convert(surface, flags = 0) ⇒ Object
Convert existing surface into this surface’s format
167 168 169 |
# File 'lib/sdl2/surface.rb', line 167 def convert(surface, flags = 0) SDL2.convert_surface!(surface, self.format, flags) end |
#fill_rect(rect, color) ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 |
# 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 ⇒ Object
73 74 75 |
# File 'lib/sdl2/surface.rb', line 73 def free SDL2.free_surface(self) end |
#get_color_key ⇒ Object Also known as: color_key
Gets the color key for this surface.
152 153 154 155 156 157 158 159 160 161 |
# 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 |
#get_palette ⇒ Object Also known as: palette
81 82 83 84 |
# File 'lib/sdl2/surface.rb', line 81 def get_palette() #SDL2.get_surface_palette!(self) format.palette end |
#lock ⇒ Object
89 90 91 |
# File 'lib/sdl2/surface.rb', line 89 def lock() SDL2.lock_surface(self) end |
#mustlock? ⇒ Boolean
Macro, redefined here for use.
104 105 106 |
# File 'lib/sdl2/surface.rb', line 104 def mustlock? self[:flags] & RLEACCEL != 0 end |
#rect ⇒ Object
Returns a RECT for the whole surface:
184 185 186 |
# File 'lib/sdl2/surface.rb', line 184 def rect Rect.cast(x: 0, y: 0, w: self.w, h: self.h) end |
#save_bmp(file) ⇒ Object
69 70 71 |
# File 'lib/sdl2/surface.rb', line 69 def save_bmp(file) SDL2.save_bmp!(self, file) end |
#save_bmp_rw(rwops, freedst = 0) ⇒ Object
65 66 67 |
# 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) ⇒ Object Also known as: color_key=
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.
135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# 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 |
#set_palette(palette) ⇒ Object Also known as: palette=
77 78 79 |
# File 'lib/sdl2/surface.rb', line 77 def set_palette(palette) SDL2.set_surface_palette!(self, palette) end |
#set_rle(flag) ⇒ Object Also known as: rle=
125 126 127 |
# File 'lib/sdl2/surface.rb', line 125 def set_rle(flag) SDL2.set_surface_rle!(self, flag) end |
#unlock ⇒ Object
93 94 95 |
# File 'lib/sdl2/surface.rb', line 93 def unlock() SDL2.unlock_surface(self) end |