[Cuis-dev] Character smalltalkUpArrow, smalltalkRightArrow
Juan Vuletich
juan at cuis.st
Wed Feb 22 10:20:14 PST 2023
Hi Hilaire,
(below)
On 2/16/2023 7:53 AM, Hilaire Fernandes via Cuis-dev wrote:
>
> Hi,
>
> Catching up with the Cuis changes for the Cuis book.
>
> Arrow keys needed in the SpaceWar game of the book to control one of
> the ship.
>
> upArrow and friends are gone from the Character class.
>
> In this class, I read now smalltalkUpArrow, smalltalkRightArrow, etc.
>
> When used in the game, I observe smalltalkUpArrow and
> smalltalkRightArrow are reversed:
>
> - when I press the up arrow of the keyboard, the ship turn right
>
> - when I press the right arrow the ship gets an engine thrust.
>
> I don't know if their numeric values can be safely reversed or if
> there is any other consideration, for example with VM events.
>
> Thanks
>
> Hilaire
>
> --
> GNU Dr. Geo
> http://drgeo.eu
> http://blog.drgeo.eu
Well, according to Unicode (UnicodeData.txt), and also ASCII
(https://en.wikipedia.org/wiki/ASCII), codes 28, 29, 30 and 31 are
"Information Separators", not arrows. Unicode defines U+2190, U+2191,
U+2192 and U+2193 as "Left Arrow" and so. This is why I removed
#arrowUp, #arrowRight, #arrowLeft and #arrowDown from Character.
I think the code in page 79 of the book should be written as:
SpaceWar>>keyStroke: event
"Check for any keyboard stroke, and take action accordingly"
event isArrowUp ifTrue: [↑ ships first push].
event isArrowRight ifTrue: [↑ ships first right].
event isArrowLeft ifTrue: [↑ ships first left].
event isArrowDown ifTrue: [↑ ships first fireTorpedo]
This is the style used in (for instance) #arrowKey: The reason is that
these key events don't generate any Character at all. So it makes sense
to ask about the key pressed instead.
What follows is completely unrelated, but unfortunately a bit confusing.
I took advantage of those essentially unused codes to store arrow glyphs
in TrueType fonts, for Smalltalk assignment and return. I preferred to
use those and not just U+2190, U+2191, U+2192 and U+2193 to make it easy
to personalize the look of the Smalltalk arrows (for instance, if the
"real" Unicode arrows are used for something else). Then, I chose to
store the arrows in the same order as Unicode (i.e. left, up, right,
down). This is different from the order the VM uses in KeyboardEvents:
(left, right, up, down). Any ordering would do. I assumed it made more
sense to follow Unicode here. You can see #mapAndStoreGlyphsUsing: and
the use of FallbackArrowGlyphs.
Perhaps we could modify #keyCharacter to answer the Unicode arrows. That
would make more sense, I guess. Something like:
keyCharacter
"Answer the character corresponding this keystroke. This is defined
only for keystroke events."
| codePoint |
codePoint := keyValue.
self isArrowLeft ifTrue: [ codePoint := 16r2190 ].
self isArrowUp ifTrue: [ codePoint := 16r2191 ].
self isArrowRight ifTrue: [ codePoint := 16r2192 ].
self isArrowDown ifTrue: [ codePoint := 16r2193 ].
^ UnicodeCodePoint codePoint: codePoint.
Thanks,
--
Juan Vuletich
cuis.st
github.com/jvuletich
researchgate.net/profile/Juan-Vuletich
independent.academia.edu/JuanVuletich
patents.justia.com/inventor/juan-manuel-vuletich
linkedin.com/in/juan-vuletich-75611b3
twitter.com/JuanVuletich
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20230222/1b7ece7b/attachment-0001.htm>
More information about the Cuis-dev
mailing list