+++ /dev/null
-/*\r
- * wevalgraph.c - Evaluation graph front-end part\r
- *\r
- * Author: Alessandro Scotti (Dec 2005)\r
- *\r
- * Copyright 2005 Alessandro Scotti\r
- *\r
- * Enhancements Copyright 2009, 2010, 2011, 2012, 2013, 2014, 2015,\r
- * 2016 Free Software Foundation, Inc.\r
- *\r
- * ------------------------------------------------------------------------\r
- *\r
- * GNU XBoard is free software: you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation, either version 3 of the License, or (at\r
- * your option) any later version.\r
- *\r
- * GNU XBoard is distributed in the hope that it will be useful, but\r
- * WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
- * General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program. If not, see http://www.gnu.org/licenses/. *\r
- *\r
- *------------------------------------------------------------------------\r
- ** See the file ChangeLog for a revision history. */\r
-\r
-// code refactored by HGM to obtain front-end / back-end separation\r
-\r
-#include "config.h"\r
-\r
-#include <windows.h>\r
-#include <commdlg.h>\r
-#include <dlgs.h>\r
-#include <stdio.h>\r
-\r
-#include "common.h"\r
-#include "frontend.h"\r
-#include "backend.h"\r
-#include "winboard.h"\r
-#include "evalgraph.h"\r
-#include "wsnap.h"\r
-\r
-#define WM_REFRESH_GRAPH (WM_USER + 1)\r
-\r
-/* Module globals */\r
-static BOOLEAN evalGraphDialogUp;\r
-\r
-static COLORREF crWhite = RGB( 0xFF, 0xFF, 0xB0 );\r
-static COLORREF crBlack = RGB( 0xAD, 0x5D, 0x3D );\r
-\r
-static HDC hdcPB = NULL;\r
-static HBITMAP hbmPB = NULL;\r
-static HPEN pens[PEN_ANY+1]; // [HGM] put all pens in one array\r
-static HBRUSH hbrHist[3] = { NULL, NULL, NULL };\r
-\r
-Boolean EvalGraphIsUp()\r
-{\r
- return evalGraphDialogUp;\r
-}\r
-\r
-// [HGM] front-end, added as wrapper to avoid use of LineTo and MoveToEx in other routines (so they can be back-end) \r
-void DrawSegment( int x, int y, int *lastX, int *lastY, int penType )\r
-{\r
- POINT stPt;\r
- if(penType == PEN_NONE) MoveToEx( hdcPB, x, y, &stPt ); else {\r
- HPEN hp = SelectObject( hdcPB, pens[penType] );\r
- LineTo( hdcPB, x, y );\r
- SelectObject( hdcPB, hp );\r
- }\r
- if(lastX != NULL) { *lastX = stPt.x; *lastY = stPt.y; }\r
-}\r
-\r
-// front-end wrapper for drawing functions to do rectangles\r
-void DrawRectangle( int left, int top, int right, int bottom, int side, int style )\r
-{\r
- HPEN hp = SelectObject( hdcPB, pens[PEN_BLACK] );\r
- RECT rc;\r
-\r
- rc.top = top; rc.left = left; rc.bottom = bottom; rc.right = right;\r
- if(style == FILLED)\r
- FillRect( hdcPB, &rc, hbrHist[side] );\r
- else {\r
- SelectObject( hdcPB, hbrHist[side] );\r
- Rectangle( hdcPB, left, top, right, bottom );\r
- }\r
- SelectObject( hdcPB, hp );\r
-}\r
-\r
-// front-end wrapper for putting text in graph\r
-void DrawEvalText(char *buf, int cbBuf, int y)\r
-{\r
- SIZE stSize;\r
- SetBkMode( hdcPB, TRANSPARENT );\r
- GetTextExtentPoint32( hdcPB, buf, cbBuf, &stSize );\r
- TextOut( hdcPB, MarginX - stSize.cx - 2, y - stSize.cy / 2, buf, cbBuf );\r
-}\r
-\r
-// front-end\r
-static HBRUSH CreateBrush( UINT style, COLORREF color )\r
-{\r
- LOGBRUSH stLB;\r
-\r
- stLB.lbStyle = style;\r
- stLB.lbColor = color;\r
- stLB.lbHatch = 0;\r
-\r
- return CreateBrushIndirect( &stLB );\r
-}\r
-\r
-// front-end. Create pens, device context and buffer bitmap for global use, copy result to display\r
-// The back-end part n the middle has been taken out and moed to PainEvalGraph()\r
-static VOID DisplayEvalGraph( HWND hWnd, HDC hDC )\r
-{\r
- RECT rcClient;\r
- int width;\r
- int height;\r
-\r
- /* Get client area */\r
- GetClientRect( hWnd, &rcClient );\r
-\r
- width = rcClient.right - rcClient.left;\r
- height = rcClient.bottom - rcClient.top;\r
-\r
- /* Create or recreate paint box if needed */\r
- if( hbmPB == NULL || width != nWidthPB || height != nHeightPB ) {\r
- if( pens[PEN_DOTTED] == NULL ) {\r
- pens[PEN_BLACK] = GetStockObject(BLACK_PEN);\r
- pens[PEN_DOTTED] = CreatePen( PS_DOT, 0, RGB(0xA0,0xA0,0xA0) );\r
- pens[PEN_BLUEDOTTED] = CreatePen( PS_DOT, 0, RGB(0x00,0x00,0xFF) );\r
- pens[PEN_BOLDWHITE] = CreatePen( PS_SOLID, 2, crWhite );\r
- pens[PEN_BOLDBLACK] = CreatePen( PS_SOLID, 2, crBlack );\r
- hbrHist[0] = CreateBrush( BS_SOLID, crWhite );\r
- hbrHist[1] = CreateBrush( BS_SOLID, crBlack );\r
- hbrHist[2] = CreateBrush( BS_SOLID, GetSysColor( COLOR_3DFACE ) ); // background\r
- }\r
-\r
- if( hdcPB != NULL ) {\r
- DeleteDC( hdcPB );\r
- hdcPB = NULL;\r
- }\r
-\r
- if( hbmPB != NULL ) {\r
- DeleteObject( hbmPB );\r
- hbmPB = NULL;\r
- }\r
-\r
- hdcPB = CreateCompatibleDC( hDC );\r
-\r
- nWidthPB = width;\r
- nHeightPB = height;\r
- hbmPB = CreateCompatibleBitmap( hDC, nWidthPB, nHeightPB );\r
-\r
- SelectObject( hdcPB, hbmPB );\r
- }\r
-\r
- // back-end painting; calls back front-end primitives for lines, rectangles and text\r
- PaintEvalGraph();\r
- SetWindowText(hWnd, MakeEvalTitle(differentialView ? T_("Blunder Graph") : T_("Evaluation Graph")));\r
-\r
- /* Copy bitmap into destination DC */\r
- BitBlt( hDC, 0, 0, nWidthPB, nHeightPB, hdcPB, 0, 0, SRCCOPY );\r
-}\r
-\r
-// Note: Once the eval graph is opened, this window-proc lives forever; een closing the\r
-// eval-graph window merely hides it. On opening we re-initialize it, though, so it could\r
-// as well hae been destroyed. While it is open it processes the REFRESH_GRAPH commands.\r
-LRESULT CALLBACK EvalGraphProc( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )\r
-{\r
- static SnapData sd;\r
-\r
- PAINTSTRUCT stPS;\r
- HDC hDC;\r
-\r
- switch (message) {\r
- case WM_INITDIALOG:\r
- Translate(hDlg, DLG_EvalGraph);\r
- if( evalGraphDialog == NULL ) {\r
- evalGraphDialog = hDlg;\r
-\r
- RestoreWindowPlacement( hDlg, &wpEvalGraph ); /* Restore window placement */\r
- }\r
-\r
- return FALSE;\r
-\r
- case WM_COMMAND:\r
- switch (LOWORD(wParam)) {\r
- case IDOK:\r
- EndDialog(hDlg, TRUE);\r
- return TRUE;\r
-\r
- case IDCANCEL:\r
- EndDialog(hDlg, FALSE);\r
- return TRUE;\r
-\r
- default:\r
- break;\r
- }\r
-\r
- break;\r
-\r
- case WM_ERASEBKGND:\r
- return TRUE;\r
-\r
- case WM_PAINT:\r
- hDC = BeginPaint( hDlg, &stPS );\r
- DisplayEvalGraph( hDlg, hDC );\r
- EndPaint( hDlg, &stPS );\r
- break;\r
-\r
- case WM_MOUSEWHEEL:\r
- if((short)HIWORD(wParam) < 0) appData.zoom++;\r
- if((short)HIWORD(wParam) > 0 && appData.zoom > 1) appData.zoom--;\r
- goto paint;\r
- case WM_RBUTTONDOWN:\r
- differentialView = !differentialView;\r
- case WM_REFRESH_GRAPH:\r
- paint:\r
- hDC = GetDC( hDlg );\r
- DisplayEvalGraph( hDlg, hDC );\r
- ReleaseDC( hDlg, hDC );\r
- break;\r
-\r
- case WM_LBUTTONDOWN:\r
- if( wParam == 0 || wParam == MK_LBUTTON ) {\r
- int index = GetMoveIndexFromPoint( LOWORD(lParam), HIWORD(lParam) );\r
-\r
- if( index >= 0 && index < currLast ) {\r
- ToNrEvent( index + 1 );\r
- }\r
- }\r
- return TRUE;\r
-\r
- case WM_SIZE:\r
- InvalidateRect( hDlg, NULL, FALSE );\r
- break;\r
-\r
- case WM_GETMINMAXINFO:\r
- {\r
- MINMAXINFO * mmi = (MINMAXINFO *) lParam;\r
- \r
- mmi->ptMinTrackSize.x = 100;\r
- mmi->ptMinTrackSize.y = 100;\r
- }\r
- break;\r
-\r
- /* Support for captionless window */\r
- case WM_CLOSE:\r
- EvalGraphPopDown();\r
- break;\r
-\r
- case WM_ENTERSIZEMOVE:\r
- return OnEnterSizeMove( &sd, hDlg, wParam, lParam );\r
-\r
- case WM_SIZING:\r
- return OnSizing( &sd, hDlg, wParam, lParam );\r
-\r
- case WM_MOVING:\r
- return OnMoving( &sd, hDlg, wParam, lParam );\r
-\r
- case WM_EXITSIZEMOVE:\r
- return OnExitSizeMove( &sd, hDlg, wParam, lParam );\r
- }\r
-\r
- return FALSE;\r
-}\r
-\r
-// creates the eval graph, or unhides it.\r
-VOID EvalGraphPopUp()\r
-{\r
- FARPROC lpProc;\r
- \r
- CheckMenuItem(GetMenu(hwndMain), IDM_ShowEvalGraph, MF_CHECKED);\r
-\r
- if( evalGraphDialog ) {\r
- SendMessage( evalGraphDialog, WM_INITDIALOG, 0, 0 );\r
-\r
- if( ! evalGraphDialogUp ) {\r
- ShowWindow(evalGraphDialog, SW_SHOW);\r
- }\r
- }\r
- else {\r
- crWhite = appData.evalHistColorWhite;\r
- crBlack = appData.evalHistColorBlack;\r
-\r
- lpProc = MakeProcInstance( (FARPROC) EvalGraphProc, hInst );\r
-\r
- /* Note to self: dialog must have the WS_VISIBLE style set, otherwise it's not shown! */\r
- CreateDialog( hInst, MAKEINTRESOURCE(DLG_EvalGraph), hwndMain, (DLGPROC)lpProc );\r
-\r
- FreeProcInstance(lpProc);\r
- }\r
-\r
- evalGraphDialogUp = TRUE;\r
-}\r
-\r
-// Note that this hides the window. It could as well have destroyed it.\r
-VOID EvalGraphPopDown()\r
-{\r
- CheckMenuItem(GetMenu(hwndMain), IDM_ShowEvalGraph, MF_UNCHECKED);\r
-\r
- if( evalGraphDialog ) {\r
- ShowWindow(evalGraphDialog, SW_HIDE);\r
- }\r
-\r
- evalGraphDialogUp = FALSE;\r
-}\r
-\r
-// This function is the interface to the back-end. It is currently called through the front-end,\r
-// though, where it shares the HistorySet() wrapper with MoveHistorySet(). Once all front-ends\r
-// support the eval graph, it would be more logical to call it directly from the back-end.\r
-VOID EvalGraphSet( int first, int last, int current, ChessProgramStats_Move * pvInfo )\r
-{\r
- /* [AS] Danger! For now we rely on the pvInfo parameter being a static variable! */\r
-\r
- currFirst = first;\r
- currLast = last;\r
- currCurrent = current;\r
- currPvInfo = pvInfo;\r
-\r
- if( evalGraphDialog ) {\r
- SendMessage( evalGraphDialog, WM_REFRESH_GRAPH, 0, 0 );\r
- }\r
-}\r