class SDL2::Window
System Window
A rectangular area you can blit into.
Constants
- DEFAULT
These are the defaults a
Window
is created with unless overridden
Public Class Methods
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
# File lib/sdl2/window.rb, line 165 def self.create(options = {}) o = DEFAULT.merge(options) 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
Constructs a new window from arbitrary system-specific structure
* data: Some system-specific pointer
See SDL Documentation
# 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
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
# 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
Returns the identified window already created
* id: The window identifier to retrieve
# File lib/sdl2/window.rb, line 182 def self.from_id(id) get_window_from_id!(id) end
Construct a new window.
SDL2::Struct::new
# File lib/sdl2/window.rb, line 144 def initialize(*args, &block) super(*args, &block) end
Release memory utilized by structure
# File lib/sdl2/window.rb, line 202 def self.release(pointer) fc = caller.first Debug.log(self){"Release ignored from #{fc}"} end
Public Instance Methods
Return the brightness level
# File lib/sdl2/window.rb, line 219 def brightness SDL2.get_window_brightness(self) end
Set the brightness level
# 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
Get the window’s current size @return Array => [<width>, <height>]
# 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
Set the window’s current size
* size: A array containing the [width,height]
# File lib/sdl2/window.rb, line 340 def current_size=(size) SDL2.set_window_size(self, size[0], size[1]) end
The Window’s data manager.
# File lib/sdl2/window.rb, line 139 def data @data ||= Data.new(self) end
Tell SDL we are done with the window. Any further use could result in a crash.
# 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
Get the display associated with this window
# File lib/sdl2/window.rb, line 242 def display Display[display_index] end
Get the display index associated with this window
# File lib/sdl2/window.rb, line 237 def display_index SDL2.get_window_display_index(self) end
Get a copy of the DisplayMode structure
# File lib/sdl2/window.rb, line 230 def display_mode dm = SDL2::Display::Mode.new SDL2.get_window_display_mode!(self, dm) dm end
Get the window flags
# File lib/sdl2/window.rb, line 247 def flags SDL2.get_window_flags(self) end
Set the window’s FULLSCREEN mode flags.
# File lib/sdl2/window.rb, line 394 def fullscreen=(flags) SDL2.set_window_fullscreen(self, flags) end
Set the input grab mode
# File lib/sdl2/window.rb, line 257 def grab=(value) SDL2.set_window_grab(self, value) end
The window’s input grab mode
# File lib/sdl2/window.rb, line 252 def grab? SDL2.get_window_grab?(self) end
# File lib/sdl2/window.rb, line 333 def height current_size[1] end
Hide the window
# File lib/sdl2/window.rb, line 282 def hide SDL2.hide_window(self) end
Set the window’s icon from a surface
# File lib/sdl2/window.rb, line 312 def icon=(surface) set_window_icon(self, surface) end
Get the window identifier
# File lib/sdl2/window.rb, line 262 def id SDL2.get_window_id(self) end
Maximize the window
# File lib/sdl2/window.rb, line 287 def maximize SDL2.maximize_window(self) end
Get the window’s maximum_size
@return Array => [<width>, <height>]
# 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
Set the window’s maximum size
* size: A array containing the [width,height]
# File lib/sdl2/window.rb, line 354 def maximum_size=(size) SDL2.set_window_maximum_size(self, size[0], size[1]) end
Minimize the window
# File lib/sdl2/window.rb, line 292 def minimize SDL2.minimize_window(self) end
Get the window’s minimum size @return Array => [<width>, <height>]
# 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
Set the window’s minimum size
* size: A array containing the [width,height]
# File lib/sdl2/window.rb, line 368 def minimum_size=(size) SDL2.set_window_minimum_size(self, size[0], size[1]) end
Get the window pixel format
# File lib/sdl2/window.rb, line 267 def pixel_format SDL2.get_window_pixel_format(self) end
Get the window’s position @return Array => [<x>, <y>]
# 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
Set the window’s position
* size: A array containing the [x,y]
# File lib/sdl2/window.rb, line 384 def position=(location) SDL2::set_window_position(self, location[0],location[1]) end
Raise the window
# File lib/sdl2/window.rb, line 297 def raise_above SDL2.raise_window(self) end
Returns the renderer associated with this window
# File lib/sdl2/window.rb, line 401 def renderer SDL2.get_renderer(self) end
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.
# 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 the window
# File lib/sdl2/window.rb, line 302 def restore SDL2.restore_window(self) end
Show the window
# File lib/sdl2/window.rb, line 307 def show SDL2.show_window(self) end
Return the surface associated with the window
# File lib/sdl2/window.rb, line 389 def surface SDL2.get_window_surface(self) end
Get the window title caption
# File lib/sdl2/window.rb, line 272 def title SDL2.get_window_title(self) end
Set the window title caption
# File lib/sdl2/window.rb, line 277 def title=(value) SDL2.set_window_title(self, value) end
Update the window’s surface
# File lib/sdl2/window.rb, line 317 def update_surface() SDL2.update_window_surface!(self) end
# File lib/sdl2/window.rb, line 329 def width current_size[0] end