rubysketch 0.5.5 → 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: 11852910038d162e39601eb01056ee3b4161c4ac0576ac93aef87e25eed557ee
4
- data.tar.gz: 6d978cf96d2e8d32df00477e77f03c645840bb70985f74e5d254ff5f47f5cd4c
3
+ metadata.gz: 739c6814b5036acf34bf85ff187adb2c2c4781663cb88a2ac261ccde7016a7ac
4
+ data.tar.gz: a51e5ab02cb6353bbe56f9a697bcd7d56cd6ca8d7fa6bf83028258f236f30ed2
5
5
  SHA512:
6
- metadata.gz: '0593125c1c609a1f1c38eb45631f558fcb525db85792335524a37718d306c770d12f12012d3ddf5752080318070eb139d8ece676fb436f5a10abd88af02b2c8b'
7
- data.tar.gz: 2d78202eb29f9541886efc54ec44142caf1cbd192ff58e51a26af5d3a0b8cb242c80be05171013f215b698a01cd70b9878fb10a2364abb4259402c48f6ea8475
6
+ metadata.gz: 01ab6b71222edc9fda13fbce1812f69fb14534f2019ad76c6f6a511bb579d3bedc34f0d13a8aaa3da9c068365a06cef5de7cce38206fb76c61abb6cf96e3b26d
7
+ data.tar.gz: 4442846bd3b378ca0b06cd70aadfef0fdfe3fce2df69ba223b1f5e06602d5eb086c936743c646da90d11fad9e2962fc2099f2fd864bb0481d188e873553c424f
data/ChangeLog.md CHANGED
@@ -1,6 +1,22 @@
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
+
9
+ ## [v0.5.7] - 2023-05-13
10
+
11
+ - Update dependencies
12
+
13
+
14
+ ## [v0.5.6] - 2023-05-11
15
+
16
+ - Add Sprite#center accessor
17
+ - Add Sprite#size=, Sprite#width=, and Sprite#height=
18
+
19
+
4
20
  ## [v0.5.5] - 2023-05-08
5
21
 
6
22
  - Add Sprite#draw()
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.5
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
@@ -78,18 +78,18 @@ module RubySketch
78
78
  f, degrees, pivot = view.frame, view.angle, view.pivot
79
79
  if draw
80
80
  push do
81
- translate f.x + pivot.x * f.w, f.y + pivot.y * f.h
81
+ translate f.x + pivot.x * f.w, f.y + pivot.y * f.h
82
82
  rotate fromDegrees__ degrees
83
- translate -pivot.x * f.w, -pivot.y * f.h
83
+ translate (-pivot.x) * f.w, (-pivot.y) * f.h
84
84
  draw.call {drawSprite__ sp, 0, 0, f.w, f.h}
85
85
  end
86
86
  elsif degrees == 0
87
87
  drawSprite__ sp, f.x, f.y, f.w, f.h
88
88
  else
89
89
  pushMatrix do
90
- translate f.x + pivot.x * f.w, f.y + pivot.y * f.h
90
+ translate f.x + pivot.x * f.w, f.y + pivot.y * f.h
91
91
  rotate fromDegrees__ degrees
92
- translate -pivot.x * f.w, -pivot.y * f.h
92
+ translate (-pivot.x) * f.w, (-pivot.y) * f.h
93
93
  drawSprite__ sp, 0, 0, f.w, f.h
94
94
  end
95
95
  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,9 +115,52 @@ 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
 
140
+ # Returns the center position of the sprite.
141
+ #
142
+ # @return [Vector] center position
143
+ #
144
+ def center()
145
+ Vector.new(x + w / 2, y + h / 2)
146
+ end
147
+
148
+ # Sets the center position of the sprite.
149
+ #
150
+ # @overload center=(vec)
151
+ # @param [Vector] vec center position
152
+ #
153
+ # @overload center=(ary)
154
+ # @param [Array<Numeric>] ary an array of centerX and centerY
155
+ #
156
+ # @return [Vector] center position
157
+ #
158
+ def center=(arg)
159
+ x, y = *(arg.is_a?(Vector) ? arg.getInternal__.to_a : arg)
160
+ self.pos = [x - w / 2, y - h / 2]
161
+ self.center
162
+ end
163
+
121
164
  # Returns the size of the sprite.
122
165
  #
123
166
  # @return [Vector] size
@@ -126,6 +169,15 @@ module RubySketch
126
169
  @view__.size.toVector
127
170
  end
128
171
 
172
+ # Returns the size of the sprite.
173
+ #
174
+ # @return [Vector] size
175
+ #
176
+ def size=(arg)
177
+ @view__.size = arg.is_a?(Vector) ? arg.getInternal__ : arg
178
+ arg
179
+ end
180
+
129
181
  # Returns the width of the sprite.
130
182
  #
