r2dsvg 0.4.0 → 0.4.1

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: 6da60aae210c67cdc2a6c908e0721ddcfc07a6b516fbdedb49fb8ba33736dd43
4
- data.tar.gz: 3a2735d01e9aaa4e319c4481ecce6d811fac9f7506086627865fe4a8be40a3c3
3
+ metadata.gz: 2b561aa931c1a66e2884576dea1525f9f3c77cb07b5757fb11081b8f807aaf91
4
+ data.tar.gz: 45a8bd9cca6d36ffb694c8c1337849ebfe4819fb0f06493799131a171a168a95
5
5
  SHA512:
6
- metadata.gz: 7370accf36a0322a26c0885f535f6fdc866fbbb65ff8f250d6a827d97251446fa716a71e2859a2f45873433f307001eaf78e48a491c5944fdacf04a3f8515cdc
7
- data.tar.gz: 390bb9e097fb6660f8bc6f73750dab72f6b92500a521c094bf92b103311744cb5d41e7671e590b6d62116a2115afdb278e96a129c7fd0f8a98cad84bbd5e42ac
6
+ metadata.gz: a117efd8624e7b97c7b35dc84fa10f4ed683841c86377c13c81c7c41fb8bc262d47ec178445333f173e6dade0a6d54ddbd7eb83f3743bc9129536166df76f5f2
7
+ data.tar.gz: cdb7a48f18fe178376f3b4331a969e1793d62863bc15bd6c1ce7cd47e9bba31fde0dfee99eec927284859066f88cb9aa69661e3c102a549ea242723a6a711a42
checksums.yaml.gz.sig CHANGED
Binary file
data/lib/r2dsvg.rb CHANGED
@@ -34,6 +34,20 @@ module SvgleX
34
34
 
35
35
  end
36
36
 
37
+ refine Svgle::Text do
38
+
39
+ def text=(raw_s)
40
+
41
+ oldval = @child_elements.first
42
+
43
+ r = super(raw_s)
44
+ self.obj.text = raw_s if oldval != raw_s
45
+
46
+ return r
47
+
48
+ end
49
+ end
50
+
37
51
  end
38
52
 
39
53
  class R2dSvg
@@ -346,6 +360,7 @@ class R2dSvg
346
360
  color: style[:color],
347
361
  z: style[:"z-index"].to_i
348
362
  )
363
+ puts 'e: ' + e.inspect
349
364
  e.obj = obj
350
365
  @window.add obj
351
366
 
@@ -401,11 +416,11 @@ class R2dSvg
401
416
 
402
417
  def draw(a)
403
418
 
404
- threads = []
419
+ #threads = []
405
420
 
406
421
  a.each do |rawx|
407
422
 
408
- threads << Thread.new do
423
+ #threads << Thread.new do
409
424
  x, *remaining = rawx
410
425
 
411
426
  if x.is_a? Symbol then
@@ -417,11 +432,11 @@ class R2dSvg
417
432
  else
418
433
  method(x).call(remaining.take 2)
419
434
  end
420
- end
435
+ #end
421
436
 
422
437
  end
423
438
 
424
- threads.join
439
+ #threads.join
425
440
 
426
441
  end
427
442
 
@@ -434,35 +449,62 @@ class R2dSvg
434
449
  @debug = debug
435
450
 
436
451
  @window = window = Window.new
452
+ @loaded = false
437
453
 
438
- @doc = read(s, title)
454
+ read(s, title)
439
455
 
440
456
  drb = OneDrb::Server.new host: '127.0.0.1', port: '57844', obj: self
441
457
  Thread.new { drb.start }
442
458
 
443
- window.on(:mouse_move) do |event|
444
- mouse :mousemove, event
445
- mouse :mouseenter, event
446
- end
447
-
448
- window.on(:mouse_down) do |event|
459
+ if @loaded then
460
+
461
+ window.on(:mouse_move) do |event|
462
+ mouse :mousemove, event
463
+ mouse :mouseenter, event
464
+ end
449
465
 
450
- if event.button == :left then
466
+ window.on(:mouse_down) do |event|
467
+
468
+ if event.button == :left then
469
+
470
+ # click and mousedown do the same thing
471
+ mouse :click, event
472
+ mouse :mousedown, event
473
+ end
451
474
 
452
- # click and mousedown do the same thing
453
- mouse :click, event
454
- mouse :mousedown, event
475
+ end
476
+
477
+ window.on :key_down do |event|
478
+ # A key was pressed
479
+ keyboard :keydown, event
455
480
  end
456
481
 
457
- end
458
-
482
+ end
483
+ =begin
484
+ window.on :key_held do |event|
485
+ # A key is being held down
486
+ puts event.key
487
+ keyboard :onkeyheld, event
488
+ end
489
+
490
+ window.on :key_up do |event|
491
+ # A key was released
492
+ puts event.key
493
+ keyboard :onkeyup, event
494
+ end
495
+ =end
459
496
  window.show
460
497
 
461
498
 
462
499
  end
463
500
 
501
+ def clear()
502
+ @window.clear
503
+ end
504
+
464
505
  def read(s, title=@title)
465
-
506
+ @loaded = false
507
+ @window.clear
466
508
  svg, _ = RXFHelper.read(s)
467
509
  doc = Svgle.new(svg, callback: self, debug: @debug)
468
510
  instructions = Render.new(doc, debug: @debug).to_a
@@ -478,14 +520,38 @@ class R2dSvg
478
520
  doc.root.xpath('//script').each {|x| eval x.text.unescape }
479
521
  drawing.render instructions
480
522
  end
481
-
482
- doc
523
+
524
+ @loaded = true
525
+ @doc = doc
483
526
 
484
527
  end
485
528
 
486
529
 
487
530
  private
488
531
 
532
+ def keyboard(action, event)
533
+
534
+ doc = @doc
535
+
536
+ @doc.root.xpath("//*[@on#{action}]").each do |x|
537
+
538
+ if block_given? then
539
+ valid = yield(x)
540
+ statement = x.method(('on' + action.to_s).to_sym).call()
541
+ puts 'statement: ' + statement.inspect if @debug
542
+ eval statement if valid
543
+ else
544
+ statement = x.method(('on' + action.to_s).to_sym).call()
545
+ puts 'statement: ' + statement.inspect if @debug
546
+ eval statement
547
+ end
548
+
549
+ end
550
+
551
+ @doc.event[action].each {|name| method(name).call event.key }
552
+
553
+ end
554
+
489
555
  def mouse(action, event)
490
556
 
491
557
  doc = @doc
data.tar.gz.sig CHANGED
Binary file
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.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
metadata.gz.sig CHANGED
Binary file