From 4adfbee49d31cb701663bc60aab4b1197f9afb28 Mon Sep 17 00:00:00 2001 From: Tom Black Date: Sun, 17 Jul 2016 23:56:42 -0500 Subject: Add `close` to DSL --- ext/ruby2d/ruby2d.c | 12 ++++++++++++ lib/ruby2d/application.rb | 4 ++++ lib/ruby2d/dsl.rb | 8 ++++++-- tests/testcard.rb | 5 ++++- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/ext/ruby2d/ruby2d.c b/ext/ruby2d/ruby2d.c index 0a727c9..d891c6a 100644 --- a/ext/ruby2d/ruby2d.c +++ b/ext/ruby2d/ruby2d.c @@ -270,6 +270,15 @@ static VALUE ruby2d_show(VALUE s) { } +/* + * Ruby2D::Window#close + */ +static VALUE ruby2d_close() { + S2D_Close(window); + return Qnil; +} + + /* * Ruby C extension init */ @@ -284,6 +293,9 @@ void Init_ruby2d() { // Ruby2D::Window#show rb_define_method(ruby2d_window_klass, "show", ruby2d_show, 0); + // Ruby2D::Window#close + rb_define_method(ruby2d_window_klass, "close", ruby2d_close, 0); + // Ruby2D::CData c_data_klass = rb_define_class_under(ruby2d_module, "CData", rb_cObject); } diff --git a/lib/ruby2d/application.rb b/lib/ruby2d/application.rb index 3883a88..2ceff4b 100644 --- a/lib/ruby2d/application.rb +++ b/lib/ruby2d/application.rb @@ -35,5 +35,9 @@ module Ruby2D::Application def show @@window.show end + + def close + @@window.close + end end end diff --git a/lib/ruby2d/dsl.rb b/lib/ruby2d/dsl.rb index af9f598..3960a0f 100644 --- a/lib/ruby2d/dsl.rb +++ b/lib/ruby2d/dsl.rb @@ -16,13 +16,17 @@ module Ruby2D::DSL def update(&proc) Application.update(&proc) end + + def clear + Application.clear end def show Application.show end - def clear - Ruby2D::Application.clear + def close + Application.close end + end diff --git a/tests/testcard.rb b/tests/testcard.rb index e5b5f8a..e96c217 100644 --- a/tests/testcard.rb +++ b/tests/testcard.rb @@ -139,10 +139,13 @@ t = Text.new(0, 275, 30, "Hello Ruby 2D!", "media/bitstream_vera/vera.ttf") t.color = 'red' # Doesn't work yet fps = Text.new(0, 325, 20) - # Pointer for mouse pointer = Square.new(0, 0, 10, 'white') +on key: "escape" do + close +end + update do pointer.x = (get :mouse_x) - 5 pointer.y = (get :mouse_y) - 7 -- cgit v1.2.3