processing 0.5.16 → 0.5.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b6025b178164394ad3493995863e8077280dbf2745abd4c2a84223fcbfb6aa65
4
- data.tar.gz: 41a9a7b7410d0a6aa5bc34e611e17432722a85a15179eb746511aa75f46eaa97
3
+ metadata.gz: 38d42dd83841388f9b8370f48c36eabcaae5dce9f9ae584449d8825e2590f7d8
4
+ data.tar.gz: 46b6326966f81f0a9c40973462dbc58ce6c3806824f8dffed255233301f2797f
5
5
  SHA512:
6
- metadata.gz: cbdf458466e765affb174fce19573fab4d4cfe76e106aaef421fc4e66f95e7b02a6c2d5bc11662756a313f0cabbadfb705f75306b0f7627c32386a17da365030
7
- data.tar.gz: 11a736963e87ab5b91c087dce0fcd863c29f5912a6bbfd20d643345f0ead8f268e7a0784f3ceeb7bf903a0d06d500c350e82f9fc34c25d61f23d0cdf2b828554
6
+ metadata.gz: 60eb487e89d54e1961c7dcf522b14693083d6b84883aa482d310b87ad05a462ffbf837860b9bbcfc7f045fcdf446fbf32ee92b5ea1e565a87595ce281fa8076e
7
+ data.tar.gz: b898bb281b641d2f7ac64523c5d8a0ca7d8ee8e86f0e4f2a3af47d0f51cb5d739cdd9fe28f26bb864177b56a51425c732a0b526592c45d95d340cd233e5f53a7
data/ChangeLog.md CHANGED
@@ -1,6 +1,20 @@
1
1
  # processing ChangeLog
2
2
 
3
3
 
4
+ ## [v0.5.18] - 2023-06-11
5
+
6
+ - mousePressed, mouseReleased, mouseMoved, mouseDragged, mouseClicked ignore multiple touches
7
+ - Fix that pointer event handles only the first pointer’s type and ignoring rest pointer's types
8
+
9
+
10
+ ## [v0.5.17] - 2023-06-07
11
+
12
+ - Add Image#set() and Image#get()
13
+ - Add color(), red(), green(), blue(), and alpha()
14
+ - Add lerpColor()
15
+ - Add focused()
16
+
17
+
4
18
  ## [v0.5.16] - 2023-06-02
5
19
 
6
20
  - Fix failed tests and add tests
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.16
1
+ 0.5.18
@@ -42,8 +42,8 @@ module Processing
42
42
  @key__ = nil
43
43
  @keyCode__ = nil
44
44
  @keysPressed__ = Set.new
45
- @pointerPos__ =
46
- @pointerPrevPos__ = Rays::Point.new 0
45
+ @pointer__ = nil
46
+ @pointerPrev__ = nil
47
47
  @pointersPressed__ = []
48
48
  @pointersReleased__ = []
49
49
  @touches__ = []
@@ -92,19 +92,24 @@ module Processing
92
92
  mouse_middle: CENTER
93
93
  }
94
94
 
