Morphic event-handling confusion

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

Morphic event-handling confusion

Max OrHai
I'm trying to use Morphic, in Squeak 3.9, to make a very simple "physics
model" I call a HockeyPuck. The idea is that it's a CircleMorph subclass
that one should be able to pick up with the Hand and "throw", and have
it bounce off the World edge (and then, hopefully, other such Pucks).
I've got the "step" animation thing figured out pretty well, and I have
some idea how to compute the motion and bounces and such, but I'm
stumped as to how to properly handle the mouse events. On Eddie
Cottongim's suggestion, at http://wiki.squeak.org/squeak/2477 , I tried
using  "self on: #startDrag send: #beginThrow to: self" (in my
initialize method) but that seems a little weird, and doesn't seem to
allow the default dragging behavior to go through. I also tried the
approach of overriding handlesMouseDown and mouseDown, and sending
"super mouseDown" in the latter, but that doesn't seem to work any
better, although it makes a little more sense to me.

There's a two-step sequence of messages I'd like my Puck to receive
while still doing the normal getting-moved-by-the-Hand stuff. The first
is #beginThrow, to be sent either on a mouseDown or (preferably) on a
startDrag event. The second is #endThrow, to be sent on the subsequent
mouseUp. How can I make this happen?

Thank you very much for your time.



_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Morphic event-handling confusion

Michael van der Gulik-3
Max OrHai wrote:

>I'm trying to use Morphic, in Squeak 3.9, to make a very simple "physics
>model" I call a HockeyPuck. The idea is that it's a CircleMorph subclass
>that one should be able to pick up with the Hand and "throw", and have
>it bounce off the World edge (and then, hopefully, other such Pucks).
>I've got the "step" animation thing figured out pretty well, and I have
>some idea how to compute the motion and bounces and such, but I'm
>stumped as to how to properly handle the mouse events. On Eddie
>Cottongim's suggestion, at http://wiki.squeak.org/squeak/2477 , I tried
>using  "self on: #startDrag send: #beginThrow to: self" (in my
>initialize method) but that seems a little weird, and doesn't seem to
>allow the default dragging behavior to go through. I also tried the
>approach of overriding handlesMouseDown and mouseDown, and sending
>"super mouseDown" in the latter, but that doesn't seem to work any
>better, although it makes a little more sense to me.
>
>There's a two-step sequence of messages I'd like my Puck to receive
>while still doing the normal getting-moved-by-the-Hand stuff. The first
>is #beginThrow, to be sent either on a mouseDown or (preferably) on a
>startDrag event. The second is #endThrow, to be sent on the subsequent
>mouseUp. How can I make this happen?
>  
>
Hi Max.

Firstly, I might just make the point that Morphic is a pain to work
with. I've often been at my wits end trying to work out what on earth it
is doing and how to get it to behave. You're not the only one.

I've just had a bit of a play around, and I think you'll want the
following six methods in your Puck morph:

handlesMouseDown: evt
    ^ true.

mouseDown: evt
    Transcript show: 'Mouse down'; cr.

handlesMouseStillDown: evt
    ^ true

mouseStillDown: evt
    self position: evt hand position.

handlesMouseUp: evt
    ^ true

mouseUp: evt
    Transcript show: 'Mouse up'; cr.

You can also define all the above methods using the "on:send:to:"
mechanism if you want.

Cheers,
Michael.
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Morphic event-handling confusion

Bert Freudenberg
On Mar 15, 2007, at 11:23 , Michael van der Gulik wrote:

> There's a two-step sequence of messages I'd like my Puck to receive
> while still doing the normal getting-moved-by-the-Hand stuff.

