From 72f29984231db32d8fa942538bc3c6ddaecd3180 Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Tue, 19 Jan 2010 20:15:49 +0100 Subject: [PATCH] Right-click refactoring: step III Let WinBoard call RightClick in back-end, and delete the duplicate code it had for this, after rescuing the front-end bits, and let the letter act depending on the result returned by RightClick. --- backend.c | 20 +++++++++++++------- winboard/winboard.c | 45 +++++++++------------------------------------ xboard.c | 1 + 3 files changed, 23 insertions(+), 43 deletions(-) diff --git a/backend.c b/backend.c index e0e1ab2..cc58afe 100644 --- a/backend.c +++ b/backend.c @@ -5943,14 +5943,19 @@ void LeftClick(ClickType clickType, int xPix, int yPix) 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; + case EditPosition: + if (xSqr == BOARD_LEFT-1 || xSqr == BOARD_RGHT) return -1; + if (xSqr < 0 || ySqr < 0) return -1; + whichMenu = 0; // edit-position menu break; case IcsObserving: if(!appData.icsEngineAnalyze) return -1; @@ -5964,23 +5969,24 @@ int RightClick(ClickType action, int x, int y, int *fromX, int *fromY) 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; } diff --git a/winboard/winboard.c b/winboard/winboard.c index d790116..81d5d03 100644 --- a/winboard/winboard.c +++ b/winboard/winboard.c @@ -3652,7 +3652,7 @@ void DragPieceEnd(int x, int y) VOID MouseEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { - int x, y; + int x, y, menuNr; POINT pt; static int recursive = 0; HMENU hmenu; @@ -3760,7 +3760,7 @@ MouseEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) case WM_MBUTTONUP: case WM_RBUTTONUP: ReleaseCapture(); - UnLoadPV(); + RightClick(Release, pt.x - boardRect.left, pt.y - boardRect.top, &fromX, &fromY); break; case WM_MBUTTONDOWN: @@ -3785,14 +3785,9 @@ MouseEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) } DrawPosition(TRUE, NULL); - switch (gameMode) { - case IcsExamining: - if(x < BOARD_LEFT || x >= BOARD_RGHT) break; - case EditPosition: - if (x == BOARD_LEFT-1 || x == BOARD_RGHT) break; - if (x < 0 || y < 0) break; - fromX = x; - fromY = y; + menuNr = RightClick(Press, pt.x - boardRect.left, pt.y - boardRect.top, &fromX, &fromY); + switch (menuNr) { + case 0: if (message == WM_MBUTTONDOWN) { buttonCount = 3; /* even if system didn't think so */ if (wParam & MK_SHIFT) @@ -3809,35 +3804,13 @@ MouseEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) MenuPopup(hwnd, pt, LoadMenu(hInst, "ShogiPieceMenu"), -1); } break; - case IcsObserving: - if(!appData.icsEngineAnalyze) break; - case IcsPlayingWhite: - case IcsPlayingBlack: - if(!appData.zippyPlay) goto noZip; - case MachinePlaysWhite: - case MachinePlaysBlack: - case TwoMachinesPlay: - case AnalyzeMode: - case AnalyzeFile: - if (!appData.dropMenu) { - SetCapture(hwndMain); - LoadPV(pt.x - boardRect.left, pt.y - boardRect.top); - break; - } - if(gameMode == TwoMachinesPlay || gameMode == AnalyzeMode || - gameMode == AnalyzeFile || gameMode == IcsObserving) break; - case EditGame: - noZip: - if (x < 0 || y < 0) break; - if (!appData.dropMenu || appData.testLegality && - gameInfo.variant != VariantBughouse && - gameInfo.variant != VariantCrazyhouse) break; - fromX = x; - fromY = y; + case 2: + SetCapture(hwndMain); + break; + case 1: hmenu = LoadMenu(hInst, "DropPieceMenu"); SetupDropMenu(hmenu); MenuPopup(hwnd, pt, hmenu, -1); - break; default: break; } diff --git a/xboard.c b/xboard.c index cbe40e1..581206c 100644 --- a/xboard.c +++ b/xboard.c @@ -3722,6 +3722,7 @@ void PieceMenuPopup(w, event, params, num_params) switch(menuNr) { case 0: whichMenu = params[0]; break; case 1: SetupDropMenu(); whichMenu = "menuD"; break; + case 2: case -1: if (errorUp) ErrorPopDown(); default: return; } -- 1.7.0.4