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 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 */
52 #include <X11/Intrinsic.h>
53 #include <X11/StringDefs.h>
54 #include <X11/Shell.h>
55 #include <X11/Xaw/Dialog.h>
56 #include <X11/Xaw/Form.h>
57 #include <X11/Xaw/List.h>
58 #include <X11/Xaw/Label.h>
59 #include <X11/Xaw/SimpleMenu.h>
60 #include <X11/Xaw/SmeBSB.h>
61 #include <X11/Xaw/SmeLine.h>
62 #include <X11/Xaw/Box.h>
63 #include <X11/Xaw/Paned.h>
64 #include <X11/Xaw/MenuButton.h>
65 #include <X11/cursorfont.h>
66 #include <X11/Xaw/Text.h>
67 #include <X11/Xaw/AsciiText.h>
68 #include <X11/Xaw/Viewport.h>
76 #include "evalgraph.h"
80 # define _(s) gettext (s)
81 # define N_(s) gettext_noop (s)
95 Pixmap icons[8]; // [HGM] this front-end array translates back-end icon indicator to handle
96 Widget outputField[2][7]; // [HGM] front-end array to translate output field to window handle
97 static char *title = N_("Evaluation graph");
99 //extern WindowPlacement wpEvalGraph;
101 Position evalGraphX = -1, evalGraphY = -1;
102 Dimension evalGraphW, evalGraphH;
104 /* Module variables */
106 char *crWhite = "#FFFFB0";
107 char *crBlack = "#AD5D3D";
108 static Window eGraphWindow;
110 static GC pens[6]; // [HGM] put all pens in one array
111 static GC hbrHist[3];
113 // [HGM] front-end, added as wrapper to avoid use of LineTo and MoveToEx in other routines (so they can be back-end)
115 DrawSegment (int x, int y, int *lastX, int *lastY, int penType)
117 static int curX, curY;
119 if(penType != PEN_NONE)
120 XDrawLine(xDisplay, eGraphWindow, pens[penType], curX, curY, x, y);
121 if(lastX != NULL) { *lastX = curX; *lastY = curY; }
125 // front-end wrapper for drawing functions to do rectangles
127 DrawRectangle (int left, int top, int right, int bottom, int side, int style)
129 XFillRectangle(xDisplay, eGraphWindow, hbrHist[side], left, top, right-left, bottom-top);
131 XDrawRectangle(xDisplay, eGraphWindow, pens[PEN_BLACK], left, top, right-left-1, bottom-top-1);
134 // front-end wrapper for putting text in graph
136 DrawEvalText (char *buf, int cbBuf, int y)
138 // the magic constants 7 and 5 should really be derived from the font size somehow
139 XDrawString(xDisplay, eGraphWindow, coordGC, MarginX - 2 - 7*cbBuf, y+5, buf, cbBuf);
144 MakeColor (char *color)
148 vFrom.addr = (caddr_t) color;
149 vFrom.size = strlen(color);
150 XtConvert(shells[EvalGraphDlg], XtRString, &vFrom, XtRPixel, &vTo);
153 return *(Pixel *) vTo.addr;
157 CreateGC (int width, char *fg, char *bg, int style)
159 XtGCMask value_mask = GCLineWidth | GCLineStyle | GCForeground
160 | GCBackground | GCFunction | GCPlaneMask;
163 gc_values.plane_mask = AllPlanes;
164 gc_values.line_width = width;
165 gc_values.line_style = style;
166 gc_values.function = GXcopy;
168 gc_values.foreground = MakeColor(fg);
169 gc_values.background = MakeColor(bg);
171 return XtGetGC(shells[EvalGraphDlg], value_mask, &gc_values);
174 static int initDone = FALSE;
177 InitializeEvalGraph (Option *opt)
179 eGraphWindow = XtWindow(opt->handle);
181 pens[PEN_BLACK] = CreateGC(1, "black", "black", LineSolid);
182 pens[PEN_DOTTED] = CreateGC(1, "#A0A0A0", "#A0A0A0", LineOnOffDash);
183 pens[PEN_BLUEDOTTED] = CreateGC(1, "#0000FF", "#0000FF", LineOnOffDash);
184 pens[PEN_BOLD] = CreateGC(3, crWhite, crWhite, LineSolid);
185 pens[PEN_BOLD+1] = CreateGC(3, crBlack, crBlack, LineSolid);
186 hbrHist[0] = CreateGC(3, crWhite, crWhite, LineSolid);
187 hbrHist[1] = CreateGC(3, crBlack, crBlack, LineSolid);
188 hbrHist[2] = CreateGC(3, "#E0E0F0", "#E0E0F0", LineSolid);; // background (a bit blueish, for contrst with yellow curve)
193 // The following stuff is really back-end (but too little to bother with a separate file)
197 { // back-end painting; calls back front-end primitives for lines, rectangles and text
198 char *t = MakeEvalTitle(_(title));
199 if(t != title && nWidthPB < 340) t = MakeEvalTitle(nWidthPB < 240 ? "" : _("Eval"));
201 SetDialogTitle(EvalGraphDlg, t);
205 EvalClick (int x, int y)
207 int index = GetMoveIndexFromPoint( x, y );
209 if( index >= 0 && index < currLast ) ToNrEvent( index + 1 );
213 EvalCallback (int button, int x, int y)
215 if(!initDone) return NULL;
218 case 10: // expose event
219 /* Create or recreate paint box if needed */
224 case 1: EvalClick(x, y); // left button
225 default: break; // other buttons ignored
227 return NULL; // no context menu!
230 static Option graphOptions[] = {
231 { 150, 0x9C, 300, NULL, (void*) &EvalCallback, NULL, NULL, Graph , "" },
232 { 0, 2, 0, NULL, NULL, "", NULL, EndMark , "" }
241 if (GenericPopUp(graphOptions, _(title), EvalGraphDlg, BoardWindow, NONMODAL, 1)) {
242 InitializeEvalGraph(&graphOptions[0]); // first time: add callbacks and initialize pens
244 SetDialogTitle(EvalGraphDlg, _(title));
245 SetIconName(EvalGraphDlg, _(title));
248 MarkMenu("Show Evaluation Graph", EvalGraphDlg);
250 // ShowThinkingEvent(); // [HGM] thinking: might need to prompt engine for thinking output
256 PopDown(EvalGraphDlg);
258 // ShowThinkingEvent(); // [HGM] thinking: might need to shut off thinking output
264 return shellUp[EvalGraphDlg];
268 EvalGraphDialogExists ()
270 return DialogExists(EvalGraphDlg);
276 if (!PopDown(EvalGraphDlg)) EvalGraphPopUp();
279 // This function is the interface to the back-end.
282 EvalGraphSet (int first, int last, int current, ChessProgramStats_Move * pvInfo)
284 /* [AS] Danger! For now we rely on the pvInfo parameter being a static variable! */
288 currCurrent = current;
291 if( DialogExists(EvalGraphDlg) ) {