rubysketch 0.5.7 → 0.5.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a9465d904b4ad4eed514cb114281c1f19b49e692750456714152033cbabd3bea
4
- data.tar.gz: aff3bf85d73c1dc26fc200647a77c0dc2c0133630450f33bb0e98c62b5ac6f5e
3
+ metadata.gz: 739c6814b5036acf34bf85ff187adb2c2c4781663cb88a2ac261ccde7016a7ac
4
+ data.tar.gz: a51e5ab02cb6353bbe56f9a697bcd7d56cd6ca8d7fa6bf83028258f236f30ed2
5
5
  SHA512:
6
- metadata.gz: 68579b3732c2a114b8d421b61a92cbe611d412ed84bc3f1bb7cb3d81ff2cd28ecbbd35aa2469cad156fb7510cafcf624d79630a4422f4ba85ce98fd47a06b8c4
7
- data.tar.gz: a8227ef0c4a0e7c9653f0825c3b8dfb74036058b2550cc1e5075f85d85579c1450e69f93d5bfd543e66f883b2798eca98af04b2f2747da7e54bdafeb5b99e60e
6
+ metadata.gz: 01ab6b71222edc9fda13fbce1812f69fb14534f2019ad76c6f6a511bb579d3bedc34f0d13a8aaa3da9c068365a06cef5de7cce38206fb76c61abb6cf96e3b26d
7
+ data.tar.gz: 4442846bd3b378ca0b06cd70aadfef0fdfe3fce2df69ba223b1f5e06602d5eb086c936743c646da90d11fad9e2962fc2099f2fd864bb0481d188e873553c424f
data/ChangeLog.md CHANGED
@@ -1,6 +1,11 @@
1
1
  # rubysketch ChangeLog
2
2
 
3
3
 
4
+ ## [v0.5.8] - 2023-05-18
5
+
6
+ - Dispatch pointer events only to the topmost sprite
7
+
8
+
4
9
  ## [v0.5.7] - 2023-05-13
5
10
 
6
11
  - Update dependencies
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.7
1
+ 0.5.8
data/examples/sprite.rb CHANGED
@@ -5,43 +5,80 @@
5
5
  require 'rubysketch'
6
6
  using RubySketch
7
7
 
8
- sp = createSprite 100, 100, 50, 50
9
- sp.angle += Math::PI * 0.2
8
+ red = green = 0
10
9
 
11
- red = 0
10
+ sprites = (0..10).map do |n|
11
+ createSprite(100 + 50 * n, 100 + 50 * n, 100, 100).tap do |sp|
12
+ name = "sp#{n}"
13
+ sp.instance_variable_set :@n, n
14
+ sp.mousePressed do
15
+ p [name, :pressed, sp.mouseX, sp.mouseY, sp.mouseButton]
16
+ end
12
17
 
13
- sp.update do
14
- red = (red + 1) % 255
18
+ sp.mouseReleased do
19
+ p [name, :released, sp.mouseX, sp.mouseY, sp.mouseButton]
20
+ end
21
+
22
+ sp.mouseMoved do
23
+ p [name, :moved, sp.mouseX, sp.mouseY, sp.pmouseX, sp.pmouseY]
24
+ end
25
+
26
+ sp.mouseDragged do
27
+ p [name, :dragged, sp.mouseX, sp.mouseY, sp.pmouseX, sp.pmouseY]
28
+ end
29
+
30
+ sp.mouseClicked do
31
+ p [name, :clicked, sp.mouseX, sp.mouseY, sp.mouseButton]
32
+ sp.z += 10
33
+ end
34
+ end
15
35
  end
16
36
 
17
- sp.draw do |&draw|
37
+ sprites[1].angle += Math::PI * 0.2
38
+ sprites[1].z = 10
39
+
40
+ sprites[1].update {red = (red + 1) % 255}
41
+ sprites[2].update {green = (green + 1) % 255}
42
+
43
+ sprites[1].draw do |&draw|
18
44
  fill red, 200, 200
19
45
  draw.call
20
46
  fill 0
21
47
  text :hello, 10, 20
22
48
  end
23
49
 
24
- sp.mousePressed do
25
- p [:pressed, sp.mouseX, sp.mouseY, sp.mouseButton]
50
+ sprites[2].draw do |&draw|
51
+ fill 200, green, 200
52
+ draw.call
53
+ fill 0
54
+ text :world, 10, 20
26
55
  end
27
56
 
28
- sp.mouseReleased do
29
- p [:released, sp.mouseX, sp.mouseY, sp.mouseButton]
57
+ draw do
58
+ background 0
59
+ text sprites.map {|sp| sp.z}, 100, 50
60
+ sprite sprites.sort {|a, b|
61
+ an, bn = [a, b].map {|o| o.instance_variable_get :@n}
62
+ a.z != b.z ? a.z <=> b.z : an <=> bn
63
+ }
30
64
  end
31
65
 
32
- sp.mouseMoved do
33
- p [:moved, sp.mouseX, sp.mouseY, sp.pmouseX, sp.pmouseY]
66
+ mousePressed do
67
+ p [:pressed, mouseX, mouseY, mouseButton]
34
68
  end
35
69
 
36
- sp.mouseDragged do
37
- p [:dragged, sp.mouseX, sp.mouseY, sp.pmouseX, sp.pmouseY]
70
+ mouseReleased do
71
+ p [:released, mouseX, mouseY, mouseButton]
38
72
  end
