Class: RBGL::GUI::Window
- Inherits:
-
Object
- Object
- RBGL::GUI::Window
- 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
-
#backend ⇒ Object
readonly
Returns the value of attribute backend.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
- #close ⇒ Object
- #dropped_frames ⇒ Object
- #fps ⇒ Object
-
#initialize(width:, height:, title: "RBGL", backend: :auto, **options) ⇒ Window
constructor
A new instance of Window.
- #metal_available? ⇒ Boolean
- #native_handle ⇒ Object
- #on(event_type, &block) ⇒ Object
- #poll_events_raw ⇒ Object
- #present_framebuffer(framebuffer = nil) ⇒ Object
- #run(&frame_callback) ⇒ Object
- #set_pixels(buffer) ⇒ Object
- #should_close? ⇒ Boolean
- #stop ⇒ Object
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, **) @width = width @height = height @title = title @context = Engine::Context.new(width: width, height: height) @backend = build_backend(backend, width: width, height: height, title: title, **) @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
#backend ⇒ Object (readonly)
Returns the value of attribute backend.
9 10 11 |
# File 'lib/rbgl/gui/window.rb', line 9 def backend @backend end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
9 10 11 |
# File 'lib/rbgl/gui/window.rb', line 9 def context @context end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
9 10 11 |
# File 'lib/rbgl/gui/window.rb', line 9 def height @height end |
#width ⇒ Object (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
#close ⇒ Object
71 72 73 |
# File 'lib/rbgl/gui/window.rb', line 71 def close @backend.close end |
#dropped_frames ⇒ Object
79 80 81 |
# File 'lib/rbgl/gui/window.rb', line 79 def dropped_frames @render_loop.dropped_frames end |
#fps ⇒ Object
75 76 77 |
# File 'lib/rbgl/gui/window.rb', line 75 def fps @render_loop.fps end |
#metal_available? ⇒ Boolean
55 56 57 |
# File 'lib/rbgl/gui/window.rb', line 55 def @backend. end |
#native_handle ⇒ Object
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_raw ⇒ Object
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
63 64 65 |
# File 'lib/rbgl/gui/window.rb', line 63 def should_close? @backend.should_close? end |
#stop ⇒ Object
42 43 44 |
# File 'lib/rbgl/gui/window.rb', line 42 def stop @render_loop.stop end |