From 8d1cc97c26458f4f5a8ffbfaaea5aaf71a5dcbca Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Fri, 8 Jan 2010 11:41:26 +0100 Subject: [PATCH] Display PV right-clicked from EngineOutput window The clicked PV is selected and the memo gets focus, so that it is highlighted. This selection is restored in the proper place after insetrtion of a new line in the memo. --- backend.c | 28 ++++++++++++++++++++---- backend.h | 1 + winboard/wengineoutput.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 5 deletions(-) diff --git a/backend.c b/backend.c index 9cfb1a2..741a93b 100644 --- a/backend.c +++ b/backend.c @@ -4433,21 +4433,39 @@ fprintf(debugFP,"parsePV: %d %c%c%c%c '%s'\n", valid, fromX+AAA, fromY+ONE, toX+ moveList[endPV-1][3] = toY + ONE; parseList[endPV-1][0] = NULLCHAR; } while(valid); + currentMove = endPV; + if(currentMove == forwardMostMove) ClearPremoveHighlights(); else + SetPremoveHighlights(moveList[currentMove-1][0]-AAA, moveList[currentMove-1][1]-ONE, + moveList[currentMove-1][2]-AAA, moveList[currentMove-1][3]-ONE); + DrawPosition(TRUE, boards[currentMove]); } static int lastX, lastY; Boolean +LoadMultiPV(int x, int y, char *buf, int index, int *start, int *end) +{ + int startPV; + + if(index < 0 || index >= strlen(buf)) return FALSE; // sanity + lastX = x; lastY = y; + while(index > 0 && buf[index-1] != '\n') index--; // beginning of line + startPV = index; + while(buf[index] != '\n') if(buf[index++] == '\t') startPV = index; + index = startPV; + while(buf[index] && buf[index] != '\n') index++; + buf[index] = 0; + ParsePV(buf+startPV); + *start = startPV; *end = index-1; + return TRUE; +} + +Boolean LoadPV(int x, int y) { // called on right mouse click to load PV int which = gameMode == TwoMachinesPlay && (WhiteOnMove(forwardMostMove) == (second.twoMachinesColor[0] == 'w')); lastX = x; lastY = y; ParsePV(lastPV[which]); // load the PV of the thinking engine in the boards array. - currentMove = endPV; - if(currentMove == forwardMostMove) ClearPremoveHighlights(); else - SetPremoveHighlights(moveList[currentMove-1][0]-AAA, moveList[currentMove-1][1]-ONE, - moveList[currentMove-1][2]-AAA, moveList[currentMove-1][3]-ONE); - DrawPosition(TRUE, boards[currentMove]); return TRUE; } diff --git a/backend.h b/backend.h index ccfd91e..e38297f 100644 --- a/backend.h +++ b/backend.h @@ -206,6 +206,7 @@ void OutputChatMessage P((int partner, char *mess)); void EditPositionDone P((Boolean fakeRights)); Boolean GetArgValue P((char *name)); Boolean LoadPV P((int x, int y)); +Boolean LoadMultiPV P((int x, int y, char *buf, int index, int *start, int *end)); void UnLoadPV P(()); void MovePV P((int x, int y, int h)); diff --git a/winboard/wengineoutput.c b/winboard/wengineoutput.c index bb51525..2acb145 100644 --- a/winboard/wengineoutput.c +++ b/winboard/wengineoutput.c @@ -223,12 +223,39 @@ void ResizeWindowControls( int mode ) InvalidateRect( GetDlgItem(hDlg,IDC_EngineMemo2), NULL, FALSE ); } +static int currentPV, highTextStart[2], highTextEnd[2]; +extern RECT boardRect; + +VOID +GetMemoLine(HWND hDlg, int x, int y) +{ // [HGM] pv: translate click to PV line, and load it for display + char buf[10000]; + int index, start, end, memo; + POINT pt; + + pt.x = x; pt.y = y; + memo = currentPV ? IDC_EngineMemo2 : IDC_EngineMemo1; + index = SendDlgItemMessage( hDlg, memo, EM_CHARFROMPOS, 0, (LPARAM) &pt ); + GetDlgItemText(hDlg, memo, buf, sizeof(buf)); + if(LoadMultiPV(x, y, buf, index, &start, &end)) { + SetCapture(hDlg); + SendMessage( outputField[currentPV][nMemo], EM_SETSEL, (WPARAM)start, (LPARAM)end ); + highTextStart[currentPV] = start; highTextEnd[currentPV] = end; + SetFocus(outputField[currentPV][nMemo]); + } +} + // front end. Actual printing of PV lines into the output field void InsertIntoMemo( int which, char * text, int where ) { SendMessage( outputField[which][nMemo], EM_SETSEL, where, where ); // [HGM] multivar: choose insertion point SendMessage( outputField[which][nMemo], EM_REPLACESEL, (WPARAM) FALSE, (LPARAM) text ); + if(where < highTextStart[which]) { // [HGM] multiPVdisplay: move highlighting + int len = strlen(text); + highTextStart[which] += len; highTextEnd[which] += len; + SendMessage( outputField[which][nMemo], EM_SETSEL, highTextStart[which], highTextEnd[which] ); + } } // front end. Associates an icon with an output field ("control" in Windows jargon). @@ -261,6 +288,9 @@ LRESULT CALLBACK EngineOutputProc( HWND hDlg, UINT message, WPARAM wParam, LPARA ResizeWindowControls( windowMode ); + SendDlgItemMessage( hDlg, IDC_EngineMemo1, EM_SETEVENTMASK, 0, ENM_MOUSEEVENTS ); + SendDlgItemMessage( hDlg, IDC_EngineMemo2, EM_SETEVENTMASK, 0, ENM_MOUSEEVENTS ); + /* Set font */ SendDlgItemMessage( engineOutputDialog, IDC_EngineMemo1, WM_SETFONT, (WPARAM)font[boardSize][MOVEHISTORY_FONT]->hf, MAKELPARAM(TRUE, 0 )); SendDlgItemMessage( engineOutputDialog, IDC_EngineMemo2, WM_SETFONT, (WPARAM)font[boardSize][MOVEHISTORY_FONT]->hf, MAKELPARAM(TRUE, 0 )); @@ -287,6 +317,27 @@ LRESULT CALLBACK EngineOutputProc( HWND hDlg, UINT message, WPARAM wParam, LPARA break; + case WM_MOUSEMOVE: + MovePV(LOWORD(lParam) - boardRect.left, HIWORD(lParam) - boardRect.top, boardRect.bottom - boardRect.top); + break; + + case WM_RBUTTONUP: + ReleaseCapture(); + SendMessage( outputField[currentPV][nMemo], EM_SETSEL, 0, 0 ); + highTextStart[currentPV] = highTextEnd[currentPV] = 0; + UnLoadPV(); + break; + + case WM_NOTIFY: + if( wParam == IDC_EngineMemo1 || wParam == IDC_EngineMemo2 ) { + MSGFILTER * lpMF = (MSGFILTER *) lParam; + if( lpMF->msg == WM_RBUTTONDOWN && (lpMF->wParam & (MK_CONTROL | MK_SHIFT)) == 0 ) { + currentPV = (wParam == IDC_EngineMemo2); + GetMemoLine(hDlg, LOWORD(lpMF->lParam), HIWORD(lpMF->lParam)); + } + } + break; + case WM_GETMINMAXINFO: { MINMAXINFO * mmi = (MINMAXINFO *) lParam; -- 1.7.0.4