Class: RBGL::GUI::X11::Backend
Instance Attribute Summary
Attributes inherited from Backend
#height, #title, #width
Instance Method Summary
collapse
Methods inherited from Backend
#metal_available?, #native_handle, #poll_events_raw, #resize, #set_pixels
Constructor Details
#initialize(width, height, title = "RBGL", env: ENV) ⇒ Backend
Returns a new instance of Backend.
9
10
11
12
13
14
|
# File 'lib/rbgl/gui/x11/backend.rb', line 9
def initialize(width, height, title = "RBGL", env: ENV)
super(width, height, title)
@display = Connection.new(env["DISPLAY"] || ":0")
@windows = {}
setup_window(width, height, title)
end
|
Instance Method Details
#close ⇒ Object
98
99
100
101
102
103
104
105
|
# File 'lib/rbgl/gui/x11/backend.rb', line 98
def close
return unless @handle
@windows[@handle][:should_close] = true
@display.destroy_window(@handle)
@windows.delete(@handle)
@handle = nil
end
|
#poll_events ⇒ Object
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/rbgl/gui/x11/backend.rb', line 78
def poll_events
events = []
while @display.pending > 0
raw_event = @display.next_event
next unless raw_event
event = convert_event(raw_event)
events << event if event
end
events
end
|
#present(framebuffer) ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/rbgl/gui/x11/backend.rb', line 55
def present(framebuffer)
return false unless @handle
window = @windows[@handle]
return false unless window
buffer = convert_to_x11_format(framebuffer)
@display.put_image(
format: :z_pixmap,
drawable: @handle,
gc: window[:gc],
width: framebuffer.width,
height: framebuffer.height,
dst_x: 0, dst_y: 0,
depth: @display.root_depth,
data: buffer
)
@display.flush
true
end
|
#should_close? ⇒ Boolean
92
93
94
95
96
|
# File 'lib/rbgl/gui/x11/backend.rb', line 92
def should_close?
return false unless @handle
@windows[@handle]&.[](:should_close) || false
end
|