[squeak-dev] Some beginner questions about the EventHandler of a PolygonMorph
Eduardo Ochs
eduardoochs at gmail.com
Thu Feb 9 06:32:22 UTC 2023
Hi list,
I asked this question here on the list a few days ago,
http://lists.squeakfoundation.org/pipermail/squeak-dev/2023-February/223398.html
on how to write code that _sends_ certain keyboard events. I think
that I got a prototype of an answer for it, that "just" needs some
debugging... and then I started to work on ways to debug my prototype.
The ideal way to test sending keyboard events would be to have some
code that _receives_ and _handles_ keyboard events, and that runs
things like "Transcript show: evt" or "evt halt" when it receives a
keyboard event. I tried to adapt the code from these wiki pages
https://wiki.squeak.org/squeak/1125 Programming Morphs (Active Essay)
https://wiki.squeak.org/squeak/1216 Programming morphs - page 7 -
keyboard events
https://wiki.squeak.org/squeak/3503 Morphic Key Events
without much success, and I also tried to modify the keyboard
exerciser - i.e., this:
"World menu -> objects (o) -> Categories -> Demo -> Exercise Keyboard"
KeyboardExerciser new openInWorld.
...and then I saw a way to play with keyboard handlers that does not
require creating any classes or modifying any methods, and that can be
run entirely from a workspace with "do it"s and "print it" in the
right places. It is here:
"The first lines were adapted from:
https://wiki.squeak.org/squeak/2188 PolygonMorph"
a := Array with: 50 at 100 with: 200 at 300 with: 100 at 400.
b := (PolygonMorph
vertices: a color: Color red
borderWidth: 1 borderColor: Color black).
World addMorph: b.
b beSmoothCurve.
b beStraightSegments.
b vertices.
b vertices at: 1.
b vertices at: 1 put: 40 at 100.
b vertices at: 1 put: 50 at 100.
b vertices at: 1 put: 40 at 100. b computeBounds.
b vertices at: 1 put: 50 at 100. b computeBounds.
a at: 1 put: 40 at 100. b computeBounds.
a at: 1 put: 50 at 100. b computeBounds.
b color.
b color: Color banana.
b color: Color fern.
b color: Color red.
e := EventHandler new.
b eventHandler.
b eventHandler: nil.
b eventHandler: e.
Now how do I change that event handler in interesting ways?
Does this make sense?
e on: #keyStroke send: #halt to: b.
Also, is there a way to transfer the keyboard focus to the
PolygonMorph with a "do it" in that workspace? I guess that we
need to run the method #newKeyboardFocus:, but how exactly?
Anyone has examples to share?
Thanks in advance,
Eduardo Ochs
http://anggtwu.net/eev-squeak.html
More information about the Squeak-dev
mailing list
|