summaryrefslogtreecommitdiffhomepage
path: root/test/contains.rb
diff options
context:
space:
mode:
authorlstrzebinczyk <[email protected]>2017-05-21 21:26:12 +0200
committerTom Black <[email protected]>2017-05-31 23:36:04 -0400
commit65187cd5126227778146ec33c2857a391fbab620 (patch)
tree328c21a2bdf9365d5c018326c229760986cf412f /test/contains.rb
parent09ed2811ad3ccb9af50028447fabbcee5b5c5ae2 (diff)
downloadruby2d-65187cd5126227778146ec33c2857a391fbab620.tar.gz
ruby2d-65187cd5126227778146ec33c2857a391fbab620.zip
Implement #contains? for all renderables
Diffstat (limited to 'test/contains.rb')
-rw-r--r--test/contains.rb32
1 files changed, 32 insertions, 0 deletions
diff --git a/test/contains.rb b/test/contains.rb
new file mode 100644
index 0000000..5a11064
--- /dev/null
+++ b/test/contains.rb
@@ -0,0 +1,32 @@
+require 'ruby2d'
+
+set title: "Ruby 2D — Contains", height: 350
+
+if RUBY_ENGINE == 'opal'
+ media = "../test/media"
+ font = "sans-serif"
+else
+ media = "media"
+ font = "#{media}/bitstream_vera/vera.ttf"
+end
+
+objects = []
+objects.push Square.new(50, 50, 100)
+objects.push Rectangle.new(200, 50, 100, 75)
+objects.push Quad.new(350, 50, 500, 75, 450, 150, 375, 125)
+objects.push Triangle.new(550, 50, 600, 125, 500, 150)
+objects.push Line.new(225, 175, 375, 225, 20)
+objects.push Image.new(50, 200, "#{media}/colors.png")
+objects.push Text.new(450, 200, "Hello", 50, font)
+
+on :key_down do |event|
+ close if event.key == 'escape'
+end
+
+update do
+ objects.each do |o|
+ o.contains?(get(:mouse_x), get(:mouse_y)) ? o.opacity = 1.0 : o.opacity = 0.5
+ end
+end
+
+show