Class: SDL2::Window
Overview
System Window A rectangular area you can blit into.
Defined Under Namespace
Constant Summary collapse
- DEFAULT =
These are the defaults a Window is created with unless overridden
{ title: "SDL2::Window", x: :CENTERED, y: :CENTERED, width: 320, height: 240, flags: 0 }
Class Method Summary collapse
-
.create(options = {}) ⇒ Object
Construct a new window with given: * title: The caption to use for the window * x: The x-position of the window * y: The y-position of the window * w: The width of the window * h: The height of the window * flags: Window Flags to use in construction.
-
.create_from(data) ⇒ Object
Constructs a new window from arbitrary system-specific structure * data: Some system-specific pointer See SDL Documentation.
-
.create_with_renderer(w, h, flags) ⇒ Object
Constructs both a window and a renderer * w: The Width of the pair to create * h: The Height of the pair to create * flags: Window flags to utilize in creation.
-
.from_id(id) ⇒ Object
Returns the identified window already created * id: The window identifier to retrieve.
-
.release(pointer) ⇒ Object
Release memory utilized by structure.
Instance Method Summary collapse
-
#brightness ⇒ Object
Return the brightness level.
-
#brightness=(level) ⇒ Object
Set the brightness level.
-
#current_size ⇒ Object
Get the window’s current size.
-
#current_size=(size) ⇒ Object
Set the window’s current size * size: A array containing the [width,height].
-
#data ⇒ Object
The Window’s data manager.
-
#destroy ⇒ Object
Tell SDL we are done with the window.
-
#display ⇒ Object
Get the display associated with this window.
-
#display_index ⇒ Object
Get the display index associated with this window.
-
#display_mode ⇒ Object
Get a copy of the DisplayMode structure.
-
#flags ⇒ Object
Get the window flags.
-
#fullscreen=(flags) ⇒ Object
Set the window’s FULLSCREEN mode flags.
-
#grab=(value) ⇒ Object
Set the input grab mode.
-
#grab? ⇒ Boolean
The window’s input grab mode.
- #height ⇒ Object
-
#hide ⇒ Object
Hide the window.
-
#icon=(surface) ⇒ Object
Set the window’s icon from a surface.
-
#id ⇒ Object
Get the window identifier.
-
#initialize(*args, &block) ⇒ Window
constructor
Construct a new window.
-
#maximize ⇒ Object
Maximize the window.
-
#maximum_size ⇒ Object
Get the window’s maximum_size.
-
#maximum_size=(size) ⇒ Object
Set the window’s maximum size * size: A array containing the [width,height].
-
#minimize ⇒ Object
Minimize the window.
-
#minimum_size ⇒ Object
Get the window’s minimum size.
-
#minimum_size=(size) ⇒ Object
Set the window’s minimum size * size: A array containing the [width,height].
-
#pixel_format ⇒ Object
Get the window pixel format.
-
#position ⇒ Object
Get the window’s position.
-
#position=(location) ⇒ Object
Set the window’s position * size: A array containing the [x,y].
-
#raise_above ⇒ Object
Raise the window.
-
#renderer ⇒ Object
Returns the renderer associated with this window.
-
#renderer_to_surface(renderer = renderer) ⇒ Object
Utility function that returns an SDL2::Surface of a given render.
-
#restore ⇒ Object
Restore the window.
-
#show ⇒ Object
Show the window.
-
#surface ⇒ Object
Return the surface associated with the window.
-
#title ⇒ Object
Get the window title caption.
-
#title=(value) ⇒ Object
Set the window title caption.
-
#update_surface ⇒ Object
Update the window’s surface.
- #width ⇒ Object
Methods inherited from Struct
#==, cast, #free, #to_s, #update_members
Methods included from StructHelper
#member_readers, #member_writers
Constructor Details
#initialize(*args, &block) ⇒ Window
Construct a new window.
144 145 146 |
# File 'lib/sdl2/window.rb', line 144 def initialize(*args, &block) super(*args, &block) end |
Class Method Details
.create(options = {}) ⇒ Object
Construct a new window with given:
* title: The caption to use for the window
* x: The x-position of the window
* y: The y-position of the window
* w: The width of the window
* h: The height of the window
* flags: Window Flags to use in construction
165 166 167 168 169 170 |
# File 'lib/sdl2/window.rb', line 165 def self.create( = {}) o = DEFAULT.merge() Debug.log(self){"Creating with options: #{o.inspect}"} # TODO: Log unused option keys SDL2.create_window!(o[:title], o[:x], o[:y], o[:width], o[:height], o[:flags]) end |
.create_from(data) ⇒ Object
Constructs a new window from arbitrary system-specific structure
* data: Some system-specific pointer
See SDL Documentation
175 176 177 178 |
# File 'lib/sdl2/window.rb', line 175 def self.create_from(data) Debug.log(self){"Creating from data: #{data.inspect}"} create_window_from!(data) end |
.create_with_renderer(w, h, flags) ⇒ Object
Constructs both a window and a renderer
* w: The Width of the pair to create
* h: The Height of the pair to create
* flags: Window flags to utilize in creation
190 191 192 193 194 195 196 197 198 199 |
# File 'lib/sdl2/window.rb', line 190 def self.create_with_renderer(w, h, flags) window = Window.new renderer = Renderer.new if SDL2.create_window_and_renderer(w,h,flags,window,renderer) == 0 [window, renderer] else nil end end |
.from_id(id) ⇒ Object
Returns the identified window already created
* id: The window identifier to retrieve
182 183 184 |
# File 'lib/sdl2/window.rb', line 182 def self.from_id(id) get_window_from_id!(id) end |
.release(pointer) ⇒ Object
Release memory utilized by structure
202 203 204 205 |
# File 'lib/sdl2/window.rb', line 202 def self.release(pointer) fc = caller.first Debug.log(self){"Release ignored from #{fc}"} end |
Instance Method Details
#brightness ⇒ Object
Return the brightness level
219 220 221 |
# File 'lib/sdl2/window.rb', line 219 def brightness SDL2.get_window_brightness(self) end |
#brightness=(level) ⇒ Object
Set the brightness level
224 225 226 227 |
# File 'lib/sdl2/window.rb', line 224 def brightness=(level) Debug.log(self){"Setting brightness to: #{level}"} SDL2.set_window_brightness(self, level.to_f) end |
#current_size ⇒ Object
Get the window’s current size
323 324 325 326 327 |
# File 'lib/sdl2/window.rb', line 323 def current_size() size = 2.times.map{TypedPointer::Int.new} SDL2::get_window_size(self, *size) size.map(&:value) end |
#current_size=(size) ⇒ Object
Set the window’s current size
* size: A array containing the [width,height]
340 341 342 |
# File 'lib/sdl2/window.rb', line 340 def current_size=(size) SDL2.set_window_size(self, size[0], size[1]) end |
#data ⇒ Object
The Window’s data manager.
139 140 141 |
# File 'lib/sdl2/window.rb', line 139 def data @data ||= Data.new(self) end |
#destroy ⇒ Object
Tell SDL we are done with the window. Any further use could result in a crash.
208 209 210 211 212 213 214 |
# File 'lib/sdl2/window.rb', line 208 def destroy unless self.null? SDL2.destroy_window(self) else Debug.log(self){"Destruction of window null window requested."} end end |
#display ⇒ Object
Get the display associated with this window
242 243 244 |
# File 'lib/sdl2/window.rb', line 242 def display Display[display_index] end |
#display_index ⇒ Object
Get the display index associated with this window
237 238 239 |
# File 'lib/sdl2/window.rb', line 237 def display_index SDL2.get_window_display_index(self) end |
#display_mode ⇒ Object
Get a copy of the DisplayMode structure
230 231 232 233 234 |
# File 'lib/sdl2/window.rb', line 230 def display_mode dm = SDL2::Display::Mode.new SDL2.get_window_display_mode!(self, dm) dm end |
#flags ⇒ Object
Get the window flags
247 248 249 |
# File 'lib/sdl2/window.rb', line 247 def flags SDL2.get_window_flags(self) end |
#fullscreen=(flags) ⇒ Object
Set the window’s FULLSCREEN mode flags.
394 395 396 |
# File 'lib/sdl2/window.rb', line 394 def fullscreen=(flags) SDL2.set_window_fullscreen(self, flags) end |
#grab=(value) ⇒ Object
Set the input grab mode
257 258 259 |
# File 'lib/sdl2/window.rb', line 257 def grab=(value) SDL2.set_window_grab(self, value) end |
#grab? ⇒ Boolean
The window’s input grab mode
252 253 254 |
# File 'lib/sdl2/window.rb', line 252 def grab? SDL2.get_window_grab?(self) end |
#height ⇒ Object
333 334 335 |
# File 'lib/sdl2/window.rb', line 333 def height current_size[1] end |
#hide ⇒ Object
Hide the window
282 283 284 |
# File 'lib/sdl2/window.rb', line 282 def hide SDL2.hide_window(self) end |
#icon=(surface) ⇒ Object
Set the window’s icon from a surface
312 313 314 |
# File 'lib/sdl2/window.rb', line 312 def icon=(surface) set_window_icon(self, surface) end |
#id ⇒ Object
Get the window identifier
262 263 264 |
# File 'lib/sdl2/window.rb', line 262 def id SDL2.get_window_id(self) end |
#maximize ⇒ Object
Maximize the window
287 288 289 |
# File 'lib/sdl2/window.rb', line 287 def maximize SDL2.maximize_window(self) end |
#maximum_size ⇒ Object
Get the window’s maximum_size
346 347 348 349 350 |
# File 'lib/sdl2/window.rb', line 346 def maximum_size size = 2.times.map{TypedPointer::Int.new} SDL2::get_window_maximum_size(self, *size) size.map(&:value) end |
#maximum_size=(size) ⇒ Object
Set the window’s maximum size
* size: A array containing the [width,height]
354 355 356 |
# File 'lib/sdl2/window.rb', line 354 def maximum_size=(size) SDL2.set_window_maximum_size(self, size[0], size[1]) end |
#minimize ⇒ Object
Minimize the window
292 293 294 |
# File 'lib/sdl2/window.rb', line 292 def minimize SDL2.minimize_window(self) end |
#minimum_size ⇒ Object
Get the window’s minimum size
360 361 362 363 364 |
# File 'lib/sdl2/window.rb', line 360 def minimum_size size = 2.times.map{TypedPointer::Int.new} SDL2::get_window_minimum_size(self, *size) size.map(&:value) end |
#minimum_size=(size) ⇒ Object
Set the window’s minimum size
* size: A array containing the [width,height]
368 369 370 |
# File 'lib/sdl2/window.rb', line 368 def minimum_size=(size) SDL2.set_window_minimum_size(self, size[0], size[1]) end |
#pixel_format ⇒ Object
Get the window pixel format
267 268 269 |
# File 'lib/sdl2/window.rb', line 267 def pixel_format SDL2.get_window_pixel_format(self) end |
#position ⇒ Object
Get the window’s position
374 375 376 377 378 379 380 |
# File 'lib/sdl2/window.rb', line 374 def position position = [TypedPointer::Int.new, TypedPointer::Int.new] SDL2::get_window_position(self, position[0], position[1]) x, y = position[0][:value], position[1][:value] position.each(&:free) [x, y] end |
#position=(location) ⇒ Object
Set the window’s position
* size: A array containing the [x,y]
384 385 386 |
# File 'lib/sdl2/window.rb', line 384 def position=(location) SDL2::set_window_position(self, location[0],location[1]) end |
#raise_above ⇒ Object
Raise the window
297 298 299 |
# File 'lib/sdl2/window.rb', line 297 def raise_above SDL2.raise_window(self) end |
#renderer ⇒ Object
Returns the renderer associated with this window
401 402 403 |
# File 'lib/sdl2/window.rb', line 401 def renderer SDL2.get_renderer(self) end |
#renderer_to_surface(renderer = renderer) ⇒ Object
Utility function that returns an SDL2::Surface of a given render. Defaults to the renderer returned by SDL_GetRenderer(window=self) Added by BadQuanta originally for approval testing.
407 408 409 410 411 412 413 414 415 416 417 418 419 |
# File 'lib/sdl2/window.rb', line 407 def renderer_to_surface(renderer = renderer) w, h = renderer.output_size fmt = surface.format surface = SDL2::Surface.create_rgb(0,w,h, fmt.bits_per_pixel, fmt.r_mask, fmt.g_mask, fmt.b_mask, fmt.a_mask ) SDL2.render_read_pixels!(renderer, nil, fmt.format, surface.pixels, surface.pitch) surface end |
#restore ⇒ Object
Restore the window
302 303 304 |
# File 'lib/sdl2/window.rb', line 302 def restore SDL2.restore_window(self) end |
#show ⇒ Object
Show the window
307 308 309 |
# File 'lib/sdl2/window.rb', line 307 def show SDL2.show_window(self) end |
#surface ⇒ Object
Return the surface associated with the window
389 390 391 |
# File 'lib/sdl2/window.rb', line 389 def surface SDL2.get_window_surface(self) end |
#title ⇒ Object
Get the window title caption
272 273 274 |
# File 'lib/sdl2/window.rb', line 272 def title SDL2.get_window_title(self) end |
#title=(value) ⇒ Object
Set the window title caption
277 278 279 |
# File 'lib/sdl2/window.rb', line 277 def title=(value) SDL2.set_window_title(self, value) end |
#update_surface ⇒ Object
Update the window’s surface
317 318 319 |
# File 'lib/sdl2/window.rb', line 317 def update_surface() SDL2.update_window_surface!(self) end |
#width ⇒ Object
329 330 331 |
# File 'lib/sdl2/window.rb', line 329 def width current_size[0] end |