Fix multi-leg promotions
[xboard.git] / evalgraph.c
index 9c26897..1a8bd07 100644 (file)
@@ -5,7 +5,8 @@
  *
  * Copyright 2005 Alessandro Scotti
  *
- * Enhancments Copyright 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
+ * Enhancments Copyright 2009, 2010, 2011, 2012, 2013, 2014, 2015,
+ * 2016 Free Software Foundation, Inc.
  *
  * ------------------------------------------------------------------------
  *
@@ -53,6 +54,7 @@ int currFirst = 0;
 int currLast = 0;
 int currCurrent = -1;
 int range = 1;
+int differentialView;
 
 int nWidthPB = 0;
 int nHeightPB = 0;
@@ -85,6 +87,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;
@@ -102,7 +105,7 @@ MakeEvalTitle (char *title)
 
     if( depth <=0 ) return title;
     if( currCurrent & 1 ) score = -score; /* Flip score for black */
-    snprintf(buf, MSG_SIZ, "%s {%d: %s%.2f/%-2d %d}", title, currCurrent/2+1, 
+    snprintf(buf, MSG_SIZ, "%s {%d: %s%.2f/%-2d %d}", title, currCurrent/2+1,
                                score>0 ? "+" : " ", score/100., depth, (currPvInfo[currCurrent].time+50)/100);
 
     return buf;
@@ -120,8 +123,8 @@ GetValueY (int value)
 {
     if( value < -range*700 ) value = -range*700;
     if( value > +range*700 ) value = +range*700;
-    if(value > 100*range)  value += appData.zoom * 100 - 100*range; else
-    if(value < -100*range) value -= appData.zoom * 100 - 100*range; else
+    if(value > 100*range)  value += (appData.zoom - 1)*100*range; else
+    if(value < -100*range) value -= (appData.zoom - 1)*100*range; else
        value *= appData.zoom;
     return (nHeightPB / 2) - (int)(value * (nHeightPB - 2*MarginH) / ((1200. + 200.*appData.zoom)*range));
 }
@@ -152,7 +155,7 @@ static void
 DrawAxis ()
 {
     int cy = nHeightPB / 2, space = nHeightPB/(6 + appData.zoom);
-    
+
     DrawAxisSegmentHoriz( +5, TRUE );
     DrawAxisSegmentHoriz( +3, space >= 20 );
     DrawAxisSegmentHoriz( +1, space >= 20 && space*appData.zoom >= 40 );
@@ -245,7 +248,7 @@ DrawHistogramAsDiagram (int cy, int paint_width, int hist_count)
 
             /* Extend line up to current point */
             if( currPvInfo[index].depth > 0 ) {
-                DrawSegment((int) x, GetValueY( GetPvScore(index) ), NULL, NULL, PEN_BOLD + side );
+             DrawSegment((int) x, GetValueY( GetPvScore(index) ), NULL, NULL, (side==0 ? PEN_BOLDWHITE: PEN_BOLDBLACK) );
             }
 
             index += 2;
@@ -312,15 +315,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; i<vd.hist_count; i++ ) {
+        int index = currFirst + i;
+        int x = MarginX + MarginW + index * step + step/2;
+        DrawSegment((int) x, GetValueY( GetPvScore(index) ), NULL, NULL, PEN_ANY );
+    }
+    differentialView = 1;
 }
 
 // back-end