4 * Author: Alessandro Scotti (Dec 2005)
5 * Translated to X by H.G.Muller (Nov 2009)
7 * Copyright 2005 Alessandro Scotti
9 * Enhancements Copyright 2009, 2010, 2011, 2012, 2013, 2014, 2015 Free Software Foundation, Inc.
11 * ------------------------------------------------------------------------
13 * GNU XBoard is free software: you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation, either version 3 of the License, or (at
16 * your option) any later version.
18 * GNU XBoard is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see http://www.gnu.org/licenses/.
26 * ------------------------------------------------------------------------
27 ** See the file ChangeLog for a revision history. */
34 #include <sys/types.h>
39 #else /* not STDC_HEADERS */
40 extern char *getenv();
43 # else /* not HAVE_STRING_H */
45 # endif /* not HAVE_STRING_H */
46 #endif /* not STDC_HEADERS */
56 #include "evalgraph.h"
61 # define _(s) gettext (s)
62 # define N_(s) gettext_noop (s)
68 static char *title[2] = { N_("Evaluation graph"), N_("Blunder graph") };
71 /* Module variables */
73 static Option *EvalCallback P((int button, int x, int y));
75 static int initDone = FALSE;
78 InitializeEvalGraph (Option *opt, int w, int h)
80 nWidthPB = w, nHeightPB = h;
85 // The following stuff is really back-end (but too little to bother with a separate file)
88 EvalClick (int x, int y)
90 int index = GetMoveIndexFromPoint( x, y );
92 if( index >= 0 && index < currLast ) ToNrEvent( index + 1 );
95 static Option graphOptions[] = {
96 { 150, 0x9C, 300, NULL, (void*) &EvalCallback, NULL, NULL, Graph , "" },
97 { 0, 2, 0, NULL, NULL, "", NULL, EndMark , "" }
102 { // back-end painting; calls back front-end primitives for lines, rectangles and text
103 char *t = MakeEvalTitle(_(title[differentialView]));
104 nWidthPB = disp->max; nHeightPB = disp->value;
105 if(t != title[differentialView] && nWidthPB < 340)
106 t = MakeEvalTitle(nWidthPB < 240 ? "" : differentialView ? _("Blunder") : _("Eval"));
108 GraphExpose(graphOptions, 0, 0, nWidthPB, nHeightPB);
109 SetDialogTitle(EvalGraphDlg, t);
113 EvalCallback (int button, int x, int y)
115 int dir = appData.zoom + 1;
116 if(!initDone) return NULL;
119 case 3: dir = 0; differentialView = !differentialView;
121 case 5: if(dir > 0) appData.zoom = dir;
122 case 10: // expose event
123 /* Create or recreate paint box if needed */
124 if(x != nWidthPB || y != nHeightPB) {
125 InitializeEvalGraph(&graphOptions[0], x, y);
131 case 1: EvalClick(x, y); // left button
132 default: break; // other buttons ignored
134 return NULL; // no context menu!
140 if (GenericPopUp(graphOptions, _(title[differentialView]), EvalGraphDlg, BoardWindow, NONMODAL, appData.topLevel)) {
141 InitializeEvalGraph(&graphOptions[0], wpEvalGraph.width, wpEvalGraph.height); // first time: add callbacks and initialize pens
144 SetDialogTitle(EvalGraphDlg, _(title[differentialView]));
145 SetIconName(EvalGraphDlg, _(title[differentialView]));
148 MarkMenu("View.EvaluationGraph", EvalGraphDlg);
150 // ShowThinkingEvent(); // [HGM] thinking: might need to prompt engine for thinking output
156 PopDown(EvalGraphDlg);
158 // ShowThinkingEvent(); // [HGM] thinking: might need to shut off thinking output
164 return shellUp[EvalGraphDlg];
168 EvalGraphDialogExists ()
170 return DialogExists(EvalGraphDlg);
176 if (!PopDown(EvalGraphDlg)) EvalGraphPopUp();
179 // This function is the interface to the back-end.
182 EvalGraphSet (int first, int last, int current, ChessProgramStats_Move * pvInfo)
184 /* [AS] Danger! For now we rely on the pvInfo parameter being a static variable! */
188 currCurrent = current;
191 if( DialogExists(EvalGraphDlg) ) {