diff options
| author | lstrzebinczyk <[email protected]> | 2017-05-21 21:26:12 +0200 |
|---|---|---|
| committer | Tom Black <[email protected]> | 2017-05-31 23:36:04 -0400 |
| commit | 65187cd5126227778146ec33c2857a391fbab620 (patch) | |
| tree | 328c21a2bdf9365d5c018326c229760986cf412f /test/contains.rb | |
| parent | 09ed2811ad3ccb9af50028447fabbcee5b5c5ae2 (diff) | |
| download | ruby2d-65187cd5126227778146ec33c2857a391fbab620.tar.gz ruby2d-65187cd5126227778146ec33c2857a391fbab620.zip | |
Implement #contains? for all renderables
Diffstat (limited to 'test/contains.rb')
| -rw-r--r-- | test/contains.rb | 32 |
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 |
