Made the beep sounds for JAWS board navigation configurable through command-line...
authorH.G. Muller <h.g.muller@hccnet.nl>
Sun, 27 Sep 2009 19:14:25 +0000 (12:14 -0700)
committerArun Persaud <arun@nubati.net>
Wed, 30 Sep 2009 05:17:58 +0000 (22:17 -0700)
winboard/jaws.c

index 1891f07..95f70d2 100644 (file)
@@ -117,6 +117,22 @@ char *pieceToName[] = {
                "Empty"\r
        };\r
 \r
+char *pieceTypeName[] = {\r
+               "Pawn", "Knight", "Bishop", "Rook", "Queen", \r
+               "Guard", "Elephant", "Arch Bishop", "Chancellor",\r
+               "General", "Man", "Cannon", "Night Rider",\r
+               "Crowned Bishop", "Crowned Rook", "Grass Hopper", "Veteran",\r
+               "Falcon", "Amazon", "Snake", "Unicorn",\r
+               "King",\r
+               "Pawn", "Knight", "Bishop", "Rook", "Queen", \r
+               "Guard", "Elephant", "Arch Bishop", "Chancellor",\r
+               "General", "Man", "Cannon", "Night Rider",\r
+               "Crowned Bishop", "Crowned Rook", "Grass Hopper", "Veteran",\r
+               "Falcon", "Amazon", "Snake", "Unicorn",\r
+               "King",\r
+               "Empty"\r
+       };\r
+\r
 int CoordToNum(c)\r
                char c;\r
 {\r
@@ -130,7 +146,7 @@ char* PieceToName(p, i)
        int i;\r
 {\r
        if(i) return pieceToName[(int) p];\r
-               return pieceToName[(int) p]+6;\r
+               return pieceTypeName[(int) p];\r
 }\r
 \r
 char* SquareToChar(x)\r
@@ -219,7 +235,7 @@ AdaptMenu()
 {\r
        HMENU menuMain, menuJAWS;\r
        MENUBARINFO helpMenuInfo;\r
-       int e, i;\r
+       int i;\r
 \r
        helpMenuInfo.cbSize = sizeof(helpMenuInfo);\r
        menuMain = GetMenu(hwndMain);\r
@@ -275,12 +291,15 @@ InitJAWS()
        return TRUE;\r
 }\r
 \r
+int beeps[] = { 1, 0, 0, 0, 0 };\r
+int beepCodes[] = { 0, MB_OK, MB_ICONERROR, MB_ICONQUESTION, MB_ICONEXCLAMATION, MB_ICONASTERISK };\r
+\r
 VOID\r
 KeyboardEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)\r
 {\r
        ChessSquare currentPiece;\r
        char *piece, *xchar, *ynum ;\r
-       int n;\r
+       int n, beepType = 1; // empty beep\r
 \r
        if(fromX == -1 || fromY == -1) {\r
                fromX = BOARD_LEFT; fromY = 0;\r
@@ -288,34 +307,37 @@ KeyboardEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
        switch(wParam) {\r
        case VK_LEFT:\r
                if(fromX == BOARD_RGHT+1) fromX -= 2; else\r
-               if(fromX == BOARD_LEFT) { if(fromY >= BOARD_HEIGHT - gameInfo.holdingsSize) fromX -= 2; } else\r
-               if(fromX > BOARD_LEFT) fromX--;\r
+               if(fromX == BOARD_LEFT) { if(fromY >= BOARD_HEIGHT - gameInfo.holdingsSize) fromX -= 2; else beepType = 0; } else\r
+               if(fromX > BOARD_LEFT) fromX--; else beepType = 0; // off-board beep\r
                break;\r
        case VK_RIGHT:\r
                if(fromX == BOARD_LEFT-2) fromX += 2; else\r
-               if(fromX == BOARD_RGHT-1) { if(fromY < gameInfo.holdingsSize) fromX += 2; } else\r
-               if(fromX < BOARD_RGHT-1) fromX++;\r
+               if(fromX == BOARD_RGHT-1) { if(fromY < gameInfo.holdingsSize) fromX += 2; else beepType = 0; } else\r
+               if(fromX < BOARD_RGHT-1) fromX++; else beepType = 0;\r
                break;\r
        case VK_UP:\r
-               if(fromX == BOARD_RGHT+1) { if(fromY < gameInfo.holdingsSize - 1) fromY++; } else\r
-               if(fromY < BOARD_HEIGHT-1) fromY++;\r
+               if(fromX == BOARD_RGHT+1) { if(fromY < gameInfo.holdingsSize - 1) fromY++; else beepType = 0; } else\r
+               if(fromY < BOARD_HEIGHT-1) fromY++; else beepType = 0;\r
                break;\r
        case VK_DOWN:\r
-               if(fromX == BOARD_LEFT-2) { if(fromY > BOARD_HEIGHT - gameInfo.holdingsSize) fromY--; } else\r
-               if(fromY > 0) fromY--;\r
+               if(fromX == BOARD_LEFT-2) { if(fromY > BOARD_HEIGHT - gameInfo.holdingsSize) fromY--; else beepType = 0; } else\r
+               if(fromY > 0) fromY--; else beepType = 0;\r
                break;\r
        }\r
        SetHighlights(fromX, fromY, -1, -1);\r
        DrawPosition(FALSE, NULL);\r
        currentPiece = boards[currentMove][fromY][fromX];\r
        piece = PieceToName(currentPiece,1);\r
-       if(currentPiece != EmptySquare) MessageBeep(currentPiece < (int)BlackPawn ? MB_OK : MB_ICONEXCLAMATION);\r
+       if(beepType == 1 && currentPiece != EmptySquare) beepType = currentPiece < (int) BlackPawn ? 2 : 3; // white or black beep\r
+       if(beeps[beepType] == beeps[1] && (fromX == BOARD_RGHT+1 || fromX == BOARD_LEFT-2)) beepType = 4; // holdings beep\r
+       beepType = beeps[beepType]%6;\r
+       if(beepType) MessageBeep(beepCodes[beepType]);\r
        if(fromX == BOARD_LEFT - 2) {\r
                SayString("black holdings", FALSE);\r
                if(currentPiece != EmptySquare) {\r
                        char buf[MSG_SIZ];\r
                        n = boards[currentMove][fromY][1];\r
-                       sprintf(buf, "%d %s%s", n, piece+6, n == 1 ? "" : "s");\r
+                       sprintf(buf, "%d %s%s", n, PieceToName(currentPiece,0), n == 1 ? "" : "s");\r
                        SayString(buf, TRUE);\r
                }\r
        } else\r
@@ -324,7 +346,7 @@ KeyboardEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
                if(currentPiece != EmptySquare) {\r
                        char buf[MSG_SIZ];\r
                        n = boards[currentMove][fromY][BOARD_WIDTH-2];\r
-                       sprintf(buf, "%d %s%s", n, piece+6, n == 1 ? "" : "s");\r
+                       sprintf(buf, "%d %s%s", n, PieceToName(currentPiece,0), n == 1 ? "" : "s");\r
                        SayString(buf, TRUE);\r
                }\r
        } else\r
@@ -814,7 +836,7 @@ SayAllBoard()
 {\r
        int Xpos, Ypos;\r
        ChessSquare currentpiece;\r
-       char *piece, *xchar, *ynum ;\r
+       char *piece, *ynum ;\r
        \r
        if(gameInfo.holdingsWidth) {\r
                int first = 0;\r
@@ -848,7 +870,7 @@ SayAllBoard()
                for(Xpos=BOARD_LEFT; Xpos<BOARD_RGHT; Xpos++) {\r
                        currentpiece = boards[currentMove][Ypos][Xpos]; \r
                        if(currentpiece != EmptySquare) {\r
-                               int count = 0, oldX = Xpos;\r
+                               int count = 0;\r
                                char buf[50];\r
                                piece = PieceToName(currentpiece,1);\r
                                while(Xpos < BOARD_RGHT && boards[currentMove][Ypos][Xpos] == currentpiece)\r
@@ -1167,12 +1189,12 @@ NiceTime(int x)
        return (x%3000 == 0);\r
 }\r
 \r
-#if 0\r
-           if(isalpha((char)wParam)) {\r
-               /* capitals of any ind are intercepted and distinguished by left and right shift */\r
-               int mine = GetKeyState(VK_RSHIFT) < 0;\r
-               if(mine || GetKeyState(VK_LSHIFT) < 0) {\r
-#endif\r
+#define JAWS_ARGS \\r
+  { "beepOffBoard", ArgInt, (LPVOID) beeps, TRUE },\\r
+  { "beepEmpty", ArgInt, (LPVOID) (beeps+1), TRUE },\\r
+  { "beepWhite", ArgInt, (LPVOID) (beeps+2), TRUE },\\r
+  { "beepBlack", ArgInt, (LPVOID) (beeps+3), TRUE },\\r
+  { "beepHoldings", ArgInt, (LPVOID) (beeps+4), TRUE },\\r
 \r
 #define JAWS_ALT_INTERCEPT \\r
            if(suppressOneKey) {\\r