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,
10 * 2016 Free Software Foundation, Inc.
12 * ------------------------------------------------------------------------
14 * GNU XBoard is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or (at
17 * your option) any later version.
19 * GNU XBoard is distributed in the hope that it will be useful, but
20 * WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program. If not, see http://www.gnu.org/licenses/.
27 * ------------------------------------------------------------------------
28 ** See the file ChangeLog for a revision history. */
35 #include <sys/types.h>
40 #else /* not STDC_HEADERS */
41 extern char *getenv();
44 # else /* not HAVE_STRING_H */
46 # endif /* not HAVE_STRING_H */
47 #endif /* not STDC_HEADERS */
57 #include "evalgraph.h"
62 # define _(s) gettext (s)
63 # define N_(s) gettext_noop (s)
69 static char *title[2] = { N_("Evaluation graph"), N_("Blunder graph") };
72 /* Module variables */
74 static Option *EvalCallback P((int button, int x, int y));
76 static int initDone = FALSE;
79 InitializeEvalGraph (Option *opt, int w, int h)
81 nWidthPB = w, nHeightPB = h;
86 // The following stuff is really back-end (but too little to bother with a separate file)
89 EvalClick (int x, int y)
91 int index = GetMoveIndexFromPoint( x, y );
93 if( index >= 0 && index < currLast ) ToNrEvent( index + 1 );
96 static Option graphOptions[] = {
97 { 150, 0x9C, 300, NULL, (void*) &EvalCallback, NULL, NULL, Graph , "" },
98 { 0, 2, 0, NULL, NULL, "", NULL, EndMark , "" }
103 { // back-end painting; calls back front-end primitives for lines, rectangles and text
104 char *t = MakeEvalTitle(_(title[differentialView]));
105 nWidthPB = disp->max; nHeightPB = disp->value;
106 if(t != title[differentialView] && nWidthPB < 340)
107 t = MakeEvalTitle(nWidthPB < 240 ? "" : differentialView ? _("Blunder") : _("Eval"));
109 GraphExpose(graphOptions, 0, 0, nWidthPB, nHeightPB);
110 SetDialogTitle(EvalGraphDlg, t);
114 EvalCallback (int button, int x, int y)
116 int dir = appData.zoom + 1;
117 if(!initDone) return NULL;
120 case 3: dir = 0; differentialView = !differentialView;
122 case 5: if(dir > 0) appData.zoom = dir;
123 case 10: // expose event
124 /* Create or recreate paint box if needed */
125 if(x != nWidthPB || y != nHeightPB) {
126 InitializeEvalGraph(&graphOptions[0], x, y);
132 case 1: EvalClick(x, y); // left button
133 default: break; // other buttons ignored
135 return NULL; // no context menu!
141 if (GenericPopUp(graphOptions, _(title[differentialView]), EvalGraphDlg, BoardWindow, NONMODAL, appData.topLevel)) {
142 InitializeEvalGraph(&graphOptions[0], wpEvalGraph.width, wpEvalGraph.height); // first time: add callbacks and initialize pens
145 SetDialogTitle(EvalGraphDlg, _(title[differentialView]));
146 SetIconName(EvalGraphDlg, _(title[differentialView]));
149 MarkMenu("View.EvaluationGraph", EvalGraphDlg);
151 // ShowThinkingEvent(); // [HGM] thinking: might need to prompt engine for thinking output
157 PopDown(EvalGraphDlg);
159 // ShowThinkingEvent(); // [HGM] thinking: might need to shut off thinking output
165 return shellUp[EvalGraphDlg];
169 EvalGraphDialogExists ()
171 return DialogExists(EvalGraphDlg);
177 if (!PopDown(EvalGraphDlg)) EvalGraphPopUp();
180 // This function is the interface to the back-end.
183 EvalGraphSet (int first, int last, int current, ChessProgramStats_Move * pvInfo)
185 /* [AS] Danger! For now we rely on the pvInfo parameter being a static variable! */
189 currCurrent = current;
192 if( DialogExists(EvalGraphDlg) ) {