From 33ddf089fa72ec8ed7e9613b1325d71cfe77fc63 Mon Sep 17 00:00:00 2001 From: H.G.Muller Date: Sun, 21 Sep 2014 16:47:41 +0200 Subject: [PATCH] Control Eval Graph with mouse Let mousewheel control evalZoom, and right-click toggle between normal view and differential view ('blunder graph'). --- evalgraph.c | 15 ++++++++++++++- evalgraph.h | 3 ++- nevalgraph.c | 17 +++++++++++------ winboard/wevalgraph.c | 11 +++++++++-- 4 files changed, 36 insertions(+), 10 deletions(-) diff --git a/evalgraph.c b/evalgraph.c index 2767560..e3608f0 100644 --- a/evalgraph.c +++ b/evalgraph.c @@ -53,6 +53,7 @@ int currFirst = 0; int currLast = 0; int currCurrent = -1; int range = 1; +int differentialView; int nWidthPB = 0; int nHeightPB = 0; @@ -85,6 +86,7 @@ GetPvScore (int index) { int score = currPvInfo[ index ].score; + if(differentialView) score = index < currLast-1 ? -currPvInfo[ index+1 ].score - score : 0; if( index & 1 ) score = -score; /* Flip score for black */ return score; @@ -312,15 +314,26 @@ static void DrawHistograms () { VisualizationData vd; + int i; double step = 1; if( InitVisualization( &vd ) ) { if( vd.hist_width < MIN_HIST_WIDTH ) { DrawHistogramAsDiagram( vd.cy, vd.paint_width, vd.hist_count ); + step = 0.5*vd.paint_width / (((vd.hist_count | 7) + 1)/2 + 1.); } else { - DrawHistogramFull( vd.cy, vd.hist_width, vd.hist_count ); + DrawHistogramFull( vd.cy, step = vd.hist_width, vd.hist_count ); } } + if(!differentialView) return; + differentialView = 0; + DrawSegment( MarginX + MarginW, vd.cy, NULL, NULL, PEN_NONE ); + for( i=0; imax; nHeightPB = disp->value; - if(t != title && nWidthPB < 340) t = MakeEvalTitle(nWidthPB < 240 ? "" : _("Eval")); + if(t != title[differentialView] && nWidthPB < 340) + t = MakeEvalTitle(nWidthPB < 240 ? "" : differentialView ? _("Blunder") : _("Eval")); PaintEvalGraph(); GraphExpose(graphOptions, 0, 0, nWidthPB, nHeightPB); SetDialogTitle(EvalGraphDlg, t); @@ -111,9 +112,13 @@ DisplayEvalGraph () static Option * EvalCallback (int button, int x, int y) { + int dir = appData.zoom + 1; if(!initDone) return NULL; switch(button) { + case 3: dir = 0; differentialView = !differentialView; + case 4: dir -= 2; + case 5: if(dir > 0) appData.zoom = dir; case 10: // expose event /* Create or recreate paint box if needed */ if(x != nWidthPB || y != nHeightPB) { @@ -132,12 +137,12 @@ EvalCallback (int button, int x, int y) void EvalGraphPopUp () { - if (GenericPopUp(graphOptions, _(title), EvalGraphDlg, BoardWindow, NONMODAL, appData.topLevel)) { + if (GenericPopUp(graphOptions, _(title[differentialView]), EvalGraphDlg, BoardWindow, NONMODAL, appData.topLevel)) { InitializeEvalGraph(&graphOptions[0], wpEvalGraph.width, wpEvalGraph.height); // first time: add callbacks and initialize pens disp = graphOptions; } else { - SetDialogTitle(EvalGraphDlg, _(title)); - SetIconName(EvalGraphDlg, _(title)); + SetDialogTitle(EvalGraphDlg, _(title[differentialView])); + SetIconName(EvalGraphDlg, _(title[differentialView])); } MarkMenu("View.EvaluationGraph", EvalGraphDlg); diff --git a/winboard/wevalgraph.c b/winboard/wevalgraph.c index ee71b60..ca04343 100644 --- a/winboard/wevalgraph.c +++ b/winboard/wevalgraph.c @@ -51,7 +51,7 @@ static COLORREF crBlack = RGB( 0xAD, 0x5D, 0x3D ); static HDC hdcPB = NULL; static HBITMAP hbmPB = NULL; -static HPEN pens[6]; // [HGM] put all pens in one array +static HPEN pens[PEN_ANY+1]; // [HGM] put all pens in one array static HBRUSH hbrHist[3] = { NULL, NULL, NULL }; Boolean EvalGraphIsUp() @@ -156,7 +156,7 @@ static VOID DisplayEvalGraph( HWND hWnd, HDC hDC ) // back-end painting; calls back front-end primitives for lines, rectangles and text PaintEvalGraph(); - SetWindowText(hWnd, MakeEvalTitle(T_("Evaluation Graph"))); + SetWindowText(hWnd, MakeEvalTitle(differentialView ? T_("Blunder Graph") : T_("Evaluation Graph"))); /* Copy bitmap into destination DC */ BitBlt( hDC, 0, 0, nWidthPB, nHeightPB, hdcPB, 0, 0, SRCCOPY ); @@ -208,7 +208,14 @@ LRESULT CALLBACK EvalGraphProc( HWND hDlg, UINT message, WPARAM wParam, LPARAM l EndPaint( hDlg, &stPS ); break; + case WM_MOUSEWHEEL: + if((short)HIWORD(wParam) < 0) appData.zoom++; + if((short)HIWORD(wParam) > 0 && appData.zoom > 1) appData.zoom--; + goto paint; + case WM_RBUTTONDOWN: + differentialView = !differentialView; case WM_REFRESH_GRAPH: + paint: hDC = GetDC( hDlg ); DisplayEvalGraph( hDlg, hDC ); ReleaseDC( hDlg, hDC ); -- 1.7.0.4