Class: RBGL::GUI::FileBackend

Inherits:
Backend
  • Object
show all
Defined in:
lib/rbgl/gui/file_backend.rb,
lib/rbgl/gui/file_backend/bmp_writer.rb,
lib/rbgl/gui/file_backend/ppm_writer.rb,
lib/rbgl/gui/file_backend/frame_writer.rb

Defined Under Namespace

Classes: BmpWriter, FrameWriter, PpmWriter

Constant Summary collapse

SUPPORTED_FORMATS =
%i[ppm bmp].freeze
PPM_MODES =
%i[ascii binary].freeze

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", format: :ppm, ppm_mode: :ascii, output_dir: ".") ⇒ FileBackend

Returns a new instance of FileBackend.



13
14
15
16
17
18
19
20
21
22
# File 'lib/rbgl/gui/file_backend.rb', line 13

def initialize(width, height, title = "RBGL", format: :ppm, ppm_mode: :ascii, output_dir: ".")
  super(width, height, title)
  @format = normalize_format(format)
  @ppm_mode = normalize_ppm_mode(ppm_mode, @format)
  @writer = FrameWriter.build(@format, ppm_mode: @ppm_mode)
  @output_dir = output_dir
  @frame_count = 0
  @should_close = false
  @max_frames = nil
end

Instance Method Details

#closeObject



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

def close
  @should_close = true
end

#poll_eventsObject



34
35
36
# File 'lib/rbgl/gui/file_backend.rb', line 34

def poll_events
  []
end

#present(framebuffer) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/rbgl/gui/file_backend.rb', line 24

def present(framebuffer)
  filename = File.join(@output_dir, format("frame_%05d.#{@writer.extension}", @frame_count))
  @writer.write(filename, framebuffer)

  @frame_count += 1

  @should_close = true if @max_frames && @frame_count >= @max_frames
  true
end

#set_max_frames(count) ⇒ Object



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

def set_max_frames(count)
  @max_frames = count
end

#should_close?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/rbgl/gui/file_backend.rb', line 38

def should_close?
  @should_close
end