Class: RBGL::GUI::Window

Inherits:
Object
  • Object
show all
Defined in:
lib/rbgl/gui/window.rb,
lib/rbgl/gui/window/render_loop.rb,
lib/rbgl/gui/window/event_dispatcher.rb

Defined Under Namespace

Classes: EventDispatcher, RenderLoop

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(width:, height:, title: "RBGL", backend: :auto, **options) ⇒ Window

Returns a new instance of Window.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/rbgl/gui/window.rb', line 11

def initialize(width:, height:, title: "RBGL", backend: :auto, **options)
  @width = width
  @height = height
  @title = title
  @context = Engine::Context.new(width: width, height: height)
  @backend = build_backend(backend, width: width, height: height, title: title, **options)
  @event_handlers = Hash.new { |h, k| h[k] = [] }
  @event_dispatcher = EventDispatcher.new(
    backend: @backend,
    event_handlers: @event_handlers,
    on_resize: method(:apply_resize)
  )
  @render_loop = RenderLoop.new
end

Instance Attribute Details

#backendObject (readonly)

Returns the value of attribute backend.



9
10
11
# File 'lib/rbgl/gui/window.rb', line 9

def backend
  @backend
end

#contextObject (readonly)

Returns the value of attribute context.



9
10
11
# File 'lib/rbgl/gui/window.rb', line 9

def context
  @context
end

#heightObject (readonly)

Returns the value of attribute height.



9
10
11
# File 'lib/rbgl/gui/window.rb', line 9

def height
  @height
end

#widthObject (readonly)

Returns the value of attribute width.



9
10
11
# File 'lib/rbgl/gui/window.rb', line 9

def width
  @width
end

Instance Method Details

#closeObject



71
72
73
# File 'lib/rbgl/gui/window.rb', line 71

def close
  @backend.close
end

#dropped_framesObject



79
80
81
# File 'lib/rbgl/gui/window.rb', line 79

def dropped_frames
  @render_loop.dropped_frames
end

#fpsObject



75
76
77
# File 'lib/rbgl/gui/window.rb', line 75

def fps
  @render_loop.fps
end

#metal_available?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/rbgl/gui/window.rb', line 55

def metal_available?
  @backend.metal_available?
end

#native_handleObject



59
60
61
# File 'lib/rbgl/gui/window.rb', line 59

def native_handle
  @backend.native_handle
end

#on(event_type, &block) ⇒ Object



26
27
28
29
# File 'lib/rbgl/gui/window.rb', line 26

def on(event_type, &block)
  validate_event_handler!(event_type, block)
  @event_handlers[event_type] << block
end

#poll_events_rawObject



67
68
69
# File 'lib/rbgl/gui/window.rb', line 67

def poll_events_raw
  @backend.poll_events_raw
end

#present_framebuffer(framebuffer = nil) ⇒ Object



46
47
48
49
# File 'lib/rbgl/gui/window.rb', line 46

def present_framebuffer(framebuffer = nil)
  fb = framebuffer || @context.framebuffer
  @render_loop.record_present_result(@backend.present(fb))
end

#run(&frame_callback) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/rbgl/gui/window.rb', line 31

def run(&frame_callback)
  @render_loop.run(
    backend: @backend,
    context: @context,
    process_events: method(:process_events),
    &frame_callback
  )
ensure
  @backend.close if @backend
end

#set_pixels(buffer) ⇒ Object



51
52
53
# File 'lib/rbgl/gui/window.rb', line 51

def set_pixels(buffer)
  @backend.set_pixels(buffer, @width, @height)
end

#should_close?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/rbgl/gui/window.rb', line 63

def should_close?
  @backend.should_close?
end

#stopObject



42
43
44
# File 'lib/rbgl/gui/window.rb', line 42

def stop
  @render_loop.stop
end