processing 1.2.1 → 1.3.0
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 +4 -4
- data/ChangeLog.md +13 -0
- data/VERSION +1 -1
- data/lib/processing/all.rb +29 -12
- data/lib/processing/context.rb +23 -29
- data/lib/processing/graphics.rb +1 -1
- data/lib/processing/graphics_context.rb +11 -39
- data/lib/processing/shape.rb +1 -1
- data/lib/processing/vector.rb +1 -1
- data/lib/processing/window.rb +25 -45
- data/lib/processing.rb +12 -13
- data/processing.gemspec +4 -4
- data/test/helper.rb +2 -2
- metadata +10 -10
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fd57a24e5a09714e3e180593bf043bf50d6c9e139a9a328fed418108ab09cff2
|
|
4
|
+
data.tar.gz: 1d41bb1e917ebccd7f1846bdc61c3e61fcb97949f90fada484d8dc8f746ebe4f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d5f97970e139cc2a6fe93533743e4adcb7f817ed68ab355ba03aec5b130a23d9e84321f7b2ad8040460f3205bc88a93d1f290a1469726b57cbe150b5f739f901
|
|
7
|
+
data.tar.gz: 1aa80a66186bd1a8f74591d9dd6a078d7eb3d651a2fc76d6087d57e83309bf9b312eefeaecaa55f967d764f0a3fcc08b5f44ca017eaa2411735f825b957f18a3
|
data/ChangeLog.md
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
# processing ChangeLog
|
|
2
2
|
|
|
3
3
|
|
|
4
|
+
## [v1.3.0] - 2026-06-12
|
|
5
|
+
|
|
6
|
+
- [BREAKING] Drop redundant drawXxx aliases from GraphicsContext
|
|
7
|
+
- [BREAKING] Make pixelDensity a keyword arg in createGraphics
|
|
8
|
+
|
|
9
|
+
- Give each Window its own Context for multi-window support
|
|
10
|
+
- Add AUTO pixel density that tracks display * window scale
|
|
11
|
+
- Make context dispatch survive across event paths
|
|
12
|
+
- Skip alias_snake_case_methods__ warning by removing the prior definition
|
|
13
|
+
|
|
14
|
+
- Fix noSmooth disabling canvas auto-resize and monitor density tracking
|
|
15
|
+
|
|
16
|
+
|
|
4
17
|
## [v1.2.1] - 2026-05-20
|
|
5
18
|
|
|
6
19
|
- Update dependencies
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
1.
|
|
1
|
+
1.3.0
|
data/lib/processing/all.rb
CHANGED
|
@@ -24,34 +24,46 @@ module Processing
|
|
|
24
24
|
|
|
25
25
|
SUFFIX_PRIVATE = /__[!?]?$/
|
|
26
26
|
|
|
27
|
+
$processing_context__ = nil
|
|
28
|
+
|
|
29
|
+
# Returns current processing context.
|
|
30
|
+
#
|
|
31
|
+
# @return [Processing::Context] context
|
|
32
|
+
#
|
|
33
|
+
def self.context()
|
|
34
|
+
$processing_context__
|
|
35
|
+
end
|
|
36
|
+
|
|
27
37
|
# @private
|
|
28
|
-
def self.setup__(
|
|
38
|
+
def self.setup__(window_class, context_class)
|
|
39
|
+
tmpdir__.tap {|dir| FileUtils.rm_r dir.to_s if dir.directory?} unless Xot.wasm?
|
|
40
|
+
|
|
29
41
|
w = (ENV['WIDTH'] || 500).to_i
|
|
30
42
|
h = (ENV['HEIGHT'] || 500).to_i
|
|
31
|
-
|
|
32
|
-
window = Processing::Window.new(w, h) {start}
|
|
33
|
-
context = namespace::Context.new window
|
|
34
|
-
|
|
35
|
-
return window, context
|
|
43
|
+
window_class.new w, h, context_class: context_class
|
|
36
44
|
end
|
|
37
45
|
|
|
38
46
|
# @private
|
|
39
|
-
def self.funcs__(
|
|
40
|
-
(
|
|
47
|
+
def self.funcs__(context_class)
|
|
48
|
+
(context_class.instance_methods - Object.instance_methods)
|
|
41
49
|
.reject {_1 =~ SUFFIX_PRIVATE} # methods for internal use
|
|
42
50
|
end
|
|
43
51
|
|
|
44
52
|
# @private
|
|
45
|
-
def self.events__(
|
|
46
|
-
|
|
53
|
+
def self.events__(context_class)
|
|
54
|
+
methods = context_class.instance_methods
|
|
55
|
+
to_snake_case__(EVENT_NAMES__).flatten.uniq.select {methods.include? _1}
|
|
47
56
|
end
|
|
48
57
|
|
|
49
58
|
# @private
|
|
50
59
|
def self.alias_snake_case_methods__(klass, recursive = 1)
|
|
51
60
|
to_snake_case__(klass.instance_methods false)
|
|
52
|
-
.reject {|camel,
|
|
61
|
+
.reject {|camel, _| camel =~ SUFFIX_PRIVATE}
|
|
53
62
|
.reject {|camel, snake| camel == snake}
|
|
54
|
-
.each
|
|
63
|
+
.each do |camel, snake|
|
|
64
|
+
klass.remove_method snake if klass.method_defined?(snake, false)
|
|
65
|
+
klass.alias_method snake, camel
|
|
66
|
+
end
|
|
55
67
|
if recursive > 0
|
|
56
68
|
klass.constants.map {klass.const_get _1}
|
|
57
69
|
.flatten
|
|
@@ -68,6 +80,11 @@ module Processing
|
|
|
68
80
|
end
|
|
69
81
|
end
|
|
70
82
|
|
|
83
|
+
# @private
|
|
84
|
+
def self.tmpdir__()
|
|
85
|
+
Pathname(Dir.tmpdir) + Digest::SHA1.hexdigest(name)
|
|
86
|
+
end
|
|
87
|
+
|
|
71
88
|
end# Processing
|
|
72
89
|
|
|
73
90
|
|
data/lib/processing/context.rb
CHANGED
|
@@ -26,27 +26,20 @@ module Processing
|
|
|
26
26
|
LANDSCAPE = :landscape
|
|
27
27
|
|
|
28
28
|
# @private
|
|
29
|
-
@@
|
|
29
|
+
@@current__ = nil
|
|
30
30
|
|
|
31
31
|
# @private
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
# @private
|
|
35
|
-
def self.context__()
|
|
36
|
-
@@context__ || @@rootContext__
|
|
32
|
+
def self.current__()
|
|
33
|
+
@@current__ || Processing.context
|
|
37
34
|
end
|
|
38
35
|
|
|
39
36
|
# @private
|
|
40
|
-
def self.
|
|
41
|
-
@@
|
|
37
|
+
def self.setCurrent__(context)
|
|
38
|
+
@@current__ = context
|
|
42
39
|
end
|
|
43
40
|
|
|
44
41
|
# @private
|
|
45
42
|
def initialize(window)
|
|
46
|
-
@@rootContext__ = self
|
|
47
|
-
|
|
48
|
-
tmpdir__.tap {|dir| FileUtils.rm_r dir.to_s if dir.directory?} unless Xot.wasm?
|
|
49
|
-
|
|
50
43
|
@window__ = window
|
|
51
44
|
init__(
|
|
52
45
|
@window__.canvas.image,
|
|
@@ -416,33 +409,33 @@ module Processing
|
|
|
416
409
|
|
|
417
410
|
# Changes canvas size.
|
|
418
411
|
#
|
|
419
|
-
# @param width [Integer]
|
|
420
|
-
# @param height [Integer]
|
|
421
|
-
# @param pixelDensity [Numeric] new pixel density
|
|
412
|
+
# @param width [Integer] new width
|
|
413
|
+
# @param height [Integer] new height
|
|
414
|
+
# @param pixelDensity [Numeric, AUTO] new pixel density, or AUTO to track display
|
|
422
415
|
#
|
|
423
416
|
# @return [nil] nil
|
|
424
417
|
#
|
|
425
418
|
# @see https://processing.org/reference/size_.html
|
|
426
419
|
#
|
|
427
|
-
def size(width, height, pixelDensity:
|
|
420
|
+
def size(width, height, pixelDensity: nil)
|
|
428
421
|
windowResize width, height
|
|
429
|
-
resizeCanvas__ width, height, pixelDensity
|
|
422
|
+
resizeCanvas__ width, height, pixelDensity: pixelDensity, autoResize: false
|
|
430
423
|
nil
|
|
431
424
|
end
|
|
432
425
|
|
|
433
426
|
# Changes canvas size.
|
|
434
427
|
#
|
|
435
|
-
# @param width [Integer]
|
|
436
|
-
# @param height [Integer]
|
|
437
|
-
# @param pixelDensity [Numeric] new pixel density
|
|
428
|
+
# @param width [Integer] new width
|
|
429
|
+
# @param height [Integer] new height
|
|
430
|
+
# @param pixelDensity [Numeric, AUTO] new pixel density, or AUTO to track display
|
|
438
431
|
#
|
|
439
432
|
# @return [nil] nil
|
|
440
433
|
#
|
|
441
434
|
# @see https://p5js.org/reference/p5/createCanvas/
|
|
442
435
|
#
|
|
443
|
-
def createCanvas(width, height, pixelDensity:
|
|
436
|
+
def createCanvas(width, height, pixelDensity: nil)
|
|
444
437
|
windowResize width, height
|
|
445
|
-
resizeCanvas__ width, height, pixelDensity
|
|
438
|
+
resizeCanvas__ width, height, pixelDensity: pixelDensity, autoResize: false
|
|
446
439
|
nil
|
|
447
440
|
end
|
|
448
441
|
|
|
@@ -461,7 +454,7 @@ module Processing
|
|
|
461
454
|
|
|
462
455
|
# Changes and returns canvas pixel density.
|
|
463
456
|
#
|
|
464
|
-
# @param density [Numeric] new pixel density
|
|
457
|
+
# @param density [Numeric, AUTO] new pixel density, or AUTO to track display
|
|
465
458
|
#
|
|
466
459
|
# @return [Numeric] current pixel density
|
|
467
460
|
#
|
|
@@ -469,7 +462,7 @@ module Processing
|
|
|
469
462
|
# @see https://p5js.org/reference/p5/pixelDensity/
|
|
470
463
|
#
|
|
471
464
|
def pixelDensity(density = nil)
|
|
472
|
-
resizeCanvas__ width, height, density if density
|
|
465
|
+
resizeCanvas__ width, height, pixelDensity: density if density
|
|
473
466
|
@window__.canvas.pixel_density
|
|
474
467
|
end
|
|
475
468
|
|
|
@@ -499,7 +492,7 @@ module Processing
|
|
|
499
492
|
#
|
|
500
493
|
def smooth()
|
|
501
494
|
@smooth__ = true
|
|
502
|
-
resizeCanvas__ width, height
|
|
495
|
+
resizeCanvas__ width, height
|
|
503
496
|
nil
|
|
504
497
|
end
|
|
505
498
|
|
|
@@ -512,13 +505,14 @@ module Processing
|
|
|
512
505
|
#
|
|
513
506
|
def noSmooth()
|
|
514
507
|
@smooth__ = false
|
|
515
|
-
resizeCanvas__ width, height
|
|
508
|
+
resizeCanvas__ width, height
|
|
516
509
|
end
|
|
517
510
|
|
|
518
511
|
# @private
|
|
519
|
-
def resizeCanvas__(width, height, pixelDensity)
|
|
520
|
-
@window__.resize_canvas
|
|
521
|
-
|
|
512
|
+
def resizeCanvas__(width, height, pixelDensity: nil, autoResize: nil)
|
|
513
|
+
@window__.resize_canvas(
|
|
514
|
+
width, height, pixel_density: pixelDensity, antialiasing: @smooth__)
|
|
515
|
+
@window__.auto_resize = autoResize unless autoResize.nil?
|
|
522
516
|
end
|
|
523
517
|
|
|
524
518
|
# Returns the width of the display.
|
data/lib/processing/graphics.rb
CHANGED
|
@@ -15,7 +15,7 @@ module Processing
|
|
|
15
15
|
#
|
|
16
16
|
# @see https://p5js.org/reference/p5/p5.Graphics/
|
|
17
17
|
#
|
|
18
|
-
def initialize(width, height, pixelDensity
|
|
18
|
+
def initialize(width, height, pixelDensity: 1)
|
|
19
19
|
image = Rays::Image.new(
|
|
20
20
|
width, height, Rays::RGBA, pixel_density: pixelDensity)
|
|
21
21
|
init__ image, image.painter
|
|
@@ -33,6 +33,11 @@ module Processing
|
|
|
33
33
|
#
|
|
34
34
|
P5JS = :p5js
|
|
35
35
|
|
|
36
|
+
# Auto mode for pixelDensity() and createCanvas() / size().
|
|
37
|
+
# Unlocks the canvas pixel density so it tracks the display.
|
|
38
|
+
#
|
|
39
|
+
AUTO = :auto
|
|
40
|
+
|
|
36
41
|
# RGBA format for createImage().
|
|
37
42
|
#
|
|
38
43
|
RGBA = :rgba
|
|
@@ -1502,8 +1507,6 @@ module Processing
|
|
|
1502
1507
|
nil
|
|
1503
1508
|
end
|
|
1504
1509
|
|
|
1505
|
-
alias drawPoint point
|
|
1506
|
-
|
|
1507
1510
|
# Draws a line.
|
|
1508
1511
|
#
|
|
1509
1512
|
# @param x1 [Numeric] horizontal position of first point
|
|
@@ -1526,8 +1529,6 @@ module Processing
|
|
|
1526
1529
|
nil
|
|
1527
1530
|
end
|
|
1528
1531
|
|
|
1529
|
-
alias drawLine line
|
|
1530
|
-
|
|
1531
1532
|
# Draws a rectangle.
|
|
1532
1533
|
#
|
|
1533
1534
|
# The parameters a, b, c, and d are determined by rectMode().
|
|
@@ -1568,8 +1569,6 @@ module Processing
|
|
|
1568
1569
|
nil
|
|
1569
1570
|
end
|
|
1570
1571
|
|
|
1571
|
-
alias drawRect rect
|
|
1572
|
-
|
|
1573
1572
|
# Draws an ellipse.
|
|
1574
1573
|
#
|
|
1575
1574
|
# The parameters a, b, c, and d are determined by ellipseMode().
|
|
@@ -1599,8 +1598,6 @@ module Processing
|
|
|
1599
1598
|
nil
|
|
1600
1599
|
end
|
|
1601
1600
|
|
|
1602
|
-
alias drawEllipse ellipse
|
|
1603
|
-
|
|
1604
1601
|
# Draws a circle.
|
|
1605
1602
|
#
|
|
1606
1603
|
# @param x [Numeric] horizontal position of the shape
|
|
@@ -1620,8 +1617,6 @@ module Processing
|
|
|
1620
1617
|
ellipse x, y, extent, extent
|
|
1621
1618
|
end
|
|
1622
1619
|
|
|
1623
|
-
alias drawCircle circle
|
|
1624
|
-
|
|
1625
1620
|
# Draws an arc.
|
|
1626
1621
|
#
|
|
1627
1622
|
# The parameters a, b, c, and d are determined by ellipseMode().
|
|
@@ -1646,8 +1641,6 @@ module Processing
|
|
|
1646
1641
|
nil
|
|
1647
1642
|
end
|
|
1648
1643
|
|
|
1649
|
-
alias drawArc arc
|
|
1650
|
-
|
|
1651
1644
|
# Draws a square.
|
|
1652
1645
|
#
|
|
1653
1646
|
# @param x [Numeric] horizontal position of the shape
|
|
@@ -1663,8 +1656,6 @@ module Processing
|
|
|
1663
1656
|
rect x, y, extent, extent
|
|
1664
1657
|
end
|
|
1665
1658
|
|
|
1666
|
-
alias drawSquare square
|
|
1667
|
-
|
|
1668
1659
|
# Draws a triangle.
|
|
1669
1660
|
#
|
|
1670
1661
|
# @param x1 [Numeric] horizontal position of first point
|
|
@@ -1685,8 +1676,6 @@ module Processing
|
|
|
1685
1676
|
nil
|
|
1686
1677
|
end
|
|
1687
1678
|
|
|
1688
|
-
alias drawTriangle triangle
|
|
1689
|
-
|
|
1690
1679
|
# Draws a quad.
|
|
1691
1680
|
#
|
|
1692
1681
|
# @param x1 [Numeric] horizontal position of first point
|
|
@@ -1709,8 +1698,6 @@ module Processing
|
|
|
1709
1698
|
nil
|
|
1710
1699
|
end
|
|
1711
1700
|
|
|
1712
|
-
alias drawQuad quad
|
|
1713
|
-
|
|
1714
1701
|
# Draws a Catmull-Rom spline curve.
|
|
1715
1702
|
#
|
|
1716
1703
|
# @param cx1 [Numeric] horizontal position of beginning control point
|
|
@@ -1735,8 +1722,6 @@ module Processing
|
|
|
1735
1722
|
nil
|
|
1736
1723
|
end
|
|
1737
1724
|
|
|
1738
|
-
alias drawCurve curve
|
|
1739
|
-
|
|
1740
1725
|
# Draws a Bezier spline curve.
|
|
1741
1726
|
#
|
|
1742
1727
|
# @param x1 [Numeric] horizontal position of first point
|
|
@@ -1761,8 +1746,6 @@ module Processing
|
|
|
1761
1746
|
nil
|
|
1762
1747
|
end
|
|
1763
1748
|
|
|
1764
|
-
alias drawBezier bezier
|
|
1765
|
-
|
|
1766
1749
|
# Draws a text.
|
|
1767
1750
|
#
|
|
1768
1751
|
# The parameters a, b, c, and d are determined by rectMode().
|
|
@@ -1807,8 +1790,6 @@ module Processing
|
|
|
1807
1790
|
nil
|
|
1808
1791
|
end
|
|
1809
1792
|
|
|
1810
|
-
alias drawText text
|
|
1811
|
-
|
|
1812
1793
|
# Draws an image.
|
|
1813
1794
|
#
|
|
1814
1795
|
# The parameters a, b, c, and d are determined by imageMode().
|
|
@@ -1845,8 +1826,6 @@ module Processing
|
|
|
1845
1826
|
end
|
|
1846
1827
|
end
|
|
1847
1828
|
|
|
1848
|
-
alias drawImage image
|
|
1849
|
-
|
|
1850
1829
|
# Draws a shape.
|
|
1851
1830
|
#
|
|
1852
1831
|
# The parameters a, b, c, and d are determined by shapeMode().
|
|
@@ -1879,8 +1858,6 @@ module Processing
|
|
|
1879
1858
|
nil
|
|
1880
1859
|
end
|
|
1881
1860
|
|
|
1882
|
-
alias drawShape shape
|
|
1883
|
-
|
|
1884
1861
|
# Begins drawing complex shapes.
|
|
1885
1862
|
#
|
|
1886
1863
|
# @param type [POINTS, LINES, TRIANGLES, TRIANGLE_FAN, TRIANGLE_STRIP, QUADS, QUAD_STRIP, TESS]
|
|
@@ -3326,8 +3303,8 @@ module Processing
|
|
|
3326
3303
|
# @see https://processing.org/reference/createGraphics_.html
|
|
3327
3304
|
# @see https://p5js.org/reference/p5/createGraphics/
|
|
3328
3305
|
#
|
|
3329
|
-
def createGraphics(width, height, pixelDensity
|
|
3330
|
-
Graphics.new width, height, pixelDensity
|
|
3306
|
+
def createGraphics(width, height, pixelDensity: 1)
|
|
3307
|
+
Graphics.new width, height, pixelDensity: pixelDensity
|
|
3331
3308
|
end
|
|
3332
3309
|
|
|
3333
3310
|
# Creates a shader object.
|
|
@@ -3462,27 +3439,22 @@ module Processing
|
|
|
3462
3439
|
|
|
3463
3440
|
# @private
|
|
3464
3441
|
private def httpGet__(uri, ext)
|
|
3465
|
-
|
|
3466
|
-
path
|
|
3467
|
-
path
|
|
3442
|
+
dir = Processing.tmpdir__
|
|
3443
|
+
path = dir + Digest::SHA1.hexdigest(uri)
|
|
3444
|
+
path = path.sub_ext ext
|
|
3468
3445
|
|
|
3469
3446
|
unless path.file?
|
|
3470
3447
|
raise NotImplementedError, 'HTTP request is not supported on WASM' if Xot.wasm?
|
|
3471
3448
|
require 'net/http'
|
|
3472
3449
|
Net::HTTP.get_response URI.parse(uri) do |res|
|
|
3473
3450
|
res.value # raise an error unless successful
|
|
3474
|
-
|
|
3451
|
+
dir.mkdir unless dir.directory?
|
|
3475
3452
|
path.open('wb') {|file| res.read_body {|body| file.write body}}
|
|
3476
3453
|
end
|
|
3477
3454
|
end
|
|
3478
3455
|
path.to_s
|
|
3479
3456
|
end
|
|
3480
3457
|
|
|
3481
|
-
# @private
|
|
3482
|
-
private def tmpdir__()
|
|
3483
|
-
Pathname(Dir.tmpdir) + Digest::SHA1.hexdigest(self.class.name)
|
|
3484
|
-
end
|
|
3485
|
-
|
|
3486
3458
|
end# GraphicsContext
|
|
3487
3459
|
|
|
3488
3460
|
|
data/lib/processing/shape.rb
CHANGED
|
@@ -10,7 +10,7 @@ module Processing
|
|
|
10
10
|
# @private
|
|
11
11
|
def initialize(polygon = nil, children = nil, context: nil)
|
|
12
12
|
@polygon, @children = polygon, children
|
|
13
|
-
@context = context || Context.
|
|
13
|
+
@context = context || Context.current__
|
|
14
14
|
@visible = true
|
|
15
15
|
@fill = @stroke = @strokeWeight = @strokeCap = @strokeJoin = @matrix = nil
|
|
16
16
|
@type = @points = @curvePoints = @colors = @texcoords = @close = nil
|
data/lib/processing/vector.rb
CHANGED
|
@@ -35,7 +35,7 @@ module Processing
|
|
|
35
35
|
when Array then Rays::Point.new x[0] || 0, x[1] || 0, x[2] || 0
|
|
36
36
|
else Rays::Point.new x || 0, y || 0, z || 0
|
|
37
37
|
end
|
|
38
|
-
@context = context || Context.
|
|
38
|
+
@context = context || Context.current__
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
# Initializer for dup or clone
|
data/lib/processing/window.rb
CHANGED
|
@@ -6,7 +6,7 @@ module Processing
|
|
|
6
6
|
|
|
7
7
|
include Xot::Inspectable
|
|
8
8
|
|
|
9
|
-
def initialize(width = 500, height = 500, *args, **kwargs
|
|
9
|
+
def initialize(width = 500, height = 500, *args, context_class: Context, **kwargs)
|
|
10
10
|
Processing.instance_variable_set :@window, self
|
|
11
11
|
|
|
12
12
|
@events = []
|
|
@@ -22,10 +22,12 @@ module Processing
|
|
|
22
22
|
# at a safe point (on_canvas_update) to avoid this.
|
|
23
23
|
GC.disable if Xot.wasm?
|
|
24
24
|
|
|
25
|
-
super(*args, size: [width, height], **kwargs
|
|
25
|
+
super(*args, size: [width, height], **kwargs) {on_setup}
|
|
26
26
|
|
|
27
27
|
self.center = screen.center
|
|
28
28
|
@canvas_view.focus
|
|
29
|
+
|
|
30
|
+
@context = context_class.new self
|
|
29
31
|
end
|
|
30
32
|
|
|
31
33
|
attr_accessor :setup, :update, :draw, :move, :resize, :motion,
|
|
@@ -35,7 +37,7 @@ module Processing
|
|
|
35
37
|
|
|
36
38
|
attr_accessor :auto_resize
|
|
37
39
|
|
|
38
|
-
attr_reader :canvas
|
|
40
|
+
attr_reader :canvas, :context
|
|
39
41
|
|
|
40
42
|
def event()
|
|
41
43
|
@events.last
|
|
@@ -53,21 +55,8 @@ module Processing
|
|
|
53
55
|
@overlay_view.remove view
|
|
54
56
|
end
|
|
55
57
|
|
|
56
|
-
def start(&block)
|
|
57
|
-
draw_canvas do
|
|
58
|
-
block.call if block
|
|
59
|
-
on_setup
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
|
|
63
58
|
def on_setup()
|
|
64
|
-
call_block @setup, nil
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
def on_change_pixel_density(pixel_density)
|
|
68
|
-
resize_canvas(
|
|
69
|
-
@canvas.width, @canvas.height,
|
|
70
|
-
window_pixel_density: pixel_density)
|
|
59
|
+
draw_canvas {call_block @setup, nil}
|
|
71
60
|
end
|
|
72
61
|
|
|
73
62
|
def on_activate(e)
|
|
@@ -85,7 +74,7 @@ module Processing
|
|
|
85
74
|
def on_draw(e)
|
|
86
75
|
painter.pixel_density.tap do |pd|
|
|
87
76
|
prev, @prev_pixel_density = @prev_pixel_density, pd
|
|
88
|
-
|
|
77
|
+
resize_canvas @canvas.width, @canvas.height if prev && pd != prev
|
|
89
78
|
end
|
|
90
79
|
update_canvas_view
|
|
91
80
|
end
|
|
@@ -95,7 +84,7 @@ module Processing
|
|
|
95
84
|
end
|
|
96
85
|
|
|
97
86
|
def on_resize(e)
|
|
98
|
-
|
|
87
|
+
(@auto_resize ? e : @canvas).tap {resize_canvas _1.width, _1.height}
|
|
99
88
|
draw_canvas {call_block @resize, e} if @resize
|
|
100
89
|
end
|
|
101
90
|
|
|
@@ -148,24 +137,21 @@ module Processing
|
|
|
148
137
|
end
|
|
149
138
|
|
|
150
139
|
def on_canvas_resize(e)
|
|
151
|
-
|
|
140
|
+
(@auto_resize ? e : @canvas).tap {resize_canvas _1.width, _1.height}
|
|
152
141
|
draw_canvas {call_block @resize, e} if @resize
|
|
153
142
|
end
|
|
154
143
|
|
|
155
|
-
def resize_canvas(
|
|
156
|
-
width, height,
|
|
157
|
-
pixel_density = nil,
|
|
158
|
-
window_pixel_density: nil,
|
|
159
|
-
antialiasing: nil)
|
|
160
|
-
|
|
144
|
+
def resize_canvas(width, height, pixel_density: nil, antialiasing: nil)
|
|
161
145
|
painting = @canvas.painter.painting?
|
|
162
146
|
@canvas.painter.__send__ :end_paint if painting
|
|
163
147
|
|
|
164
|
-
@pixel_density = pixel_density if pixel_density
|
|
148
|
+
@pixel_density = pixel_density == :auto ? nil : pixel_density if pixel_density
|
|
165
149
|
|
|
166
150
|
resized =
|
|
167
151
|
begin
|
|
168
|
-
pd = @pixel_density ||
|
|
152
|
+
pd = @pixel_density || painter.pixel_density.then {
|
|
153
|
+
_1 * (self.width > 0 && width > 0 ? self.width / width.to_f : 1)
|
|
154
|
+
}
|
|
169
155
|
@canvas.resize width, height, pd, antialiasing
|
|
170
156
|
ensure
|
|
171
157
|
@canvas.painter.__send__ :begin_paint if painting
|
|
@@ -180,12 +166,12 @@ module Processing
|
|
|
180
166
|
scrollx, scrolly, zoom = get_scroll_and_zoom
|
|
181
167
|
@canvas_view.scroll_to scrollx, scrolly
|
|
182
168
|
@canvas_view.zoom = zoom
|
|
183
|
-
@overlay_view.size = @canvas.
|
|
169
|
+
@overlay_view.size = [@canvas.width, @canvas.height]
|
|
184
170
|
end
|
|
185
171
|
|
|
186
172
|
def get_scroll_and_zoom()
|
|
187
|
-
ww, wh =
|
|
188
|
-
cw, ch = @canvas.
|
|
173
|
+
ww, wh = width.to_f, height.to_f
|
|
174
|
+
cw, ch = @canvas.width.to_f, @canvas.height.to_f
|
|
189
175
|
return 0, 0, 1 if ww == 0 || wh == 0 || cw == 0 || ch == 0
|
|
190
176
|
|
|
191
177
|
wratio, cratio = ww / wh, cw / ch
|
|
@@ -227,6 +213,7 @@ module Processing
|
|
|
227
213
|
end
|
|
228
214
|
|
|
229
215
|
def call_block(block, event, *args)
|
|
216
|
+
$processing_context__ = @context
|
|
230
217
|
@events.push event
|
|
231
218
|
block.call event, *args if block && !@error
|
|
232
219
|
rescue Exception => e
|
|
@@ -252,7 +239,7 @@ module Processing
|
|
|
252
239
|
resize width, height
|
|
253
240
|
end
|
|
254
241
|
|
|
255
|
-
attr_reader :painter
|
|
242
|
+
attr_reader :painter, :width, :height
|
|
256
243
|
|
|
257
244
|
def resize(width, height, pixel_density = nil, antialiasing = nil)
|
|
258
245
|
return false if width <= 0 || height <= 0
|
|
@@ -261,17 +248,18 @@ module Processing
|
|
|
261
248
|
pd = pixel_density || (@framebuffer || @painter).pixel_density
|
|
262
249
|
aa = antialiasing == nil ? antialiasing? : (antialiasing && pd < 2)
|
|
263
250
|
return false if
|
|
264
|
-
width == @
|
|
265
|
-
height == @
|
|
251
|
+
width == @width &&
|
|
252
|
+
height == @height &&
|
|
266
253
|
pd == @framebuffer&.pixel_density &&
|
|
267
254
|
aa == antialiasing?
|
|
268
255
|
|
|
269
256
|
old_paintable, old_painter = @paintable, @painter
|
|
270
257
|
|
|
271
|
-
@
|
|
272
|
-
@
|
|
258
|
+
@width, @height = width, height
|
|
259
|
+
@framebuffer = Rays::Image.new width, height, cs, pixel_density: pd
|
|
260
|
+
@paintable = aa ?
|
|
273
261
|
Rays::Image.new(width, height, cs, pixel_density: pd * 2) : @framebuffer
|
|
274
|
-
@painter
|
|
262
|
+
@painter = @paintable.painter
|
|
275
263
|
|
|
276
264
|
@painter.paint {image old_paintable} if old_paintable
|
|
277
265
|
copy_painter old_painter, @painter
|
|
@@ -289,14 +277,6 @@ module Processing
|
|
|
289
277
|
@paintable
|
|
290
278
|
end
|
|
291
279
|
|
|
292
|
-
def width()
|
|
293
|
-
@framebuffer.width
|
|
294
|
-
end
|
|
295
|
-
|
|
296
|
-
def height()
|
|
297
|
-
@framebuffer.height
|
|
298
|
-
end
|
|
299
|
-
|
|
300
280
|
def pixel_density()
|
|
301
281
|
@framebuffer.pixel_density
|
|
302
282
|
end
|
data/lib/processing.rb
CHANGED
|
@@ -2,13 +2,13 @@ require 'processing/all'
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
module Processing
|
|
5
|
-
WINDOW__
|
|
5
|
+
WINDOW__ = Processing.setup__ Window, Context
|
|
6
|
+
$processing_context__ = WINDOW__.context
|
|
6
7
|
|
|
7
8
|
refine Object do
|
|
8
|
-
|
|
9
|
-
Processing.funcs__(context).each do |func|
|
|
9
|
+
Processing.funcs__(Context).each do |func|
|
|
10
10
|
define_method func do |*args, **kwargs, &block|
|
|
11
|
-
|
|
11
|
+
$processing_context__.__send__ func, *args, **kwargs, &block
|
|
12
12
|
end
|
|
13
13
|
end
|
|
14
14
|
end
|
|
@@ -22,10 +22,9 @@ def Processing(snake_case: false)
|
|
|
22
22
|
Processing.alias_snake_case_methods__ Processing
|
|
23
23
|
|
|
24
24
|
refine Object do
|
|
25
|
-
|
|
26
|
-
Processing.funcs__(context).each do |func|
|
|
25
|
+
Processing.funcs__(Processing::Context).each do |func|
|
|
27
26
|
define_method func do |*args, **kwargs, &block|
|
|
28
|
-
|
|
27
|
+
$processing_context__.__send__ func, *args, **kwargs, &block
|
|
29
28
|
end
|
|
30
29
|
end
|
|
31
30
|
end
|
|
@@ -34,20 +33,20 @@ end
|
|
|
34
33
|
|
|
35
34
|
|
|
36
35
|
begin
|
|
37
|
-
w
|
|
36
|
+
w = Processing::WINDOW__
|
|
38
37
|
|
|
39
|
-
|
|
38
|
+
w.context.class.constants
|
|
40
39
|
.reject {_1 =~ /__$/}
|
|
41
|
-
.each {self.class.const_set _1,
|
|
40
|
+
.each {self.class.const_set _1, w.context.class.const_get(_1)}
|
|
42
41
|
|
|
43
42
|
w.__send__ :begin_draw
|
|
44
43
|
at_exit do
|
|
45
|
-
Processing.events__(
|
|
44
|
+
Processing.events__(w.context.class).each do |event|
|
|
46
45
|
m = begin method event; rescue NameError; nil end
|
|
47
|
-
|
|
46
|
+
w.context.__send__(event) {__send__ event} if m
|
|
48
47
|
end
|
|
49
48
|
|
|
50
49
|
w.__send__ :end_draw
|
|
51
|
-
Processing::App.new {w.show}.start if
|
|
50
|
+
Processing::App.new {w.show}.start if w.context.hasUserBlocks__ && !$!
|
|
52
51
|
end
|
|
53
52
|
end
|
data/processing.gemspec
CHANGED
|
@@ -26,10 +26,10 @@ Gem::Specification.new do |s|
|
|
|
26
26
|
s.required_ruby_version = '>= 3.0.0'
|
|
27
27
|
|
|
28
28
|
s.add_dependency 'rexml'
|
|
29
|
-
s.add_dependency 'xot', '~> 0.3.
|
|
30
|
-
s.add_dependency 'rucy', '~> 0.3.
|
|
31
|
-
s.add_dependency 'rays', '~> 0.3.
|
|
32
|
-
s.add_dependency 'reflexion', '~> 0.4.
|
|
29
|
+
s.add_dependency 'xot', '~> 0.3.14'
|
|
30
|
+
s.add_dependency 'rucy', '~> 0.3.14'
|
|
31
|
+
s.add_dependency 'rays', '~> 0.3.15'
|
|
32
|
+
s.add_dependency 'reflexion', '~> 0.4.2'
|
|
33
33
|
|
|
34
34
|
s.files = `git ls-files`.split $/
|
|
35
35
|
s.test_files = s.files.grep %r{^(test|spec|features)/}
|
data/test/helper.rb
CHANGED
|
@@ -66,8 +66,8 @@ def get_pixels(image)
|
|
|
66
66
|
.pixels
|
|
67
67
|
end
|
|
68
68
|
|
|
69
|
-
def graphics(width = 10, height = 10,
|
|
70
|
-
Processing::Graphics.new(width, height,
|
|
69
|
+
def graphics(width = 10, height = 10, pixelDensity = 1, &block)
|
|
70
|
+
Processing::Graphics.new(width, height, pixelDensity: pixelDensity).tap do |g|
|
|
71
71
|
g.beginDraw {block.call g, g.getInternal__} if block
|
|
72
72
|
end
|
|
73
73
|
end
|
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: 1.
|
|
4
|
+
version: 1.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- xordog
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-06-12 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rexml
|
|
@@ -30,56 +30,56 @@ dependencies:
|
|
|
30
30
|
requirements:
|
|
31
31
|
- - "~>"
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: 0.3.
|
|
33
|
+
version: 0.3.14
|
|
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.3.
|
|
40
|
+
version: 0.3.14
|
|
41
41
|
- !ruby/object:Gem::Dependency
|
|
42
42
|
name: rucy
|
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
|
44
44
|
requirements:
|
|
45
45
|
- - "~>"
|
|
46
46
|
- !ruby/object:Gem::Version
|
|
47
|
-
version: 0.3.
|
|
47
|
+
version: 0.3.14
|
|
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.3.
|
|
54
|
+
version: 0.3.14
|
|
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.3.
|
|
61
|
+
version: 0.3.15
|
|
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.3.
|
|
68
|
+
version: 0.3.15
|
|
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.4.
|
|
75
|
+
version: 0.4.2
|
|
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.4.
|
|
82
|
+
version: 0.4.2
|
|
83
83
|
description: Creative Coding Framework has API compatible to Processing or p5.js.
|
|
84
84
|
email: xordog@gmail.com
|
|
85
85
|
executables: []
|