Class: WGPU::Window::SDLWindow
- Inherits:
-
Object
- Object
- WGPU::Window::SDLWindow
- Defined in:
- lib/wgpu/window.rb
Constant Summary collapse
- SDL_PROP_WINDOW_WIN32_HWND_POINTER =
Property names for native window handles
"SDL.window.win32.hwnd"- SDL_PROP_WINDOW_WIN32_INSTANCE_POINTER =
"SDL.window.win32.instance"- SDL_PROP_WINDOW_X11_DISPLAY_POINTER =
"SDL.window.x11.display"- SDL_PROP_WINDOW_X11_WINDOW_NUMBER =
"SDL.window.x11.window"- SDL_PROP_WINDOW_WAYLAND_DISPLAY_POINTER =
"SDL.window.wayland.display"- SDL_PROP_WINDOW_WAYLAND_SURFACE_POINTER =
"SDL.window.wayland.surface"
Instance Attribute Summary collapse
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
-
#window ⇒ Object
readonly
Returns the value of attribute window.
Instance Method Summary collapse
-
#close ⇒ void
Destroys platform-specific resources and the SDL window.
-
#create_surface(instance) ⇒ Surface
Creates a presentation surface for this native window.
-
#drawable_size ⇒ Array(Integer, Integer)
Returns the drawable size in physical pixels.
-
#initialize(title:, width: 800, height: 600, resizable: true) ⇒ SDLWindow
constructor
Creates an SDL window suitable for WebGPU presentation.
-
#key_pressed?(events, key) ⇒ Boolean
Reports whether a key-down event matches the requested key.
-
#poll_events ⇒ Array
Collects currently pending SDL events.
-
#should_close?(events) ⇒ Boolean
Reports whether a quit event is present.
Constructor Details
#initialize(title:, width: 800, height: 600, resizable: true) ⇒ SDLWindow
Creates an SDL window suitable for WebGPU presentation.
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/wgpu/window.rb', line 30 def initialize(title:, width: 800, height: 600, resizable: true) @width = width @height = height @metal_view = nil flags = 0 flags |= SDL3::Raw::SDL_WINDOW_RESIZABLE if resizable flags |= SDL3::Raw::SDL_WINDOW_HIGH_PIXEL_DENSITY if macos? flags |= SDL3::Raw::SDL_WINDOW_METAL if macos? @window = SDL3::Window.new(title, width, height, flags) end |
Instance Attribute Details
#height ⇒ Object (readonly)
Returns the value of attribute height.
15 16 17 |
# File 'lib/wgpu/window.rb', line 15 def height @height end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
15 16 17 |
# File 'lib/wgpu/window.rb', line 15 def width @width end |
#window ⇒ Object (readonly)
Returns the value of attribute window.
15 16 17 |
# File 'lib/wgpu/window.rb', line 15 def window @window end |
Instance Method Details
#close ⇒ void
This method returns an undefined value.
Destroys platform-specific resources and the SDL window.
113 114 115 116 117 118 119 |
# File 'lib/wgpu/window.rb', line 113 def close if @metal_view && !@metal_view.null? SDL3::Raw.SDL_Metal_DestroyView(@metal_view) @metal_view = nil end @window.destroy if @window end |
#create_surface(instance) ⇒ Surface
Creates a presentation surface for this native window.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/wgpu/window.rb', line 48 def create_surface(instance) case platform when :macos (instance) when :windows create_windows_surface(instance) when :linux_x11 create_x11_surface(instance) when :linux_wayland create_wayland_surface(instance) else raise WindowError, "Unsupported platform: #{RbConfig::CONFIG["host_os"]}" end end |
#drawable_size ⇒ Array(Integer, Integer)
Returns the drawable size in physical pixels.
104 105 106 107 108 |
# File 'lib/wgpu/window.rb', line 104 def drawable_size @window.size_in_pixels rescue [@width, @height] end |
#key_pressed?(events, key) ⇒ Boolean
Reports whether a key-down event matches the requested key.
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/wgpu/window.rb', line 85 def key_pressed?(events, key) scancode = case key when :escape then SDL3::Raw::SDL_SCANCODE_ESCAPE when :space then SDL3::Raw::SDL_SCANCODE_SPACE when :return, :enter then SDL3::Raw::SDL_SCANCODE_RETURN else key end events.any? do |event| next unless event.key_down? event_scancode = event.raw[:key][:scancode] rescue nil event_scancode == scancode end end |
#poll_events ⇒ Array
Collects currently pending SDL events.
66 67 68 69 70 71 72 |
# File 'lib/wgpu/window.rb', line 66 def poll_events events = [] SDL3::Event.each do |event| events << event end events end |
#should_close?(events) ⇒ Boolean
Reports whether a quit event is present.
77 78 79 |
# File 'lib/wgpu/window.rb', line 77 def should_close?(events) events.any?(&:quit?) end |