Class: SDL2::Window

Inherits:
Struct
  • Object
show all
Includes:
WINDOW
Defined in:
lib/sdl2/window.rb

Overview

System Window A rectangular area you can blit into.

Defined Under Namespace

Classes: Data

Constant Summary

Constants included from WINDOW

SDL2::WINDOW::BORDERLESS, SDL2::WINDOW::FOREIGN, SDL2::WINDOW::FULLSCREEN, SDL2::WINDOW::FULLSCREEN_DESKTOP, SDL2::WINDOW::HIDDEN, SDL2::WINDOW::INPUT_FOCUS, SDL2::WINDOW::INPUT_GRABBED, SDL2::WINDOW::MAXIMIZED, SDL2::WINDOW::MINIMIZED, SDL2::WINDOW::MOUSE_FOCUS, SDL2::WINDOW::OPENGL, SDL2::WINDOW::RESIZABLE, SDL2::WINDOW::SHOWN

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from EnumerableConstants

included

Methods inherited from Struct

#==, cast

Methods included from StructHelper

#member_readers, #member_writers

Constructor Details

#initialize(*args, &block) ⇒ Window

Construct a new window.



140
141
142
143
# File 'lib/sdl2/window.rb', line 140

def initialize(*args, &block)
  super(*args, &block)
  @data = Data.new(self)
end

Instance Attribute Details

#dataObject (readonly)

The Window’s data manager.



137
138
139
# File 'lib/sdl2/window.rb', line 137

def data
  @data
end

Class Method Details

.create(title = '', x = 0, y = 0, w = 100, h = 100, flags = 0) ⇒ Object

Construct a new window with given:

Parameters:

  • 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



152
153
154
# File 'lib/sdl2/window.rb', line 152

def self.create(title ='', x = 0, y = 0, w = 100, h = 100, flags = 0)
  SDL2.create_window!(title, x, y, w, h, flags)
end

.create_from(data) ⇒ Object

Constructs a new window from arbitrary system-specific structure See SDL Documentation

Parameters:

  • data:

    Some system-specific pointer



159
160
161
# File 'lib/sdl2/window.rb', line 159

def self.create_from(data)
  create_window_from!(data)
end

.create_with_renderer(w, h, flags) ⇒ Object

Constructs both a window and a renderer

Parameters:

  • w:

    The Width of the pair to create

  • h:

    The Height of the pair to create

  • flags:

    Window flags to utilize in creation



173
174
175
176
177
178
179
180
181
# File 'lib/sdl2/window.rb', line 173

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

Parameters:

  • id:

    The window identifier to retrieve



165
166
167
# File 'lib/sdl2/window.rb', line 165

def self.from_id(id)
  get_window_from_id!(id)
end

.release(pointer) ⇒ Object

Release memory utilized by structure



184
185
186
# File 'lib/sdl2/window.rb', line 184

def self.release(pointer)
  destroy_window(pointer)
end

Instance Method Details

#brightnessObject

Return the brightness level



189
190
191
# File 'lib/sdl2/window.rb', line 189

def brightness
  SDL2.get_window_brightness(self)
end

#brightness=(level) ⇒ Object

Set the brightness level



194
195
196
# File 'lib/sdl2/window.rb', line 194

def brightness=(level)
  SDL2.set_window_brightness(self, level.to_f)
end

#current_sizeObject

Get the window’s current size

Returns:

  • Array => [<width>, <height>]



296
297
298
299
300
301
# File 'lib/sdl2/window.rb', line 296

def current_size()
  w_struct, h_struct = IntStruct.new, IntStruct.new
  SDL2::get_window_size(self, w_struct, h_struct)
  w, h = w_struct[:value], h_struct[:value]
  [w, h]
end

#current_size=(size) ⇒ Object

Set the window’s current size

Parameters:

  • size:

    A array containing the [width,height]



305
306
307
# File 'lib/sdl2/window.rb', line 305

def current_size=(size)
  SDL2.set_window_size(self, size[0], size[1])
end

#displayObject

Get the display associated with this window



215
216
217
# File 'lib/sdl2/window.rb', line 215

def display
  Display[display_index]
end

#display_indexObject

Get the display index associated with this window



210
211
212
# File 'lib/sdl2/window.rb', line 210

def display_index
  SDL2.get_window_display_index(self)
end

#display_modeObject

Get a copy of the DisplayMode structure



199
200
201
202
203
204
205
206
207
# File 'lib/sdl2/window.rb', line 199

def display_mode
  dm = SDL2::Display::Mode.new
  if SDL2.get_window_display_mode(self, dm) == 0
    return dm
  else
    dm.pointer.free
    return nil
  end
end

#flagsObject

Get the window flags



220
221
222
# File 'lib/sdl2/window.rb', line 220

def flags
  SDL2.get_window_flags(self)
end

#fullscreen=(flags) ⇒ Object

