rubysketch 0.3.19 → 0.3.20

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: 4d4db586910af2d484acc1ca1b63d49402804a8067097cd39121c34b584672c5
4
- data.tar.gz: 53485422b257e6ce5d92e019c7568ea9c462241305997afaa10d7317d1255102
3
+ metadata.gz: 0d0836f855d3ae54ed3cdeaec0d4d479da386cb0a09684fce54d5b2b17cc4c72
4
+ data.tar.gz: 72af8263d9531136860ce15145b59011c838743f64659362bd66e4ae6c717d1c
5
5
  SHA512:
6
- metadata.gz: 05f812e6830f10453a82845d936205c3f8d7738d3a0236161f27244c6af7ae9a5d03de377f00069353b0ebc449c09012a649a7c153e78ad947a6223f5b66f95b
7
- data.tar.gz: f55999518e51caec7adcf662a67a522ed6baaa3a4956b9161776fb5f99e0ee1c1fb2011af2a41219ee2cefb43e1f02ab458f3b16281b430bf5c7c01f2c6f1530
6
+ metadata.gz: 5dc6de1cba1571960c9cd9a621b568ee7257b11c537ac74a827cdf3d95fadbb33a0c25258177b0fec299e766c7f78c0e82a308319a38fdd004fe340a7be4ebe4
7
+ data.tar.gz: 9cac5e78ddb2a9c7bf4e5e53c294321155bc4276cefed59ba115e44e1370fe9ca15c2ebd404615bceb72305f022a329be915d1d197df587770fe42376df87f88
@@ -13,10 +13,10 @@ jobs:
13
13
  steps:
14
14
  - uses: actions/checkout@v2
15
15
 
16
- - name: ruby 2.7
16
+ - name: ruby 3.0
17
17
  uses: actions/setup-ruby@v1
18
18
  with:
19
- ruby-version: 2.7.x
19
+ ruby-version: 3.0.x
20
20
 
21
21
  - name: install gems
22
22
  run: |
data/ChangeLog.md CHANGED
@@ -1,6 +1,15 @@
1
1
  # RubySketch ChangeLog
2
2
 
3
3
 
4
+ ## [0.3.20] - 2022-07-24
5
+
6
+ - add mouseClicked()
7
+ - add blendMode()
8
+ - add clip() and noClip()
9
+ - translate() can take 'z' parameter
10
+ - fix that resizing canvas consumes too much memory
11
+
12
+
4
13
  ## [0.3.19] - 2021-12-5
5
14
 
6
15
  - fix runtime error
@@ -0,0 +1,28 @@
1
+ # -*- mode: ruby -*-
2
+
3
+
4
+ Pod::Spec.new do |s|
5
+ s.name = "RubySketch"
6
+ s.version = File.readlines(File.expand_path 'VERSION', __dir__)[0].chomp
7
+ s.summary = "Yet Another Processing implementation for Ruby"
8
+ s.description = "Yet Another Processing implementation for Ruby"
9
+ s.license = "MIT"
10
+ s.source = {:git => "https://github.com/xord/rubysketch.git"}
11
+ s.author = {"xordog" => "xordog@gmail.com"}
12
+ s.homepage = "https://github.com/xord/rubysketch"
13
+
14
+ s.osx.deployment_target = "10.10"
15
+ s.ios.deployment_target = "10.0"
16
+
17
+ incdirs = %W[
18
+ #{s.name}/src
19
+ CRuby/CRuby/include
20
+ Reflexion/reflex/include
21
+ ].map {|s| "${PODS_ROOT}/#{s}"}
22
+
23
+ s.preserve_paths = "src"
24
+ s.source_files = "src/*.mm"
25
+ s.xcconfig = {"HEADER_SEARCH_PATHS" => incdirs.join(' ')}
26
+
27
+ s.resource_bundles = {'RubySketch' => %w[lib VERSION]}
28
+ end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.19
1
+ 0.3.20
@@ -882,6 +882,73 @@ module RubySketch
882
882
  #
883
883
  RADIUS = :radius
884
884
 
