rubysketch 0.5.7 → 0.5.9

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: 5385034a66ab2a3bba10f16e08dc828f6f8dd4d3dc9f8425a4d009e46945e9e7
4
+ data.tar.gz: 60027fb7618e84373d0943d5a091548e5d503e6234f61344d57de8a2d9805714
5
5
  SHA512:
6
- metadata.gz: 68579b3732c2a114b8d421b61a92cbe611d412ed84bc3f1bb7cb3d81ff2cd28ecbbd35aa2469cad156fb7510cafcf624d79630a4422f4ba85ce98fd47a06b8c4
7
- data.tar.gz: a8227ef0c4a0e7c9653f0825c3b8dfb74036058b2550cc1e5075f85d85579c1450e69f93d5bfd543e66f883b2798eca98af04b2f2747da7e54bdafeb5b99e60e
6
+ metadata.gz: 36c596d721b9d2965fcb32f7cd1b28e1d76120a71283c11f11be37b983988ac31cfb350f46c9b7441efecb66260c39762cbe6ef4b3a8292b5c89445f7b20154b
7
+ data.tar.gz: eaa2be7d0033d6f7c37d4252cd45acfbdc6d6567139f5e87627bdc9260e80d827b52ffddde6650fac30241e289b6cb328f21a21f62d5a147af04d74a19280334
data/ChangeLog.md CHANGED
@@ -1,6 +1,19 @@
1
1
  # rubysketch ChangeLog
2
2
 
3
3
 
4
+ ## [v0.5.9] - 2023-05-19
5
+
6
+ - Add Sprite#clickCount()
7
+ - Add Sprite#from_screen() and to_screen()
8
+ - Sprite#update returns nil
9
+ - Sprite#center includes z
10
+
11
+
12
+ ## [v0.5.8] - 2023-05-18
13
+
14
+ - Dispatch pointer events only to the topmost sprite
15
+
16
+
4
17
  ## [v0.5.7] - 2023-05-13
5
18
 
6
19
  - Update dependencies
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.7
1
+ 0.5.9
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
 
@@ -123,7 +142,7 @@ module RubySketch
123
142
  # @return [Vector] center position
124
143
  #
125
144
  def center()
126
- Vector.new(x + w / 2, y + h / 2)
145
+ Vector.new(x + w / 2, y + h / 2, z)
127
146
  end
128
147
 
129
148
  # Sets the center position of the sprite.
@@ -138,7 +157,7 @@ module RubySketch
138
157
  #
139
158
  def center=(arg)
140
159
  x, y = *(arg.is_a?(Vector) ? arg.getInternal__.to_a : arg)
141
- self.pos = [x - w / 2, y - h / 2]
160
+ self.pos = [x - w / 2, y - h / 2, z]
142
161
  self.center
143
162
  end
144
163
 
@@ -473,6 +492,26 @@ module RubySketch
473
492
  alias rest restitution
474
493
  alias rest= restitution=
475
494
 
495
+ # Converts a vector from the screen coordinate
496
+ #
497
+ # @param [Vector] vec screen coordinate vector
498
+ #
499
+ # @return [Vector] sprite coordinate vector
500
+ #
501
+ def from_screen(vec)
502
+ @view__.from_parent(vec.getInternal__).toVector
503
+ end
504
+
505
+ # Converts a vector to the screen coordinate
506
+ #
507
+ # @param [Vector] vec sprite coordinate vector
508
+ #
509
+ # @return [Vector] screen coordinate vector
510
+ #
511
+ def to_screen(vec)
512
+ @view__.to_parent(vec.getInternal__).toVector
513
+ end
514
+
476
515
  # Returns the x-position of the mouse in the sprite coordinates.
477
516
  #
478
517
  # @return [Numeric] x position
@@ -513,6 +552,14 @@ module RubySketch
513
552
  @view__.mouseButton
514
553
  end
515
554
 
555
+ # Returns the mouse button click count on the sprite.
556
+ #
557
+ # @return [Numeric] click count
558
+ #
559
+ def clickCount()
560
+ @view__.clickCount
561
+ end
562
+
516
563
  # Returns the touch objects touched on the sprite.
517
564
  #
518
565
  # @return [Array<Touch>] touches
@@ -532,6 +579,7 @@ module RubySketch
532
579
  #
533
580
  def update(&block)
534
581
  @view__.update = block
582
+ nil
535
583
  end
536
584
 
537
585
  # Defines draw block.
@@ -737,29 +785,34 @@ module RubySketch
737
785
  ((@pointersPressed + @pointersReleased) & [LEFT, RIGHT, CENTER]).last
738
786
  end
739
787
 
788
+ def clickCount()
789
+ clicked? ? 1 : 0
790
+ end
791
+
740
792
  def on_update(e)
741
793
  @update&.call
742
794
  end
743
795
 
744
796
  def on_pointer_down(e)
745
797
  updatePointerStates e, true
746
- @pointerDownStartPos = @pointerPos.dup
747
- (@touchStarted || @mousePressed)&.call
798
+ @pointerDownStartPos = to_screen @pointerPos
799
+ (@touchStarted || @mousePressed)&.call if e.view_index == 0
748
800
  end
749
801
 
750
802
  def on_pointer_up(e)
751
803
  updatePointerStates e, false
752
- (@touchEnded || @mouseReleased)&.call
753
- if startPos = @pointerDownStartPos
754
- @mouseClicked&.call if (@pointerPos - startPos).length < 3
755
- @pointerDownStartPos = nil
804
+ if e.view_index == 0
805
+ (@touchEnded || @mouseReleased)&.call
806
+ @mouseClicked&.call if clicked?
756
807
  end
808
+ @pointerDownStartPos = nil
757
809
  @pointersReleased.clear
758
810
  end
759
811
 
760
812
  def on_pointer_move(e)
761
813
  updatePointerStates e
762
- (@touchMoved || (e.drag? ? @mouseDragged : @mouseMoved))&.call
814
+ mouseMoved = e.drag? ? @mouseDragged : @mouseMoved
815
+ (@touchMoved || mouseMoved)&.call if e.view_index == 0
763
816
  end
764
817
 
765
818
  def on_pointer_cancel(e)
@@ -799,6 +852,13 @@ module RubySketch
799
852
  end
800
853
  end
801
854
 
855
+ def clicked?()
856
+ return false unless @pointerPos && @pointerDownStartPos
857
+ [to_screen(@pointerPos), @pointerDownStartPos]
858
+ .map {|pos| Rays::Point.new pos.x, pos.y, 0}
859
+ .then {|pos, startPos| (pos - startPos).length < 3}
860
+ end
861
+
802
862
  end# SpriteView
803
863
 
804
864
 
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.10'
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.9
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-19 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.10
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.10
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rake
99
99
  requirement: !ruby/object:Gem::Requirement