Button tracking Morph

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

Button tracking Morph

K. K. Subramaniam
Hi,

Is there a way to get notified (not polling) when any mouse button/modifier
key goes up/down?

I was trying to put together a Morph (like the Mouse button indicator in the
Orange Book) that tracks up/down status of mouse buttons and modifier keys in
real time. I got stuck because all existing usage of Sensor is based on
polling while I would rather get notified on changes.

I tried stepping the following code every 175 ms:

        self color: Color lightGray.
        #(red yellow blue) do: [ :c |
                (Sensor perform: (c , 'Pressed') asSymbol) ifTrue: [
                        self color: (Color perform: c) ]
        ].

There must be better way,
TIA .. Subbu


Reply | Threaded
Open this post in threaded view
|

Re: Button tracking Morph

Bert Freudenberg

On May 24, 2007, at 16:34 , subbukk wrote:

> Hi,
>
> Is there a way to get notified (not polling) when any mouse button/
> modifier
> key goes up/down?
>
> I was trying to put together a Morph (like the Mouse button  
> indicator in the
> Orange Book) that tracks up/down status of mouse buttons and  
> modifier keys in
> real time. I got stuck because all existing usage of Sensor is  
> based on
> polling while I would rather get notified on changes.

You should never use Sensor in Morphic, this is from MVC days.

Use Morphic events: http://wiki.squeak.org/squeak/2477

- Bert -



Reply | Threaded
Open this post in threaded view
|

Re: Button tracking Morph

David Mitchell-10
Have you looked at:

    HandMorph showEvents: true

found at:

http://wiki.squeak.org/squeak/2332

On 5/24/07, Bert Freudenberg <[hidden email]> wrote:

>
> On May 24, 2007, at 16:34 , subbukk wrote:
>
> > Hi,
> >
> > Is there a way to get notified (not polling) when any mouse button/
> > modifier
> > key goes up/down?
> >
> > I was trying to put together a Morph (like the Mouse button
> > indicator in the
> > Orange Book) that tracks up/down status of mouse buttons and
> > modifier keys in
> > real time. I got stuck because all existing usage of Sensor is
> > based on
> > polling while I would rather get notified on changes.
>
> You should never use Sensor in Morphic, this is from MVC days.
>
> Use Morphic events: http://wiki.squeak.org/squeak/2477
>
> - Bert -
>
>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: Button tracking Morph

K. K. Subramaniam
In reply to this post by Bert Freudenberg
On Thursday 24 May 2007 8:07 pm, Bert Freudenberg wrote:
> You should never use Sensor in Morphic, this is from MVC days.
>
> Use Morphic events: http://wiki.squeak.org/squeak/2477

I tried the on:send:to: method, but the events get sent only when the cursor
is over the Morph. The button should be able to reflect the status of button
presses anywhere in World.

Regards .. Subbu

Reply | Threaded
Open this post in threaded view
|

Re: Button tracking Morph

Bert Freudenberg

On May 24, 2007, at 17:58 , subbukk wrote:

> On Thursday 24 May 2007 8:07 pm, Bert Freudenberg wrote:
>> You should never use Sensor in Morphic, this is from MVC days.
>>
>> Use Morphic events: http://wiki.squeak.org/squeak/2477
>
> I tried the on:send:to: method, but the events get sent only when  
> the cursor
> is over the Morph. The button should be able to reflect the status  
> of button
> presses anywhere in World.

See addEventListener:

- Bert -



Reply | Threaded
Open this post in threaded view
|

Re: Button tracking Morph

K. K. Subramaniam
In reply to this post by David Mitchell-10
On Thursday 24 May 2007 9:01 pm, David Mitchell wrote:
> Have you looked at:
>
>     HandMorph showEvents: true
Thanks. I noticed that HandMorph maintains a collection of listeners who get
notified on all events. I suppose I can:

ActiveHand addEventListener: self
and
ActiveHand removeEventListener: self

to turn listening on and off and then define

ButtonMorph>>handleListenEvent: evt
        "process events here"

BTW, EventStats and ShowEvents could have been implemented as listeners
instead of hacking into the handler itself. Any reason why they were done
that way?

Regards .. Subbu

Reply | Threaded
Open this post in threaded view
|

Re: Button tracking Morph

K. K. Subramaniam
On Thursday 24 May 2007 9:49 pm, subbukk wrote:
> ButtonMorph>>handleListenEvent: evt
>         "process events here"
>
> BTW, EventStats and ShowEvents could have been implemented as listeners
> instead of hacking into the handler itself. Any reason why they were done
> that way?
Well, I tried to adapt SimpleSwitchMorph by adding handleEvent:

SimpleSwitchMorph>>handleEvent: anEvent
        | modifier |
        modifier := '    '.
        anEvent anyModifierKeyPressed ifTrue: [
                anEvent commandKeyPressed ifTrue: [ modifier := 'Alt' ].
                anEvent controlKeyPressed ifTrue: [ modifier := modifier, ' Ctrl' ].
                anEvent shiftPressed ifTrue: [ modifier := modifier, ' Shift' ].
        ].
        self label: modifier.

I was able to pick a sample instance of this morph and place it in the world.
But after the first halo click, all morphs stopped responding to mouse
events :-o. Alt-. shows the system stuck in processEvents. Without Morphic
responses, I am unable to debug further.  Appending a "super handleEvent:
evt" in the end of this method doesn't solve the problem.

Any help is appreciated .. Subbu