[squeak-dev] Re: ActiveEvent/Object>>currentEvent broken by Morphic-mt.1283?

marcel.taeumel Marcel.Taeumel at hpi.de
Sun Aug 21 07:04:06 UTC 2016


Hey Tim,

the use of #currentEvent is, basically, fine in Scratch and in Squeak. It
only gets tricky if you do it in a loop like this:

[self currentEvent anyButtonPressed] whileTrue: [
   ...
   self currentWorld doOneCycle].

After doing another cycle, another event dispatching got finished and
#currentEvent is again the object it was when entering the method were this
loop is running. If you really want the "last mouse event", you should call
"self currentHand lastEvent" -- which only keeps track of the last mouse
event (no other kinds of events) compared to #currentEvent, which can also
have keyboard events or drop events.

In general, using #currentEvent without spawning another world cycle in a
loop is fine:

"self currentEvent shiftPressed" (BookMorph >> #showMoreControls)
If you cannot pass the current event as an argument from call to call but
want to reuse some piece of code that just accesses that current event.

"menu popUpEvent: self currentEvent in: self world." (DialogWindow >>
#offerDialogMenu)
Same here. Note that there *is* a world cycle below but the conditions are
quite different: "[menu isInWorld] whileTrue: [self world doOneSubCycle]."

"aMenu popUpEvent: self currentEvent in: self world" (FlapTab >>
#setEdgeToAdhereTo:)
Same here. No loop with do-one-cycle.

"...self currentEvent isMouse  and: [self currentEvent isMouseUp]..."
(MorphicToolBuilder >> #open:)
Single query, no loop. Fine.

******************

Scratch uses #currentEvent in 22 places. Only these 2 places bother me:

PaintCanvas >> #selectRectangleStartingAt:
ScriptableScratchMorph class >> #fromUser

Because they do event dispatching again in a loop and assume that their own
current event changes. You should use "self currentHand lastEvent" here.

There are also 4 step methods:

ScratchNoteSelector >> #step
LibraryItemMorph >> #step
MediaItemMorph >> #step
PaintCanvas >> #step

Which get called outside any event dispatching but separately. These will
automatically fall-back to "self currentHand lastEvent" because ActiveEvent
will be nil then.

I hope this helps. 

Best,
Marcel



--
View this message in context: http://forum.world.st/ActiveEvent-Object-currentEvent-broken-by-Morphic-mt-1283-tp4912022p4912090.html
Sent from the Squeak - Dev mailing list archive at Nabble.com.


More information about the Squeak-dev mailing list