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

create(options = {}) click to toggle source

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
create_from(data) click to toggle source

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
create_with_renderer(w, h, flags) click to toggle source

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
from_id(id) click to toggle source

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
new(*args, &block) click to toggle source

Construct a new window.

Calls superclass method SDL2::Struct::new
# File lib/sdl2/window.rb, line 144
def initialize(*args, &block)
  super(*args, &block)
end
release(pointer) click to toggle source

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

brightness() click to toggle source

Return the brightness level

# File lib/sdl2/window.rb, line 219
def brightness
  SDL2.get_window_brightness(self)
end
brightness=(level) click to toggle source

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
current_size() click to toggle source

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
current_size=(size) click to toggle source

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
data() click to toggle source

The Window’s data manager.

# File lib/sdl2/window.rb, line 139
def data
  @data ||= Data.new(self)
end
destroy() click to toggle source

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
display() click to toggle source

Get the display associated with this window

# File lib/sdl2/window.rb, line 242
def display
  Display[display_index]
end
display_index() click to toggle source

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
display_mode() click to toggle source

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
flags() click to toggle source

Get the window flags

# File lib/sdl2/window.rb, line 247
def flags
  SDL2.get_window_flags(self)
end
fullscreen=(flags) click to toggle source

Set the window’s FULLSCREEN mode flags.

# File lib/sdl2/window.rb, line 394
def fullscreen=(flags)
  SDL2.set_window_fullscreen(self, flags)
end
grab=(value) click to toggle source

Set the input grab mode

# File lib/sdl2/window.rb, line 257
def grab=(value)
  SDL2.set_window_grab(self, value)
end
grab?() click to toggle source

The window’s input grab mode

# File lib/sdl2/window.rb, line 252
def grab?
  SDL2.get_window_grab?(self)
end
height() click to toggle source
# File lib/sdl2/window.rb, line 333
def height
  current_size[1]
end
hide() click to toggle source

Hide the window

# File lib/sdl2/window.rb, line 282
def hide
  SDL2.hide_window(self)
end
icon=(surface) click to toggle source

Set the window’s icon from a surface

# File lib/sdl2/window.rb, line 312
def icon=(surface)
  set_window_icon(self, surface)
end
id() click to toggle source

Get the window identifier

# File lib/sdl2/window.rb, line 262
def id
  SDL2.get_window_id(self)
end
maximize() click to toggle source

Maximize the window

# File lib/sdl2/window.rb, line 287
def maximize
  SDL2.maximize_window(self)
end
maximum_size() click to toggle source

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
maximum_size=(size) click to toggle source

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() click to toggle source

Minimize the window

# File lib/sdl2/window.rb, line 292
def minimize
  SDL2.minimize_window(self)
end
minimum_size() click to toggle source

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
minimum_size=(size) click to toggle source

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
pixel_format() click to toggle source

Get the window pixel format

# File lib/sdl2/window.rb, line 267
def pixel_format
  SDL2.get_window_pixel_format(self)
end
position() click to toggle source

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
position=(location) click to toggle source

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_above() click to toggle source

Raise the window

# File lib/sdl2/window.rb, line 297
def raise_above
  SDL2.raise_window(self)
end
renderer() click to toggle source

Returns the renderer associated with this window

# File lib/sdl2/window.rb, line 401
def renderer
  SDL2.get_renderer(self)
end
renderer_to_surface(renderer = renderer) click to toggle source

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() click to toggle source

Restore the window

# File lib/sdl2/window.rb, line 302
def restore
  SDL2.restore_window(self)
end
show() click to toggle source

Show the window

# File lib/sdl2/window.rb, line 307
def show
  SDL2.show_window(self)
end
surface() click to toggle source

Return the surface associated with the window

# File lib/sdl2/window.rb, line 389
def surface
  SDL2.get_window_surface(self)
end
title() click to toggle source

Get the window title caption

# File lib/sdl2/window.rb, line 272
def title
  SDL2.get_window_title(self)
end
title=(value) click to toggle source

Set the window title caption

# File lib/sdl2/window.rb, line 277
def title=(value)
  SDL2.set_window_title(self, value)
end
update_surface() click to toggle source

Update the window’s surface

# File lib/sdl2/window.rb, line 317
def update_surface()
  SDL2.update_window_surface!(self)      
end
width() click to toggle source
# File lib/sdl2/window.rb, line 329
def width
  current_size[0]
end