rubysketch 0.5.16 → 0.5.17

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: 1ed7b40a8931568bfd81cd39f25ec6abca7ba60e5d0b6a991de18408f9bd6ccf
4
- data.tar.gz: 9ac428feb4aa2594929cdfddc813b0512dedf24661096ab4ca48b41c60a95f39
3
+ metadata.gz: 93686f5e5b80dac29a8c7993c4372d3674a5bbe92ef22331d8e895da75a7b15c
4
+ data.tar.gz: 6b495222f590b892311174a068b9c8cb0e8b0f25d7e21cd3438d76a15aa04ff7
5
5
  SHA512:
6
- metadata.gz: 12664a28fdc8bd19cfd3587bf19da5f8e975b3cb20899af3f5eeb02a4c03dff1af2d7cc62fcc5f15a96100bbfdc4b11e306fe01899134abe050f9e0412c19496
7
- data.tar.gz: ec1e31873aae6a80404a99c9c8079beefefa124e03ad3b6e8c0dc7d942bdb7dec89084a28e537249abb138c8a66c75c0a6523b49265b85e217e50bec1fa12b8c
6
+ metadata.gz: 1b7a0890ac1cf8861b009df29db44a474a242eeaeacb626a0dec3728aa0bcf79d577b994e04de52d54f00cf9ec09a04129cde5b194da045b1be3a4cd40a80fea
7
+ data.tar.gz: 7a92b59921075b96ec61349c9b5b7db24c168adba51be66c13369b5135b7e6aa7c015ea781622253238922b913fe6fc6853eb03c18103a4b175e00b5a3ff2f2d
data/ChangeLog.md CHANGED
@@ -1,6 +1,11 @@
1
1
  # rubysketch ChangeLog
2
2
 
3
3
 
4
+ ## [v0.5.17] - 2023-06-11
5
+
6
+ - Improve mouse event handling for Sprite class
7
+
8
+
4
9
  ## [v0.5.16] - 2023-06-08
5
10
 
6
11
  - Update dependencies
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.16
1
+ 0.5.17
@@ -726,11 +726,11 @@ module RubySketch
726
726
  # p [sprite.mouseX, sprite.mouseY, sprite.mouseButton]
727
727
  # end
728
728
  #
729
- # @return [nil] nil
729
+ # @return [Boolean] is any mouse button pressed or not
730
730
  #
731
731
  def mousePressed(&block)
732
732
  @view__.mousePressed = block
733
- nil
733
+ @view__.mousePressed?
734
734
  end
735
735
 
736
736
  # Defines mouseReleased block.
@@ -879,27 +879,31 @@ module RubySketch
879
879
  @sprite = sprite
880
880
  super(*a, **k, &b)
881
881
 
882
- @pointerPos =
883
- @pointerPrevPos = Rays::Point.new 0
882
+ @pointer = nil
883
+ @pointerPrev = nil
884
884
  @pointersPressed = []
885
885
  @pointersReleased = []
886
886
  @touches = []
887
887
  end
888
888
 
889
889
  def mouseX()
890
- @pointerPos.x
890
+ @pointer&.x || 0
891
891
  end
892
892
 
893
893
  def mouseY()
894
- @pointerPos.y
894
+ @pointer&.y || 0
895
895
  end
896
896
 
897
897
  def pmouseX()
898
- @pointerPrevPos.x
898
+ @pointerPrev&.x || 0
899
899
  end
900
900
 
901
901
  def pmouseY()
902
- @pointerPrevPos.y
902
+ @pointerPrev&.y || 0
903
+ end
904
+
905
+ def mousePressed?()
906
+ not @pointersPressed.empty?
903
907
  end
904
908
 
905
909
  def mouseButton()
@@ -907,7 +911,7 @@ module RubySketch
907
911
  end
908
912
 
909
913
  def clickCount()
910
- clicked? ? 1 : 0
914
+ mouseClicked? ? 1 : 0
911
915
  end
912
916
 
913
917
  def on_update(e)
@@ -915,16 +919,24 @@ module RubySketch
915
919
  end
916
920
 
917
921
  def on_pointer_down(e)
918
- updatePointerStates e, true
919
- @pointerDownStartPos = to_screen @pointerPos
920
- (@touchStarted || @mousePressed)&.call if e.view_index == 0
922
+ updatePointerStates e
923
+ updatePointersPressedAndReleased e, true
924
+ @pointerDownStartPos = to_screen @pointer.pos
925
+ if e.view_index == 0
926
+ @mousePressed&.call if e.any? {|p| p.id == @pointer.id}
927
+ @touchStarted&.call
928
+ end
921
929
  end
922
930
 
923
931
  def on_pointer_up(e)
924
- updatePointerStates e, false
932
+ updatePointerStates e
933
+ updatePointersPressedAndReleased e, false
925
934
  if e.view_index == 0
926
- (@touchEnded || @mouseReleased)&.call
927
- @mouseClicked&.call if clicked?
935
+ if e.any? {|p| p.id == @pointer.id}
936
+ @mouseReleased&.call
937
+ @mouseClicked&.call if mouseClicked?
938
+ end
939
+ @touchEnded&.call
928
940
  end