885
+ # Mode for strokeCap().
886
+ #
887
+ BUTT = :butt
888
+
889
+ # Mode for strokeJoin().
890
+ #
891
+ MITER = :miter
892
+
893
+ # Mode for strokeCap() and strokeJoin().
894
+ #
895
+ ROUND = :round
896
+
897
+ # Mode for strokeCap() and strokeJoin().
898
+ #
899
+ SQUARE = :square
900
+
901
+ # Mode for blendMode().
902
+ #
903
+ BLEND = :normal
904
+
905
+ # Mode for blendMode().
906
+ #
907
+ ADD = :add
908
+
909
+ # Mode for blendMode().
910
+ #
911
+ SUBTRACT = :subtract
912
+
913
+ # Mode for blendMode().
914
+ #
915
+ LIGHTEST = :lightest
916
+
917
+ # Mode for blendMode().
918
+ #
919
+ DARKEST = :darkest
920
+
921
+ # Mode for blendMode().
922
+ #
923
+ EXCLUSION = :exclusion
924
+
925
+ # Mode for blendMode().
926
+ #
927
+ MULTIPLY = :multiply
928
+
929
+ # Mode for blendMode().
930
+ #
931
+ SCREEN = :screen
932
+
933
+ # Mode for blendMode().
934
+ #
935
+ REPLACE = :replace
936
+
937
+ # Key code or Mode for textAlign().
938
+ LEFT = :left
939
+
940
+ # Key code or Mode for textAlign().
941
+ RIGHT = :right
942
+
943
+ # Mode for textAlign().
944
+ TOP = :top
945
+
946
+ # Mode for textAlign().
947
+ BOTTOM = :bottom
948
+
949
+ # Mode for textAlign().
950
+ BASELINE = :baseline
951
+
885
952
  # Key codes.
886
953
  ENTER = :enter
887
954
  SPACE = :space
@@ -931,37 +998,7 @@ module RubySketch
931
998
  UP = :up
932
999
  DOWN = :down
933
1000
 
934
- # Key code or Mode for textAlign().
935
- LEFT = :left
936
-
937
- # Key code or Mode for textAlign().
938
- RIGHT = :right
939
-
940
- # Mode for textAlign().
941
- TOP = :top
942
-
943
- # Mode for textAlign().
944
- BOTTOM = :bottom
945
-
946
- # Mode for textAlign().
947
- BASELINE = :baseline
948
-
949
- # Mode for strokeCap().
950
- #
951
- BUTT = :butt
952
-
953
- # Mode for strokeJoin().
954
- #
955
- MITER = :miter
956
-
957
- # Mode for strokeCap() and strokeJoin().
958
- #
959
- ROUND = :round
960
-
961
- # Mode for strokeCap() and strokeJoin().
962
- #
963
- SQUARE = :square
964
-
1001
+ # @private
965
1002
  def init__(image, painter)
966
1003
  @drawing__ = false
967
1004
  @hsbColor__ = false
@@ -974,6 +1011,7 @@ module RubySketch
974
1011
  @textAlignV__ = nil
975
1012
  @matrixStack__ = []
976
1013
  @styleStack__ = []
1014
+ @fontCache__ = {}
977
1015
 
978
1016
  updateCanvas__ image, painter
979
1017
 
@@ -982,6 +1020,7 @@ module RubySketch
982
1020
  rectMode CORNER
983
1021
  ellipseMode CENTER
984
1022
  imageMode CORNER
1023
+ blendMode BLEND
985
1024
  textAlign LEFT
986
1025
 
987
1026
  fill 255
@@ -989,6 +1028,7 @@ module RubySketch
989
1028
  strokeWeight 1
990
1029
  end
991
1030
 
1031
+ # @private
992
1032
  def updateCanvas__(image, painter)
993
1033
  @image__, @painter__ = image, painter
994
1034
  end
@@ -1169,6 +1209,15 @@ module RubySketch
1169
1209
  nil
1170
1210
  end
1171
1211
 
1212
+ # Disables filling.
1213
+ #
1214
+ # @return [nil] nil
1215
+ #
1216
+ def noFill()
1217
+ @painter__.fill nil
1218
+ nil
1219
+ end
1220
+
1172
1221
  # Sets stroke color.
1173
1222
  #
1174
1223
  # @overload stroke(rgb)
@@ -1192,6 +1241,15 @@ module RubySketch
1192
1241
  nil
1193
1242
  end
1194
1243
 
