- if( index > 0 ) {\r
- if( index == currCurrent ) {\r
- HPEN hp = SelectObject( hdcPB, hpenBlueDotted );\r
- DrawLineEx( x, MarginH, x, nHeightPB - MarginH );\r
- SelectObject( hdcPB, hp );\r
- }\r
- else if( (index % 20) == 0 ) {\r
- HPEN hp = SelectObject( hdcPB, hpenDotted );\r
- DrawLineEx( x, MarginH, x, nHeightPB - MarginH );\r
- SelectObject( hdcPB, hp );\r
- }\r
- }\r
-}\r
-\r
-/* Actually draw histogram as a diagram, cause there's too much data */\r
-static VOID DrawHistogramAsDiagram( int cy, int paint_width, int hist_count )\r
-{\r
- double step;\r
- int i;\r
-\r
- /* Rescale the graph every few moves (as opposed to every move) */\r
- hist_count -= hist_count % 8;\r
- hist_count += 8;\r
- hist_count /= 2;\r
-\r
- step = (double) paint_width / (hist_count + 1);\r
-\r
- for( i=0; i<2; i++ ) {\r
- int index = currFirst;\r
- int side = (currCurrent + i + 1) & 1; /* Draw current side last */\r
- double x = MarginX + MarginW;\r
-\r
- if( (index & 1) != side ) {\r
- x += step / 2;\r
- index++;\r
- }\r
-\r
- SelectObject( hdcPB, hpenBold[side] );\r
-\r
- MoveToEx( hdcPB, (int) x, cy, NULL );\r
-\r
- index += 2;\r
-\r
- while( index < currLast ) {\r
- x += step;\r
-\r
- DrawSeparator( index, (int) x );\r
-\r
- /* Extend line up to current point */\r
- if( currPvInfo[index].depth > 0 ) {\r
- LineTo( hdcPB, (int) x, GetValueY( GetPvScore(index) ) );\r
- }\r
-\r
- index += 2;\r
- }\r
- }\r
-}\r
-\r
-static VOID DrawHistogramFull( int cy, int hist_width, int hist_count )\r
-{\r
- int i;\r
-\r
- SelectObject( hdcPB, GetStockObject(BLACK_PEN) );\r
-\r
- for( i=0; i<hist_count; i++ ) {\r
- int index = currFirst + i;\r
- int x = MarginX + MarginW + index * hist_width;\r
-\r
- /* Draw a separator every 10 moves */\r
- DrawSeparator( index, x );\r
-\r
- /* Draw histogram */\r
- if( currPvInfo[i].depth > 0 ) {\r
- DrawHistogram( x, cy, hist_width, GetPvScore(index), index & 1 );\r
- }\r
- }\r
-}\r
-\r
-typedef struct {\r
- int cy;\r
- int hist_width;\r
- int hist_count;\r
- int paint_width;\r
-} VisualizationData;\r
-\r
-static BOOL InitVisualization( VisualizationData * vd )\r
-{\r
- BOOL result = FALSE;\r
-\r
- vd->cy = nHeightPB / 2;\r
- vd->hist_width = MIN_HIST_WIDTH;\r
- vd->hist_count = currLast - currFirst;\r
- vd->paint_width = nWidthPB - MarginX - 2*MarginW;\r
-\r
- if( vd->hist_count > 0 ) {\r
- result = TRUE;\r
-\r
- /* Compute width */\r
- vd->hist_width = vd->paint_width / vd->hist_count;\r
-\r
- if( vd->hist_width > MAX_HIST_WIDTH ) vd->hist_width = MAX_HIST_WIDTH;\r
-\r
- vd->hist_width -= vd->hist_width % 2;\r
- }\r
-\r
- return result;\r
-}\r
-\r
-static VOID DrawHistograms()\r
-{\r
- VisualizationData vd;\r
-\r
- if( InitVisualization( &vd ) ) {\r
- if( vd.hist_width < MIN_HIST_WIDTH ) {\r
- DrawHistogramAsDiagram( vd.cy, vd.paint_width, vd.hist_count );\r
- }\r
- else {\r
- DrawHistogramFull( vd.cy, vd.hist_width, vd.hist_count );\r
- }\r
- }\r
-}\r
-\r
-static int GetMoveIndexFromPoint( int x, int y )\r
-{\r
- int result = -1;\r
- int start_x = MarginX + MarginW;\r
- VisualizationData vd;\r
-\r
- if( x >= start_x && InitVisualization( &vd ) ) {\r
- /* Almost an hack here... we duplicate some of the paint logic */\r
- if( vd.hist_width < MIN_HIST_WIDTH ) {\r
- double step;\r
-\r
- vd.hist_count -= vd.hist_count % 8;\r
- vd.hist_count += 8;\r
- vd.hist_count /= 2;\r
-\r
- step = (double) vd.paint_width / (vd.hist_count + 1);\r
- step /= 2;\r
-\r
- result = (int) (0.5 + (double) (x - start_x) / step);\r
- }\r
- else {\r
- result = (x - start_x) / vd.hist_width;\r
- }\r
- }\r
-\r
- if( result >= currLast ) {\r
- result = -1;\r
- }\r
-\r
- return result;\r