929
941
  @pointerDownStartPos = nil
930
942
  @pointersReleased.clear
@@ -932,8 +944,11 @@ module RubySketch
932
944
 
933
945
  def on_pointer_move(e)
934
946
  updatePointerStates e
935
- mouseMoved = e.drag? ? @mouseDragged : @mouseMoved
936
- (@touchMoved || mouseMoved)&.call if e.view_index == 0
947
+ if e.view_index == 0
948
+ mouseMoved = e.drag? ? @mouseDragged : @mouseMoved
949
+ mouseMoved&.call if e.any? {|p| p.id == @pointer.id}
950
+ @touchMoved&.call
951
+ end
937
952
  end
938
953
 
939
954
  def on_pointer_cancel(e)
@@ -958,24 +973,29 @@ module RubySketch
958
973
  mouse_middle: Processing::GraphicsContext::CENTER
959
974
  }
960
975
 
961
- def updatePointerStates(event, pressed = nil)
962
- @pointerPrevPos = @pointerPos
963
- @pointerPos = event.pos.dup
964
- @touches = event.pointers.map {|p| Touch.new(p.id, *p.pos.to_a)}
965
- if pressed != nil
966
- event.types
967
- .tap {|types| types.delete :mouse}
968
- .map {|type| MOUSE_BUTTON_MAP[type] || type}
969
- .each do |type|
970
- (pressed ? @pointersPressed : @pointersReleased).push type
971
- @pointersPressed.delete type unless pressed
972
- end
976
+ def updatePointerStates(event)
977
+ pointer = event.find {|p| p.id == @pointer&.id} || event.first
978
+ if !mousePressed? || pointer.id == @pointer&.id
979
+ @pointerPrev, @pointer = @pointer, pointer.dup
973
980
  end
981
+ @touches = event.map {|p| Touch.new(p.id, *p.pos.to_a)}
982
+ end
983
+
984
+ def updatePointersPressedAndReleased(event, pressed)
985
+ event.map(&:types).flatten
986
+ .tap {|types| types.delete :mouse}
987
+ .map {|type| MOUSE_BUTTON_MAP[type] || type}
988
+ .each do |type|
989
+ (pressed ? @pointersPressed : @pointersReleased).push type
990
+ if !pressed && index = @pointersPressed.index(type)
991
+ @pointersPressed.delete_at index
992
+ end
993
+ end
974
994
  end
975
995
 
976
- def clicked?()
977
- return false unless @pointerPos && @pointerDownStartPos
978
- [to_screen(@pointerPos), @pointerDownStartPos]
996
+ def mouseClicked?()
997
+ return false unless @pointer && @pointerDownStartPos
998
+ [to_screen(@pointer.pos), @pointerDownStartPos]
979
999
  .map {|pos| Rays::Point.new pos.x, pos.y, 0}
980
1000
  .then {|pos, startPos| (pos - startPos).length < 3}
981
1001
  end
data/rubysketch.gemspec CHANGED
@@ -25,12 +25,12 @@ Gem::Specification.new do |s|
25
25
  s.platform = Gem::Platform::RUBY
26
26
  s.required_ruby_version = '>= 3.0.0'
27
27
 
28
- s.add_runtime_dependency 'xot', '~> 0.1.38'
29
- s.add_runtime_dependency 'rucy', '~> 0.1.38'
30
- s.add_runtime_dependency 'beeps', '~> 0.1.39'
31
- s.add_runtime_dependency 'rays', '~> 0.1.41'
32
- s.add_runtime_dependency 'reflexion', '~> 0.1.44'
33
- s.add_runtime_dependency 'processing', '~> 0.5.17'
28
+ s.add_runtime_dependency 'xot', '~> 0.1.39'
29
+ s.add_runtime_dependency 'rucy', '~> 0.1.39'
30
+ s.add_runtime_dependency 'beeps', '~> 0.1.40'
31
+ s.add_runtime_dependency 'rays', '~> 0.1.42'
32
+ s.add_runtime_dependency 'reflexion', '~> 0.1.45'
33
+ s.add_runtime_dependency 'processing', '~> 0.5.18'
34
34
 
35
35
  s.add_development_dependency 'rake'
36
36
  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.16
4
+ version: 0.5.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - xordog
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-08 00:00:00.000000000 Z
11
+ date: 2023-06-11 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.38
19
+ version: 0.1.39
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.38
26
+ version: 0.1.39
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.38
33
+ version: 0.1.39
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.38
40
+ version: 0.1.39
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.39
47
+ version: 0.1.40
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.39
54
+ version: 0.1.40
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.41
61
+ version: 0.1.42
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.41
68
+ version: 0.1.42
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.44
75
+ version: 0.1.45
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.44
82
+ version: 0.1.45
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.17
89
+ version: 0.5.18
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.17
96
+ version: 0.5.18
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rake
99
99
  requirement: !ruby/object:Gem::Requirement