Module: Ruby2D::DSL

Defined in:
lib/ruby2d/dsl.rb

Overview

Domain-specific language methods for the top-level Ruby2D interface

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.windowObject

Get the DSL window instance, constructing a default on first access



5
6
7
# File 'lib/ruby2d/dsl.rb', line 5

def self.window
  @window ||= Ruby2D::Window.new
end

.window=(window) ⇒ Object

Set the DSL window instance



10
11
12
# File 'lib/ruby2d/dsl.rb', line 10

def self.window=(window)
  @window = window
end

.window?Boolean

Whether a DSL window already exists, without constructing one. Used to enforce the single-window rule (reading window would auto-create one).

Returns:

  • (Boolean)


16
17
18
# File 'lib/ruby2d/dsl.rb', line 16

def self.window?
  !@window.nil?
end

Instance Method Details

#add_gamepad_mapping(path_or_string) ⇒ Object

Load a gamepad mapping from a file path or a single mapping string



72
73
74
# File 'lib/ruby2d/dsl.rb', line 72

def add_gamepad_mapping(path_or_string)
  DSL.window.add_gamepad_mapping(path_or_string)
end

#clearObject

Clear all objects from the window



62
63
64
# File 'lib/ruby2d/dsl.rb', line 62

def clear
  DSL.window.clear
end

#closeObject

Close the window



82
83
84
# File 'lib/ruby2d/dsl.rb', line 82

def close
  DSL.window.close
end

#elapsedObject

Monotonic seconds since the engine started (see Window#elapsed)



57
58
59
# File 'lib/ruby2d/dsl.rb', line 57

def elapsed
  DSL.window.elapsed
end

#gamepadsObject

The connected gamepads, in connect order



67
68
69
# File 'lib/ruby2d/dsl.rb', line 67

def gamepads
  DSL.window.gamepads
end

#get(sym) ⇒ Object

Get a window attribute by name



21
22
23
# File 'lib/ruby2d/dsl.rb', line 21

def get(sym)
  DSL.window.get(sym)
end

#off(event_descriptor) ⇒ Object

Remove an event handler



41
42
43
# File 'lib/ruby2d/dsl.rb', line 41

def off(event_descriptor)
  DSL.window.off(event_descriptor)
end

#on(event = nil, **filters, &proc) ⇒ Object

Register an event handler



36
37
38
# File 'lib/ruby2d/dsl.rb', line 36

def on(event = nil, **filters, &proc)
  DSL.window.on(event, **filters, &proc)
end

#render(z: :foreground, &proc) ⇒ Object

Set the render callback. z: positions the block in the scene's z-order — :foreground (default), :background, or a number.



52
53
54
# File 'lib/ruby2d/dsl.rb', line 52

def render(z: :foreground, &proc)
  DSL.window.render(z: z, &proc)
end

#request_renderObject

Request a render on the next tick (for :on_demand render mode)



87
88
89
# File 'lib/ruby2d/dsl.rb', line 87

def request_render
  DSL.window.request_render
end

#screenshot(path = nil) ⇒ Object

Take a screenshot, saving to path (or a timestamped file if omitted)



31
32
33
# File 'lib/ruby2d/dsl.rb', line 31

def screenshot(path = nil)
  DSL.window.screenshot(path)
end

#set(opts) ⇒ Object

Set window attributes



26
27
28
# File 'lib/ruby2d/dsl.rb', line 26

def set(opts)
  DSL.window.set(opts)
end

#showObject

Show the window



77
78
79
# File 'lib/ruby2d/dsl.rb', line 77

def show
  DSL.window.show
end

#update(&proc) ⇒ Object

Set the update callback



46
47
48
# File 'lib/ruby2d/dsl.rb', line 46

def update(&proc)
  DSL.window.update(&proc)
end