No go. You need to implement your mouse behavior on your own, using  
an event handler (#on:send:to:) or by overriding the mouse event  
methods. Only if you do neither (that is, your morph answers false to  
#handlesMouseDown), the default getting-moved-by-the-Hand kicks in.  
This is meant for authoring, not for actual usage.

Of course, implementing the "default" behavior in your morph is  
utterly trivial - send #attachMorph: or #grabMorph: to the event's hand.

- Bert -


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Morphic event-handling confusion

Max OrHai
In reply to this post by Michael van der Gulik-3
On Thu, 2007-03-15 at 23:23 +1300, Michael van der Gulik wrote:

> Firstly, I might just make the point that Morphic is a pain to work
> with. I've often been at my wits end trying to work out what on earth it
> is doing and how to get it to behave. You're not the only one.

Oh, I know that. :-) I've heard plenty of complaints about how arcane
Morphic is. I figure, it's the easiest way to do graphics programming in
Squeak. Given all that it does, of course it's complex.

> handlesMouseStillDown: evt
>     ^ true
>
> mouseStillDown: evt
>     self position: evt hand position.

These apparently don't do anything. But, that's OK, because I can, as
Bert suggested, just send "evt hand #grabMorph: self".

Except, oops, that's NOT OK, because now mouseUp: apparently never gets
sent to my Morph.

So, I still need help. Thank you both very much.


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Morphic event-handling confusion

Michael van der Gulik-3
Max OrHai wrote:

>  
>
>>handlesMouseStillDown: evt
>>    ^ true
>>
>>mouseStillDown: evt
>>    self position: evt hand position.
>>    
>>
>
>These apparently don't do anything. But, that's OK, because I can, as
>Bert suggested, just send "evt hand #grabMorph: self".
>
>Except, oops, that's NOT OK, because now mouseUp: apparently never gets
>sent to my Morph.
>
>So, I still need help. Thank you both very much.
>  
>
They "worked for me" - I was dragging a Morph around, and had readouts
for the start and end positions of the dragging. Try making a completely
fresh subclass of Morph with only the methods I suggested. I used Squeak
3.9.

If I was going to implement momentum, I'd take the current position on
mouseUp: and the position received by the very latest mouseStillDown:,
and work out which vector the puck should travel in from that. I suppose
you'd also need the times of those two events as well to calculate the
velocity vector.

Michael.
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Morphic event-handling confusion

Max OrHai
Thanks, I already got it working, which was in fact a very satisfying experience. My previous failure was using a "handlesMousedown" method, rather than "handlesMouseDown:evt" method. An important distinction.

Sent via BlackBerry from T-Mobile  

-----Original Message-----
From: Michael van der Gulik <[hidden email]>
Date: Sat, 17 Mar 2007 17:45:07
To:"A friendly place to get answers to even the most basic questions aboutSqueak." <[hidden email]>
Subject: Re: [Newbies] Morphic event-handling confusion

Max OrHai wrote:

>  
>
>>handlesMouseStillDown: evt
>>    ^ true
>>
>>mouseStillDown: evt
>>    self position: evt hand position.
>>    
>>
>
>These apparently don't do anything. But, that's OK, because I can, as
>Bert suggested, just send "evt hand #grabMorph: self".
>
>Except, oops, that's NOT OK, because now mouseUp: apparently never gets
>sent to my Morph.
>
>So, I still need help. Thank you both very much.
>  
>
They "worked for me" - I was dragging a Morph around, and had readouts
for the start and end positions of the dragging. Try making a completely
fresh subclass of Morph with only the methods I suggested. I used Squeak
3.9.

If I was going to implement momentum, I'd take the current position on
mouseUp: and the position received by the very latest mouseStillDown:,
and work out which vector the puck should travel in from that. I suppose
you'd also need the times of those two events as well to calculate the
velocity vector.

Michael.
_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners


_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: Morphic event-handling confusion

stephane ducasse
In reply to this post by Max OrHai
here is an example of drag and drop and repel :)



Have fun
On 15 mars 07, at 07:31, Max OrHai wrote:

> I'm trying to use Morphic, in Squeak 3.9, to make a very simple  
> "physics
> model" I call a HockeyPuck. The idea is that it's a CircleMorph  
> subclass
> that one should be able to pick up with the Hand and "throw", and have
> it bounce off the World edge (and then, hopefully, other such Pucks).
> I've got the "step" animation thing figured out pretty well, and I  
> have
> some idea how to compute the motion and bounces and such, but I'm
> stumped as to how to properly handle the mouse events. On Eddie
> Cottongim's suggestion, at http://wiki.squeak.org/squeak/2477 , I  
> tried
> using  "self on: #startDrag send: #beginThrow to: self" (in my
> initialize method) but that seems a little weird, and doesn't seem to
> allow the default dragging behavior to go through. I also tried the
> approach of overriding handlesMouseDown and mouseDown, and sending
> "super mouseDown" in the latter, but that doesn't seem to work any
> better, although it makes a little more sense to me.
>
> There's a two-step sequence of messages I'd like my Puck to receive
> while still doing the normal getting-moved-by-the-Hand stuff. The  
> first
> is #beginThrow, to be sent either on a mouseDown or (preferably) on a
> startDrag event. The second is #endThrow, to be sent on the subsequent
> mouseUp. How can I make this happen?
>
> Thank you very much for your time.
>
>
>
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners

DragAndDropRepel.3.cs (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Morphic event-handling confusion

stephane ducasse
In reply to this post by Max OrHai
could you sahre your result?
May be publish it on Squeaksource.com?

Stef
On 18 mars 07, at 07:27, [hidden email] wrote:

> Thanks, I already got it working, which was in fact a very  
> satisfying experience. My previous failure was using a  
> "handlesMousedown" method, rather than "handlesMouseDown:evt"  
> method. An important distinction.
>
> Sent via BlackBerry from T-Mobile
>
> -----Original Message-----
> From: Michael van der Gulik <[hidden email]>
> Date: Sat, 17 Mar 2007 17:45:07
> To:"A friendly place to get answers to even the most basic  
> questions aboutSqueak." <[hidden email]>
> Subject: Re: [Newbies] Morphic event-handling confusion
>
> Max OrHai wrote:
>
>>
>>
>>> handlesMouseStillDown: evt
>>>    ^ true
>>>
>>> mouseStillDown: evt
>>>    self position: evt hand position.
>>>
>>>
>>
>> These apparently don't do anything. But, that's OK, because I can, as
>> Bert suggested, just send "evt hand #grabMorph: self".
>>
>> Except, oops, that's NOT OK, because now mouseUp: apparently never  
>> gets
>> sent to my Morph.
>>
>> So, I still need help. Thank you both very much.
>>
>>
> They "worked for me" - I was dragging a Morph around, and had readouts
> for the start and end positions of the dragging. Try making a  
> completely
> fresh subclass of Morph with only the methods I suggested. I used  
> Squeak
> 3.9.
>
> If I was going to implement momentum, I'd take the current position on
> mouseUp: and the position received by the very latest mouseStillDown:,
> and work out which vector the puck should travel in from that. I  
> suppose
> you'd also need the times of those two events as well to calculate the
> velocity vector.
>
> Michael.
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/beginners