Class: Stagecraft::Window::Glfw

Inherits:
Adapter
  • Object
show all
Defined in:
lib/stagecraft/window/glfw.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Adapter

#on_pointer_button, #on_pointer_move, #on_resize, #on_scroll

Constructor Details

#initialize(title:, width:, height:, resizable: true, surface_factory: nil) ⇒ Glfw

Returns a new instance of Glfw.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/stagecraft/window/glfw.rb', line 8

def initialize(title:, width:, height:, resizable: true, surface_factory: nil)
  super()
  require "glfw"
  ::GLFW.init
  @native = ::GLFW::Window.new(
    width, height, title,
    client_api: ::GLFW::GLFW_NO_API,
    resizable:
  )
  @surface_factory = surface_factory
  attach_callbacks
end

Instance Attribute Details

#nativeObject (readonly)

Returns the value of attribute native.



6
7
8
# File 'lib/stagecraft/window/glfw.rb', line 6

def native
  @native
end

Instance Method Details

#closeObject



43
44
45
46
# File 'lib/stagecraft/window/glfw.rb', line 43

def close
  native.destroy
  ::GLFW.terminate
end

#create_surface(instance) ⇒ Object

Raises:



21
22
23
24
25
26
27
28
# File 'lib/stagecraft/window/glfw.rb', line 21

def create_surface(instance)
  return @surface_factory.call(instance, native) if @surface_factory

  raise Error, <<~MESSAGE.strip
    glfw-ruby does not expose a portable WebGPU surface handle; pass surface_factory:
    or use window: :sdl3, whose native surface bridge is built into wgpu
  MESSAGE
end

#drawable_sizeObject



39
40
41
# File 'lib/stagecraft/window/glfw.rb', line 39

def drawable_size
  native.framebuffer_size
end

#poll_eventsObject



30
31
32
33
# File 'lib/stagecraft/window/glfw.rb', line 30

def poll_events
  ::GLFW.poll_events
  []
end

#should_close?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/stagecraft/window/glfw.rb', line 35

def should_close?
  native.should_close?
end