Set the window’s FULLSCREEN mode flags.



361
362
363
# File 'lib/sdl2/window.rb', line 361

def fullscreen=(flags)
  SDL2.set_window_fullscreen(self, flags)
end

#grab=(value) ⇒ Object

Set the input grab mode



230
231
232
# File 'lib/sdl2/window.rb', line 230

def grab=(value)
  SDL2.set_window_grab(self, value)
end

#grab?Boolean

The window’s input grab mode

Returns:

  • (Boolean)


225
226
227
# File 'lib/sdl2/window.rb', line 225

def grab?
  SDL2.get_window_grab?(self)
end

#hideObject

Hide the window



255
256
257
# File 'lib/sdl2/window.rb', line 255

def hide
  SDL2.hide_window(self)
end

#icon=(surface) ⇒ Object

Set the window’s icon from a surface



285
286
287
# File 'lib/sdl2/window.rb', line 285

def icon=(surface)
  set_window_icon(self, surface)
end

#idObject

Get the window identifier



235
236
237
# File 'lib/sdl2/window.rb', line 235

def id
  SDL2.get_window_id(self)
end

#maximizeObject

Maximize the window



260
261
262
# File 'lib/sdl2/window.rb', line 260

def maximize
  SDL2.maximize_window(self)
end

#maximum_sizeObject

Get the window’s maximum_size

Returns:

  • Array => [<width>, <height>]



311
312
313
314
315
316
# File 'lib/sdl2/window.rb', line 311

def maximum_size
  w_struct, h_struct = IntStruct.new, IntStruct.new
  SDL2::get_window_maximum_size(self, w_struct, h_struct)
  w, h = w_struct[:value], h_struct[:value]
  [w, h]
end

#maximum_size=(size) ⇒ Object

Set the window’s maximum size

Parameters:

  • size:

    A array containing the [width,height]



320
321
322
# File 'lib/sdl2/window.rb', line 320

def maximum_size=(size)
  SDL2.set_window_maximum_size(self, size[0], size[1])
end

#minimizeObject

Minimize the window



265
266
267
# File 'lib/sdl2/window.rb', line 265

def minimize
  SDL2.minimize_window(self)
end

#minimum_sizeObject

Get the window’s minimum size

Returns:

  • Array => [<width>, <height>]



326
327
328
329
330
331
# File 'lib/sdl2/window.rb', line 326

def minimum_size
  w_struct, h_struct = IntStruct.new, IntStruct.new
  SDL2::get_window_minimum_size(self, w_struct, h_struct)
  w, h = w_struct[:value], h_struct[:value]
  [w, h]
end

#minimum_size=(size) ⇒ Object

Set the window’s minimum size

Parameters:

  • size:

    A array containing the [width,height]



335
336
337
# File 'lib/sdl2/window.rb', line 335

def minimum_size=(size)
  SDL2.set_window_minimum_size(self, size[0], size[1])
end

#pixel_formatObject

Get the window pixel format



240
241
242
# File 'lib/sdl2/window.rb', line 240

def pixel_format
  SDL2.get_window_pixel_format(self)
end

#positionObject

Get the window’s position

Returns:

  • Array => [<x>, <y>]



341
342
343
344
345
346
347
# File 'lib/sdl2/window.rb', line 341

def position
  position = [IntStruct.new, IntStruct.new]
  SDL2::get_window_position(self, position[0], position[1])
  x, y = position[0][:value], position[1][:value]
  position.each{|struct|struct.pointer.free}
  [x, y]
end

#position=(location) ⇒ Object

Set the window’s position

Parameters:

  • size:

    A array containing the [x,y]



351
352
353
# File 'lib/sdl2/window.rb', line 351

def position=(location)
  SDL2::set_window_position(self, location[0],location[1])
end

#raise_aboveObject

Raise the window



270
271
272
# File 'lib/sdl2/window.rb', line 270

def raise_above
  SDL2.raise_window(self)
end

#restoreObject

Restore the window



275
276
277
# File 'lib/sdl2/window.rb', line 275

def restore
  SDL2.restore_window(self)
end

#showObject

Show the window



280
281
282
# File 'lib/sdl2/window.rb', line 280

def show
  SDL2.show_window(self)
end

#surfaceObject

Return the surface associated with the window



356
357
358
# File 'lib/sdl2/window.rb', line 356

def surface
  SDL2.get_window_surface(self)
end

#titleObject

Get the window title caption



245
246
247
# File 'lib/sdl2/window.rb', line 245

def title
  SDL2.get_window_title(self)
end

#title=(value) ⇒ Object

Set the window title caption



250
251
252
# File 'lib/sdl2/window.rb', line 250

def title=(value)
  SDL2.set_window_title(self, value)
end

#update_surfaceObject

Update the window’s surface



290
291
292
# File 'lib/sdl2/window.rb', line 290

def update_surface()
  SDL2.update_window_surface!(self)
end