Make flipping view also work to listeners
authorH.G.Muller <hgm@hgm-xboard.(none)>
Tue, 5 Jul 2022 19:18:58 +0000 (21:18 +0200)
committerH.G.Muller <hgm@hgm-xboard.(none)>
Tue, 5 Jul 2022 19:18:58 +0000 (21:18 +0200)
The functions of the arrow keys controlling the board cursor in the
accessible version are now reversed in case the view is flipped.
The same for the meaning of upper and lower diagonals.

winboard/jaws.c

index 4c7416a..1524a80 100644 (file)
@@ -295,6 +295,12 @@ KeyboardEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
        if(fromX == -1 || fromY == -1) {\r
                fromX = BOARD_LEFT; fromY = 0;\r
         }\r
+       if(flipView) switch(wParam) {\r
+       case VK_LEFT:  wParam = VK_RIGHT; break;\r
+       case VK_RIGHT: wParam = VK_LEFT;  break;\r
+       case VK_UP:    wParam = VK_DOWN;  break;\r
+       case VK_DOWN:  wParam = VK_UP;    break;\r
+        }\r
        switch(wParam) {\r
        case VK_LEFT:\r
                if(fromX == BOARD_RGHT+1) fromX -= 2; else\r
@@ -536,20 +542,26 @@ ReadColumn()
        SayString("", TRUE); // flush\r
 }\r
 \r
+int\r
+OnBoard(int x, int y)\r
+{\r
+       return x >= BOARD_LEFT && x < BOARD_RGHT && y >= 0 && y < BOARD_HEIGHT;\r
+}\r
+\r
 VOID\r
 SayUpperDiagnols()\r
 {\r
        ChessSquare currentpiece;\r
        char *piece, *xchar, *ynum ;\r
-       int yPos, xPos;\r
+       int yPos, xPos, dir = (flipView ? -1 : 1);\r
 \r
        if(fromX < 0 || fromY < 0) return;\r
 \r
-       if(fromX < BOARD_RGHT-1 && fromY < BOARD_HEIGHT-1) {\r
+       if(OnBoard(fromX+dir, fromY+dir)) {\r
                SayString("The diagnol squares to your upper right contain", FALSE);\r
-               yPos = fromY+1;\r
-               xPos = fromX+1;\r
-               while(yPos<BOARD_HEIGHT && xPos<BOARD_RGHT) {\r
+               yPos = fromY+dir;\r
+               xPos = fromX+dir;\r
+               while(OnBoard(xPos, yPos)) {\r
                        currentpiece = boards[currentMove][yPos][xPos];\r
                        piece = PieceToName(currentpiece,1);\r
                        xchar = SquareToChar(xPos);\r
@@ -557,17 +569,17 @@ SayUpperDiagnols()
                        SayString(xchar , FALSE);\r
                        SayString(ynum, FALSE);\r
                        SayString(piece, FALSE);\r
-                       yPos++;\r
-                       xPos++;\r
+                       yPos+=dir;\r
+                       xPos+=dir;\r
                }\r
        }\r
        else SayString("There is no squares to your upper right", FALSE);\r
 \r
-       if(fromX > BOARD_LEFT && fromY < BOARD_HEIGHT-1) {\r
+       if(OnBoard(fromX-dir, fromY+dir)) {\r
                SayString("The diagnol squares to your upper left contain", FALSE);\r
-               yPos = fromY+1;\r
-               xPos = fromX-1;\r
-               while(yPos<BOARD_HEIGHT && xPos>=BOARD_LEFT) {\r
+               yPos = fromY+dir;\r
+               xPos = fromX-dir;\r
+               while(OnBoard(xPos, yPos)) {\r
                        currentpiece = boards[currentMove][yPos][xPos];\r
                        piece = PieceToName(currentpiece,1);\r
                        xchar = SquareToChar(xPos);\r
@@ -575,8 +587,8 @@ SayUpperDiagnols()
                        SayString(xchar , FALSE);\r
                        SayString(ynum, FALSE);\r
                        SayString(piece, FALSE);\r
-                       yPos++;\r
-                       xPos--;\r
+                       yPos+=dir;\r
+                       xPos-=dir;\r
                }\r
        }\r
        else SayString("There is no squares to your upper left", FALSE);\r
@@ -588,15 +600,15 @@ SayLowerDiagnols()
 {\r
        ChessSquare currentpiece;\r
        char *piece, *xchar, *ynum ;\r
-       int yPos, xPos;\r
+       int yPos, xPos, dir = (flipView ? -1 : 1);\r
 \r
        if(fromX < 0 || fromY < 0) return;\r
 \r
-       if(fromX < BOARD_RGHT-1 && fromY > 0) {\r
+       if(OnBoard(fromX+dir, fromY-dir)) {\r
                SayString("The diagnol squares to your lower right contain", FALSE);\r
-               yPos = fromY-1;\r
-               xPos = fromX+1;\r
-               while(yPos>=0 && xPos<BOARD_RGHT) {\r
+               yPos = fromY-dir;\r
+               xPos = fromX+dir;\r
+               while(OnBoard(xPos, yPos)) {\r
                        currentpiece = boards[currentMove][yPos][xPos];\r
                        piece = PieceToName(currentpiece,1);\r
                        xchar = SquareToChar(xPos);\r
@@ -604,17 +616,17 @@ SayLowerDiagnols()
                        SayString(xchar , FALSE);\r
                        SayString(ynum, FALSE);\r
                        SayString(piece, FALSE);\r
-                       yPos--;\r
-                       xPos++;\r
+                       yPos-=dir;\r
+                       xPos+=dir;\r
                }\r
        }\r
        else SayString("There is no squares to your lower right", FALSE);\r
 \r
-       if(fromX > BOARD_LEFT && fromY > 0) {\r
+       if(OnBoard(fromX-dir, fromY-dir)) {\r
                SayString("The diagnol squares to your lower left contain", FALSE);\r
-               yPos = fromY-1;\r
-               xPos = fromX-1;\r
-               while(yPos>=0 && xPos>=BOARD_LEFT) {\r
+               yPos = fromY-dir;\r
+               xPos = fromX-dir;\r
+               while(OnBoard(xPos, yPos)) {\r
                        currentpiece = boards[currentMove][yPos][xPos];\r
                        piece = PieceToName(currentpiece,1);\r
                        xchar = SquareToChar(xPos);\r
@@ -622,8 +634,8 @@ SayLowerDiagnols()
                        SayString(xchar , FALSE);\r
                        SayString(ynum, FALSE);\r
                        SayString(piece, FALSE);\r
-                       yPos--;\r
-                       xPos--;\r
+                       yPos-=dir;\r
+                       xPos-=dir;\r
                }\r
        }\r
        else SayString("There is no squares to your lower left", FALSE);\r