<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Hi Hilaire,<br>
<br>
(below)<br>
<br>
On 2/16/2023 7:53 AM, Hilaire Fernandes via Cuis-dev wrote:
<blockquote cite="mid:42ac3820-a9fd-f5be-e6fe-9cf1ccdeb935@free.fr"
type="cite">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<p><font size="4">Hi,</font></p>
<p>Catching up with the Cuis changes for the Cuis book.<br>
</p>
<p>Arrow keys needed in the SpaceWar game of the book to control
one of the ship.<br>
</p>
<p><font size="4">upArrow and friends are gone from the Character
class.</font></p>
<p><font size="4">In this class, I read now smalltalkUpArrow,
smalltalkRightArrow, etc.</font></p>
<p><font size="4">When used in the game, I observe
smalltalkUpArrow and smalltalkRightArrow are reversed:</font></p>
<p><font size="4">- when I press the up arrow of the keyboard, the
ship turn right</font></p>
<p>- when I press the right arrow the ship gets an engine thrust.</p>
<p>I don't know if their numeric values can be safely reversed or
if there is any other consideration, for example with VM events.</p>
<p>Thanks</p>
<p>Hilaire<br>
</p>
<pre class="moz-signature" cols="72">--
GNU Dr. Geo
<a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://drgeo.eu">http://drgeo.eu</a>
<a moz-do-not-send="true" class="moz-txt-link-freetext" href="http://blog.drgeo.eu">http://blog.drgeo.eu</a></pre>
</blockquote>
<br>
Well, according to Unicode (UnicodeData.txt), and also ASCII
(<a class="moz-txt-link-freetext" href="https://en.wikipedia.org/wiki/ASCII">https://en.wikipedia.org/wiki/ASCII</a>), 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.<br>
<br>
I think the code in page 79 of the book should be written as:<br>
<br>
SpaceWar>>keyStroke: event<br>
"Check for any keyboard stroke, and take action accordingly"<br>
event isArrowUp ifTrue: [↑ ships first push].<br>
event isArrowRight ifTrue: [↑ ships first right].<br>
event isArrowLeft ifTrue: [↑ ships first left].<br>
event isArrowDown ifTrue: [↑ ships first fireTorpedo]<br>
<br>
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.<br>
<br>
What follows is completely unrelated, but unfortunately a bit
confusing.<br>
<br>
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.<br>
<br>
Perhaps we could modify #keyCharacter to answer the Unicode arrows.
That would make more sense, I guess. Something like:<br>
<br>
keyCharacter<br>
"Answer the character corresponding this keystroke. This is
defined only for keystroke events."<br>
| codePoint |<br>
codePoint := keyValue.<br>
self isArrowLeft ifTrue: [ codePoint := 16r2190 ].<br>
self isArrowUp ifTrue: [ codePoint := 16r2191 ].<br>
self isArrowRight ifTrue: [ codePoint := 16r2192 ].<br>
self isArrowDown ifTrue: [ codePoint := 16r2193 ].<br>
^ UnicodeCodePoint codePoint: codePoint.<br>
<br>
Thanks,<br>
<pre class="moz-signature" cols="72">--
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</pre>
</body>
</html>