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 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 = N_("Evaluation 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));
104 nWidthPB = disp->max; nHeightPB = disp->value;
105 if(t != title && nWidthPB < 340) t = MakeEvalTitle(nWidthPB < 240 ? "" : _("Eval"));
107 GraphExpose(graphOptions, 0, 0, nWidthPB, nHeightPB);
108 SetDialogTitle(EvalGraphDlg, t);
112 EvalCallback (int button, int x, int y)
114 if(!initDone) return NULL;
117 case 10: // expose event
118 /* Create or recreate paint box if needed */
119 if(x != nWidthPB || y != nHeightPB) {
120 InitializeEvalGraph(&graphOptions[0], x, y);
126 case 1: EvalClick(x, y); // left button
127 default: break; // other buttons ignored
129 return NULL; // no context menu!
135 if (GenericPopUp(graphOptions, _(title), EvalGraphDlg, BoardWindow, NONMODAL, appData.topLevel)) {
136 InitializeEvalGraph(&graphOptions[0], wpEvalGraph.width, wpEvalGraph.height); // first time: add callbacks and initialize pens
139 SetDialogTitle(EvalGraphDlg, _(title));
140 SetIconName(EvalGraphDlg, _(title));
143 MarkMenu("View.EvaluationGraph", EvalGraphDlg);
145 // ShowThinkingEvent(); // [HGM] thinking: might need to prompt engine for thinking output
151 PopDown(EvalGraphDlg);
153 // ShowThinkingEvent(); // [HGM] thinking: might need to shut off thinking output
159 return shellUp[EvalGraphDlg];
163 EvalGraphDialogExists ()
165 return DialogExists(EvalGraphDlg);
171 if (!PopDown(EvalGraphDlg)) EvalGraphPopUp();
174 // This function is the interface to the back-end.
177 EvalGraphSet (int first, int last, int current, ChessProgramStats_Move * pvInfo)
179 /* [AS] Danger! For now we rely on the pvInfo parameter being a static variable! */
183 currCurrent = current;
186 if( DialogExists(EvalGraphDlg) ) {