diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/ruby2d/dsl.rb | 4 | ||||
| -rw-r--r-- | lib/ruby2d/window.rb | 22 |
2 files changed, 21 insertions, 5 deletions
diff --git a/lib/ruby2d/dsl.rb b/lib/ruby2d/dsl.rb index a6818fa..62352b4 100644 --- a/lib/ruby2d/dsl.rb +++ b/lib/ruby2d/dsl.rb @@ -4,8 +4,8 @@ module Ruby2D::DSL Ruby2D::Window.new - def get(sym) - Window.get(sym) + def get(sym, opts = nil) + Window.get(sym, opts) end def set(opts) diff --git a/lib/ruby2d/window.rb b/lib/ruby2d/window.rb index 7db80a9..a952134 100644 --- a/lib/ruby2d/window.rb +++ b/lib/ruby2d/window.rb @@ -111,9 +111,10 @@ module Ruby2D def mouse_x; get(:mouse_x) end def mouse_y; get(:mouse_y) end def diagnostics; get(:diagnostics) end + def screenshot(opts = nil); get(:screenshot, opts) end - def get(sym) - @@window.get(sym) + def get(sym, opts = nil) + @@window.get(sym, opts) end def set(opts) @@ -156,7 +157,7 @@ module Ruby2D # Public instance methods # Retrieve an attribute of the window - def get(sym) + def get(sym, opts = nil) case sym when :window; self when :title; @title @@ -182,6 +183,7 @@ module Ruby2D when :mouse_x; @mouse_x when :mouse_y; @mouse_y when :diagnostics; @diagnostics + when :screenshot; screenshot(opts) end end @@ -383,6 +385,20 @@ module Ruby2D ext_show end + # Take screenshot + def screenshot(path) + if path + ext_screenshot(path) + else + if RUBY_ENGINE == 'ruby' + time = Time.now.utc.strftime '%Y-%m-%d--%H-%M-%S' + else + time = Time.now.utc.to_i + end + ext_screenshot("./screenshot-#{time}.png") + end + end + # Close the window def close ext_close |
