Advertisement
Guest User

Untitled

a guest
Aug 13th, 2014
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. | v e1 e2 e ctrlShape ctrls ctrl shape  addBlock |
  2. v := RTView new.
  3.  
  4. e1 := (RTEllipse new size: 30) elementOn: 'A'.
  5. e2 := (RTEllipse new size: 30) elementOn: 'B'.
  6.  
  7. ctrlShape := RTEllipse new size: 10; color: (Color purple alpha: 0.3).
  8. "collection holding all control points INCLUDING starting & ending"
  9. ctrls := (ctrlShape elementsOn: (1 to: 2)).
  10.  
  11. v
  12.     add: e1;
  13.     add: e2;
  14.     addAll: ctrls.
  15. v elements @ RTDraggable.
  16.  
  17. e := REEdge from: e1 to: e2.
  18.  
  19. ctrls do: [ :el | el addConnectedEdge: e ].
  20.  
  21. ctrls
  22.     addFirst: e1;
  23.     addLast: e2.
  24.  
  25. ctrls @ (RTLabelled new text: [ :el | el ]).
  26.  
  27. shape := RTMultiLine new color: Color blue.
  28. shape block: [ :fromPoint :toPoint |
  29.     | points |
  30.     points := ctrls collect: [ :el | el position ].
  31.     points asArray.
  32. ].
  33.  
  34. ctrls first translateBy: -50 @ 100.
  35. ctrls second translateBy: -50 @ 0.
  36. ctrls third translateBy: 50 @ 0.
  37. ctrls fourth translateBy: 50 @ 100.
  38.  
  39. e + shape.
  40.  
  41. v add: e.
  42. e trachelShape pushBack.
  43.  
  44. v open.
  45.  
  46. ctrls inspect.
  47.  
  48. addBlock := [ :point |
  49.     | index |
  50.     "find between which control points are we adding a new one"
  51.     index := (2 to: ctrls size) detect: [ :i |
  52.         | fromPoint toPoint |
  53.         fromPoint := (ctrls at: (i - 1)) position.
  54.         toPoint := (ctrls at: i) position.
  55.         point onLineFrom: fromPoint to: toPoint.
  56.     ].
  57.    
  58.    
  59.     ctrl := ctrlShape elementOn: 'X'.
  60.     v add: ctrl.
  61.     ctrl @ RTDraggable.
  62.     ctrl addConnectedEdge: e.
  63.     ctrl @ (RTLabelled new text: [:el | el ]).
  64.     ctrl translateBy: point.
  65.     ctrls add: ctrl beforeIndex: index.
  66.    
  67.     shape block: [ :fromPoint :toPoint |
  68.         | points |
  69.         points := ctrls collect: [ :el | el position ].
  70.         points asArray.
  71.     ].
  72.  
  73.     "reset all the things"
  74.     v removeEdge: e.
  75.     e resetShape.
  76.     v add: e.
  77.     e trachelShape pushBack.
  78.     v signalUpdate.
  79. ].
  80.  
  81. e when: TRMouseRightClick do: [ :event |
  82.     addBlock value: event position.
  83. ].
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement