rubysketch 0.9.4 → 0.10.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.
@@ -54,8 +54,7 @@ module RubySketch
54
54
  # @param [Shape] shp shape of the sprite for physics calculations
55
55
  #
56
56
  def initialize(
57
- x = 0, y = 0, w = nil, h = nil, image: nil, offset: nil, shape: nil,
58
- physics: true, context: nil)
57
+ x = 0, y = 0, w = nil, h = nil, image: nil, offset: nil, shape: nil, physics: true)
59
58
 
60
59
  w ||= (image&.width || shape&.width || 0)
61
60
  h ||= (image&.height || shape&.height || 0)
@@ -63,7 +62,7 @@ module RubySketch
63
62
  raise 'invalid image' if image && !image.getInternal__.is_a?(Rays::Image)
64
63
  raise 'invalid shape' if shape && !shape.getInternal__.is_a?(Reflex::Shape)
65
64
 
66
- @context__ = context || Context.current__
65
+ @world__ = nil
67
66
  @shape__ = shape
68
67
  @view__ = View.new(
69
68
  self, x: x, y: y, w: w, h: h,
@@ -162,7 +161,6 @@ module RubySketch
162
161
  #
163
162
  def x=(n)
164
163
  @view__.x = n
165
- n
166
164
  end
167
165
 
168
166
  # Returns the y-coordinate position of the sprite.
@@ -181,7 +179,6 @@ module RubySketch
181
179
  #
182
180
  def y=(n)
183
181
  @view__.y = n
184
- n
185
182
  end
186
183
 
187
184
  # Returns the z-coordinate position of the sprite.
@@ -200,7 +197,6 @@ module RubySketch
200
197
  #
201
198
  def z=(n)
202
199
  @view__.z = n
203
- n
204
200
  end
205
201
 
206
202
  alias pos position
@@ -222,7 +218,6 @@ module RubySketch
222
218
  #
223
219
  def left=(n)
224
220
  @view__.left = n
225
- n
226
221
  end
227
222
 
228
223
  # Returns the top position of the sprite.
@@ -311,7 +306,7 @@ module RubySketch
311
306
  @view__.size.toVector
312
307
  end
313
308
 
314
- # Returns the size of the sprite.
309
+ # Sets the size of the sprite.
315
310
  #
316
311
  # @return [Vector] size
317
312
  #
@@ -366,7 +361,7 @@ module RubySketch
366
361
  # @return [Numeric] radians or degrees depending on angleMode()
367
362
  #
368
363
  def angle()
369
- @context__.fromDegrees__ @view__.angle
364
+ getContext__.fromDegrees__ @view__.angle
370
365
  end
371
366
 
372
367
  # Sets the rotation angle of the sprite.
@@ -376,7 +371,7 @@ module RubySketch
376
371
  # @return [Numeric] angle
377
372
  #
378
373
  def angle=(angle)
379
- @view__.angle = @context__.toDegrees__ angle
374
+ @view__.angle = getContext__.toDegrees__ angle
380
375
  angle
381
376
  end
382
377
 
@@ -458,7 +453,6 @@ module RubySketch
458
453
  #
459
454
  def vx=(n)
460
455
  @view__.velocity = @view__.velocity.tap {|v| v.x = n}
461
- n
462
456
  end
463
457
 
464
458
  # Returns the y-axis velocity of the sprite.
@@ -477,7 +471,6 @@ module RubySketch
477
471
  #
478
472
  def vy=(n)
479
473
  @view__.velocity = @view__.velocity.tap {|v| v.y = n}
480
- n
481
474
  end
482
475
 
483
476
  alias vel velocity
@@ -546,7 +539,6 @@ module RubySketch
546
539
  #
547
540
  def ox=(x)
548
541
  self.offset = [x, oy]
549
- x
550
542
  end
551
543
 
552
544
  # Returns the y-axis offset of the sprite image.
@@ -565,7 +557,6 @@ module RubySketch
565
557
  #
566
558
  def oy=(y)
567
559
  self.offset = [ox, y]
568
- y
569
560
  end
570
561
 
571
562
  # Returns whether the sprite is movable by the physics engine.
@@ -584,7 +575,6 @@ module RubySketch
584
575
  #
585
576
  def dynamic=(bool)
586
577
  @view__.dynamic = bool
587
- bool
588
578
  end
589
579
 
590
580
  # Returns the density of the sprite.
@@ -603,7 +593,6 @@ module RubySketch
603
593
  #
604
594
  def density=(n)
605
595
  @view__.density = n
606
- n
607
596
  end
608
597
 
609
598
  # Returns the friction of the sprite.
@@ -622,7 +611,6 @@ module RubySketch
622
611
  #
623
612
  def friction=(n)
624
613
  @view__.friction = n
625
- n
626
614
  end
627
615
 
628
616
  # Returns the restitution of the sprite.
@@ -641,7 +629,6 @@ module RubySketch
641
629
  #
642
630
  def restitution=(n)
643
631
  @view__.restitution = n
644
- n
645
632
  end
646
633
 
647
634
  alias dens density
@@ -688,16 +675,90 @@ module RubySketch
688
675
 
689
676
  # @deprecated Use {#gravityScale=} instead.
690
677
  def gravity_scale=(scale)
691
- warn "Sprite#gravity_scale= is deprecated, use #gravityScale= instead", uniq: true
678
+ Xot.warn "Sprite#gravity_scale= is deprecated, use #gravityScale= instead", uniq: true
692
679
  self.gravityScale = scale
693
680
  end
694
681
 
695
682
  # @deprecated Use {#gravityScale} instead.
696
683
  def gravity_scale()
697
- warn "Sprite#gravity_scale is deprecated, use #gravityScale instead", uniq: true
684
+ Xot.warn "Sprite#gravity_scale is deprecated, use #gravityScale instead", uniq: true
698
685
  gravityScale
699
686
  end
700
687
 
688
+ # Creates a pin that fastens a point on the sprite.
689
+ #
690
+ # @overload pin()
691
+ # a pin at the center of the sprite
692
+ # @overload pin(x, y)
693
+ # @param [Numeric] x x of the sprite-local position
694
+ # @param [Numeric] y y of the sprite-local position
695
+ #
696
+ # @return [Pin] a new pin
697
+ #
698
+ def pin(x = nil, y = nil)
699
+ Pin.new self, x, y
700
+ end
701
+
702
+ # Creates a constraint that makes the center of the sprite and the
703
+ # target point coincide.
704
+ #
705
+ # @param [Sprite, Pin, Vector, Array<Numeric>, nil] target
706
+ # the center of a sprite, a pin, or a point in the world.
707
+ # snaps to the world when target is omitted
708
+ #
709
+ # @return [SnapConstraint] a new constraint
710
+ #
711
+ def snap(*args, **options, &block)
712
+ pin.snap(*args, **options, &block)
713
+ end
714
+
715
+ # Creates a constraint that keeps the distance between the center of
716
+ # the sprite and the target point.
717
+ #
718
+ # @param [Sprite, Pin, Vector, Array<Numeric>, nil] target
719
+ # the center of a sprite, a pin, or a point in the world.
720
+ # links to the world when target is omitted
721
+ #
722
+ # @return [LinkConstraint] a new constraint
723
+ #
724
+ def link(*args, **options, &block)
725
+ pin.link(*args, **options, &block)
726
+ end
727
+
728
+ # Creates a constraint that makes the sprite ride on the target like
729
+ # a wheel: it slides along an axis for the suspension and spins freely.
730
+ #
731
+ # @param [Sprite, Pin, Vector, Array<Numeric>, nil] target
732
+ # the center of a sprite, a pin, or a point in the world.
733
+ # rides on the world when target is omitted
734
+ #
735
+ # @return [WheelConstraint] a new constraint
736
+ #
737
+ def wheel(*args, **options, &block)
738
+ pin.wheel(*args, **options, &block)
739
+ end
740
+
741
+ # Creates a constraint that moves the sprite toward the target every
742
+ # frame.
743
+ #
744
+ # @param [Sprite, Pin, Vector, Array<Numeric>, nil] target
745
+ # the center of a sprite, a pin, or a point in the world.
746
+ # chases nothing when target is omitted
747
+ #
748
+ # @return [ChaseConstraint] a new constraint
749
+ #
750
+ def chase(*args, **options, &block)
751
+ pin.chase(*args, **options, &block)
752
+ end
753
+
754
+ # Returns the constraints fastened to the sprite.
755
+ #
756
+ # @return [Array<Constraint>] constraints
757
+ #
758
+ def constraints()
759
+ @view__.constraints.map {|c| Constraint.wrap__ c}
760
+ end
761
+
701
762
  # Converts a vector from the screen coordinate
702
763
  #
703
764
  # @param [Vector] vec screen coordinate vector
@@ -943,6 +1004,34 @@ module RubySketch
943
1004
  nil
944
1005
  end
945
1006
 
1007
+ # Defines mouseOver block.
1008
+ #
1009
+ # @example Highlight the sprite while hovered
1010
+ # sprite.mouseOver do
1011
+ # $hovered = true
1012
+ # end
1013
+ #
1014
+ # @return [Boolean] is the mouse over the sprite or not
1015
+ #
1016
+ def mouseOver(&block)
1017
+ setViewBlock__ :mouseOver, block if block
1018
+ @view__.mouseOver?
1019
+ end
1020
+
1021
+ # Defines mouseOut block.
1022
+ #
1023
+ # @example Unhighlight the sprite on unhover
1024
+ # sprite.mouseOut do
1025
+ # $hovered = false
1026
+ # end
1027
+ #
1028
+ # @return [nil] nil
1029
+ #
1030
+ def mouseOut(&block)
1031
+ setViewBlock__ :mouseOut, block if block
1032
+ nil
1033
+ end
1034
+
946
1035
  # Defines mouseWheel block.
947
1036
  #
948
1037
  # @example Print wheel states on mouse wheel
@@ -1046,6 +1135,21 @@ module RubySketch
1046
1135
  @view__
1047
1136
  end
1048
1137
 
1138
+ # @private
1139
+ def setWorld__(world)
1140
+ @world__ = world
1141
+ end
1142
+
1143
+ # @private
1144
+ def getWorld__()
1145
+ @world__
1146
+ end
1147
+
1148
+ # @private
1149
+ def getContext__()
1150
+ @world__&.getContext__ || Processing.context
1151
+ end
1152
+
1049
1153
  # @private
1050
1154
  def drawSprite__(c)
1051
1155
  return if hidden?
@@ -1086,9 +1190,9 @@ module RubySketch
1086
1190
 
1087
1191
  # @private
1088
1192
  def setViewBlock__(name, block)
1089
- c = @context__
1193
+ self_ = self
1090
1194
  @view__.__send__ "#{name}=", block && (proc do |*a, **k, &b|
1091
- prev, $processing_context__ = $processing_context__, c
1195
+ prev, $processing_context__ = $processing_context__, self_.getContext__
1092
1196
  block.call(*a, **k, &b)
1093
1197
  ensure
1094
1198
  $processing_context__ = prev
@@ -1105,7 +1209,8 @@ module RubySketch
1105
1209
  # Create a new physics world.
1106
1210
  #
1107
1211
  def initialize(pixelsPerMeter: 0)
1108
- @view, @debug = View.new(pixelsPerMeter: pixelsPerMeter), false
1212
+ @context, @sprites, @debug = nil, [], false
1213
+ @view = View.new pixelsPerMeter: pixelsPerMeter
1109
1214
  end
1110
1215
 
1111
1216
  # Creates a new sprite and add it to physics engine.
@@ -1156,35 +1261,48 @@ module RubySketch
1156
1261
  #
1157
1262
  # @return [Sprite] the new sprite object
1158
1263
  #
1159
- def createSprite(*args, klass: nil, context: nil, **kwargs)
1160
- klass ||= RubySketch::Sprite
1161
- context ||= Context.current__
1162
- addSprite klass.new(*args, context: context, **kwargs)
1264
+ def createSprite(*args, klass: nil, **kwargs)
1265
+ klass ||= RubySketch::Sprite
1266
+ addSprite klass.new(*args, **kwargs)
1163
1267
  end
1164
1268
 
1165
1269
  # Adds sprite to the physics engine.
1166
1270
  #
1167
- # @param [Array] array user array to store the sprite
1168
1271
  # @param [Sprite] sprite sprite object
1272
+ # @param [Array] to user array to store the sprite
1169
1273
  #
1170
1274
  # @return [Sprite] the added sprite
1171
1275
  #
1172
- def addSprite(array = nil, sprite)
1276
+ def addSprite(sprite, deprecatedSprite__ = nil, to: nil)
1277
+ if sprite.is_a?(Array)
1278
+ Xot.warn "addSprite(array, sprite) is deprecated; use addSprite(sprite, to: array) instead", uniq: true
1279
+ sprite, to = deprecatedSprite__, sprite
1280
+ end
1281
+ raise ArgumentError if sprite.getWorld__
1173
1282
  @view.add sprite.getInternal__
1174
- array&.push sprite
1283
+ @sprites.push sprite
1284
+ to.push sprite if to
1285
+ sprite.setWorld__ self
1175
1286
  sprite
1176
1287
  end
1177
1288
 
1178
1289
  # Removes sprite from the physics engine.
1179
1290
  #
1180
- # @param [Array] array user array to remove the sprite
1181
1291
  # @param [Sprite] sprite sprite object
1292
+ # @param [Array] from user array to remove the sprite
1182
1293
  #
1183
1294
  # @return [Sprite] the removed sprite
1184
1295
  #
1185
- def removeSprite(array = nil, sprite)
1296
+ def removeSprite(sprite, deprecatedSprite__ = nil, from: nil)
1297
+ if sprite.is_a?(Array)
1298
+ Xot.warn "removeSprite(array, sprite) is deprecated; use removeSprite(sprite, from: array) instead", uniq: true
1299
+ sprite, from = deprecatedSprite__, sprite
1300
+ end
1301
+ raise ArgumentError if sprite.getWorld__ != self
1186
1302
  @view.remove sprite.getInternal__
1187
- array&.delete sprite
1303
+ @sprites.delete sprite
1304
+ from.delete sprite if from
1305
+ sprite.setWorld__ nil
1188
1306
  sprite
1189
1307
  end
1190
1308
 
@@ -1213,16 +1331,250 @@ module RubySketch
1213
1331
  nil
1214
1332
  end
1215
1333
 
1216
- # Returns the offset of the sprite world.
1334
+ # Returns the position of the world.
1335
+ #
1336
+ # @return [Vector] position
1337
+ #
1338
+ def position()
1339
+ @view.position.toVector
1340
+ end
1341
+
1342
+ # Sets the position of the world.
1343
+ #
1344
+ # @overload position=(vec)
1345
+ # @param [Vector] vec position vector
1346
+ #
1347
+ # @overload position=(ary)
1348
+ # @param [Array<Numeric>] ary an array of positionX and positionY
1349
+ #
1350
+ # @return [Vector] position
1351
+ #
1352
+ def position=(arg)
1353
+ @view.position = arg.is_a?(Vector) ? arg.getInternal__ : arg
1354
+ arg
1355
+ end
1356
+
1357
+ # Returns the x-coordinate position of the world.
1358
+ #
1359
+ # @return [Numeric] world position x
1360
+ #
1361
+ def x()
1362
+ @view.x
1363
+ end
1364
+
1365
+ # Set the x-coordinate position of the world.
1366
+ #
1367
+ # @param [Numeric] n world position x
1368
+ #
1369
+ # @return [Numeric] world position x
1370
+ #
1371
+ def x=(n)
1372
+ @view.x = n
1373
+ end
1374
+
1375
+ # Returns the y-coordinate position of the world.
1376
+ #
1377
+ # @return [Numeric] world position y
1378
+ #
1379
+ def y()
1380
+ @view.y
1381
+ end
1382
+
1383
+ # Set the y-coordinate position of the world.
1384
+ #
1385
+ # @param [Numeric] n world position y
1386
+ #
1387
+ # @return [Numeric] world position y
1388
+ #
1389
+ def y=(n)
1390
+ @view.y = n
1391
+ end
1392
+
1393
+ # Returns the z-coordinate position of the world.
1394
+ #
1395
+ # @return [Numeric] world position z
1396
+ #
1397
+ def z()
1398
+ @view.z
1399
+ end
1400
+
1401
+ # Set the z-coordinate position of the world.
1402
+ #
1403
+ # @param [Numeric] n world position z
1404
+ #
1405
+ # @return [Numeric] world position z
1406
+ #
1407
+ def z=(n)
1408
+ @view.z = n
1409
+ end
1410
+
1411
+ alias pos position
1412
+ alias pos= position=
1413
+
1414
+ # Returns the left position of the world.
1415
+ #
1416
+ # @return [Numeric] left position
1417
+ #
1418
+ def left()
1419
+ @view.left
1420
+ end
1421
+
1422
+ # Set the left position of the world.
1423
+ #
1424
+ # @param [Numeric] n world left position
1425
+ #
1426
+ # @return [Numeric] world left position
1427
+ #
1428
+ def left=(n)
1429
+ @view.left = n
1430
+ end
1431
+
1432
+ # Returns the top position of the world.
1433
+ #
1434
+ # @return [Numeric] top position
1435
+ #
1436
+ def top()
1437
+ @view.top
1438
+ end
1439
+
1440
+ # Set the top position of the world.
1441
+ #
1442
+ # @param [Numeric] n world top position
1443
+ #
1444
+ # @return [Numeric] world top position
1445
+ #
1446
+ def top=(n)
1447
+ @view.top = n
1448
+ end
1449
+
1450
+ # Returns the right position of the world.
1451
+ #
1452
+ # @return [Numeric] right position
1453
+ #
1454
+ def right()
1455
+ @view.right
1456
+ end
1457
+
1458
+ # Set the right position of the world.
1217
1459
  #
1218
- # @return [Vector] offset of the sprite world
1460
+ # @param [Numeric] n world right position
1461
+ #
1462
+ # @return [Numeric] world right position
1463
+ #
1464
+ def right=(n)
1465
+ @view.right = n
1466
+ end
1467
+
1468
+ # Returns the bottom position of the world.
1469
+ #
1470
+ # @return [Numeric] bottom
1471
+ #
1472
+ def bottom()
1473
+ @view.bottom
1474
+ end
1475
+
1476
+ # Set the bottom position of the world.
1477
+ #
1478
+ # @param [Numeric] n world bottom position
1479
+ #
1480
+ # @return [Numeric] world bottom position
1481
+ #
1482
+ def bottom=(n)
1483
+ @view.bottom = n
1484
+ end
1485
+
1486
+ # Returns the center position of the world.
1487
+ #
1488
+ # @return [Vector] center position
1489
+ #
1490
+ def center()
1491
+ Vector.new(x + w / 2, y + h / 2, z)
1492
+ end
1493
+
1494
+ # Sets the center position of the world.
1495
+ #
1496
+ # @overload center=(vec)
1497
+ # @param [Vector] vec center position
1498
+ #
1499
+ # @overload center=(ary)
1500
+ # @param [Array<Numeric>] ary an array of centerX and centerY
1501
+ #
1502
+ # @return [Vector] center position
1503
+ #
1504
+ def center=(arg)
1505
+ x, y = *(arg.is_a?(Vector) ? arg.getInternal__.to_a : arg)
1506
+ self.pos = [x - w / 2, y - h / 2, z]
1507
+ self.center
1508
+ end
1509
+
1510
+ # Returns the size of the world.
1511
+ #
1512
+ # @return [Vector] size
1513
+ #
1514
+ def size()
1515
+ @view.size.toVector
1516
+ end
1517
+
1518
+ # Sets the size of the world.
1519
+ #
1520
+ # @return [Vector] size
1521
+ #
1522
+ def size=(arg)
1523
+ @view.size = arg.is_a?(Vector) ? arg.getInternal__ : arg
1524
+ arg
1525
+ end
1526
+
1527
+ # Returns the width of the world.
1528
+ #
1529
+ # @return [Numeric] width
1530
+ #
1531
+ def width()
1532
+ @view.width
1533
+ end
1534
+
1535
+ # Sets the width of the world.
1536
+ #
1537
+ # @param [Numeric] w width
1538
+ #
1539
+ # @return [Numeric] width
1540
+ #
1541
+ def width=(w)
1542
+ @view.width = w
1543
+ end
1544
+
1545
+ # Returns the height of the world.
1546
+ #
1547
+ # @return [Numeric] height
1548
+ #
1549
+ def height()
1550
+ @view.height
1551
+ end
1552
+
1553
+ # Sets the height of the world.
1554
+ #
1555
+ # @param [Numeric] h height
1556
+ #
1557
+ # @return [Numeric] height
1558
+ #
1559
+ def height=(h)
1560
+ @view.height = h
1561
+ end
1562
+
1563
+ alias w width
1564
+ alias w= width=
1565
+ alias h height
1566
+ alias h= height=
1567
+
1568
+ # Returns the offset of the world.
1569
+ #
1570
+ # @return [Vector] offset of the world
1219
1571
  #
1220
1572
  def offset()
1221
1573
  s, z = @view.scroll, zoom
1222
1574
  Vector.new(-s.x / z, -s.y / z, -s.z / z)
1223
1575
  end
1224
1576
 
1225
- # Sets the offset of the sprite world.
1577
+ # Sets the offset of the world.
1226
1578
  #
1227
1579
  # @overload offset=(vec)
1228
1580
  # @param [Vector] vec offset
@@ -1230,7 +1582,7 @@ module RubySketch
1230
1582
  # @overload offset=(ary)
1231
1583
  # @param [Array<Numeric>] ary an array of offsetX and offsetY
1232
1584
  #
1233
- # @return [Vector] offset of the sprite world
1585
+ # @return [Vector] offset of the world
1234
1586
  #
1235
1587
  def offset=(arg)
1236
1588
  zoom_ = zoom
@@ -1245,7 +1597,7 @@ module RubySketch
1245
1597
  offset
1246
1598
  end
1247
1599
 
1248
- # Returns the x-axis offset of the sprite world.
1600
+ # Returns the x-axis offset of the world.
1249
1601
  #
1250
1602
  # @return [Numeric] offset.x
1251
1603
  #
@@ -1253,7 +1605,7 @@ module RubySketch
1253
1605
  offset.x
1254
1606
  end
1255
1607
 
1256
- # Sets the x-axis offset of the sprite world.
1608
+ # Sets the x-axis offset of the world.
1257
1609
  #
1258
1610
  # @param [Numeric] x x-axis offset
1259
1611
  #
@@ -1263,10 +1615,9 @@ module RubySketch
1263
1615
  o = offset
1264
1616
  o.x = x
1265
1617
  self.offset = o
1266
- x
1267
1618
  end
1268
1619
 
1269
- # Returns the y-axis offset of the sprite world.
1620
+ # Returns the y-axis offset of the world.
1270
1621
  #
1271
1622
  # @return [Numeric] offset.y
1272
1623
  #
@@ -1274,20 +1625,19 @@ module RubySketch
1274
1625
  offset.y
1275
1626
  end
1276
1627
 
1277
- # Sets the y-axis offset of the sprite world.
1628
+ # Sets the y-axis offset of the world.
1278
1629
  #
1279
- # @param [Numeric] x y-axis offset
1630
+ # @param [Numeric] y y-axis offset
1280
1631
  #
1281
1632
  # @return [Numeric] offset.y
1282
1633
  #
1283
- def oy=(x)
1634
+ def oy=(y)
1284
1635
  o = offset
1285
1636
  o.y = y
1286
1637
  self.offset = o
1287
- y
1288
1638
  end
1289
1639
 
1290
- # Returns the zoom value of the sprite world.
1640
+ # Returns the zoom value of the world.
1291
1641
  #
1292
1642
  # @return [Numeric] zoom
1293
1643
  #
@@ -1295,7 +1645,7 @@ module RubySketch
1295
1645
  @view.zoom
1296
1646
  end
1297
1647
 
1298
- # Sets the zoom value of the sprite world.
1648
+ # Sets the zoom value of the world.
1299
1649
  #
1300
1650
  # @return [Numeric] zoom
1301
1651
  #
@@ -1309,11 +1659,38 @@ module RubySketch
1309
1659
 
1310
1660
  def debug? = @view.debug?
1311
1661
 
1662
+ # @private
1663
+ def attached__()
1664
+ @context = @view.window.context
1665
+ end
1666
+
1667
+ # @private
1668
+ def detached__()
1669
+ @context = nil
1670
+ end
1671
+
1312
1672
  # @private
1313
1673
  def getInternal__()
1314
1674
  @view
1315
1675
  end
1316
1676
 
1677
+ # @private
1678
+ def getContext__()
1679
+ @context
1680
+ end
1681
+
1682
+ # @private
1683
+ def drawSprite__(c)
1684
+ o, z_ = offset, zoom
1685
+ c.push do
1686
+ c.clip x, y, w, h
1687
+ c.translate x, y, z
1688
+ c.scale z_, z_
1689
+ c.translate(-o.x, -o.y, -o.z)
1690
+ c.sprite(*@sprites)
1691
+ end
1692
+ end
1693
+
1317
1694
  end# SpriteWorld
1318
1695
 
1319
1696
 
@@ -1333,6 +1710,7 @@ module RubySketch
1333
1710
  @pointerPrev = nil
1334
1711
  @pointersPressed = []
1335
1712
  @pointersReleased = []
1713
+ @pointerOver = false
1336
1714
  @touches = []
1337
1715
 
1338
1716
  self.shape = shape.getInternal__ if shape
@@ -1341,7 +1719,8 @@ module RubySketch
1341
1719
 
1342
1720
  attr_accessor :update,
1343
1721
  :mousePressed, :mouseReleased, :mouseMoved, :mouseDragged,
1344
- :mouseClicked, :mouseWheel, :touchStarted, :touchEnded, :touchMoved,
1722
+ :mouseClicked, :mouseOver, :mouseOut, :mouseWheel,
1723
+ :touchStarted, :touchEnded, :touchMoved,
1345
1724
  :keyPressed, :keyReleased, :keyTyped,
1346
1725
  :contact, :contactEnd, :willContact
1347
1726
 
@@ -1375,6 +1754,10 @@ module RubySketch
1375
1754
  ((@pointersPressed + @pointersReleased) & MOUSE_BUTTONS).last
1376
1755
  end
1377
1756
 
1757
+ def mouseOver?()
1758
+ @pointerOver
1759
+ end
1760
+
1378
1761
  def clickCount()
1379
1762
  mouseClicked? ? 1 : 0
1380
1763
  end
@@ -1420,6 +1803,17 @@ module RubySketch
1420
1803
  on_pointer_up e
1421
1804
  end
1422
1805
 
1806
+ def on_pointer_enter(e)
1807
+ updatePointerStates e
1808
+ @pointerOver = true
1809
+ callBlock @mouseOver
1810
+ end
1811
+
1812
+ def on_pointer_leave(e)
1813
+ @pointerOver = false
1814
+ callBlock @mouseOut
1815
+ end
1816
+
1423
1817
  def on_wheel(e)
1424
1818
  callBlock @mouseWheel, WheelEvent.new(e)
1425
1819
  end