int RightClick(ClickType action, int x, int y, int *fromX, int *fromY)
{ // front-end-free part taken out of PieceMenuPopup
- int whichMenu;
+ int whichMenu; int xSqr, ySqr;
+ xSqr = EventToSquare(x, BOARD_WIDTH);
+ ySqr = EventToSquare(y, BOARD_HEIGHT);
if (action == Release) UnLoadPV(); // [HGM] pv
if (action != Press) return -2;
switch (gameMode) {
- case EditPosition:
case IcsExamining:
- whichMenu = 0;
+ if(xSqr < BOARD_LEFT || xSqr >= BOARD_RGHT) return -1;\r
+ case EditPosition:
+ if (xSqr == BOARD_LEFT-1 || xSqr == BOARD_RGHT) return -1;\r
+ if (xSqr < 0 || ySqr < 0) return -1;\r
+ whichMenu = 0; // edit-position menu
break;
case IcsObserving:
if(!appData.icsEngineAnalyze) return -1;
case TwoMachinesPlay: // [HGM] pv: use for showing PV
if (!appData.dropMenu) {
LoadPV(x, y);
- return -1;
+ return 2; // flag front-end to grab mouse events
}
if(gameMode == TwoMachinesPlay || gameMode == AnalyzeMode ||
gameMode == AnalyzeFile || gameMode == IcsObserving) return -1;
case EditGame:
noZip:
+ if (xSqr < 0 || ySqr < 0) return -1;
if (!appData.dropMenu || appData.testLegality &&
gameInfo.variant != VariantBughouse &&
gameInfo.variant != VariantCrazyhouse) return -1;
- whichMenu = 1;
+ whichMenu = 1; // drop menu
break;
default:
return -1;
}
- if (((*fromX = EventToSquare(x, BOARD_WIDTH)) < 0) ||
- ((*fromY = EventToSquare(y, BOARD_HEIGHT)) < 0)) {
+ if (((*fromX = xSqr) < 0) ||
+ ((*fromY = ySqr) < 0)) {
*fromX = *fromY = -1;
return -1;
}
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
case WM_MBUTTONUP:\r
case WM_RBUTTONUP:\r
ReleaseCapture();\r
- UnLoadPV();\r
+ RightClick(Release, pt.x - boardRect.left, pt.y - boardRect.top, &fromX, &fromY);\r
break;\r
\r
case WM_MBUTTONDOWN:\r
}\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
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