Getting notified when a morph moves

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

Getting notified when a morph moves

Stephan Eggermont-3
I'm trying to keep a line morph connected between two morphs
while moving one of them.
When I add the morph to the hand and start dragging the morph
no longer receives mouseMove:. I can think of several ways to get  
position updates. Is there a best/easy way?

Stephan

Reply | Threaded
Open this post in threaded view
|

Re: Getting notified when a morph moves

Aliaksei Syrel
Hi,

I think you need to subscribe to the hand morph. It provides some possibilities. Of course if you drag morphs only inside it's parent, you can implement dragging by yourself without adding to hand. In this case mouseMove can be received.

Cheers,
Alex

On Wed, Feb 11, 2015 at 9:19 PM, Stephan Eggermont <[hidden email]> wrote:
I'm trying to keep a line morph connected between two morphs
while moving one of them.
When I add the morph to the hand and start dragging the morph
no longer receives mouseMove:. I can think of several ways to get
position updates. Is there a best/easy way?

Stephan


Reply | Threaded
Open this post in threaded view
|

Re: Getting notified when a morph moves

HilaireFernandes
In reply to this post by Stephan Eggermont-3
Le 11/02/2015 21:19, Stephan Eggermont a écrit :
> I'm trying to keep a line morph connected between two morphs
> while moving one of them.
> When I add the morph to the hand and start dragging the morph
> no longer receives mouseMove:. I can think of several ways to get  
> position updates. Is there a best/easy way?
>
> Stephan
>
>
I tried something like bellow but it did not produced any output in the
transcript.
Only "b doAnnounce: MorphChanged" produce an output in the Transcript.
Not sure how to get an anonymous morph to announce changes.

| b |
b := BorderedMorph new color: Color red.
b onAnnouncement: MorphChanged do: [ Transcript show: 'Changed' ].
b openInWorld


--
Dr. Geo - http://drgeo.eu
iStoa - http://istoa.drgeo.eu



Reply | Threaded
Open this post in threaded view
|

Re: Getting notified when a morph moves

HilaireFernandes
In reply to this post by Stephan Eggermont-3
Hi,

Here is an implementation example.
From a workspace, do:

| morphA morphB follower |
morphA := Morph new position: 10@10.
morphB := Morph new position: 100@100.
follower := FollowerLineMoprh from: morphA to: morphB.
morphA openInWorld.
morphB openInWorld.
follower openInWorld.


Frankly I don't like the idea to subscribe to the HandMorph, because at
each mouse move event, you have to check for the morph A and B if they
move. It is a waste of CPU cycles.
Ideally you will want receive event from morph A and B whenever they
changed. I am surious to know if it is possible.

Thanks

Hilaire

Le 11/02/2015 21:19, Stephan Eggermont a écrit :
> I'm trying to keep a line morph connected between two morphs
> while moving one of them.
> When I add the morph to the hand and start dragging the morph
> no longer receives mouseMove:. I can think of several ways to get  
> position updates. Is there a best/easy way?
>
> Stephan
>
>


--
Dr. Geo - http://drgeo.eu
iStoa - http://istoa.drgeo.eu


FollowerLineMoprh.st (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Getting notified when a morph moves

Stephan Eggermont-3



On 12/02/15 10:20, Hilaire wrote:
> Frankly I don't like the idea to subscribe to the HandMorph, because at
> each mouse move event, you have to check for the morph A and B if they
> move. It is a waste of CPU cycles.
> Ideally you will want receive event from morph A and B whenever they
> changed. I am surious to know if it is possible.

Thanks Hilaire,

This works for me. I can attach the listener when the dragging starts,
and detach it when it stops. That should do.

Stephan




Reply | Threaded
Open this post in threaded view
|

Re: Getting notified when a morph moves

Stephan Eggermont-3
In reply to this post by Stephan Eggermont-3
Thanks Hilaire,

that works fine. I can add the listener when the actual dragging starts and remove it
on mouseUp.

MDShape>>doDrag: aMouseMoveEvent with: aMDShape
        ActiveHand addEventListener: self.
        aMouseMoveEvent hand startDrag: aMouseMoveEvent with: aMDShape.

MDShape>>handleListenEvent: anEvent
        anEvent isMouse ifFalse: [ ^self].
        anEvent isMouseUp ifTrue: [ ActiveHand removeEventListener: self ].
        anEvent isMouseMove ifTrue: [ self moved ]

MDShape>>moved
        connectors do: [ :connector | connector moved ]

Stephan
Reply | Threaded
Open this post in threaded view
|

Re: Getting notified when a morph moves

HilaireFernandes
In reply to this post by Stephan Eggermont-3
Le 12/02/2015 11:04, Stephan Eggermont a écrit :
>
> This works for me. I can attach the listener when the dragging starts,
> and detach it when it stops. That should do.

Okay if I understand correctly, the two morphs you want to link with a
line are also morphs of yours? So you can mangle into them. I was
supposing the two morphs to link could be arbitrary ones, i.e. ones you
can't modify.


--
Dr. Geo - http://drgeo.eu
iStoa - http://istoa.drgeo.eu



Reply | Threaded
Open this post in threaded view
|

Re: Getting notified when a morph moves

Stephan Eggermont-3
In reply to this post by Stephan Eggermont-3
Hilaire wrote:
>Okay if I understand correctly, the two morphs you want to link with a
>line are also morphs of yours? So you can mangle into them. I was
>supposing the two morphs to link could be arbitrary ones, i.e. ones you
>can't modify.

I am trying to get a better understanding of Morphic by writing a
small drawing editor suitable for a tutorial.

current state:
http://smalltalkhub.com/#!/~StephanEggermont/MorphicDraw/

Stephan

Reply | Threaded
Open this post in threaded view
|

Re: Getting notified when a morph moves

HilaireFernandes
Le 12/02/2015 17:12, Stephan Eggermont a écrit :

> Hilaire wrote:
>> Okay if I understand correctly, the two morphs you want to link with a
>> line are also morphs of yours? So you can mangle into them. I was
>> supposing the two morphs to link could be arbitrary ones, i.e. ones you
>> can't modify.
> I am trying to get a better understanding of Morphic by writing a
> small drawing editor suitable for a tutorial.
>
> current state:
> http://smalltalkhub.com/#!/~StephanEggermont/MorphicDraw/
>
> Stephan
>
>

Nice :)
You may find some useful information in the collaboractive book in the
Morph chapter
http://pharo.gemtalksystems.com

Hilarie

--
Dr. Geo - http://drgeo.eu
iStoa - http://istoa.drgeo.eu