1244
+ # Disables drawing stroke.
1245
+ #
1246
+ # @return [nil] nil
1247
+ #
1248
+ def noStroke()
1249
+ @painter__.stroke nil
1250
+ nil
1251
+ end
1252
+
1195
1253
  # Sets stroke weight.
1196
1254
  #
1197
1255
  # @param weight [Numeric] width of stroke
@@ -1225,33 +1283,58 @@ module RubySketch
1225
1283
  nil
1226
1284
  end
1227
1285
 
1228
- # Disables filling.
1286
+ # Limits the drawable rectangle.
1287
+ #
1288
+ # The parameters a, b, c, and d are determined by rectMode().
1289
+ #
1290
+ # @param a [Numeric] horizontal position of the drawable area, by default
1291
+ # @param b [Numeric] vertical position of the drawable area, by default
1292
+ # @param c [Numeric] width of the drawable area, by default
1293
+ # @param d [Numeric] height of the drawable area, by default
1229
1294
  #
1230
1295
  # @return [nil] nil
1231
1296
  #
1232
- def noFill()
1233
- @painter__.fill nil
1297
+ def clip(a, b, c, d)
1298
+ x, y, w, h = toXYWH__ @imageMode__, a, b, c, d
1299
+ @painter__.clip x, y, w, h
1234
1300
  nil
1235
1301
  end
1236
1302
 
1237
- # Disables drawing stroke.
1303
+ # Disables clipping.
1238
1304
  #
1239
1305
  # @return [nil] nil
1240
1306
  #
1241
- def noStroke()
1242
- @painter__.stroke nil
1307
+ def noClip()
1308
+ @painter__.no_clip
1309
+ nil
1310
+ end
1311
+
1312
+ # Sets blend mode. Default is BLEND.
1313
+ #
1314
+ # @param mode [BLEND, ADD, SUBTRACT, LIGHTEST, DARKEST, EXCLUSION, MULTIPLY, SCREEN, REPLACE]
1315
+ #
1316
+ # @return [nil] nil
1317
+ #
1318
+ def blendMode(mode)
1319
+ @painter__.blend_mode = mode
1243
1320
  nil
1244
1321
  end
1245
1322
 
1246
1323
  # Sets font.
1247
1324
  #
1325
+ # @overload textFont(font)
1326
+ # @overload textFont(name)
1327
+ # @overload textFont(font, size)
1328
+ # @overload textFont(name, size)
1329
+ #
1330
+ # @param font [Font] font
1248
1331
  # @param name [String] font name
1249
1332
  # @param size [Numeric] font size (max 256)
1250
1333
  #
1251
1334
  # @return [Font] current font
1252
1335
  #
1253
- def textFont(name = nil, size = nil)
1254
- setFont__ name, size if name || size
1336
+ def textFont(font = nil, size = nil)
1337
+ setFont__ font, size if font || size
1255
1338
  Font.new @painter__.font
1256
1339
  end
1257
1340
 
@@ -1262,7 +1345,7 @@ module RubySketch
1262
1345
  # @return [nil] nil
1263
1346
  #
1264
1347
  def textSize(size)
1265
- setFont__ @painter__.font.name, size
1348
+ setFont__ nil, size
1266
1349
  nil
1267
1350
  end
1268
1351
 
@@ -1284,9 +1367,15 @@ module RubySketch
1284
1367
  end
1285
1368
 
1286
1369
  # @private
1287
- def setFont__(name, size)
1288
- size = 256 if size && size > 256
1289
- @painter__.font name, size
1370
+ def setFont__(fontOrName, size)
1371
+ name = case fontOrName
1372
+ when Font then fontOrName.name
1373
+ else fontOrName || @painter__.font.name
1374
+ end
1375
+ size ||= @painter__.font.size
1376
+ size = 256 if size > 256
1377
+ font = @fontCache__[[name, size]] ||= Rays::Font.new name, size
1378
+ @painter__.font = font
1290
1379
  end
1291
1380
 
1292
1381
  # Clears screen.
@@ -1352,14 +1441,16 @@ module RubySketch
1352
1441
 
1353
1442
  # Draws a rectangle.
1354
1443
  #
1444
+ # The parameters a, b, c, and d are determined by rectMode().
1445
+ #
1355
1446
  # @overload rect(a, b, c, d)
1356
1447
  # @overload rect(a, b, c, d, r)
1357
1448
  # @overload rect(a, b, c, d, tl, tr, br, bl)
