Class: RBGL::GUI::Cocoa::Backend

Inherits:
Backend
  • Object
show all
Defined in:
lib/rbgl/gui/cocoa/backend.rb

Instance Attribute Summary

Attributes inherited from Backend

#height, #title, #width

Instance Method Summary collapse

Methods inherited from Backend

#resize

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

#closeObject



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

Returns:

  • (Boolean)


66
67
68
69
70
# File 'lib/rbgl/gui/cocoa/backend.rb', line 66

def metal_available?
  return false unless @handle

  Metaco.metal_compute_available?(@handle)
end

#native_handleObject



72
73
74
# File 'lib/rbgl/gui/cocoa/backend.rb', line 72

def native_handle
  @handle
end

#poll_eventsObject



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_rawObject



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

Returns:

  • (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