r2dsvg 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/r2dsvg.rb +53 -13
- metadata +1 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ecd5ec0962a23e7eb820a5e46386c608707a5c1aa1bf5dfc85d259b94977ab60
|
4
|
+
data.tar.gz: cce9e032a47c4bc7ca2eb29e89b943e57ed908677ce0e203b7f5a3f93f0dbc0e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 51b383f6ff282e6e0dc6085ff6f1c486e195c10adbd769d96e284bcd6db31bbf600570c88ed7832f6f00ffc46876f97b7552a836c9ebe54682c62c36313239c0
|
7
|
+
data.tar.gz: ea9389beabc45a478f37870be2192e31310c085ec64086e54c8068267b1f32a5eaeebfea47ff4400fd8c583373ab56fc4db7307ded178d86ef009df3325f8bec
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/r2dsvg.rb
CHANGED
@@ -268,21 +268,20 @@ class R2dSvg
|
|
268
268
|
|
269
269
|
def draw_polygon(args)
|
270
270
|
|
271
|
-
|
271
|
+
vertices, style, e = args
|
272
272
|
|
273
|
-
puts ('
|
274
|
-
coords = points
|
273
|
+
puts ('vertices: ' + vertices.inspect).debug if @debug
|
275
274
|
|
276
275
|
if @debug then
|
277
276
|
puts 'inside draw_polygon'.info
|
278
277
|
puts ('style: ' + style.inspect).debug
|
279
278
|
end
|
280
279
|
|
281
|
-
puts ('
|
280
|
+
puts ('vertices: ' + vertices.inspect).debug if @debug
|
282
281
|
|
283
|
-
h =
|
282
|
+
h = vertices.map.with_index do |coords,i|
|
284
283
|
|
285
|
-
%w(x y).zip(
|
284
|
+
%w(x y).zip(coords).map {|key, c| [(key + (i+1).to_s).to_sym, c] }
|
286
285
|
|
287
286
|
end.flatten(1).to_h
|
288
287
|
puts ('triangle h: ' + h.inspect).debug if @debug
|
@@ -424,6 +423,7 @@ class R2dSvg
|
|
424
423
|
def initialize(svg, title: 'R2dSVG', debug: false)
|
425
424
|
|
426
425
|
@svg, @debug = svg, debug
|
426
|
+
|
427
427
|
doc = Svgle.new(svg, callback: self, debug: debug)
|
428
428
|
instructions = Render.new(doc, debug: debug).to_a
|
429
429
|
|
@@ -439,34 +439,74 @@ class R2dSvg
|
|
439
439
|
|
440
440
|
drawing.render instructions
|
441
441
|
|
442
|
-
@doc = doc
|
442
|
+
@doc = doc
|
443
443
|
|
444
|
-
window.on(:mouse_move)
|
444
|
+
window.on(:mouse_move) do |event|
|
445
|
+
mouse :mousemove, event
|
446
|
+
mouse :mouseenter, event
|
447
|
+
end
|
445
448
|
|
446
449
|
window.on(:mouse_down) do |event|
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
+
|
451
|
+
if event.button == :left then
|
452
|
+
|
453
|
+
# click and mousedown do the same thing
|
454
|
+
mouse :click, event
|
455
|
+
mouse :mousedown, event
|
456
|
+
end
|
457
|
+
|
458
|
+
end
|
450
459
|
|
451
460
|
window.show
|
452
461
|
end
|
453
462
|
|
463
|
+
|
454
464
|
private
|
455
465
|
|
456
466
|
def mouse(action, event)
|
457
467
|
|
458
468
|
doc = @doc
|
459
469
|
|
460
|
-
@doc.root.xpath("//*[@
|
470
|
+
@doc.root.xpath("//*[@on#{action}]").each do |x|
|
461
471
|
|
462
472
|
#puts 'x.class: ' + x.inspect if @debug
|
463
473
|
if x.obj and x.obj.contains? event.x, event.y then
|
464
|
-
|
474
|
+
|
475
|
+
|
476
|
+
if not x.active? then
|
477
|
+
x.active = true
|
478
|
+
elsif action == :mouseenter
|
479
|
+
next
|
480
|
+
end
|
481
|
+
|
482
|
+
if block_given? then
|
483
|
+
valid = yield(x)
|
484
|
+
eval x.method(('on' + action.to_s).to_sym).call() if valid
|
485
|
+
else
|
486
|
+
eval x.method(('on' + action.to_s).to_sym).call()
|
487
|
+
end
|
488
|
+
|
489
|
+
else
|
490
|
+
|
491
|
+
if x.active? then
|
492
|
+
x.active = false
|
493
|
+
onleave
|
494
|
+
end
|
465
495
|
end
|
466
496
|
|
467
497
|
end
|
468
498
|
|
469
499
|
end
|
500
|
+
|
501
|
+
def onleave()
|
502
|
+
|
503
|
+
@doc.root.xpath("//*[@onmouseleave]").each do |x|
|
504
|
+
puts 'onleave'.info if @debug
|
505
|
+
eval x.method(:onmouseleave).call()
|
506
|
+
end
|
507
|
+
|
508
|
+
end
|
509
|
+
|
470
510
|
end
|
471
511
|
|
472
512
|
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|