Give the dual-board option a separate board window
authorH.G. Muller <h.g.muller@hccnet.nl>
Wed, 4 Apr 2012 19:55:50 +0000 (21:55 +0200)
committerH.G. Muller <h.g.muller@hccnet.nl>
Tue, 10 Apr 2012 09:39:43 +0000 (11:39 +0200)
The second board window pops up whenever an alien board is received
during your game. Moves in it are highlighted by an arrow, irrespective
of the 'Highlight with Arrow' setting. The clocks are displayed, but do
not count down.

backend.c
board.c
board.h
dialogs.c
dialogs.h
winboard/winboard.c
xboard.c

index f733800..5715e5d 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -4265,7 +4265,10 @@ ParseBoard12 (char *string)
       if(appData.dualBoard && !twoBoards) { twoBoards = 1; InitDrawingSizes(-2,0); }
       if(twoBoards) { partnerUp = 1; flipView = !flipView; } // [HGM] dual
       if(partnerUp) DrawPosition(FALSE, partnerBoard);
-      if(twoBoards) { partnerUp = 0; flipView = !flipView; } // [HGM] dual
+      if(twoBoards) {
+         DisplayWhiteClock(white_time, to_play == 'W');
+         DisplayBlackClock(black_time, to_play != 'W');
+                     partnerUp = 0; flipView = !flipView; } // [HGM] dual
       snprintf(partnerStatus, MSG_SIZ,"W: %d:%02d B: %d:%02d (%d-%d) %c", white_time/60000, (white_time%60000)/1000,
                 (black_time/60000), (black_time%60000)/1000, white_stren, black_stren, to_play);
       DisplayMessage(partnerStatus, "");
diff --git a/board.c b/board.c
index 2b0c624..676ea0b 100644 (file)
--- a/board.c
+++ b/board.c
@@ -108,7 +108,7 @@ extern char *getenv();
 #endif
 
 
-int squareSize, lineGap, hOffset;
+int squareSize, lineGap;
 
 int damage[2][BOARD_RANKS][BOARD_FILES];
 
@@ -778,8 +778,6 @@ DrawSquare (int row, int column, ChessSquare piece, int do_flash)
          (squareSize + lineGap);
     }
 
-    if(twoBoards && partnerUp) x += hOffset; // [HGM] dual: draw second board
-
     square_color = SquareColor(row, column);
 
     string[1] = NULLCHAR;
@@ -899,6 +897,8 @@ DrawPosition (int repaint, Board board)
        MarkMenuItem("View.Flip View", flipView);
     }
 
+    if(nr) { SlavePopUp(); SwitchWindow(); } // [HGM] popup board if not yet popped up, and switch drawing to it.
+
     /*
      * It would be simpler to clear the window with XClearWindow()
      * but this causes a very distracting flicker.
@@ -907,7 +907,7 @@ DrawPosition (int repaint, Board board)
     if (!repaint && lastBoardValid[nr] && (nr == 1 || lastFlipView == flipView)) {
 
        if ( lineGap && IsDrawArrowEnabled())
-           DrawGrid(0);
+           DrawGrid();
 
        /* If too much changes (begin observing new game, etc.), don't
           do flashing */
@@ -942,7 +942,7 @@ DrawPosition (int repaint, Board board)
            }
     } else {
        if (lineGap > 0)
-         DrawGrid(twoBoards & partnerUp);
+         DrawGrid();
 
        for (i = 0; i < BOARD_HEIGHT; i++)
          for (j = 0; j < BOARD_WIDTH; j++) {
@@ -971,10 +971,13 @@ DrawPosition (int repaint, Board board)
     }
     DrawArrowHighlight(hi1X, hi1Y, hi2X, hi2Y);
   }
+  else DrawArrowHighlight (board[EP_STATUS-3], board[EP_STATUS-4], board[EP_STATUS-1], board[EP_STATUS-2]);
+
     /* If piece being dragged around board, must redraw that too */
     DrawDragPiece();
 
     FlashDelay(0); // this flushes drawing queue;
+    if(nr) SwitchWindow();
 }
 
 /* [AS] Arrow highlighting support */
@@ -1115,13 +1118,13 @@ DrawArrowBetweenPoints (int s_x, int s_y, int d_x, int d_y)
 void
 ArrowDamage (int s_col, int s_row, int d_col, int d_row)
 {
-    int hor, vert, i;
+    int hor, vert, i, n = partnerUp * twoBoards;
     hor = 64*s_col + 32; vert = 64*s_row + 32;
     for(i=0; i<= 64; i++) {
-            damage[0][vert+6>>6][hor+6>>6] = True;
-            damage[0][vert-6>>6][hor+6>>6] = True;
-            damage[0][vert+6>>6][hor-6>>6] = True;
-            damage[0][vert-6>>6][hor-6>>6] = True;
+            damage[n][vert+6>>6][hor+6>>6] = True;
+            damage[n][vert-6>>6][hor+6>>6] = True;
+            damage[n][vert+6>>6][hor-6>>6] = True;
+            damage[n][vert-6>>6][hor-6>>6] = True;
             hor += d_col - s_col; vert += d_row - s_row;
     }
 }
@@ -1173,7 +1176,7 @@ DrawArrowBetweenSquares (int s_col, int s_row, int d_col, int d_row)
 Boolean
 IsDrawArrowEnabled ()
 {
-    return appData.highlightMoveWithArrow && squareSize >= 32;
+    return (appData.highlightMoveWithArrow || twoBoards && partnerUp) && squareSize >= 32;
 }
 
 void
diff --git a/board.h b/board.h
index 47d8329..8f0c9db 100644 (file)
--- a/board.h
+++ b/board.h
@@ -80,7 +80,7 @@ extern AnimState anims[];
 void DrawPolygon P((Pnt arrow[], int nr));
 void DrawOneSquare P((int x, int y, ChessSquare piece, int square_color, int marker, char *string, int align));
 void DrawDot P((int marker, int x, int y, int r));
-void DrawGrid P((int second));
+void DrawGrid P((void));
 int SquareColor P((int row, int column));
 void ScreenSquare P((int column, int row, Pnt *pt, int *color));
 void BoardSquare P((int x, int y, int *column, int *row));
@@ -93,6 +93,5 @@ void DragPieceMove P((int x, int y));
 void DrawArrowHighlight P((int fromX, int fromY, int toX,int toY));
 Boolean IsDrawArrowEnabled P((void));
 
-extern int hOffset; // [HGM] dual
 extern int damage[2][BOARD_RANKS][BOARD_FILES];
 
index 5272657..b6abd82 100644 (file)
--- a/dialogs.c
+++ b/dialogs.c
@@ -1792,22 +1792,6 @@ DisplayTitle (char *text)
     SetWindowTitle(text, title, icon);
 }
 
-void
-DisplayWhiteClock (long timeRemaining, int highlight)
-{
-    if(appData.noGUI) return;
-    DisplayTimerLabel(11, _("White"), timeRemaining, highlight);
-    if(highlight) SetClockIcon(0);
-}
-
-void
-DisplayBlackClock (long timeRemaining, int highlight)
-{
-    if(appData.noGUI) return;
-    DisplayTimerLabel(12, _("Black"), timeRemaining, highlight);
-    if(highlight) SetClockIcon(1);
-}
-
 #define PAUSE_BUTTON "P"
 #define PIECE_MENU_SIZE 18
 static String pieceMenuStrings[2][PIECE_MENU_SIZE+1] = {
@@ -1935,11 +1919,6 @@ Exp (int n, int x, int y)
        case -3: menuNr = RightClick(Release, x, y, &pmFromX, &pmFromY), but3 = 0; break;
        case 10:
            DrawPosition(True, NULL);
-           if(twoBoards) { // [HGM] dual: draw other board in other orientation
-               flipView = !flipView; partnerUp = !partnerUp;
-               DrawPosition(True, NULL);
-               flipView = !flipView; partnerUp = !partnerUp;
-           }
        default:
            return NULL;
     }
@@ -1975,6 +1954,64 @@ BoardPopUp (int squareSize, int lineGap, void *clockFontThingy)
     return mainOptions;
 }
 
+static Option *
+SlaveExp (int n, int x, int y)
+{
+    if(n == 10) { // expose event
+       flipView = !flipView; partnerUp = !partnerUp;
+       DrawPosition(True, NULL); // [HGM] dual: draw other board in other orientation
+       flipView = !flipView; partnerUp = !partnerUp;
+    }
+    return NULL;
+}
+
+Option dualOptions[] = { // auxiliary board window
+{ 0, L2L|T2T,              198, NULL, NULL, NULL, NULL, Label, "White" }, // white clock
+{ 0, R2R|T2T|SAME_ROW,     198, NULL, NULL, NULL, NULL, Label, "Black" }, // black clock
+{ 0, LR|T2T|BORDER,        401, NULL, NULL, NULL, NULL, Label, "message" }, // message field
+{ 401, LR|TT, 401, NULL, (char*) &SlaveExp, NULL, NULL, Graph, "shadow board" }, // board
+{ 0,  NO_OK, 0, NULL, NULL, "", NULL, EndMark , "" }
+};
+
+void
+SlavePopUp ()
+{
+    // copy params from main board
+    dualOptions[0].choice = mainOptions[11].choice;
+    dualOptions[1].choice = mainOptions[12].choice;
+    dualOptions[3].value = mainOptions[22].value;
+    dualOptions[3].max = dualOptions[2].max = mainOptions[22].max; // board size
+    dualOptions[0].max = dualOptions[1].max = mainOptions[11].max; // clock width
+    GenericPopUp(dualOptions, "XBoard", DummyDlg, BoardWindow, NONMODAL, 1);
+}
+
+void
+DisplayWhiteClock (long timeRemaining, int highlight)
+{
+    if(appData.noGUI) return;
+    if(twoBoards && partnerUp) {
+       DisplayTimerLabel(&dualOptions[0], _("White"), timeRemaining, highlight);
+       return;
+    }
+    DisplayTimerLabel(&mainOptions[11], _("White"), timeRemaining, highlight);
+    if(highlight) SetClockIcon(0);
+}
+
+void
+DisplayBlackClock (long timeRemaining, int highlight)
+{
+    if(appData.noGUI) return;
+    if(twoBoards && partnerUp) {
+       DisplayTimerLabel(&dualOptions[1], _("Black"), timeRemaining, highlight);
+       return;
+    }
+    DisplayTimerLabel(&mainOptions[12], _("Black"), timeRemaining, highlight);
+    if(highlight) SetClockIcon(1);
+}
+
+
+//---------------------------------------------
+
 void
 DisplayMessage (char *message, char *extMessage)
 {
index 91b2700..a8f791a 100644 (file)
--- a/dialogs.h
+++ b/dialogs.h
@@ -148,7 +148,7 @@ void ErrorPopUp P((char *title, char *text, int modal));
 int  ShiftKeys P((void));
 void SetClockIcon P((int color));
 void DelayedLoad P((void));
-void DisplayTimerLabel P((int optNr, char *color, long timer, int highlight));
+void DisplayTimerLabel P((Option *opt, char *color, long timer, int highlight));
 Option *BoardPopUp P((int squareSize, int lineGap, void *clockFontThingy));
 
 int  SetCurrentComboSelection P((Option *opt));
index 1bea76d..86c0879 100644 (file)
@@ -7497,6 +7497,7 @@ DisplayAClock(HDC hdc, int timeRemaining, int highlight,
   COLORREF oldFg, oldBg;\r
   HFONT oldFont;\r
 \r
+  if (twoBoards && partnerUp) return;\r
   if (appData.clockMode) {\r
     if (tinyLayout)\r
       snprintf(buf, sizeof(buf)/sizeof(buf[0]), "%c %s %s", color[0], TimeString(timeRemaining), flagFell);\r
@@ -9207,6 +9208,7 @@ OpenTCP(char *host, char *port, ProcRef *pr)
   ChildProc *cp;\r
   int err;\r
   SOCKET s;\r
+\r
   struct sockaddr_in sa, mysa;\r
   struct hostent FAR *hp;\r
   unsigned short uport;\r
index 10bf034..6aea957 100644 (file)
--- a/xboard.c
+++ b/xboard.c
@@ -293,7 +293,6 @@ GC lightSquareGC, darkSquareGC, lineGC, wdPieceGC, wlPieceGC,
 Pixmap iconPixmap, wIconPixmap, bIconPixmap, xMarkPixmap;
 Widget shellWidget, formWidget, boardWidget, titleWidget, dropMenu, menuBarWidget;
 Option *optList; // contains all widgets of main window
-XSegment secondSegments[BOARD_RANKS + BOARD_FILES + 2];
 XSegment gridSegments[BOARD_RANKS + BOARD_FILES + 2];
 #if ENABLE_NLS
 XFontSet fontSet, clockFontSet;
@@ -889,6 +888,16 @@ MainWindowUp ()
   return xBoardWindow != 0;
 }
 
+void SwitchWindow()
+{
+    extern Option dualOptions[];
+    static Window dual;
+    Window tmp = xBoardWindow;
+    if(!dual) dual = XtWindow(dualOptions[3].handle); // must be first call
+    xBoardWindow = dual; // swap them
+    dual = tmp;
+}
+
 void
 PopUpStartupDialog ()
 {  // start menu not implemented in XBoard
@@ -927,7 +936,7 @@ InitDrawingSizes (BoardSize boardSize, int flags)
     int i;
     static Dimension oldWidth, oldHeight;
     static VariantClass oldVariant;
-    static int oldDual = -1, oldMono = -1;
+    static int oldMono = -1;
 
     if(!formWidget) return;
 
@@ -935,21 +944,15 @@ InitDrawingSizes (BoardSize boardSize, int flags)
     boardWidth = lineGap + BOARD_WIDTH * (squareSize + lineGap);
     boardHeight = lineGap + BOARD_HEIGHT * (squareSize + lineGap);
 
-  if(boardWidth != oldWidth || boardHeight != oldHeight || oldDual != twoBoards) { // do resizing stuff only if size actually changed
+  if(boardWidth != oldWidth || boardHeight != oldHeight) { // do resizing stuff only if size actually changed
 
-    oldWidth = boardWidth; oldHeight = boardHeight; oldDual = twoBoards;
+    oldWidth = boardWidth; oldHeight = boardHeight;
     CreateGrid();
-    hOffset = boardWidth + 10;
-    for(i=0; i<BOARD_WIDTH+BOARD_HEIGHT+2; i++) { // [HGM] dual: grid for second board
-       secondSegments[i] = gridSegments[i];
-       secondSegments[i].x1 += hOffset;
-       secondSegments[i].x2 += hOffset;
-    }
 
     /*
      * Inhibit shell resizing.
      */
-    shellArgs[0].value = w = (XtArgVal) boardWidth + marginW + twoBoards*hOffset; // [HGM] dual
+    shellArgs[0].value = w = (XtArgVal) boardWidth + marginW ;
     shellArgs[1].value = h = (XtArgVal) boardHeight + marginH;
     shellArgs[4].value = shellArgs[2].value = w;
     shellArgs[5].value = shellArgs[3].value = h;
@@ -2750,10 +2753,9 @@ DrawSeekDot (int x, int y, int colorNr)
 }
 
 void
-DrawGrid (int second)
+DrawGrid ()
 {
          XDrawSegments(xDisplay, xBoardWindow, lineGC,
-                       second ? secondSegments : // [HGM] dual
                        gridSegments, BOARD_HEIGHT + BOARD_WIDTH + 2);
 }
 
@@ -3345,11 +3347,11 @@ StartClockTimer (long millisec)
 }
 
 void
-DisplayTimerLabel (int optNr, char *color, long timer, int highlight)
+DisplayTimerLabel (Option *opt, char *color, long timer, int highlight)
 {
     char buf[MSG_SIZ];
     Arg args[16];
-    Widget w = optList[optNr].handle;
+    Widget w = (Widget) opt->handle;
 
     /* check for low time warning */
     Pixel foregroundOrWarningColor = timerForegroundPixel;