summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTom Black <[email protected]>2016-07-17 23:56:42 -0500
committerTom Black <[email protected]>2016-07-17 23:56:42 -0500
commit4adfbee49d31cb701663bc60aab4b1197f9afb28 (patch)
tree213ee286910ca0b2b4595312fe1a1dbcba8c4d11
parent543de7e0175cd162797415b579a1c7cba7d14f22 (diff)
downloadruby2d-4adfbee49d31cb701663bc60aab4b1197f9afb28.tar.gz
ruby2d-4adfbee49d31cb701663bc60aab4b1197f9afb28.zip
Add `close` to DSL
-rw-r--r--ext/ruby2d/ruby2d.c12
-rw-r--r--lib/ruby2d/application.rb4
-rw-r--r--lib/ruby2d/dsl.rb8
-rw-r--r--tests/testcard.rb5
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
@@ -271,6 +271,15 @@ static VALUE ruby2d_show(VALUE s) {
/*
+ * Ruby2D::Window#close
+ */
+static VALUE ruby2d_close() {
+ S2D_Close(window);
+ return Qnil;
+}
+
+
+/*
* Ruby C extension init
*/
void Init_ruby2d() {
@@ -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