1358
1449
  #
1359
- # @param a [Numeric] horizontal position of the shape by default
1360
- # @param b [Numeric] vertical position of the shape by default
1361
- # @param c [Numeric] width of the shape by default
1362
- # @param d [Numeric] height of the shape by default
1450
+ # @param a [Numeric] horizontal position of the shape, by default
1451
+ # @param b [Numeric] vertical position of the shape, by default
1452
+ # @param c [Numeric] width of the shape, by default
1453
+ # @param d [Numeric] height of the shape, by default
1363
1454
  # @param r [Numeric] radius for all corners
1364
1455
  # @param tl [Numeric] radius for top-left corner
1365
1456
  # @param tr [Numeric] radius for top-right corner
@@ -1382,10 +1473,12 @@ module RubySketch
1382
1473
 
1383
1474
  # Draws an ellipse.
1384
1475
  #
1385
- # @param a [Numeric] horizontal position of the shape
1386
- # @param b [Numeric] vertical position of the shape
1387
- # @param c [Numeric] width of the shape
1388
- # @param d [Numeric] height of the shape
1476
+ # The parameters a, b, c, and d are determined by ellipseMode().
1477
+ #
1478
+ # @param a [Numeric] horizontal position of the shape, by default
1479
+ # @param b [Numeric] vertical position of the shape, by default
1480
+ # @param c [Numeric] width of the shape, by default
1481
+ # @param d [Numeric] height of the shape, by default
1389
1482
  #
1390
1483
  # @return [nil] nil
1391
1484
  #
@@ -1405,15 +1498,19 @@ module RubySketch
1405
1498
  # @return [nil] nil
1406
1499
  #
1407
1500
  def circle(x, y, extent)
1408
- ellipse x, y, extent, extent
1501
+ assertDrawing__
1502
+ @painter__.ellipse x, y, extent, extent
1503
+ nil
1409
1504
  end
1410
1505
 
1411
1506
  # Draws an arc.
1412
1507
  #
1413
- # @param a [Numeric] horizontal position of the shape
1414
- # @param b [Numeric] vertical position of the shape
1415
- # @param c [Numeric] width of the shape
1416
- # @param d [Numeric] height of the shape
1508
+ # The parameters a, b, c, and d are determined by ellipseMode().
1509
+ #
1510
+ # @param a [Numeric] horizontal position of the shape, by default
1511
+ # @param b [Numeric] vertical position of the shape, by default
1512
+ # @param c [Numeric] width of the shape, by default
1513
+ # @param d [Numeric] height of the shape, by default
1417
1514
  # @param start [Numeric] angle to start the arc
1418
1515
  # @param stop [Numeric] angle to stop the arc
1419
1516
  #
@@ -1516,6 +1613,8 @@ module RubySketch
1516
1613
 
1517
1614
  # Draws a text.
1518
1615
  #
1616
+ # The parameters a, b, c, and d are determined by rectMode().
1617
+ #
1519
1618
  # @overload text(str)
1520
1619
  # @overload text(str, x, y)
1521
1620
  # @overload text(str, a, b, c, d)
@@ -1523,10 +1622,10 @@ module RubySketch
1523
1622
  # @param str [String] text to draw
1524
1623
  # @param x [Numeric] horizontal position of the text
1525
1624
  # @param y [Numeric] vertical position of the text
1526
- # @param a [Numeric] equivalent to parameters of the rect(), see rectMode()
1527
- # @param b [Numeric] equivalent to parameters of the rect(), see rectMode()
1528
- # @param c [Numeric] equivalent to parameters of the rect(), see rectMode()
1529
- # @param d [Numeric] equivalent to parameters of the rect(), see rectMode()
1625
+ # @param a [Numeric] horizontal position of the text, by default
1626
+ # @param b [Numeric] vertical position of the text, by default
1627
+ # @param c [Numeric] width of the text, by default
1628
+ # @param d [Numeric] height of the text, by default
1530
1629
  #
1531
1630
  # @return [nil] nil
1532
1631
  #
@@ -1553,14 +1652,16 @@ module RubySketch
1553
1652
 
1554
1653
  # Draws an image.
1555
1654
  #
1655
+ # The parameters a, b, c, and d are determined by imageMode().
1656
+ #
1556
1657
  # @overload image(img, a, b)
