rubysketch 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog.md +12 -0
- data/VERSION +1 -1
- data/lib/rubysketch/processing.rb +85 -38
- data/lib/rubysketch/window.rb +5 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f63f771b469d060307fa88a2992cc373c2439cec8facf531984533303f0a023
|
4
|
+
data.tar.gz: 5787db4cf63408b746fb538a6a612c2b90f440e08c1ded38b382b69200d372c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1bcb9bfe5d0f1732c7e44a509d8c5e83b5b84f28bb988fe3e4d9083cb342b6fc4cb44df48c0f176a18599cfd334583e808db41dadb377ac5c78436ed55533c29
|
7
|
+
data.tar.gz: ac78631d29b3843a32f376b7330011477523e33f40b1adb5d40dc1a66335bc294fdf91720146194b016497e4444b9531dbdc9529723c936c939c518df343c671
|
data/ChangeLog.md
CHANGED
@@ -1,6 +1,18 @@
|
|
1
1
|
# RubySketch ChangeLog
|
2
2
|
|
3
3
|
|
4
|
+
## [0.3.1] - 2020-07-17
|
5
|
+
|
6
|
+
- add touchStarted(), touchEnded(), touchMoved() and touches()
|
7
|
+
- make all event handler drawable
|
8
|
+
- limit font max size to 256
|
9
|
+
|
10
|
+
|
11
|
+
## [0.3.0] - 2020-05-21
|
12
|
+
|
13
|
+
- add createGraphics()
|
14
|
+
|
15
|
+
|
4
16
|
## [0.2.7] - 2020-04-17
|
5
17
|
|
6
18
|
- add strokeCap() and strokeJoin()
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.1
|
@@ -143,6 +143,30 @@ module RubySketch
|
|
143
143
|
end# TextBounds
|
144
144
|
|
145
145
|
|
146
|
+
# Touch object.
|
147
|
+
#
|
148
|
+
class Touch
|
149
|
+
|
150
|
+
# Horizontal position of touch
|
151
|
+
#
|
152
|
+
attr_reader :x
|
153
|
+
|
154
|
+
# Vertical position of touch
|
155
|
+
#
|
156
|
+
attr_reader :y
|
157
|
+
|
158
|
+
# @private
|
159
|
+
def initialize (x, y)
|
160
|
+
@x, @y = x, y
|
161
|
+
end
|
162
|
+
|
163
|
+
def id ()
|
164
|
+
raise NotImplementedError
|
165
|
+
end
|
166
|
+
|
167
|
+
end# Touch
|
168
|
+
|
169
|
+
|
146
170
|
# Drawing context
|
147
171
|
#
|
148
172
|
module GraphicsContext
|
@@ -479,26 +503,32 @@ module RubySketch
|
|
479
503
|
# Sets font.
|
480
504
|
#
|
481
505
|
# @param name [String] font name
|
482
|
-
# @param size [Numeric] font size
|
506
|
+
# @param size [Numeric] font size (max 256)
|
483
507
|
#
|
484
508
|
# @return [Font] current font
|
485
509
|
#
|
486
510
|
def textFont (name = nil, size = nil)
|
487
|
-
|
511
|
+
setFont__ name, size if name || size
|
488
512
|
Font.new @painter__.font
|
489
513
|
end
|
490
514
|
|
491
515
|
# Sets text size.
|
492
516
|
#
|
493
|
-
# @param size [Numeric] font size
|
517
|
+
# @param size [Numeric] font size (max 256)
|
494
518
|
#
|
495
519
|
# @return [nil] nil
|
496
520
|
#
|
497
521
|
def textSize (size)
|
498
|
-
|
522
|
+
setFont__ @painter__.font.name, size
|
499
523
|
nil
|
500
524
|
end
|
501
525
|
|
526
|
+
# @private
|
527
|
+
def setFont__ (name, size)
|
528
|
+
size = 256 if size && size > 256
|
529
|
+
@painter__.font name, size
|
530
|
+
end
|
531
|
+
|
502
532
|
# Clears screen.
|
503
533
|
#
|
504
534
|
# @overload background(str)
|
@@ -1262,11 +1292,10 @@ module RubySketch
|
|
1262
1292
|
@loop__ = true
|
1263
1293
|
@redraw__ = false
|
1264
1294
|
@frameCount__ = 0
|
1265
|
-
@
|
1266
|
-
@
|
1267
|
-
@mousePrevX__ =
|
1268
|
-
@mousePrevY__ = 0
|
1295
|
+
@mousePos__ =
|
1296
|
+
@mousePrevPos__ = Rays::Point.new 0
|
1269
1297
|
@mousePressed__ = false
|
1298
|
+
@touches__ = []
|
1270
1299
|
|
1271
1300
|
@window__ = window
|
1272
1301
|
@image__ = @window__.canvas
|
@@ -1274,58 +1303,53 @@ module RubySketch
|
|
1274
1303
|
|
1275
1304
|
@painter__.miter_limit = 10
|
1276
1305
|
|
1277
|
-
|
1306
|
+
@window__.before_draw = proc {beginDraw}
|
1307
|
+
@window__.after_draw = proc {endDraw}
|
1308
|
+
|
1309
|
+
drawFrame = -> {
|
1278
1310
|
@image__ = @window__.canvas
|
1279
1311
|
@painter__ = @window__.canvas_painter
|
1280
1312
|
begin
|
1281
1313
|
push
|
1282
|
-
@drawBlock__.call
|
1314
|
+
@drawBlock__.call if @drawBlock__
|
1283
1315
|
ensure
|
1284
1316
|
pop
|
1285
1317
|
@frameCount__ += 1
|
1286
1318
|
end
|
1287
1319
|
}
|
1288
1320
|
|
1289
|
-
updateMouseState = -> x, y, pressed = nil {
|
1290
|
-
@mouseX__ = x
|
1291
|
-
@mouseY__ = y
|
1292
|
-
@mousePressed__ = pressed if pressed != nil
|
1293
|
-
}
|
1294
|
-
|
1295
|
-
updateMousePrevPos = -> {
|
1296
|
-
@mousePrevX__ = @mouseX__
|
1297
|
-
@mousePrevY__ = @mouseY__
|
1298
|
-
}
|
1299
|
-
|
1300
|
-
@window__.before_draw = proc {beginDraw}
|
1301
|
-
@window__.after_draw = proc {endDraw}
|
1302
|
-
|
1303
1321
|
@window__.draw = proc do |e|
|
1304
1322
|
if @loop__ || @redraw__
|
1305
1323
|
@redraw__ = false
|
1306
|
-
drawFrame.call
|
1324
|
+
drawFrame.call
|
1307
1325
|
end
|
1308
|
-
|
1326
|
+
@mousePrevPos__ = @mousePos__
|
1309
1327
|
end
|
1310
1328
|
|
1329
|
+
updatePointerStates = -> event, pressed = nil {
|
1330
|
+
@mousePos__ = event.pos
|
1331
|
+
@mousePressed__ = pressed if pressed != nil
|
1332
|
+
@touches__ = event.positions.map {|pos| Touch.new pos.x, pos.y}
|
1333
|
+
}
|
1334
|
+
|
1311
1335
|
@window__.pointer_down = proc do |e|
|
1312
|
-
|
1313
|
-
@
|
1336
|
+
updatePointerStates.call e, true
|
1337
|
+
(@touchStartedBlock__ || @mousePressedBlock__)&.call
|
1314
1338
|
end
|
1315
1339
|
|
1316
1340
|
@window__.pointer_up = proc do |e|
|
1317
|
-
|
1318
|
-
@
|
1341
|
+
updatePointerStates.call e, false
|
1342
|
+
(@touchEndedBlock__ || @mouseReleasedBlock__)&.call
|
1319
1343
|
end
|
1320
1344
|
|
1321
1345
|
@window__.pointer_move = proc do |e|
|
1322
|
-
|
1323
|
-
@
|
1346
|
+
updatePointerStates.call e
|
1347
|
+
(@touchMovedBlock__ || @mouseMovedBlock__)&.call
|
1324
1348
|
end
|
1325
1349
|
|
1326
1350
|
@window__.pointer_drag = proc do |e|
|
1327
|
-
|
1328
|
-
@
|
1351
|
+
updatePointerStates.call e
|
1352
|
+
(@touchMovedBlock__ || @mouseDraggedBlock__)&.call
|
1329
1353
|
end
|
1330
1354
|
end
|
1331
1355
|
|
@@ -1368,6 +1392,21 @@ module RubySketch
|
|
1368
1392
|
nil
|
1369
1393
|
end
|
1370
1394
|
|
1395
|
+
def touchStarted (&block)
|
1396
|
+
@touchStartedBlock__ = block if block
|
1397
|
+
nil
|
1398
|
+
end
|
1399
|
+
|
1400
|
+
def touchEnded (&block)
|
1401
|
+
@touchEndedBlock__ = block if block
|
1402
|
+
nil
|
1403
|
+
end
|
1404
|
+
|
1405
|
+
def touchMoved (&block)
|
1406
|
+
@touchMovedBlock__ = block if block
|
1407
|
+
nil
|
1408
|
+
end
|
1409
|
+
|
1371
1410
|
# @private
|
1372
1411
|
private def size__ (width, height)
|
1373
1412
|
raise 'size() must be called on startup or setup block' if @started__
|
@@ -1416,7 +1455,7 @@ module RubySketch
|
|
1416
1455
|
# @return [Numeric] horizontal position of mouse
|
1417
1456
|
#
|
1418
1457
|
def mouseX ()
|
1419
|
-
@
|
1458
|
+
@mousePos__.x
|
1420
1459
|
end
|
1421
1460
|
|
1422
1461
|
# Returns mouse y position
|
@@ -1424,7 +1463,7 @@ module RubySketch
|
|
1424
1463
|
# @return [Numeric] vertical position of mouse
|
1425
1464
|
#
|
1426
1465
|
def mouseY ()
|
1427
|
-
@
|
1466
|
+
@mousePos__.y
|
1428
1467
|
end
|
1429
1468
|
|
1430
1469
|
# Returns mouse x position in previous frame
|
@@ -1432,7 +1471,7 @@ module RubySketch
|
|
1432
1471
|
# @return [Numeric] horizontal position of mouse
|
1433
1472
|
#
|
1434
1473
|
def pmouseX ()
|
1435
|
-
@
|
1474
|
+
@mousePrevPos__.x
|
1436
1475
|
end
|
1437
1476
|
|
1438
1477
|
# Returns mouse y position in previous frame
|
@@ -1440,7 +1479,15 @@ module RubySketch
|
|
1440
1479
|
# @return [Numeric] vertical position of mouse
|
1441
1480
|
#
|
1442
1481
|
def pmouseY ()
|
1443
|
-
@
|
1482
|
+
@mousePrevPos__.y
|
1483
|
+
end
|
1484
|
+
|
1485
|
+
# Returns array of touches
|
1486
|
+
#
|
1487
|
+
# @return [Array] Touch objects
|
1488
|
+
#
|
1489
|
+
def touches ()
|
1490
|
+
@touches__
|
1444
1491
|
end
|
1445
1492
|
|
1446
1493
|
# Enables calling draw block on every frame.
|
data/lib/rubysketch/window.rb
CHANGED
@@ -42,12 +42,12 @@ module RubySketch
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def on_draw (e)
|
45
|
-
draw_canvas {call_block @draw, e}
|
45
|
+
draw_canvas {call_block @draw, e} if @draw
|
46
46
|
e.painter.image @canvas
|
47
47
|
end
|
48
48
|
|
49
49
|
def on_key (e)
|
50
|
-
call_block @key, e
|
50
|
+
draw_canvas {call_block @key, e} if @key
|
51
51
|
end
|
52
52
|
|
53
53
|
def on_pointer (e)
|
@@ -56,16 +56,16 @@ module RubySketch
|
|
56
56
|
when :up then @pointer_up
|
57
57
|
when :move then e.drag? ? @pointer_drag : @pointer_move
|
58
58
|
end
|
59
|
-
call_block block, e if block
|
59
|
+
draw_canvas {call_block block, e} if block
|
60
60
|
end
|
61
61
|
|
62
62
|
def on_motion (e)
|
63
|
-
call_block @motion, e
|
63
|
+
draw_canvas {call_block @motion, e} if @motion
|
64
64
|
end
|
65
65
|
|
66
66
|
def on_resize (e)
|
67
67
|
reset_canvas e.width, e.height if @auto_resize
|
68
|
-
call_block @resize, e
|
68
|
+
draw_canvas {call_block @resize, e} if @resize
|
69
69
|
end
|
70
70
|
|
71
71
|
private
|
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.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- xordog
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-07-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: yard
|