95
- updatePointerStates = -> event, pressed = nil {
96
- @pointerPrevPos__ = @pointerPos__
97
- @pointerPos__ = event.pos.dup
98
- @touches__ = event.pointers.map {|p| Touch.new(p.id, *p.pos.to_a)}
99
- if pressed != nil
100
- event.types
101
- .tap {|types| types.delete :mouse}
102
- .map {|type| mouseButtonMap[type] || type}
103
- .each do |type|
104
- (pressed ? @pointersPressed__ : @pointersReleased__).push type
105
- @pointersPressed__.delete type unless pressed
106
- end
95
+ updatePointerStates = -> event {
96
+ pointer = event.find {|p| p.id == @pointer__&.id} || event.first
97
+ if !mousePressed || pointer.id == @pointer__&.id
98
+ @pointerPrev__, @pointer__ = @pointer__, pointer.dup
107
99
  end
100
+ @touches__ = event.map {|p| Touch.new(p.id, *p.pos.to_a)}
101
+ }
102
+
103
+ updatePointersPressedAndReleased = -> event, pressed {
104
+ event.map(&:types).flatten
105
+ .tap {|types| types.delete :mouse}
106
+ .map {|type| mouseButtonMap[type] || type}
107
+ .each do |type|
108
+ (pressed ? @pointersPressed__ : @pointersReleased__).push type
109
+ if !pressed && index = @pointersPressed__.index(type)
110
+ @pointersPressed__.delete_at index
111
+ end
112
+ end
108
113
  }
109
114
 
110
115
  @window__.key_down = proc do |e|
@@ -119,29 +124,29 @@ module Processing
119
124
  end
120
125
 
121
126
  @window__.pointer_down = proc do |e|
122
- updatePointerStates.call e, true
123
- @pointerDownStartPos__ = @pointerPos__.dup
124
- (@touchStartedBlock__ || @mousePressedBlock__)&.call
127
+ updatePointerStates.call e
128
+ updatePointersPressedAndReleased.call e, true
129
+ @mousePressedBlock__&.call if e.any? {|p| p.id == @pointer__.id}
130
+ @touchStartedBlock__&.call
125
131
  end
126
132
 
127
133
  @window__.pointer_up = proc do |e|
128
- updatePointerStates.call e, false
129
- (@touchEndedBlock__ || @mouseReleasedBlock__)&.call
130
- if startPos = @pointerDownStartPos__
131
- @mouseClickedBlock__&.call if (@pointerPos__ - startPos).length < 3
132
- @pointerDownStartPos__ = nil
134
+ updatePointerStates.call e
135
+ updatePointersPressedAndReleased.call e, false
136
+ if e.any? {|p| p.id == @pointer__.id}
137
+ @mouseReleasedBlock__&.call
138
+ @mouseClickedBlock__&.call if
139
+ (@pointer__.pos - @pointer__.down.pos).length < 3
133
140
  end
141
+ @touchEndedBlock__&.call
134
142
  @pointersReleased__.clear
135
143
  end
136
144
 
137
145
  @window__.pointer_move = proc do |e|
138
146
  updatePointerStates.call e
139
- (@touchMovedBlock__ || @mouseMovedBlock__)&.call
140
- end
141
-
142
- @window__.pointer_drag = proc do |e|
143
- updatePointerStates.call e
144
- (@touchMovedBlock__ || @mouseDraggedBlock__)&.call
147
+ mouseMoved = e.drag? ? @mouseDraggedBlock__ : @mouseMovedBlock__
148
+ mouseMoved&.call if e.any? {|p| p.id == @pointer__.id}
149
+ @touchMovedBlock__&.call
145
150
  end
146
151
 
147
152
  @window__.move = proc do |e|
@@ -468,6 +473,14 @@ module Processing
468
473
  @window__.height
469
474
  end
470
475
 
476
+ # Returns weather the window is active or not.
477
+ #
478
+ # @return [Boolean] active or not
479
+ #
480
+ def focused()
481
+ @window__.active?
482
+ end
483
+
471
484
  # Returns the number of frames since the program started.
472
485
  #
473
486
  # @return [Integer] total number of frames
@@ -505,7 +518,7 @@ module Processing
505
518
  # @return [Numeric] horizontal position of mouse
506
519
  #
507
520
  def mouseX()
508
- @pointerPos__.x
521
+ @pointer__&.x || 0
509
522
  end
510
523
 
511
524
  # Returns mouse y position
@@ -513,7 +526,7 @@ module Processing
513
526
  # @return [Numeric] vertical position of mouse
514
527
  #
515
528
  def mouseY()
516
- @pointerPos__.y
529
+ @pointer__&.y || 0
517
530
  end
518
531
 
519
532
  # Returns mouse x position in previous frame
@@ -521,7 +534,7 @@ module Processing
521
534
  # @return [Numeric] horizontal position of mouse
522
535
  #
523
536
  def pmouseX()
524
- @pointerPrevPos__.x
537
+ @pointerPrev__&.x || 0
525
538
  end
526
539
 
527
540
  # Returns mouse y position in previous frame
@@ -529,7 +542,7 @@ module Processing
529
542
  # @return [Numeric] vertical position of mouse
530
543
  #
531
544
  def pmouseY()
532
- @pointerPrevPos__.y
545
+ @pointerPrev__&.y || 0
533
546
  end
534
547
 
535
548
  # Returns which mouse button was pressed
@@ -324,6 +324,59 @@ module Processing
324
324
  @colorMode__
325
325
  end
326
326
 
327
+ # Creates color value.
328
+ #
329
+ # @overload color(gray)
330
+ # @overload color(gray, alpha)
331
+ # @overload color(v1, v2, v3)
332
+ # @overload color(v1, v2, v3, alpha)
333
+ #
334
+ # @param gray [Numeric] the value for gray
335
+ # @param alpha [Numeric] the value for alpha
336
+ # @param v1 [Numeric] the value for red or hue
337
+ # @param v2 [Numeric] the value for green or saturation
338
+ # @param v3 [Numeric] the value for blue or brightness
339
+ #
340
+ # @return [Integer] the rgba color value
341
+ #
342
+ def color(*args)
343
+ toRGBA__(*args)
344
+ .map {|n| (n * 255).to_i.clamp 0, 255}
345
+ .then {|r, g, b, a| Image.toColor__ r, g, b, a}
346
+ end
347
+
348
+ # Returns the red value of the color.
349
+ #
350
+ # @return [Numeric] the red value
351
+ #
352
+ def red(color)
353
+ ((color >> 16) & 0xff) / 255.0 * @colorMaxes__[0]
354
+ end
355
+
356
+ # Returns the green value of the color.
357
+ #
358
+ # @return [Numeric] the green value
359
+ #
360
+ def green(color)
361
+ ((color >> 8) & 0xff) / 255.0 * @colorMaxes__[1]
362
+ end
363
+
364
+ # Returns the blue value of the color.
365
+ #
366
+ # @return [Numeric] the blue value
367
+ #
368
+ def blue(color)
369
+ (color & 0xff) / 255.0 * @colorMaxes__[2]
370
+ end
371
+
372
+ # Returns the red value of the color.
373
+ #
374
+ # @return [Numeric] the red value
375
+ #
376
+ def alpha(color)
377
+ ((color >> 24) & 0xff) / 255.0 * @colorMaxes__[3]
378
+ end
379
+
327
380
  # @private
328
381
  private def toRGBA__(*args)
329
382
  a, b, c, d = args
@@ -1427,6 +1480,22 @@ module Processing
1427
1480
  start + (stop - start) * amount
1428
1481
  end
1429
1482
 
1483
+ # Returns the interpolated color between color1 and color2.
1484
+ #
1485
+ # @param color1 [Integer] the 1st color for interpolation
1486
+ # @param color2 [Integer] the 2nd color for interpolation
1487
+ # @param amount [Numeric] amount to interpolate
1488
+ #
1489
+ # @return [Integer] interporated color
1490
+ #
1491
+ def lerpColor(color1, color2, amount)
1492
+ color(
1493
+ lerp(red( color1), red( color2), amount),
1494
+ lerp(green(color1), green(color2), amount),
1495
+ lerp(blue( color1), blue( color2), amount),
1496
+ lerp(alpha(color1), alpha(color2), amount))
1497
+ end
1498
+
1430
1499
  # Maps a number from range start1..stop1 to range start2..stop2.
1431
1500
  #
1432
1501
  # @param value [Numeric] number to be mapped
@@ -39,6 +39,30 @@ module Processing
39
39
  @image.size
40
40
  end
41
41
 
42
+ # Sets the color of the pixel.
43
+ #
44
+ # @param x [Integer] x position of the pixel
45
+ # @param y [Integer] y position of the pixel
46
+ # @param c [Integer] color value
47
+ #
48
+ # @return [nil] nil
49
+ #
50
+ def set(x, y, c)
51
+ @image.bitmap[x, y] = self.class.fromColor__ c
52
+ nil
53
+ end
54
+
55
+
56
+ # Returns the color of the pixel.
57
+ #
58
+ # @return [Integer] color value (0xAARRGGBB)
59
+ #
60
+ def get(x, y)
61
+ @image.bitmap[x, y]
62
+ .map {|n| (n * 255).to_i.clamp 0, 255}
63
+ .then {|r, g, b, a| self.class.toColor__ r, g, b, a}
64
+ end
65
+
42
66
  # Applies an image filter.
43
67
  #
44
68
  # overload filter(shader)
@@ -135,6 +159,24 @@ module Processing
135
159
  end
136
160
  end
137
161
 
162
+ # @private
163
+ def self.fromColor__(color)
164
+ [
165
+ color >> 16 & 0xff,
166
+ color >> 8 & 0xff,
167
+ color & 0xff,
168
+ color >> 24 & 0xff
169
+ ]
170
+ end
171
+
172
+ # @private
173
+ def self.toColor__(r, g, b, a)
174
+ (r & 0xff) << 16 |
175
+ (g & 0xff) << 8 |
176
+ (b & 0xff) |
177
+ (a & 0xff) << 24
178
+ end
179
+
138
180
  end# Image
139
181
 
140
182
 
@@ -6,9 +6,9 @@ module Processing
6
6
 
7
7
  include Xot::Inspectable
8
8
 
9
- attr_accessor :setup, :update, :draw, :resize,
9
+ attr_accessor :setup, :update, :draw,
10
10
  :key_down, :key_up,
11
- :pointer_down, :pointer_up, :pointer_move, :pointer_drag,
11
+ :pointer_down, :pointer_up, :pointer_move,
12
12
  :move, :resize, :motion,
13
13
  :before_draw, :after_draw, :update_canvas
14
14
 
@@ -18,6 +18,7 @@ module Processing
18
18
  Processing.instance_variable_set :@window, self
19
19
 
20
20
  @events = []
21
+ @active = false
21
22
  @error = nil
22
23
  @auto_resize = true
23
24
  @canvas = Canvas.new self, width, height
@@ -43,6 +44,10 @@ module Processing
43
44
  @events.last
44
45
  end
45
46
 
47
+ def active?()
48
+ @active
49
+ end
50
+
46
51
  def add_overlay(view)
47
52
  @overlay_view.add view
48
53
  end
@@ -58,14 +63,18 @@ module Processing
58
63
  call_block @setup, nil
59
64
  end
60
65
 
61
- def on_resize(e)
62
- on_canvas_resize e
63
- end
64
-
65
66
  def on_change_pixel_density(pixel_density)
66
67
  resize_canvas width, height, window_pixel_density: pixel_density
67
68
  end
68
69
 
70
+ def on_activate(e)
71
+ @active = true
72
+ end
73
+
74
+ def on_deactivate(e)
75
+ @active = false
76
+ end
77
+
69
78
  def on_draw(e)
70
79
  window_painter.pixel_density.tap do |pd|
71
80
  prev, @prev_pixel_density = @prev_pixel_density, pd
@@ -108,7 +117,7 @@ module Processing
108
117
  block = case e.action
109
118
  when :down then @pointer_down
110
119
  when :up, :cancel then @pointer_up
111
- when :move then e.drag? ? @pointer_drag : @pointer_move
120
+ when :move then @pointer_move
112
121
  end
113
122
  draw_canvas {call_block block, e} if block
114
123
  end
data/processing.gemspec CHANGED
@@ -25,10 +25,10 @@ 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 'rays', '~> 0.1.39'
31
- s.add_runtime_dependency 'reflexion', '~> 0.1.42'
28
+ s.add_runtime_dependency 'xot', '~> 0.1.39'
29
+ s.add_runtime_dependency 'rucy', '~> 0.1.39'
30
+ s.add_runtime_dependency 'rays', '~> 0.1.42'
31
+ s.add_runtime_dependency 'reflexion', '~> 0.1.45'
32
32
 
33
33
  s.add_development_dependency 'rake'
34
34
  s.add_development_dependency 'test-unit'
@@ -40,4 +40,44 @@ class TestGraphicsContext < Test::Unit::TestCase
40
40
  assert_raise {g.blendMode LEFT}
41
41
  end
42
42
 
43
+ def test_color()
44
+ g = graphics
45
+
46
+ g.colorMode G::RGB, 255
47
+ c = g.color 10, 20, 30, 40
48
+ assert_equal 0x280a141e, c
49
+ assert_equal [10, 20, 30, 40], [g.red(c), g.green(c), g.blue(c), g.alpha(c)]
50
+
51
+ g.colorMode G::RGB, 1.0
52
+ c = g.color 0.1, 0.2, 0.3, 0.4
53
+ assert_equal 0x6619334c, c
54
+ assert_in_delta 0.1, g.red(c), 1 / 256.0
55
+ assert_in_delta 0.2, g.green(c), 1 / 256.0
56
+ assert_in_delta 0.3, g.blue(c), 1 / 256.0
57
+ assert_in_delta 0.4, g.alpha(c), 1 / 256.0
58
+ end
59
+
60
+ def test_lerp()
61
+ g = graphics
62
+
63
+ assert_equal 1.0, g.lerp(1.0, 2.0, 0.0)
64
+ assert_equal 1.5, g.lerp(1.0, 2.0, 0.5)
65
+ assert_equal 2.0, g.lerp(1.0, 2.0, 1.0)
66
+
67
+ assert_equal 0.9, g.lerp(1.0, 2.0, -0.1)
68
+ assert_equal 2.1, g.lerp(1.0, 2.0, 1.1)
69
+ end
70
+
71
+ def test_lerpColor()
72
+ g = graphics
73
+ c = -> red, green, blue {g.color red, green, blue}
74
+
75
+ assert_equal c[10, 20, 30], g.lerpColor(c[10, 20, 30], c[50, 60, 70], 0.0)
76
+ assert_equal c[30, 40, 50], g.lerpColor(c[10, 20, 30], c[50, 60, 70], 0.5)
77
+ assert_equal c[50, 60, 70], g.lerpColor(c[10, 20, 30], c[50, 60, 70], 1.0)
78
+
79
+ assert_equal c[-10, 0, 10], g.lerpColor(c[10, 20, 30], c[50, 60, 70], -0.5)
80
+ assert_equal c[ 70, 80, 90], g.lerpColor(c[10, 20, 30], c[50, 60, 70], 1.5)
81
+ end
82
+
43
83
  end# TestGraphics
data/test/test_image.rb CHANGED
@@ -5,8 +5,36 @@ class TestImage < Test::Unit::TestCase
5
5
 
6
6
  P = Processing
7
7
 
8
- def image(w = 10, h = 10)
9
- P::Image.new(Rays::Image.new w, h)
8
+ def image(w = 10, h = 10, &block)
9
+ img = Rays::Image.new w, h
10
+ img.paint &block if block
11
+ P::Image.new img
12
+ end
13
+
14
+ def test_set_color()
15
+ g = graphics
16
+ i = image(2, 2) {fill 0; rect 0, 0, 1, 1}
17
+
18
+ assert_equal g.color(0, 0, 0), i.get(0, 0)
19
+
20
+ i.set 0, 0, g.color(0, 255, 0)
21
+ assert_equal g.color(0, 255, 0), i.get(0, 0)
22
+
23
+ i.set 0, 0, g.color(0, 0, 255)
24
+ assert_equal g.color(0, 0, 255), i.get(0, 0)
25
+ end
26
+
27
+ def test_get_color()
28
+ g = graphics
29
+ i = image 2, 2 do
30
+ fill 1, 0, 0; rect 0, 0, 1, 1
31
+ fill 0, 1, 0; rect 1, 0, 1, 1
32
+ fill 0, 0, 1; rect 0, 1, 1, 1
33
+ end
34
+
35
+ assert_equal g.color(255, 0, 0), i.get(0, 0)
36
+ assert_equal g.color(0, 255, 0), i.get(1, 0)
37
+ assert_equal g.color(0, 0, 255), i.get(0, 1)
10
38
  end
11
39
 
12
40
  def test_inspect()
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: processing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.16
4
+ version: 0.5.18
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-02 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,56 +16,56 @@ 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: rays
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.42
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.42
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: reflexion
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.1.42
61
+ version: 0.1.45
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.42
68
+ version: 0.1.45
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement