update year in copyright info
[xboard.git] / winboard / winboard.c
index d790116..b9d77e4 100644 (file)
@@ -5,7 +5,7 @@
  * Massachusetts. \r
  *\r
  * Enhancements Copyright 1992-2001, 2002, 2003, 2004, 2005, 2006,\r
- * 2007, 2008, 2009 Free Software Foundation, Inc.\r
+ * 2007, 2008, 2009, 2010 Free Software Foundation, Inc.\r
  *\r
  * Enhancements Copyright 2005 Alessandro Scotti\r
  *\r
@@ -159,7 +159,7 @@ BoardSize boardSize;
 Boolean chessProgram;\r
 //static int boardX, boardY;\r
 int  minX, minY; // [HGM] placement: volatile limits on upper-left corner\r
-static int squareSize, lineGap, minorSize;\r
+int squareSize, lineGap, minorSize;\r
 static int winW, winH;\r
 static RECT messageRect, whiteRect, blackRect, leftLogoRect, rightLogoRect; // [HGM] logo\r
 static int logoHeight = 0;\r
@@ -2005,6 +2005,8 @@ InitDrawingSizes(BoardSize boardSize, int flags)
     blackRect.right = blackRect.left + boardWidth/2 - 1;\r
     blackRect.top = whiteRect.top;\r
     blackRect.bottom = whiteRect.bottom;\r
+\r
+    logoHeight = 0; // [HGM] logo: suppress logo after change to tiny layout!\r
   }\r
 \r
   messageRect.left = OUTER_MARGIN + MESSAGE_LINE_LEFTMARGIN;\r
@@ -3082,6 +3084,62 @@ DrawLogoOnDC(HDC hdc, RECT logoRect, HBITMAP logo)
   DeleteDC(tmphdc);\r
 }\r
 \r
+static HDC hdcSeek;\r
+\r
+// [HGM] seekgraph\r
+void DrawSeekAxis( int x, int y, int xTo, int yTo )\r
+{\r
+    POINT stPt;\r
+    HPEN hp = SelectObject( hdcSeek, gridPen );\r
+    MoveToEx( hdcSeek, boardRect.left+x, boardRect.top+y, &stPt );\r
+    LineTo( hdcSeek, boardRect.left+xTo, boardRect.top+yTo );\r
+    SelectObject( hdcSeek, hp );\r
+}\r
+\r
+// front-end wrapper for drawing functions to do rectangles\r
+void DrawSeekBackground( int left, int top, int right, int bottom )\r
+{\r
+    HPEN hp;\r
+    RECT rc;\r
+\r
+    if (hdcSeek == NULL) {\r
+    hdcSeek = GetDC(hwndMain);\r
+      if (!appData.monoMode) {\r
+        SelectPalette(hdcSeek, hPal, FALSE);\r
+        RealizePalette(hdcSeek);\r
+      }\r
+    }\r
+    hp = SelectObject( hdcSeek, gridPen );\r
+    rc.top = boardRect.top+top; rc.left = boardRect.left+left; \r
+    rc.bottom = boardRect.top+bottom; rc.right = boardRect.left+right;\r
+    FillRect( hdcSeek, &rc, lightSquareBrush );\r
+    SelectObject( hdcSeek, hp );\r
+}\r
+\r
+// front-end wrapper for putting text in graph\r
+void DrawSeekText(char *buf, int x, int y)\r
+{\r
+        SIZE stSize;\r
+       SetBkMode( hdcSeek, TRANSPARENT );\r
+        GetTextExtentPoint32( hdcSeek, buf, strlen(buf), &stSize );\r
+        TextOut( hdcSeek, boardRect.left+x-3, boardRect.top+y-stSize.cy/2, buf, strlen(buf) );\r
+}\r
+\r
+void DrawSeekDot(int x, int y, int color)\r
+{\r
+       int square = color & 0x80;\r
+       color &= 0x7F;\r
+           HBRUSH oldBrush = SelectObject(hdcSeek, \r
+                       color == 0 ? markerBrush : color == 1 ? darkSquareBrush : explodeBrush);\r
+       if(square)\r
+           Rectangle(hdcSeek, boardRect.left+x - squareSize/9, boardRect.top+y - squareSize/9,\r
+                              boardRect.left+x + squareSize/9, boardRect.top+y + squareSize/9);\r
+       else\r
+           Ellipse(hdcSeek, boardRect.left+x - squareSize/8, boardRect.top+y - squareSize/8,\r
+                            boardRect.left+x + squareSize/8, boardRect.top+y + squareSize/8);\r
+           SelectObject(hdcSeek, oldBrush);\r
+}\r
+\r
 VOID\r
 HDCDrawPosition(HDC hdc, BOOLEAN repaint, Board board)\r
 {\r
@@ -3108,6 +3166,8 @@ HDCDrawPosition(HDC hdc, BOOLEAN repaint, Board board)
    */\r
   Boolean fullrepaint = repaint;\r
 \r
+  if(DrawSeekGraph()) return; // [HG} seekgraph: suppress printing board if seek graph up\r
+\r
   if( DrawPositionNeedsFullRepaint() ) {\r
       fullrepaint = TRUE;\r
   }\r
@@ -3652,7 +3712,7 @@ void DragPieceEnd(int x, int y)
 VOID\r
 MouseEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)\r
 {\r
-  int x, y;\r
+  int x, y, menuNr;\r
   POINT pt;\r
   static int recursive = 0;\r
   HMENU hmenu;\r
@@ -3719,6 +3779,7 @@ MouseEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
     break;\r
 \r
   case WM_MOUSEMOVE:\r
+    if(SeekGraphClick(Press, pt.x - boardRect.left, pt.y - boardRect.top, 1)) break;\r
     MovePV(pt.x - boardRect.left, pt.y - boardRect.top, boardRect.bottom - boardRect.top);\r
     if ((appData.animateDragging || appData.highlightDragging)\r
        && (wParam & MK_LBUTTON)\r
@@ -3760,9 +3821,13 @@ MouseEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
   case WM_MBUTTONUP:\r
   case WM_RBUTTONUP:\r
     ReleaseCapture();\r
-    UnLoadPV();\r
+    { extern int promotionChoice; extern Board promoBoard;\r
+      if(promotionChoice == 3 && (promoBoard[y][x] == EmptySquare || x == fromX && y == fromY))\r
+         break; // [HGM] promopopup: suppression of up-click selection as long as pseudo-popup is used\r
+    }\r
+    RightClick(Release, pt.x - boardRect.left, pt.y - boardRect.top, &fromX, &fromY);\r
     break;\r
\r
+\r
   case WM_MBUTTONDOWN:\r
   case WM_RBUTTONDOWN:\r
     ErrorPopDown();\r
@@ -3785,14 +3850,9 @@ MouseEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
     }\r
     DrawPosition(TRUE, NULL);\r
 \r
-    switch (gameMode) {\r
-    case IcsExamining:\r
-      if(x < BOARD_LEFT || x >= BOARD_RGHT) break;\r
-    case EditPosition:\r
-      if (x == BOARD_LEFT-1 || x == BOARD_RGHT) break;\r
-      if (x < 0 || y < 0) break;\r
-      fromX = x;\r
-      fromY = y;\r
+    menuNr = RightClick(Press, pt.x - boardRect.left, pt.y - boardRect.top, &fromX, &fromY);\r
+    switch (menuNr) {\r
+    case 0:\r
       if (message == WM_MBUTTONDOWN) {\r
        buttonCount = 3;  /* even if system didn't think so */\r
        if (wParam & MK_SHIFT) \r
@@ -3809,35 +3869,13 @@ MouseEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
             MenuPopup(hwnd, pt, LoadMenu(hInst, "ShogiPieceMenu"), -1);\r
       }\r
       break;\r
-    case IcsObserving:\r
-      if(!appData.icsEngineAnalyze) break;\r
-    case IcsPlayingWhite:\r
-    case IcsPlayingBlack:\r
-      if(!appData.zippyPlay) goto noZip;\r
-    case MachinePlaysWhite:\r
-    case MachinePlaysBlack:\r
-    case TwoMachinesPlay:\r
-    case AnalyzeMode:\r
-    case AnalyzeFile:\r
-      if (!appData.dropMenu) {\r
-        SetCapture(hwndMain);\r
-        LoadPV(pt.x - boardRect.left, pt.y - boardRect.top);\r
-        break;\r
-      }\r
-      if(gameMode == TwoMachinesPlay || gameMode == AnalyzeMode ||\r
-         gameMode == AnalyzeFile || gameMode == IcsObserving) break;\r
-    case EditGame:\r
-    noZip:\r
-      if (x < 0 || y < 0) break;\r
-      if (!appData.dropMenu || appData.testLegality &&\r
-         gameInfo.variant != VariantBughouse &&\r
-         gameInfo.variant != VariantCrazyhouse) break;\r
-      fromX = x;\r
-      fromY = y;\r
+    case 2:\r
+      SetCapture(hwndMain);
+      break;\r
+    case 1:\r
       hmenu = LoadMenu(hInst, "DropPieceMenu");\r
       SetupDropMenu(hmenu);\r
       MenuPopup(hwnd, pt, hmenu, -1);\r
-      break;\r
     default:\r
       break;\r
     }\r
@@ -4002,6 +4040,17 @@ PromotionPopUp()
   PromotionPopup(hwndMain);\r
 }\r
 \r
+void\r
+PromoDialog(int h, int w, Board board, Boolean clearBoard, char *title, int x, int y)\r
+{      // dummy routine to mimic with pseudo-popup what front-end should do:\r
+       // display a popup with h x w mini-board, and divert any mouse clicks\r
+       // on it to the back-end routines RightClick and LeftClick, just\r
+       // like the mouse event hadler of the board widget does now.\r
+       // (Note it would have to off-set x if holdings are displayed!)\r
+       DisplayMessage("Click on your piece of choice", "");\r
+       DrawPosition(TRUE, board);\r
+}\r
+\r
 /* Toggle ShowThinking */\r
 VOID\r
 ToggleShowThinking()\r