39
73
 
40
- sp.mouseClicked do
41
- p [:clicked, sp.mouseX, sp.mouseY, sp.mouseButton]
74
+ mouseMoved do
75
+ p [:moved, mouseX, mouseY, pmouseX, pmouseY]
42
76
  end
43
77
 
44
- draw do
45
- background 0
46
- sprite sp
78
+ mouseDragged do
79
+ p [:dragged, mouseX, mouseY, pmouseX, pmouseY]
80
+ end
81
+
82
+ mouseClicked do
83
+ p [:clicked, mouseX, mouseY, mouseButton]
47
84
  end
@@ -145,7 +145,7 @@ module RubySketch
145
145
  end
146
146
 
147
147
  def on_draw(e)
148
- e.block
148
+ e.block false
149
149
  end
150
150
 
151
151
  end# SpriteLayer
@@ -115,6 +115,25 @@ module RubySketch
115
115
  n
116
116
  end
117
117
 
118
+ # Returns the z-coordinate position of the sprite.
119
+ #
120
+ # @return [Numeric] sprite position z
121
+ #
122
+ def z()
123
+ @view__.z
124
+ end
125
+
126
+ # Set the z-coordinate position of the sprite.
127
+ #
128
+ # @param [Numeric] n sprite position z
129
+ #
130
+ # @return [Numeric] sprite position z
131
+ #
132
+ def z=(n)
133
+ @view__.z = n
134
+ n
135
+ end
136
+
118
137
  alias pos position
119
138
  alias pos= position=
120
139
 
@@ -744,14 +763,14 @@ module RubySketch
744
763
  def on_pointer_down(e)
745
764
  updatePointerStates e, true
746
765
  @pointerDownStartPos = @pointerPos.dup
747
- (@touchStarted || @mousePressed)&.call
766
+ (@touchStarted || @mousePressed)&.call if e.view_index == 0
748
767
  end
749
768
 
750
769
  def on_pointer_up(e)
751
770
  updatePointerStates e, false
752
- (@touchEnded || @mouseReleased)&.call
771
+ (@touchEnded || @mouseReleased)&.call if e.view_index == 0
753
772
  if startPos = @pointerDownStartPos
754
- @mouseClicked&.call if (@pointerPos - startPos).length < 3
773
+ @mouseClicked&.call if e.view_index == 0 && (@pointerPos - startPos).length < 3
755
774
  @pointerDownStartPos = nil
756
775
  end
757
776
  @pointersReleased.clear
@@ -759,7 +778,8 @@ module RubySketch
759
778
 
760
779
  def on_pointer_move(e)
761
780
  updatePointerStates e
762
- (@touchMoved || (e.drag? ? @mouseDragged : @mouseMoved))&.call
781
+ mouseMoved = e.drag? ? @mouseDragged : @mouseMoved
782
+ (@touchMoved || mouseMoved)&.call if e.view_index == 0
763
783
  end
764
784
 
765
785
  def on_pointer_cancel(e)
data/rubysketch.gemspec CHANGED
@@ -28,12 +28,12 @@ Gem::Specification.new do |s|
28
28
  s.platform = Gem::Platform::RUBY
29
29
  s.required_ruby_version = '>= 2.7.0'
30
30
 
31
- s.add_runtime_dependency 'xot', '~> 0.1.35'
32
- s.add_runtime_dependency 'rucy', '~> 0.1.35'
33
- s.add_runtime_dependency 'beeps', '~> 0.1.36'
34
- s.add_runtime_dependency 'rays', '~> 0.1.36'
35
- s.add_runtime_dependency 'reflexion', '~> 0.1.38'
36
- s.add_runtime_dependency 'processing', '~> 0.5.8'
31
+ s.add_runtime_dependency 'xot', '~> 0.1.36'
32
+ s.add_runtime_dependency 'rucy', '~> 0.1.36'
33
+ s.add_runtime_dependency 'beeps', '~> 0.1.37'
34
+ s.add_runtime_dependency 'rays', '~> 0.1.37'
35
+ s.add_runtime_dependency 'reflexion', '~> 0.1.39'
36
+ s.add_runtime_dependency 'processing', '~> 0.5.9'
37
37
 
38
38
  s.add_development_dependency 'rake'
39
39
  s.add_development_dependency 'test-unit'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubysketch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.7
4
+ version: 0.5.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - xordog
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-12 00:00:00.000000000 Z
11
+ date: 2023-05-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: xot
@@ -16,84 +16,84 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.1.35
19
+ version: 0.1.36
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.1.35
26
+ version: 0.1.36
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rucy
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.1.35
33
+ version: 0.1.36
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.1.35
40
+ version: 0.1.36
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: beeps
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.1.36
47
+ version: 0.1.37
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.1.36
54
+ version: 0.1.37
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rays
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.1.36
61
+ version: 0.1.37
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.1.36
68
+ version: 0.1.37
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: reflexion
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 0.1.38
75
+ version: 0.1.39
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 0.1.38
82
+ version: 0.1.39
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: processing
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 0.5.8
89
+ version: 0.5.9
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 0.5.8
96
+ version: 0.5.9
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rake
99
99
  requirement: !ruby/object:Gem::Requirement