1557
1658
  # @overload image(img, a, b, c, d)
1558
1659
  #
1559
1660
  # @param img [Image] image to draw
1560
- # @param a [Numeric] horizontal position of the image
1561
- # @param b [Numeric] vertical position of the image
1562
- # @param c [Numeric] width of the image
1563
- # @param d [Numeric] height of the image
1661
+ # @param a [Numeric] horizontal position of the image, by default
1662
+ # @param b [Numeric] vertical position of the image, by default
1663
+ # @param c [Numeric] width of the image, by default
1664
+ # @param d [Numeric] height of the image, by default
1564
1665
  #
1565
1666
  # @return [nil] nil
1566
1667
  #
@@ -1597,14 +1698,18 @@ module RubySketch
1597
1698
 
1598
1699
  # Applies translation matrix to current transformation matrix.
1599
1700
  #
1600
- # @param x [Numeric] horizontal transformation
1601
- # @param y [Numeric] vertical transformation
1701
+ # @overload translate(x, y)
1702
+ # @overload translate(x, y, z)
1703
+ #
1704
+ # @param x [Numeric] left/right translation
1705
+ # @param y [Numeric] up/down translation
1706
+ # @param y [Numeric] forward/backward translation
1602
1707
  #
1603
1708
  # @return [nil] nil
1604
1709
  #
1605
- def translate(x, y)
1710
+ def translate(x, y, z = 0)
1606
1711
  assertDrawing__
1607
- @painter__.translate x, y
1712
+ @painter__.translate x, y, z
1608
1713
  nil
1609
1714
  end
1610
1715
 
@@ -1684,6 +1789,8 @@ module RubySketch
1684
1789
  @painter__.stroke_width,
1685
1790
  @painter__.stroke_cap,
1686
1791
  @painter__.stroke_join,
1792
+ @painter__.clip,
1793
+ @painter__.blend_mode,
1687
1794
  @painter__.font,
1688
1795
  @hsbColor__,
1689
1796
  @colorMaxes__,
@@ -1711,6 +1818,8 @@ module RubySketch
1711
1818
  @painter__.stroke_width,
1712
1819
  @painter__.stroke_cap,
1713
1820
  @painter__.stroke_join,
1821
+ @painter__.clip,
1822
+ @painter__.blend_mode,
1714
1823
  @painter__.font,
1715
1824
  @hsbColor__,
1716
1825
  @colorMaxes__,
@@ -1828,7 +1937,7 @@ module RubySketch
1828
1937
  @keyCode__ = nil
1829
1938
  @keysPressed__ = Set.new
1830
1939
  @pointerPos__ =
1831
- @pointerPrevPos__ = [0, 0]
1940
+ @pointerPrevPos__ = Rays::Point.new 0
1832
1941
  @pointersPressed__ = []
1833
1942
  @touches__ = []
1834
1943
  @motionGravity__ = createVector 0, 0
@@ -1852,7 +1961,6 @@ module RubySketch
1852
1961
  @redraw__ = false
1853
1962
  drawFrame.call
1854
1963
  end
1855
- @pointerPrevPos__ = @pointerPos__
1856
1964
  end
1857
1965
 
1858
1966
  updateKeyStates = -> event, pressed {
@@ -1871,7 +1979,8 @@ module RubySketch
1871
1979
  }
1872
1980
 
