Hi Alex,
While the "snap to grid" might be complicated I thought of simpler solution that might be achievable purely at Roassal level without the need to change Trachel classes. You can look at Umlet, since I am trying to copy it's grid behavior here.
Basically you don't move objects with mouse immediately but only after fixed increments. However I've encountered a problem with TRMouseDragging>>step, since I would probably need to continuously sum the individual steps and then reset them when dragging has started.
Here is a _very_ crude prototype:
---------------------
"i subclassed��RTDraggable and changed initializeElement: method as follows"
initializeElement: element
| sum gridSize |
gridSize := 20.
sum := 0 @ 0.
element
when: TRMouseDragging
do: [ :e |��
| d t |
t := RTGroup withAll: groupToDrag.
(t includes: element)
ifFalse: [ t add: element ].
d := element view canvas camera distanceFromPixelToSpace: e step.
sum := sum + d.
"move element only in increments of gridSize"
d := gridSize * ((sum x / gridSize) truncated @ (sum y / gridSize) truncated).
sum := sum - d.
t translateBy: d.
e signalUpdate ]
---------------------
and here is a demo utilizing it
-----------------------------
| v e1 e2 line gridSize ��b1 b2 b3 b4 edge |
v := RTView new.
"draw grid"
gridSize := 20.
(-20 to: 20) do: [ :i |
b1 := RTBox element.
b2 := RTBox element.
b3 := RTBox element.
b4 := RTBox element.
b1 translateTo: (i * gridSize) @ -1000. "top side"
b2 translateTo: (i * gridSize) @ 1000. "bottom side"
b3 translateTo: -1000 @ (i * gridSize). "left side"
b4 translateTo: 1000 @ (i * gridSize). "right side"
"vertical line"
edge := RTLine edgeFrom: b1 to: b2.
v add: edge.
"horizontal line"
edge := RTLine edgeFrom: b3 to: b4.
v add: edge.
].
e1 := (RTEllipse new size: 30; color: Color magenta) element.
e1 translateTo: -20 @ 0.
e1 @ RGGridDraggable.
e2 := (RTEllipse new size: 30; color: Color magenta) element.
e2 translateTo: 20 @ 0.
e2 @ RGGridDraggable.
(line := RTLine edgeFrom: e1 to: e2) shape color:Color black.
v add: e1; add: e2; add: line.
v open.
-----------------------------
Obviously it needs a lot of fine-tuning and such. Since RTInteraction (RTDraggable) instances are not created directly the gridSize would have to be stored probably class side. Also there is a problem with resetting the "sum" variable when dragging starts. (There is no TRMouseDragStart event as far as I've seen). And also drawing the grid itself the way I've done is very brutal and doesn't really work if I want to move the canvas camera (perhaps image pattern as a background would work better).
What are your thoughts on this?
Peter