Hi Peter,

How things are going with having a snapOnGrid behavior?

Cheers,
Alexandre
-- 
_,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:
Alexandre Bergel  http://www.bergel.eu
^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.



On Aug 1, 2014, at 2:36 PM, Peter Uhnák <i.uh...@gmail.com> wrote:

> 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
> 
> 
> 
> 
> On Fri, Aug 1, 2014 at 4:07 PM, Alexandre Bergel <alexandre.ber...@me.com> 
> wrote:
> Hi Peter!
> 
> > While playing with RTMultiLine I thought that it would be nice to have 
> > option for RTDraggable elements to snap to a grid / move only by fixed 
> > increments - for example the position could only be divisible by 10 (grid 
> > size would be 10), so dragging from 20@10 to 26@4 would jump to 30@0. Is 
> > something like this possible with current implementation?
> 
> 
> I first thought this would be easy. But actually it is not.
> The way to achieve the snap on grid behavior is to have an indirection in the 
> Trachel classes. Each trachel shape knows its position (the position is 
> contained in the matrix attached to each shape). The snap-on-grid means you 
> need to slightly process the matrix coordinate. Maybe there are other way to 
> do this, but it does not look like. Changing Trachel because of this seems a 
> bit overkill...
> 
> Cheers,
> Alexandre
> --
> _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:
> Alexandre Bergel  http://www.bergel.eu
> ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.
> 
> 
> 
> On Jul 31, 2014, at 3:58 PM, Peter Uhnák <i.uh...@gmail.com> wrote:
> 
> > While playing with RTMultiLine I thought that it would be nice to have 
> > option for RTDraggable elements to snap to a grid / move only by fixed 
> > increments - for example the position could only be divisible by 10 (grid 
> > size would be 10), so dragging from 20@10 to 26@4 would jump to 30@0. Is 
> > something like this possible with current implementation?
> >
> > The second question is: is it possible for element to subscribe for 
> > position updates of another element? (I.e. element A watches for movement 
> > of element B and moves accordingly). I know I could add both of them to a 
> > composite shape or RTGroup (RTDraggable>>groupToDrag:), however I would 
> > prefer something more loosely coupled.
> >
> > In RTDraggable>>initializeElement: i found
> > "     element when: TRMouseDragging do: [ :e | e element translateBy: e 
> > step. e signalUpdate ]"
> > however it is commented out so perhaps there some other way?
> >
> > Peter
> 
> 
> 

Reply via email to