Class: RBGL::GUI::Cocoa::Backend
- Defined in:
- lib/rbgl/gui/cocoa/backend.rb
Instance Attribute Summary
Attributes inherited from Backend
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(width, height, title = "RBGL", env: ENV) ⇒ Backend
constructor
A new instance of Backend.
- #metal_available? ⇒ Boolean
- #native_handle ⇒ Object
- #poll_events ⇒ Object
- #poll_events_raw ⇒ Object
- #present(framebuffer) ⇒ Object
- #set_pixels(buffer, width, height) ⇒ Object
- #should_close? ⇒ Boolean
Methods inherited from Backend
Constructor Details
#initialize(width, height, title = "RBGL", env: ENV) ⇒ Backend
Returns a new instance of Backend.
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/rbgl/gui/cocoa/backend.rb', line 14 def initialize(width, height, title = "RBGL", env: ENV) @env = env unless METACO_AVAILABLE raise LoadError, "metaco gem is required for Cocoa backend. Install it with: gem install metaco" end super(width, height, title) Metaco.init @handle = Metaco.window_create(width, height, title) end |
Instance Method Details
#close ⇒ Object
52 53 54 55 56 57 |
# File 'lib/rbgl/gui/cocoa/backend.rb', line 52 def close return unless @handle Metaco.window_destroy(@handle) @handle = nil end |
#metal_available? ⇒ Boolean
66 67 68 69 70 |
# File 'lib/rbgl/gui/cocoa/backend.rb', line 66 def return false unless @handle Metaco.(@handle) end |
#native_handle ⇒ Object
72 73 74 |
# File 'lib/rbgl/gui/cocoa/backend.rb', line 72 def native_handle @handle end |
#poll_events ⇒ Object
33 34 35 36 37 38 |
# File 'lib/rbgl/gui/cocoa/backend.rb', line 33 def poll_events return [] unless @handle raw_events = Metaco.poll_events(@handle) raw_events.filter_map { |event| convert_event(event) } end |
#poll_events_raw ⇒ Object
40 41 42 43 44 |
# File 'lib/rbgl/gui/cocoa/backend.rb', line 40 def poll_events_raw return [] unless @handle Metaco.poll_events(@handle) end |
#present(framebuffer) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/rbgl/gui/cocoa/backend.rb', line 25 def present(framebuffer) return false unless @handle Metaco.set_pixels(@handle, framebuffer.to_rgba_bytes, framebuffer.width, framebuffer.height) Metaco.present(@handle) true end |
#set_pixels(buffer, width, height) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/rbgl/gui/cocoa/backend.rb', line 59 def set_pixels(buffer, width, height) return unless @handle Metaco.set_pixels(@handle, buffer, width, height) Metaco.present(@handle) end |
#should_close? ⇒ Boolean
46 47 48 49 50 |
# File 'lib/rbgl/gui/cocoa/backend.rb', line 46 def should_close? return false unless @handle Metaco.should_close?(@handle) end |