131
183
  # @return [Numeric] width
@@ -134,6 +186,16 @@ module RubySketch
134
186
  @view__.width
135
187
  end
136
188
 
189
+ # Sets the width of the sprite.
190
+ #
191
+ # @param [Numeric] w width
192
+ #
193
+ # @return [Numeric] width
194
+ #
195
+ def width=(w)
196
+ @view__.width = w
197
+ end
198
+
137
199
  # Returns the height of the sprite.
138
200
  #
139
201
  # @return [Numeric] height
@@ -142,8 +204,20 @@ module RubySketch
142
204
  @view__.height
143
205
  end
144
206
 
145
- alias w width
146
- alias h height
207
+ # Sets the height of the sprite.
208
+ #
209
+ # @param [Numeric] h height
210
+ #
211
+ # @return [Numeric] height
212
+ #
213
+ def height=(h)
214
+ @view__.height = h
215
+ end
216
+
217
+ alias w width
218
+ alias w= width=
219
+ alias h height
220
+ alias h= height=
147
221
 
148
222
  # Returns the rotation angle of sprite.
149
223
  #
@@ -689,14 +763,14 @@ module RubySketch
689
763
  def on_pointer_down(e)
690
764
  updatePointerStates e, true
691
765
  @pointerDownStartPos = @pointerPos.dup
692
- (@touchStarted || @mousePressed)&.call
766
+ (@touchStarted || @mousePressed)&.call if e.view_index == 0
693
767
  end
694
768
 
695
769
  def on_pointer_up(e)
696
770
  updatePointerStates e, false
697
- (@touchEnded || @mouseReleased)&.call
771
+ (@touchEnded || @mouseReleased)&.call if e.view_index == 0
698
772
  if startPos = @pointerDownStartPos
699
- @mouseClicked&.call if (@pointerPos - startPos).length < 3
773
+ @mouseClicked&.call if e.view_index == 0 && (@pointerPos - startPos).length < 3
700
774
  @pointerDownStartPos = nil
701
775
  end
702
776
  @pointersReleased.clear
@@ -704,7 +778,8 @@ module RubySketch
704
778
 
705
779
  def on_pointer_move(e)
706
780
  updatePointerStates e
707
- (@touchMoved || (e.drag? ? @mouseDragged : @mouseMoved))&.call
781
+ mouseMoved = e.drag? ? @mouseDragged : @mouseMoved
782
+ (@touchMoved || mouseMoved)&.call if e.view_index == 0
708
783
  end
709
784
 
710
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.35'
35
- s.add_runtime_dependency 'reflexion', '~> 0.1.36'
36
- s.add_runtime_dependency 'processing', '~> 0.5.6'
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'
data/test/test_sprite.rb CHANGED
@@ -64,16 +64,49 @@ class TestSprite < Test::Unit::TestCase
64
64
  assert_equal vec(1, 2), s.pos
65
65
  end
66
66
 
67
+ def test_center()
68
+ s = sprite 0, 0, 10, 20
69
+ assert_equal vec( 5, 10), s.center
70
+
71
+ s.center = vec 100, 200
72
+ assert_equal vec( 95, 190), s.pos
73
+
74
+ s.center = [300, 400]
75
+ assert_equal vec(295, 390), s.pos
76
+ end
77
+
67
78
  def test_size()
68
79
  assert_equal vec(0, 0), sprite .size
69
80
  assert_equal vec(1, 0), sprite(0, 0, 1) .size
70
81
  assert_equal vec(1, 2), sprite(0, 0, 1, 2) .size
71
82
  assert_equal vec(3, 4), sprite(image: image(3, 4)).size
83
+
84
+ s = sprite
85
+ s.size = vec 10, 20
86
+ assert_equal vec(10, 20), s.size
87
+
88
+ s.size = [30, 40]
89
+ assert_equal vec(30, 40), s.size
72
90
  end
73
91
 
74
92
  def test_wh()
75
93
  assert_equal 1, sprite(0, 0, 1, 2).width
94
+ assert_equal 1, sprite(0, 0, 1, 2).w
76
95
  assert_equal 2, sprite(0, 0, 1, 2).height
96
+ assert_equal 2, sprite(0, 0, 1, 2).h
97
+
98
+ s = sprite
99
+ s.width = 10
100
+ assert_equal vec(10, 0), s.size
101
+
102
+ s.w = 20
103
+ assert_equal vec(20, 0), s.size
104
+
105
+ s.height = 30
106
+ assert_equal vec(20, 30), s.size
107
+
108
+ s.h = 40
109
+ assert_equal vec(20, 40), s.size
77
110
  end
78
111
 
79
112
  def test_angle()
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.5
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-08 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.35
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.35
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.36
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.36
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.6
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.6
96
+ version: 0.5.9
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rake
99
99
  requirement: !ruby/object:Gem::Requirement