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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1b533b526c3036bd4871bd65fb8290c7940edadd27093997eeafd6dd1b9da764
4
- data.tar.gz: 720f44a65ebdd583408e11bd2538c57023f4d862e81b9a87bc8fa063f7712e02
3
+ metadata.gz: ecd5ec0962a23e7eb820a5e46386c608707a5c1aa1bf5dfc85d259b94977ab60
4
+ data.tar.gz: cce9e032a47c4bc7ca2eb29e89b943e57ed908677ce0e203b7f5a3f93f0dbc0e
5
5
  SHA512:
6
- metadata.gz: 2d0c784f1ef2a3fe4a9900e9f0d340b69f9b9d2d578a68e99d36b845f15b0ece63a4c5a8ac895c4c490466d76c68ffc77ef725ffcaa550740d83111053951eab
7
- data.tar.gz: 53a22ec28deaa9fd2f0852697f9f5a395c73ac5cc4999d9bd0502969a7f62ace94f65133d5091d336da923617d2962f2b0d816bdcb0b402e1b221197fab41b19
6
+ metadata.gz: 51b383f6ff282e6e0dc6085ff6f1c486e195c10adbd769d96e284bcd6db31bbf600570c88ed7832f6f00ffc46876f97b7552a836c9ebe54682c62c36313239c0
7
+ data.tar.gz: ea9389beabc45a478f37870be2192e31310c085ec64086e54c8068267b1f32a5eaeebfea47ff4400fd8c583373ab56fc4db7307ded178d86ef009df3325f8bec
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -268,21 +268,20 @@ class R2dSvg
268
268
 
269
269
  def draw_polygon(args)
270
270
 
271
- points, style, e = args
271
+ vertices, style, e = args
272
272
 
273
- puts ('points: ' + points.inspect).debug if @debug
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 ('coords: ' + coords.inspect).debug if @debug
280
+ puts ('vertices: ' + vertices.inspect).debug if @debug
282
281
 
283
- h = coords.map.with_index do |c2,i|
282
+ h = vertices.map.with_index do |coords,i|
284
283
 
285
- %w(x y).zip(c2).map {|key, c| [(key + (i+1).to_s).to_sym, c] }
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) {|event| mouse(:move, event) }
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
- mouse :down, event if event.button == :left
448
- end
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("//*[@onmouse#{action}]").each do |x|
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
- eval x.method(('onmouse' + action.to_s).to_sym).call()
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
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: r2dsvg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
metadata.gz.sig CHANGED
Binary file