Right-click refactoring: step II
authorH.G. Muller <h.g.muller@hccnet.nl>
Tue, 19 Jan 2010 18:07:15 +0000 (19:07 +0100)
committerH.G. Muller <h.g.muller@hccnet.nl>
Thu, 4 Feb 2010 22:17:20 +0000 (23:17 +0100)
Migrate the Right-click routine to the back-end. Let it communicate back
square coordinates through pointer arguments, to accomodate their
different naming in XBoard and WinBoard. Template added in frontend.h.

backend.c
frontend.h
xboard.c

index a9b29e4..e0e1ab2 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -5941,6 +5941,57 @@ 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;
+
+    if (action == Release) UnLoadPV(); // [HGM] pv
+    if (action != Press) return -2;
+    switch (gameMode) {
+      case EditPosition:
+      case IcsExamining:
+       whichMenu = 0;
+       break;
+      case IcsObserving:
+       if(!appData.icsEngineAnalyze) return -1;
+      case IcsPlayingWhite:
+      case IcsPlayingBlack:
+       if(!appData.zippyPlay) goto noZip;
+      case AnalyzeMode:
+      case AnalyzeFile:
+      case MachinePlaysWhite:
+      case MachinePlaysBlack:
+      case TwoMachinesPlay: // [HGM] pv: use for showing PV
+       if (!appData.dropMenu) {
+         LoadPV(x, y);
+         return -1;
+       }
+       if(gameMode == TwoMachinesPlay || gameMode == AnalyzeMode ||
+           gameMode == AnalyzeFile || gameMode == IcsObserving) return -1;
+      case EditGame:
+      noZip:
+       if (!appData.dropMenu || appData.testLegality &&
+           gameInfo.variant != VariantBughouse &&
+           gameInfo.variant != VariantCrazyhouse) return -1;
+       whichMenu = 1;
+       break;
+      default:
+       return -1;
+    }
+
+    if (((*fromX = EventToSquare(x, BOARD_WIDTH)) < 0) ||
+       ((*fromY = EventToSquare(y, BOARD_HEIGHT)) < 0)) {
+       *fromX = *fromY = -1;
+       return -1;
+    }
+    if (flipView)
+      *fromX = BOARD_WIDTH - 1 - *fromX;
+    else
+      *fromY = BOARD_HEIGHT - 1 - *fromY;
+
+    return whichMenu;
+}
+
 void SendProgramStatsToFrontend( ChessProgramState * cps, ChessProgramStats * cpstats )
 {
 //    char * hint = lastHint;
index 38abd03..b75ca7c 100644 (file)
@@ -127,6 +127,7 @@ void PromotionPopUp P((void));
 void DragPieceBegin P((int x, int y));
 void DragPieceEnd P((int x, int y));
 void LeftClick P((ClickType c, int x, int y));
+int  RightClick P((ClickType c, int x, int y, int *col, int *row));
 
 int StartChildProcess P((char *cmdLine, char *dir, ProcRef *pr));
 void DestroyChildProcess P((ProcRef pr, int/*boolean*/ signal));
index 2efc2c2..cbe40e1 100644 (file)
--- a/xboard.c
+++ b/xboard.c
@@ -3708,59 +3708,6 @@ void SetupDropMenu()
     }
 }
 
-int RightClick(int action, int x, int y)
-{   // front-end-free part taken out of PieceMenuPopup
-    int whichMenu;
-
-    if (event->type == ButtonRelease) UnLoadPV(); // [HGM] pv
-    if (event->type != ButtonPress) return;
-    if (errorUp) ErrorPopDown();
-    switch (gameMode) {
-      case EditPosition:
-      case IcsExamining:
-       whichMenu = 0;
-       break;
-      case IcsObserving:
-       if(!appData.icsEngineAnalyze) return -1;
-      case IcsPlayingWhite:
-      case IcsPlayingBlack:
-       if(!appData.zippyPlay) goto noZip;
-      case AnalyzeMode:
-      case AnalyzeFile:
-      case MachinePlaysWhite:
-      case MachinePlaysBlack:
-      case TwoMachinesPlay: // [HGM] pv: use for showing PV
-       if (!appData.dropMenu) {
-         LoadPV(x, y);
-         return;
-       }
-       if(gameMode == TwoMachinesPlay || gameMode == AnalyzeMode ||
-           gameMode == AnalyzeFile || gameMode == IcsObserving) return -1;
-      case EditGame:
-      noZip:
-       if (!appData.dropMenu || appData.testLegality &&
-           gameInfo.variant != VariantBughouse &&
-           gameInfo.variant != VariantCrazyhouse) return -1;
-       SetupDropMenu();
-       whichMenu = 1;
-       break;
-      default:
-       return -1;
-    }
-
-    if (((pmFromX = EventToSquare(x, BOARD_WIDTH)) < 0) ||
-       ((pmFromY = EventToSquare(y, BOARD_HEIGHT)) < 0)) {
-       pmFromX = pmFromY = -1;
-       return -1;
-    }
-    if (flipView)
-      pmFromX = BOARD_WIDTH - 1 - pmFromX;
-    else
-      pmFromY = BOARD_HEIGHT - 1 - pmFromY;
-
-    return whichMenu;
-}
-
 void PieceMenuPopup(w, event, params, num_params)
      Widget w;
      XEvent *event;
@@ -3768,11 +3715,14 @@ void PieceMenuPopup(w, event, params, num_params)
      Cardinal *num_params;
 {
     String whichMenu; int menuNr;
-    if (event->type == ButtonRelease) menuNr = RightClick(Release, event->xbutton.x, event->xbutton.y); // [HGM] pv
-    if (event->type == ButtonPress)   menuNr = RightClick(Press,   event->xbutton.x, event->xbutton.y);
+    if (event->type == ButtonRelease)
+        menuNr = RightClick(Release, event->xbutton.x, event->xbutton.y, &pmFromX, &pmFromY); 
+    else if (event->type == ButtonPress)
+        menuNr = RightClick(Press,   event->xbutton.x, event->xbutton.y, &pmFromX, &pmFromY);
     switch(menuNr) {
       case 0: whichMenu = params[0]; break;
-      case 1: whichMenu = "menuD"; break;
+      case 1: SetupDropMenu(); whichMenu = "menuD"; break;
+      case -1: if (errorUp) ErrorPopDown();
       default: return;
     }
     XtPopupSpringLoaded(XtNameToWidget(boardWidget, whichMenu));