Hi All,

   ah, it works :-).  I can now do 3+4 via command/option p, and bring up halos and translate.


The code in question is, first in [Foo]Simulator>>openAsMorph[NoTranscript] to do

window addMorph: (displayView := SimulatorImageMorph new image: displayForm)
frame: (0@0 corner: 1@0.8).
displayView activeHand addEventListener: self.
eventTransformer := SimulatorEventTransformer new.

and then

StackInterpreterSimulator>>handleListenEvent: aMorphicEvent
"openAsMorph[NoTranscript] regsitered me for listen events via HandMorph>>addEventListener.
Transform the listen event and add it to my event queue."

((aMorphicEvent isMouse or: [aMorphicEvent isKeyboard])
and: [displayView bounds containsPoint: aMorphicEvent position]) ifTrue:
[eventTransformer degenerateEvent: aMorphicEvent for: self]

and

Object subclass: #SimulatorEventTransformer
instanceVariableNames: 'buttons modifiers'
classVariableNames: ''
poolDictionaries: 'EventSensorConstants'
category: 'VMMaker-InterpreterSimulation-Morphic'

degenerateEvent: aMorphicEvent for: client
"Handle ''degenerating'' events for aClient.  This interface gets the client
to queue the event via queueForwardedEvent:, and may generate more
than one event for the input event (i.e. a fake mouse move before a
button down), in addition to filtering-out excessive mouse moves."

aMorphicEvent isMouse ifTrue:
[^self degenerateMouseEvent: aMorphicEvent for: client].
aMorphicEvent isKeyboard ifTrue:
[^self degenerateKeyboardEvent: aMorphicEvent for: client].
^self degenerateUnknownEvent: aMorphicEvent for: client

degenerateKeyboardEvent: aMorphicEvent for: aClient
"Convert the keyboard event into a low-level event for the VM simulator (aClient).
See HandMorph>>generateKeyboardEvent and EventSensor class comment"

aClient queueForwardedEvent:
{ 2.
aMorphicEvent timeStamp.
aMorphicEvent keyValue. "<--this is wrong. See Sensor FirstEvt: for what needs to happen. hooo boy"
aMorphicEvent type caseOf: {
[#keyDown] -> [EventKeyDown].
[#keyUp] -> [EventKeyUp].
[#keystroke] -> [EventKeyChar] }.
modifiers.
aMorphicEvent keyValue.
0.
self windowIndex }

degenerateMouseEvent: aMorphicEvent for: aClient
"Convert the mouse event into low-level events for the VM simulator (aClient).  Filter-out mouse moves,
and generate a fake mouse move before each button press.
See HandMorph>>generateMouseEvent"
| translated |
translated := aMorphicEvent position - aClient displayView bounds origin.
modifiers := aMorphicEvent buttons >> 3. "Sad, but modifiers come in on mouse move events..."

aMorphicEvent type == #mouseMove
ifTrue: "filter-out mouse moves unless buttons are pressed, so simulation doersn't get window leave events when we leave its window"
[buttons = 0 ifTrue: [^nil]]
ifFalse:"If the buttons are going down, make sure to add a mouse move event to the current position before the buttons are pressed."
[((buttons bitAnd: 7) = 0 and: [(aMorphicEvent buttons bitAnd: 7) ~= 0]) ifTrue:
[aClient queueForwardedEvent:
{ 1.
aMorphicEvent timeStamp.
translated x.
translated y.
0.
buttons >> 3.     "Thanks dtl"
0.
self windowIndex }].
buttons := aMorphicEvent buttons].
aClient queueForwardedEvent:
{ 1.
aMorphicEvent timeStamp.
translated x.
translated y.
buttons bitAnd: 7.  "thanks Ron T."
buttons >> 3.     "Thanks dtl"
0.
self windowIndex }

windowIndex
^1

and the key to catching all events without interpretation within the displayView is

ImageMorph subclass: #SimulatorImageMorph
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'VMMaker-InterpreterSimulation-Morphic'

handleMouseDown: anEvent
anEvent wasHandled: true

handleMouseEnter: anEvent
anEvent wasHandled: true

handleMouseLeave: anEvent
^super handleMouseLeave: anEvent

handleMouseOver: anEvent
anEvent wasHandled: true

handleMouseUp: anEvent
anEvent wasHandled: true

handlerForMouseDown: anEvent
"Override all mouse button shenanigans like halos by handling all mouse down events."
^self


Huge thanks for Timothy for getting this started.  I would have never got it working but for that work.  Thanks.

On Wed, Jul 15, 2015 at 1:15 PM, Eliot Miranda <eliot.miranda@gmail.com> wrote:


On Wed, Jul 15, 2015 at 1:11 PM, Bert Freudenberg <bert@freudenbergs.de> wrote:
 
In the Etoys image we changed wantsHaloFromClick to

wantsHaloFromClick
        ^ self valueOfProperty: #wantsHaloFromClick ifAbsent: [^true].

With that you could just set the property. Without that, you would have to override the method.

- Bert -

I'm pretty sure now that what I have to do is implement handlerForBlueButtonDown: in my subclass of ImageMorph so that it forwards the event directly to the simulator instead of passing it up.  The problems with the wantsHaloFromClick approaches are that they either require some special setting, which the user may not know to apply, or that the effect of the setting is merely to turn off halos on that submorph, but not on the enclosing window.

--
best,
Eliot



--
best,
Eliot