1873
1981
  updatePointerStates = -> event, pressed = nil {
1874
- @pointerPos__ = event.pos.to_a
1982
+ @pointerPrevPos__ = @pointerPos__
1983
+ @pointerPos__ = event.pos.dup
1875
1984
  @touches__ = event.pointers.map {|p| Touch.new(p.id, *p.pos.to_a)}
1876
1985
  if pressed != nil
1877
1986
  array = @pointersPressed__
@@ -1895,12 +2004,17 @@ module RubySketch
1895
2004
 
1896
2005
  @window__.pointer_down = proc do |e|
1897
2006
  updatePointerStates.call e, true
2007
+ @pointerDownStartPos__ = @pointerPos__.dup
1898
2008
  (@touchStartedBlock__ || @mousePressedBlock__)&.call
1899
2009
  end
1900
2010
 
1901
2011
  @window__.pointer_up = proc do |e|
1902
2012
  updatePointerStates.call e, false
1903
2013
  (@touchEndedBlock__ || @mouseReleasedBlock__)&.call
2014
+ if startPos = @pointerDownStartPos__
2015
+ @mouseClickedBlock__&.call if (@pointerPos__ - startPos).length < 3
2016
+ @pointerDownStartPos__ = nil
2017
+ end
1904
2018
  end
1905
2019
 
1906
2020
  @window__.pointer_move = proc do |e|
@@ -1921,6 +2035,8 @@ module RubySketch
1921
2035
 
1922
2036
  # Defines setup block.
1923
2037
  #
2038
+ # @return [nil] nil
2039
+ #
1924
2040
  def setup(&block)
1925
2041
  @window__.setup = block
1926
2042
  nil
@@ -1928,6 +2044,8 @@ module RubySketch
1928
2044
 
1929
2045
  # Defines draw block.
1930
2046
  #
2047
+ # @return [nil] nil
2048
+ #
1931
2049
  def draw(&block)
1932
2050
  @drawBlock__ = block if block
1933
2051
  nil
@@ -1944,6 +2062,8 @@ module RubySketch
1944
2062
 
1945
2063
  # Defines keyReleased block.
1946
2064
  #
2065
+ # @return [nil] nil
2066
+ #
1947
2067
  def keyReleased(&block)
1948
2068
  @keyReleasedBlock__ = block if block
1949
2069
  nil
@@ -1951,6 +2071,8 @@ module RubySketch
1951
2071
 
1952
2072
  # Defines keyTyped block.
1953
2073
  #
2074
+ # @return [nil] nil
2075
+ #
1954
2076
  def keyTyped(&block)
1955
2077
  @keyTypedBlock__ = block if block
1956
2078
  nil
@@ -1967,6 +2089,8 @@ module RubySketch
1967
2089
 
1968
2090
  # Defines mouseReleased block.
1969
2091
  #
2092
+ # @return [nil] nil
2093
+ #
1970
2094
  def mouseReleased(&block)
1971
2095
  @mouseReleasedBlock__ = block if block
1972
2096
  nil
@@ -1974,6 +2098,8 @@ module RubySketch
1974
2098
 
1975
2099
  # Defines mouseMoved block.
1976
2100
  #
2101
+ # @return [nil] nil
2102
+ #
1977
2103
  def mouseMoved(&block)
1978
2104
  @mouseMovedBlock__ = block if block
1979
2105
  nil
@@ -1981,13 +2107,26 @@ module RubySketch
1981
2107
 
1982
2108
  # Defines mouseDragged block.
1983
2109
  #
2110
+ # @return [nil] nil
2111
+ #
1984
2112
  def mouseDragged(&block)
1985
2113
  @mouseDraggedBlock__ = block if block
1986
2114
  nil
1987
2115
  end
1988
2116
 
2117
+ # Defines mouseClicked block.
2118
+ #
2119
+ # @return [nil] nil
2120
+ #
2121
+ def mouseClicked(&block)
2122
+ @mouseClickedBlock__ = block if block
2123
+ nil
2124
+ end
2125
+
1989
2126
  # Defines touchStarted block.
1990
2127
  #
2128
+ # @return [nil] nil
2129
+ #
1991
2130
  def touchStarted(&block)
1992
2131
  @touchStartedBlock__ = block if block
1993
2132
  nil
@@ -1995,6 +2134,8 @@ module RubySketch
1995
2134
 
1996
2135
  # Defines touchEnded block.
1997
2136
  #
2137
+ # @return [nil] nil
2138
+ #
1998
2139
  def touchEnded(&block)
1999
2140
  @touchEndedBlock__ = block if block
2000
2141
  nil
@@ -2002,6 +2143,8 @@ module RubySketch
2002
2143
 
2003
2144
  # Defines touchMoved block.
2004
2145
  #
2146
+ # @return [nil] nil
2147
+ #
2005
2148
  def touchMoved(&block)
2006
2149
  @touchMovedBlock__ = block if block
2007
2150
  nil
@@ -2009,6 +2152,8 @@ module RubySketch
2009
2152
 
2010
2153
  # Defines motion block.
2011
2154
  #
2155
+ # @return [nil] nil
2156
+ #
2012
2157
  def motion(&block)
2013
2158
  @motionBlock__ = block if block
2014
2159
  nil
@@ -2056,9 +2201,12 @@ module RubySketch
2056
2201
  raise '#{name}() must be called on startup or setup block' if @started__
2057
2202
 
2058
2203
  @painter__.__send__ :end_paint
2059
- @window__.__send__ :resize_canvas, width, height, pixelDensity
2060
- updateCanvas__ @window__.canvas_image, @window__.canvas_painter
2061
- @painter__.__send__ :begin_paint
2204
+ begin
2205
+ @window__.__send__ :resize_canvas, width, height, pixelDensity
2206
+ updateCanvas__ @window__.canvas_image, @window__.canvas_painter
2207
+ ensure
2208
+ @painter__.__send__ :begin_paint
2209
+ end
2062
2210
 
2063
2211
  @window__.auto_resize = false
2064
2212
  end
@@ -2124,7 +2272,7 @@ module RubySketch
2124
2272
  # @return [Numeric] horizontal position of mouse
2125
2273
  #
2126
2274
  def mouseX()
2127
- @pointerPos__[0]
2275
+ @pointerPos__.x
2128
2276
  end
2129
2277
 
2130
2278
  # Returns mouse y position
@@ -2132,7 +2280,7 @@ module RubySketch
2132
2280
  # @return [Numeric] vertical position of mouse
2133
2281
  #
2134
2282
  def mouseY()
2135
- @pointerPos__[1]
2283
+ @pointerPos__.y
2136
2284
  end
2137
2285
 
2138
2286
  # Returns mouse x position in previous frame
@@ -2140,7 +2288,7 @@ module RubySketch
2140
2288
  # @return [Numeric] horizontal position of mouse
2141
2289
  #
2142
2290
  def pmouseX()
2143
- @pointerPrevPos__[0]
2291
+ @pointerPrevPos__.x
2144
2292
  end
2145
2293
 
2146
2294
  # Returns mouse y position in previous frame
@@ -2148,7 +2296,7 @@ module RubySketch
2148
2296
  # @return [Numeric] vertical position of mouse
2149
2297
  #
2150
2298
  def pmouseY()
2151
- @pointerPrevPos__[1]
2299
+ @pointerPrevPos__.y
2152
2300
  end
2153
2301
 
2154
2302
  # Returns which mouse button was pressed
@@ -3,6 +3,24 @@ module RubySketch
3
3
 
4
4
  class Window < Reflex::Window
5
5
 
6
+ class CanvasView < Reflex::View
7
+ def on_update(e)
8
+ window.on_canvas_update e
9
+ end
10
+
11
+ def on_draw(e)
12
+ window.on_canvas_draw e
13
+ end
14
+
15
+ def on_pointer(e)
16
+ window.on_canvas_pointer e
17
+ end
18
+
19
+ def on_resize(e)
20
+ window.on_canvas_resize e
21
+ end
22
+ end
23
+
6
24
  attr_accessor :setup, :update, :draw, :before_draw, :after_draw, :resize,
7
25
  :key_down, :key_up,
8
26
  :pointer_down, :pointer_up, :pointer_move, :pointer_drag,
@@ -24,12 +42,7 @@ module RubySketch
24
42
  painter.miter_limit = 10
25
43
  resize_canvas 1, 1
26
44
 
27
- @canvas_view = add Reflex::View.new(name: :canvas) {|v|
28
- v.on(:update) {|e| on_canvas_update e}
29
- v.on(:draw) {|e| on_canvas_draw e}
30
- v.on(:pointer) {|e| on_canvas_pointer e}
31
- v.on(:resize) {|e| on_canvas_resize e}
32
- }
45
+ @canvas_view = add CanvasView.new name: :canvas
33
46
 
34
47
  super(*args, size: [width, height], **kwargs, &block)
35
48
  end
@@ -118,6 +131,7 @@ module RubySketch
118
131
  end
119
132
 
120
133
  resize_window width, height
134
+ GC.start
121
135
  end
122
136
 
123
137
  @canvas_painter
@@ -6,8 +6,8 @@ begin
6
6
  context = RubySketch::Processing::Context.new window
7
7
 
8
8
  (context.methods - Object.instance_methods).each do |method|
9
- define_method method do |*args, &block|
10
- context.__send__ method, *args, &block
9
+ define_method method do |*args, **kwargs, &block|
10
+ context.__send__ method, *args, **kwargs, &block
11
11
  end
12
12
  end
13
13
 
@@ -20,4 +20,6 @@ begin
20
20
  window.__send__ :end_draw
21
21
  RubySketch::App.new {window.show}.start unless $!
22
22
  end
23
+
24
+ RUBYSKETCH_WINDOW = window
23
25
  end
data/rubysketch.gemspec CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |s|
28
28
  s.platform = Gem::Platform::RUBY
29
29
  s.required_ruby_version = '>= 2.6.0'
30
30
 
31
- s.add_runtime_dependency 'reflexion', '~> 0.1.25'
31
+ s.add_runtime_dependency 'reflexion', '~> 0.1.26'
32
32
 
33
33
  s.files = `git ls-files`.split $/
34
34
  s.test_files = s.files.grep %r{^(test|spec|features)/}
data/src/RubySketch.h ADDED
@@ -0,0 +1,15 @@
1
+ // -*- mode: objc -*-
2
+ #import <Foundation/Foundation.h>
3
+
4
+
5
+ @interface RubySketch : NSObject
6
+
7
+ + (void) setup;
8
+
9
+ + (void) start: (NSString*) path;
10
+
11
+ + (void) setActiveReflexViewController: (id) reflexViewController;
12
+
13
+ + (void) resetActiveReflexViewController;
14
+
15
+ @end
data/src/RubySketch.mm ADDED
@@ -0,0 +1,55 @@
1
+ #import <CRuby.h>
2
+ #import "RubySketch.h"
3
+ #include "../src/ios/view_controller.h"
4
+
5
+
6
+ static ReflexViewController* active_reflex_view_controller = nil;
7
+
8
+ static ReflexViewController*
9
+ ReflexViewController_create()
10
+ {
11
+ return active_reflex_view_controller;
12
+ }
13
+
14
+ static void
15
+ ReflexViewController_show (UIViewController*, ReflexViewController*)
16
+ {
17
+ }
18
+
19
+
20
+ @implementation RubySketch
21
+
22
+ + (void) setup
23
+ {
24
+ static BOOL done = NO;
25
+ if (done) return;
26
+ done = YES;
27
+
28
+ [CRuby addLibrary:@"RubySketch" bundle:[NSBundle bundleForClass:RubySketch.class]];
29
+
30
+ ReflexViewController_set_create_fun(ReflexViewController_create);
31
+ ReflexViewController_set_show_fun(ReflexViewController_show);
32
+ }
33
+
34
+ + (void) start: (NSString*) path
35
+ {
36
+ [CRuby evaluate:[NSString stringWithFormat:@
37
+ "raise 'already started' unless require 'rubysketch-processing'\n"
38
+ "load '%@'\n"
39
+ "RUBYSKETCH_WINDOW.__send__ :end_draw\n"
40
+ "RUBYSKETCH_WINDOW.show",
41
+ path
42
+ ]];
43
+ }
44
+
45
+ + (void) setActiveReflexViewController: (id) reflexViewController
46
+ {
47
+ active_reflex_view_controller = reflexViewController;
48
+ }
49
+
50
+ + (void) resetActiveReflexViewController
51
+ {
52
+ active_reflex_view_controller = nil;
53
+ }
54
+
55
+ @end
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.3.19
4
+ version: 0.3.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - xordog
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-04 00:00:00.000000000 Z
11
+ date: 2022-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: reflexion
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.1.25
19
+ version: 0.1.26
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.25
26
+ version: 0.1.26
27
27
  description: Creative Coding Framework have API compatible to Processing API or p5.js.
28
28
  email: xordog@gmail.com
29
29
  executables: []
@@ -39,6 +39,7 @@ files:
39
39
  - LICENSE
40
40
  - README.md
41
41
  - Rakefile
42
+ - RubySketch.podspec
42
43
  - VERSION
43
44
  - examples/breakout.rb
44
45
  - examples/camera.rb
@@ -56,6 +57,8 @@ files:
56
57
  - lib/rubysketch/processing.rb
57
58
  - lib/rubysketch/window.rb
58
59
  - rubysketch.gemspec
60
+ - src/RubySketch.h
61
+ - src/RubySketch.mm
59
62
  - test/helper.rb
60
63
  - test/processing/test_utility.rb
61
64
  - test/processing/test_vector.rb