From 24eec7ef0db2c98df79453e377a72cefe12b7569 Mon Sep 17 00:00:00 2001 From: H.G.Muller Date: Fri, 26 Feb 2016 23:35:39 +0100 Subject: [PATCH] Use mouse wheel for selecting piece in Edit Position mode (XB) Rather than calling ForwardEvent() and BackwardEvent() directly from the mouse-wheel handler, we now call a backend routine Wheel(), which gets the pointer coordinates passed to it (which we must remember during mouse move events). This then calls the Forward/Backward event, except in EditPosition mode, where it changes the piece in the square below the pointer. --- backend.c | 17 +++++++++++++++++ dialogs.c | 7 ++++--- frontend.h | 1 + 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/backend.c b/backend.c index b49ba15..36131f6 100644 --- a/backend.c +++ b/backend.c @@ -7981,6 +7981,23 @@ RightClick (ClickType action, int x, int y, int *fromX, int *fromY) } void +Wheel (int dir, int x, int y) +{ + if(gameMode == EditPosition) { + int xSqr = EventToSquare(x, BOARD_WIDTH); + int ySqr = EventToSquare(y, BOARD_HEIGHT); + if(ySqr < 0 || xSqr < BOARD_LEFT || xSqr >= BOARD_RGHT) return; + if(flipView) xSqr = BOARD_WIDTH - 1 - xSqr; else ySqr = BOARD_HEIGHT - 1 - ySqr; + do { + boards[currentMove][ySqr][xSqr] += dir; + if((int) boards[currentMove][ySqr][xSqr] < WhitePawn) boards[currentMove][ySqr][xSqr] = BlackKing; + if((int) boards[currentMove][ySqr][xSqr] > BlackKing) boards[currentMove][ySqr][xSqr] = WhitePawn; + } while(PieceToChar(boards[currentMove][ySqr][xSqr]) == '.'); + DrawPosition(FALSE, boards[currentMove]); + } else if(dir > 0) ForwardEvent(); else BackwardEvent(); +} + +void SendProgramStatsToFrontend (ChessProgramState * cps, ChessProgramStats * cpstats) { // char * hint = lastHint; diff --git a/dialogs.c b/dialogs.c index 3f445bb..35b3aef 100644 --- a/dialogs.c +++ b/dialogs.c @@ -2579,7 +2579,7 @@ MenuCallback (int n) static Option * Exp (int n, int x, int y) { - static int but1, but3, oldW, oldH; + static int but1, but3, oldW, oldH, oldX, oldY; int menuNr = -3, sizing, f, r; TimeMark now; extern Boolean right; @@ -2590,6 +2590,7 @@ Exp (int n, int x, int y) } if(n == 0) { // motion + oldX = x; oldY = y; if(SeekGraphClick(Press, x, y, 1)) return NULL; if((but1 || dragging == 2) && !PromoScroll(x, y)) DragPieceMove(x, y); if(but3) MovePV(x, y, lineGap + BOARD_HEIGHT * (squareSize + lineGap)); @@ -2612,8 +2613,8 @@ Exp (int n, int x, int y) case 3: menuNr = RightClick(Press, x, y, &pmFromX, &pmFromY), but3 = 1; break; case -2: shiftKey = !shiftKey; case -3: menuNr = RightClick(Release, x, y, &pmFromX, &pmFromY), but3 = 0; break; - case 4: BackwardEvent(); break; - case 5: ForwardEvent(); break; + case 4: Wheel(-1, oldX, oldY); break; + case 5: Wheel(1, oldX, oldY); break; case 10: sizing = (oldW != x || oldH != y); oldW = x; oldH = y; diff --git a/frontend.h b/frontend.h index f536dba..2a39fca 100644 --- a/frontend.h +++ b/frontend.h @@ -136,6 +136,7 @@ void DragPieceEnd P((int x, int y)); void DragPieceMove 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)); +void Wheel P((int dir, int x, int y)); int StartChildProcess P((char *cmdLine, char *dir, ProcRef *pr)); void DestroyChildProcess P((ProcRef pr, int/*boolean*/ signal)); -- 1.7.0.4