From: H.G. Muller Date: Sun, 14 Oct 2012 13:31:56 +0000 (+0200) Subject: Make xevalgraph.c backend X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=aa694af0138b799c4de3e031d15c2a9be3112b6c;p=xboard.git Make xevalgraph.c backend The only front-end stuff left in xevalgraph.c was an unnecessary reading of the window size (which could be obtained from the WindowPlaceent struct), and drawing (all cairo now). The drawing was moved to draw.c, and the remaining part renamed nevalgraph.c. An attempt to list them in a less chaotic way. --- diff --git a/Makefile.am b/Makefile.am index 4dfe409..e771fc8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -10,14 +10,13 @@ endif ### define sources for the front-end and backend -GTKsources = xboard.c xevalgraph.c xgamelist.c \ +GTKsources = xboard.c xgamelist.c \ xhistory.c xoptions.c xboard.h \ - xengineoutput.c xevalgraph.h xgamelist.h \ + xengineoutput.c xgamelist.h \ xhistory.h Xsources = xaw/xboard.c xaw/xboard.h \ xaw/xengineoutput.c \ - xaw/xevalgraph.c xaw/xevalgraph.h \ xaw/xgamelist.c xaw/xgamelist.h \ xaw/xhistory.c xaw/xhistory.h \ xaw/xoptions.c @@ -40,7 +39,7 @@ backendsources = backend.c backend.h backendz.h \ draw.c draw.h \ dialogs.c dialogs.h \ engineoutput.c nengineoutput.c engineoutput.h \ - evalgraph.c evalgraph.h \ + evalgraph.c nevalgraph.c evalgraph.h \ history.c nhistory.c \ menus.c menus.h \ usounds.c usystem.c usystem.h \ diff --git a/backend.c b/backend.c index 9f90dad..1113781 100644 --- a/backend.c +++ b/backend.c @@ -129,6 +129,7 @@ extern int gettimeofday(struct timeval *, struct timezone *); # include "zippy.h" #endif #include "backendz.h" +#include "evalgraph.h" #include "gettext.h" #ifdef ENABLE_NLS diff --git a/backend.h b/backend.h index 9449580..fae8ee7 100644 --- a/backend.h +++ b/backend.h @@ -435,7 +435,6 @@ int WaitForEngine P((ChessProgramState *cps, DelayedEventCallback x)); void Load P((ChessProgramState *cps, int n)); int MultiPV P((ChessProgramState *cps)); void MoveHistorySet P(( char movelist[][2*MOVE_LEN], int first, int last, int current, ChessProgramStats_Move * pvInfo )); -void EvalGraphSet P(( int first, int last, int current, ChessProgramStats_Move * pvInfo )); void MakeEngineOutputTitle P((void)); /* A point in time */ diff --git a/draw.c b/draw.c index 03160f0..02c2805 100644 --- a/draw.c +++ b/draw.c @@ -77,10 +77,10 @@ extern char *getenv(); #include "common.h" #include "backend.h" -#include "xevalgraph.h" #include "board.h" #include "menus.h" #include "dialogs.h" +#include "evalgraph.h" #include "gettext.h" #include "draw.h" @@ -117,6 +117,9 @@ int useTexture, textureW[2], textureH[2]; #define White(piece) ((int)(piece) < (int)BlackPawn) +char *crWhite = "#FFFFB0"; +char *crBlack = "#AD5D3D"; + struct { int x1, x2, y1, y2; } gridSegments[BOARD_RANKS + BOARD_FILES + 2]; @@ -815,4 +818,107 @@ DrawPolygon (Pnt arrow[], int nr) // if(!dual) DoDrawPolygon(csBoardBackup, arrow, nr); } +//-------------------- Eval Graph drawing routines (formerly in xevalgraph.h) -------------------- + +static void +ChoosePen(cairo_t *cr, int i) +{ + switch(i) { + case PEN_BLACK: + SetPen(cr, 1.0, "#000000", 0); + break; + case PEN_DOTTED: + SetPen(cr, 1.0, "#A0A0A0", 1); + break; + case PEN_BLUEDOTTED: + SetPen(cr, 1.0, "#0000FF", 1); + break; + case PEN_BOLDWHITE: + SetPen(cr, 3.0, crWhite, 0); + break; + case PEN_BOLDBLACK: + SetPen(cr, 3.0, crBlack, 0); + break; + case PEN_BACKGD: + SetPen(cr, 3.0, "#E0E0F0", 0); + break; + } +} + +// [HGM] front-end, added as wrapper to avoid use of LineTo and MoveToEx in other routines (so they can be back-end) +void +DrawSegment (int x, int y, int *lastX, int *lastY, int penType) +{ + static int curX, curY; + + if(penType != PEN_NONE) { + cairo_t *cr = cairo_create(DRAWABLE(disp)); + cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE); + cairo_move_to (cr, curX, curY); + cairo_line_to (cr, x,y); + ChoosePen(cr, penType); + cairo_stroke (cr); + cairo_destroy (cr); + } + + if(lastX != NULL) { *lastX = curX; *lastY = curY; } + curX = x; curY = y; +} + +// front-end wrapper for drawing functions to do rectangles +void +DrawRectangle (int left, int top, int right, int bottom, int side, int style) +{ + cairo_t *cr; + + cr = cairo_create (DRAWABLE(disp)); + cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE); + cairo_rectangle (cr, left, top, right-left, bottom-top); + switch(side) + { + case 0: ChoosePen(cr, PEN_BOLDWHITE); break; + case 1: ChoosePen(cr, PEN_BOLDBLACK); break; + case 2: ChoosePen(cr, PEN_BACKGD); break; + } + cairo_fill (cr); + + if(style != FILLED) + { + cairo_rectangle (cr, left, top, right-left-1, bottom-top-1); + ChoosePen(cr, PEN_BLACK); + cairo_stroke (cr); + } + + cairo_destroy(cr); +} + +// front-end wrapper for putting text in graph +void +DrawEvalText (char *buf, int cbBuf, int y) +{ + // the magic constants 8 and 5 should really be derived from the font size somehow + cairo_text_extents_t extents; + cairo_t *cr = cairo_create(DRAWABLE(disp)); + + /* GTK-TODO this has to go into the font-selection */ + cairo_select_font_face (cr, "Sans", + CAIRO_FONT_SLANT_NORMAL, + CAIRO_FONT_WEIGHT_NORMAL); + cairo_set_font_size (cr, 12.0); + + + cairo_text_extents (cr, buf, &extents); + + cairo_move_to (cr, MarginX - 2 - 8*cbBuf, y+5); + cairo_text_path (cr, buf); + cairo_set_source_rgb (cr, 0.0, 0.0, 0); + cairo_fill_preserve (cr); + cairo_set_source_rgb (cr, 0, 1.0, 0); + cairo_set_line_width (cr, 0.1); + cairo_stroke (cr); + + /* free memory */ + cairo_destroy (cr); +} + diff --git a/draw.h b/draw.h index a54735f..9083968 100644 --- a/draw.h +++ b/draw.h @@ -64,6 +64,13 @@ void CreateGCs P((int redo)); void CreateAnyPieces P((void)); void CreatePNGPieces P((void)); void CreateGrid P((void)); +void DrawSegment P((int x, int y, int *lastX, int *lastY, int p)); +void DrawRectangle P((int left, int top, int right, int bottom, int side, int style)); +void DrawEvalText P((char *buf, int cbBuf, int y)); +extern Option *disp; + +// defined in evaldraw.c +float Color P((char *col, int n)); // defined in xoptions.c void GraphExpose P((Option *opt, int x, int y, int w, int h)); diff --git a/evalgraph.c b/evalgraph.c index c18d3d2..43f183d 100644 --- a/evalgraph.c +++ b/evalgraph.c @@ -63,7 +63,7 @@ int MarginH = 4; // back-end static void -DrawLine (int x1, int y1, int x2, int y2, enum PEN penType) +DrawLine (int x1, int y1, int x2, int y2, int penType) { DrawSegment( x1, y1, NULL, NULL, PEN_NONE ); DrawSegment( x2, y2, NULL, NULL, penType ); @@ -71,7 +71,7 @@ DrawLine (int x1, int y1, int x2, int y2, enum PEN penType) // back-end static void -DrawLineEx (int x1, int y1, int x2, int y2, enum PEN penType) +DrawLineEx (int x1, int y1, int x2, int y2, int penType) { int savX, savY; DrawSegment( x1, y1, &savX, &savY, PEN_NONE ); diff --git a/evalgraph.h b/evalgraph.h index 9f51fc6..67c277b 100644 --- a/evalgraph.h +++ b/evalgraph.h @@ -27,7 +27,7 @@ #define MIN_HIST_WIDTH 4 #define MAX_HIST_WIDTH 10 -enum PEN { PEN_NONE, PEN_BLACK, PEN_DOTTED, PEN_BLUEDOTTED, PEN_BOLDWHITE, PEN_BOLDBLACK, PEN_BACKGD }; +typedef enum { PEN_NONE, PEN_BLACK, PEN_DOTTED, PEN_BLUEDOTTED, PEN_BOLDWHITE, PEN_BOLDBLACK, PEN_BACKGD } PenType; #define FILLED 1 #define OPEN 0 @@ -46,9 +46,10 @@ extern int MarginW; extern int MarginH; // calls from back-end part into front-end part -void DrawSegment( int x, int y, int *lastX, int *lastY, enum PEN ); +void DrawSegment( int x, int y, int *lastX, int *lastY, int p ); void DrawRectangle( int left, int top, int right, int bottom, int side, int style ); void DrawEvalText(char *buf, int cbBuf, int y); +void EvalGraphSet P(( int first, int last, int current, ChessProgramStats_Move * pvInfo )); // calls of front-end part into back-end part extern int GetMoveIndexFromPoint( int x, int y ); diff --git a/nevalgraph.c b/nevalgraph.c new file mode 100644 index 0000000..8dc395f --- /dev/null +++ b/nevalgraph.c @@ -0,0 +1,190 @@ +/* + * Evaluation graph + * + * Author: Alessandro Scotti (Dec 2005) + * Translated to X by H.G.Muller (Nov 2009) + * + * Copyright 2005 Alessandro Scotti + * + * Enhancements Copyright 2009, 2010, 2011, 2012 Free Software Foundation, Inc. + * + * ------------------------------------------------------------------------ + * + * GNU XBoard is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * GNU XBoard is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + * + * ------------------------------------------------------------------------ + ** See the file ChangeLog for a revision history. */ + +#include "config.h" + +#include +#include +#include +#include + +#if STDC_HEADERS +# include +# include +#else /* not STDC_HEADERS */ +extern char *getenv(); +# if HAVE_STRING_H +# include +# else /* not HAVE_STRING_H */ +# include +# endif /* not HAVE_STRING_H */ +#endif /* not STDC_HEADERS */ + +#if HAVE_UNISTD_H +# include +#endif + +#include "common.h" +#include "backend.h" +#include "dialogs.h" +#include "menus.h" +#include "evalgraph.h" +#include "draw.h" +#include "gettext.h" + +#ifdef ENABLE_NLS +# define _(s) gettext (s) +# define N_(s) gettext_noop (s) +#else +# define _(s) (s) +# define N_(s) s +#endif + +static char *title = N_("Evaluation graph"); +Option *disp; + +/* Module variables */ + +static Option *EvalCallback P((int button, int x, int y)); + +static int initDone = FALSE; + +static void +InitializeEvalGraph (Option *opt, int w, int h) +{ + nWidthPB = w, nHeightPB = h; + + initDone = TRUE; +} + +// The following stuff is really back-end (but too little to bother with a separate file) + +static void +EvalClick (int x, int y) +{ + int index = GetMoveIndexFromPoint( x, y ); + + if( index >= 0 && index < currLast ) ToNrEvent( index + 1 ); +} + +static Option graphOptions[] = { +{ 150, 0x9C, 300, NULL, (void*) &EvalCallback, NULL, NULL, Graph , "" }, +{ 0, 2, 0, NULL, NULL, "", NULL, EndMark , "" } +}; + +static void +DisplayEvalGraph () +{ // back-end painting; calls back front-end primitives for lines, rectangles and text + char *t = MakeEvalTitle(_(title)); + nWidthPB = disp->max; nHeightPB = disp->value; + if(t != title && nWidthPB < 340) t = MakeEvalTitle(nWidthPB < 240 ? "" : _("Eval")); + PaintEvalGraph(); + GraphExpose(graphOptions, 0, 0, nWidthPB, nHeightPB); + SetDialogTitle(EvalGraphDlg, t); +} + +static Option * +EvalCallback (int button, int x, int y) +{ + if(!initDone) return NULL; + + switch(button) { + case 10: // expose event + /* Create or recreate paint box if needed */ + if(x != nWidthPB || y != nHeightPB) { + InitializeEvalGraph(&graphOptions[0], x, y); + } + nWidthPB = x; + nHeightPB = y; + DisplayEvalGraph(); + break; + case 1: EvalClick(x, y); // left button + default: break; // other buttons ignored + } + return NULL; // no context menu! +} + +void +EvalGraphPopUp () +{ + if (GenericPopUp(graphOptions, _(title), EvalGraphDlg, BoardWindow, NONMODAL, 1)) { + InitializeEvalGraph(&graphOptions[0], wpEvalGraph.width, wpEvalGraph.height); // first time: add callbacks and initialize pens + disp = graphOptions; + } else { + SetDialogTitle(EvalGraphDlg, _(title)); + SetIconName(EvalGraphDlg, _(title)); + } + + MarkMenu("View.EvaluationGraph", EvalGraphDlg); + +// ShowThinkingEvent(); // [HGM] thinking: might need to prompt engine for thinking output +} + +void +EvalGraphPopDown () +{ + PopDown(EvalGraphDlg); + +// ShowThinkingEvent(); // [HGM] thinking: might need to shut off thinking output +} + +Boolean +EvalGraphIsUp () +{ + return shellUp[EvalGraphDlg]; +} + +int +EvalGraphDialogExists () +{ + return DialogExists(EvalGraphDlg); +} + +void +EvalGraphProc () +{ + if (!PopDown(EvalGraphDlg)) EvalGraphPopUp(); +} + +// This function is the interface to the back-end. + +void +EvalGraphSet (int first, int last, int current, ChessProgramStats_Move * pvInfo) +{ + /* [AS] Danger! For now we rely on the pvInfo parameter being a static variable! */ + + currFirst = first; + currLast = last; + currCurrent = current; + currPvInfo = pvInfo; + + if( DialogExists(EvalGraphDlg) ) { + DisplayEvalGraph(); + } +} + diff --git a/xaw/xboard.c b/xaw/xboard.c index 0961db5..7fe789b 100644 --- a/xaw/xboard.c +++ b/xaw/xboard.c @@ -202,7 +202,6 @@ extern char *getenv(); #include "childio.h" #include "xgamelist.h" #include "xhistory.h" -#include "xevalgraph.h" #include "menus.h" #include "board.h" #include "dialogs.h" diff --git a/xaw/xevalgraph.c b/xaw/xevalgraph.c deleted file mode 100644 index f3cac1f..0000000 --- a/xaw/xevalgraph.c +++ /dev/null @@ -1,339 +0,0 @@ -/* - * Evaluation graph - * - * Author: Alessandro Scotti (Dec 2005) - * Translated to X by H.G.Muller (Nov 2009) - * - * Copyright 2005 Alessandro Scotti - * - * Enhancements Copyright 2009, 2010, 2011, 2012 Free Software Foundation, Inc. - * - * ------------------------------------------------------------------------ - * - * GNU XBoard is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * GNU XBoard is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see http://www.gnu.org/licenses/. - * - * ------------------------------------------------------------------------ - ** See the file ChangeLog for a revision history. */ - -#include "config.h" - -#include -#include -#include -#include - -#if STDC_HEADERS -# include -# include -#else /* not STDC_HEADERS */ -extern char *getenv(); -# if HAVE_STRING_H -# include -# else /* not HAVE_STRING_H */ -# include -# endif /* not HAVE_STRING_H */ -#endif /* not STDC_HEADERS */ - -#if HAVE_UNISTD_H -# include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "common.h" -#include "frontend.h" -#include "backend.h" -#include "dialogs.h" -#include "menus.h" -#include "xboard.h" -#include "evalgraph.h" -#include "xevalgraph.h" -#include "draw.h" -#include "gettext.h" - -#ifdef ENABLE_NLS -# define _(s) gettext (s) -# define N_(s) gettext_noop (s) -#else -# define _(s) (s) -# define N_(s) s -#endif - -#include - -#ifdef SNAP -#include "wsnap.h" -#endif - -#define _LL_ 100 - -Pixmap icons[8]; // [HGM] this front-end array translates back-end icon indicator to handle -Widget outputField[2][7]; // [HGM] front-end array to translate output field to window handle -static char *title = N_("Evaluation graph"); - -//extern WindowPlacement wpEvalGraph; - -Position evalGraphX = -1, evalGraphY = -1; -Dimension evalGraphW, evalGraphH; - -/* Module variables */ - -char *crWhite = "#FFFFB0"; -char *crBlack = "#AD5D3D"; -Option *disp; - -static Option *EvalCallback P((int button, int x, int y)); - -static void -ChoosePen(cairo_t *cr, int i) -{ - switch(i) { - case PEN_BLACK: - SetPen(cr, 1.0, "#000000", 0); - break; - case PEN_DOTTED: - SetPen(cr, 1.0, "#A0A0A0", 1); - break; - case PEN_BLUEDOTTED: - SetPen(cr, 1.0, "#0000FF", 1); - break; - case PEN_BOLDWHITE: - SetPen(cr, 3.0, crWhite, 0); - break; - case PEN_BOLDBLACK: - SetPen(cr, 3.0, crBlack, 0); - break; - case PEN_BACKGD: - SetPen(cr, 3.0, "#E0E0F0", 0); - break; - } -} - -// [HGM] front-end, added as wrapper to avoid use of LineTo and MoveToEx in other routines (so they can be back-end) -void -DrawSegment (int x, int y, int *lastX, int *lastY, enum PEN penType) -{ - static int curX, curY; - - if(penType != PEN_NONE) { - cairo_t *cr = cairo_create(DRAWABLE(disp)); - cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE); - cairo_move_to (cr, curX, curY); - cairo_line_to (cr, x,y); - ChoosePen(cr, penType); - cairo_stroke (cr); - cairo_destroy (cr); - } - - if(lastX != NULL) { *lastX = curX; *lastY = curY; } - curX = x; curY = y; -} - -// front-end wrapper for drawing functions to do rectangles -void -DrawRectangle (int left, int top, int right, int bottom, int side, int style) -{ - cairo_t *cr; - - cr = cairo_create (DRAWABLE(disp)); - cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE); - cairo_rectangle (cr, left, top, right-left, bottom-top); - switch(side) - { - case 0: ChoosePen(cr, PEN_BOLDWHITE); break; - case 1: ChoosePen(cr, PEN_BOLDBLACK); break; - case 2: ChoosePen(cr, PEN_BACKGD); break; - } - cairo_fill (cr); - - if(style != FILLED) - { - cairo_rectangle (cr, left, top, right-left-1, bottom-top-1); - ChoosePen(cr, PEN_BLACK); - cairo_stroke (cr); - } - - cairo_destroy(cr); -} - -// front-end wrapper for putting text in graph -void -DrawEvalText (char *buf, int cbBuf, int y) -{ - // the magic constants 8 and 5 should really be derived from the font size somehow - cairo_text_extents_t extents; - cairo_t *cr = cairo_create(DRAWABLE(disp)); - - /* GTK-TODO this has to go into the font-selection */ - cairo_select_font_face (cr, "Sans", - CAIRO_FONT_SLANT_NORMAL, - CAIRO_FONT_WEIGHT_NORMAL); - cairo_set_font_size (cr, 12.0); - - - cairo_text_extents (cr, buf, &extents); - - cairo_move_to (cr, MarginX - 2 - 8*cbBuf, y+5); - cairo_text_path (cr, buf); - cairo_set_source_rgb (cr, 0.0, 0.0, 0); - cairo_fill_preserve (cr); - cairo_set_source_rgb (cr, 0, 1.0, 0); - cairo_set_line_width (cr, 0.1); - cairo_stroke (cr); - - /* free memory */ - cairo_destroy (cr); -} - -static int initDone = FALSE; - -static void -InitializeEvalGraph (Option *opt, int w, int h) -{ - if(w == 0) { - Arg args[10]; - XtSetArg(args[0], XtNwidth, &evalGraphW); - XtSetArg(args[1], XtNheight, &evalGraphH); - XtGetValues(opt->handle, args, 2); - nWidthPB = evalGraphW; nHeightPB = evalGraphH; - } else nWidthPB = w, nHeightPB = h; - - initDone = TRUE; -} - -// The following stuff is really back-end (but too little to bother with a separate file) - -static void -EvalClick (int x, int y) -{ - int index = GetMoveIndexFromPoint( x, y ); - - if( index >= 0 && index < currLast ) ToNrEvent( index + 1 ); -} - -static Option graphOptions[] = { -{ 150, 0x9C, 300, NULL, (void*) &EvalCallback, NULL, NULL, Graph , "" }, -{ 0, 2, 0, NULL, NULL, "", NULL, EndMark , "" } -}; - -static void -DisplayEvalGraph () -{ // back-end painting; calls back front-end primitives for lines, rectangles and text - char *t = MakeEvalTitle(_(title)); - nWidthPB = disp->max; nHeightPB = disp->value; - if(t != title && nWidthPB < 340) t = MakeEvalTitle(nWidthPB < 240 ? "" : _("Eval")); - PaintEvalGraph(); - GraphExpose(graphOptions, 0, 0, nWidthPB, nHeightPB); - SetDialogTitle(EvalGraphDlg, t); -} - -static Option * -EvalCallback (int button, int x, int y) -{ - if(!initDone) return NULL; - - switch(button) { - case 10: // expose event - /* Create or recreate paint box if needed */ - if(x != nWidthPB || y != nHeightPB) { - InitializeEvalGraph(&graphOptions[0], x, y); - } - nWidthPB = x; - nHeightPB = y; - DisplayEvalGraph(); - break; - case 1: EvalClick(x, y); // left button - default: break; // other buttons ignored - } - return NULL; // no context menu! -} - -void -EvalGraphPopUp () -{ - if (GenericPopUp(graphOptions, _(title), EvalGraphDlg, BoardWindow, NONMODAL, 1)) { - InitializeEvalGraph(&graphOptions[0], 0, 0); // first time: add callbacks and initialize pens - disp = graphOptions; - } else { - SetDialogTitle(EvalGraphDlg, _(title)); - SetIconName(EvalGraphDlg, _(title)); - } - - MarkMenu("View.EvaluationGraph", EvalGraphDlg); - -// ShowThinkingEvent(); // [HGM] thinking: might need to prompt engine for thinking output -} - -void -EvalGraphPopDown () -{ - PopDown(EvalGraphDlg); - -// ShowThinkingEvent(); // [HGM] thinking: might need to shut off thinking output -} - -Boolean -EvalGraphIsUp () -{ - return shellUp[EvalGraphDlg]; -} - -int -EvalGraphDialogExists () -{ - return DialogExists(EvalGraphDlg); -} - -void -EvalGraphProc () -{ - if (!PopDown(EvalGraphDlg)) EvalGraphPopUp(); -} - -// This function is the interface to the back-end. - -void -EvalGraphSet (int first, int last, int current, ChessProgramStats_Move * pvInfo) -{ - /* [AS] Danger! For now we rely on the pvInfo parameter being a static variable! */ - - currFirst = first; - currLast = last; - currCurrent = current; - currPvInfo = pvInfo; - - if( DialogExists(EvalGraphDlg) ) { - DisplayEvalGraph(); - } -} - diff --git a/xaw/xevalgraph.h b/xaw/xevalgraph.h deleted file mode 100644 index e1227c6..0000000 --- a/xaw/xevalgraph.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * xevalgraph.h - * - * Copyright 2010, 2011, 2012 Free Software Foundation, Inc. - * - * ------------------------------------------------------------------------ - * - * GNU XBoard is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * GNU XBoard is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see http://www.gnu.org/licenses/. * - * - *------------------------------------------------------------------------ - ** See the file ChangeLog for a revision history. */ - -#ifndef XB_XEVALGRAPH -#define XB_XEVALGRAPH - -void EvalGraphSet P(( int first, int last, int current, ChessProgramStats_Move * pvInfo )); -float Color P((char *col, int n)); -void SetPen P((cairo_t *cr, float w, char *col, int dash)); - -#endif diff --git a/xboard.c b/xboard.c index f430375..a42ef8a 100644 --- a/xboard.c +++ b/xboard.c @@ -203,7 +203,6 @@ extern char *getenv(); #include "childio.h" #include "xgamelist.h" #include "xhistory.h" -#include "xevalgraph.h" #include "menus.h" #include "board.h" #include "dialogs.h" diff --git a/xevalgraph.c b/xevalgraph.c deleted file mode 100644 index f3cac1f..0000000 --- a/xevalgraph.c +++ /dev/null @@ -1,339 +0,0 @@ -/* - * Evaluation graph - * - * Author: Alessandro Scotti (Dec 2005) - * Translated to X by H.G.Muller (Nov 2009) - * - * Copyright 2005 Alessandro Scotti - * - * Enhancements Copyright 2009, 2010, 2011, 2012 Free Software Foundation, Inc. - * - * ------------------------------------------------------------------------ - * - * GNU XBoard is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * GNU XBoard is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see http://www.gnu.org/licenses/. - * - * ------------------------------------------------------------------------ - ** See the file ChangeLog for a revision history. */ - -#include "config.h" - -#include -#include -#include -#include - -#if STDC_HEADERS -# include -# include -#else /* not STDC_HEADERS */ -extern char *getenv(); -# if HAVE_STRING_H -# include -# else /* not HAVE_STRING_H */ -# include -# endif /* not HAVE_STRING_H */ -#endif /* not STDC_HEADERS */ - -#if HAVE_UNISTD_H -# include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "common.h" -#include "frontend.h" -#include "backend.h" -#include "dialogs.h" -#include "menus.h" -#include "xboard.h" -#include "evalgraph.h" -#include "xevalgraph.h" -#include "draw.h" -#include "gettext.h" - -#ifdef ENABLE_NLS -# define _(s) gettext (s) -# define N_(s) gettext_noop (s) -#else -# define _(s) (s) -# define N_(s) s -#endif - -#include - -#ifdef SNAP -#include "wsnap.h" -#endif - -#define _LL_ 100 - -Pixmap icons[8]; // [HGM] this front-end array translates back-end icon indicator to handle -Widget outputField[2][7]; // [HGM] front-end array to translate output field to window handle -static char *title = N_("Evaluation graph"); - -//extern WindowPlacement wpEvalGraph; - -Position evalGraphX = -1, evalGraphY = -1; -Dimension evalGraphW, evalGraphH; - -/* Module variables */ - -char *crWhite = "#FFFFB0"; -char *crBlack = "#AD5D3D"; -Option *disp; - -static Option *EvalCallback P((int button, int x, int y)); - -static void -ChoosePen(cairo_t *cr, int i) -{ - switch(i) { - case PEN_BLACK: - SetPen(cr, 1.0, "#000000", 0); - break; - case PEN_DOTTED: - SetPen(cr, 1.0, "#A0A0A0", 1); - break; - case PEN_BLUEDOTTED: - SetPen(cr, 1.0, "#0000FF", 1); - break; - case PEN_BOLDWHITE: - SetPen(cr, 3.0, crWhite, 0); - break; - case PEN_BOLDBLACK: - SetPen(cr, 3.0, crBlack, 0); - break; - case PEN_BACKGD: - SetPen(cr, 3.0, "#E0E0F0", 0); - break; - } -} - -// [HGM] front-end, added as wrapper to avoid use of LineTo and MoveToEx in other routines (so they can be back-end) -void -DrawSegment (int x, int y, int *lastX, int *lastY, enum PEN penType) -{ - static int curX, curY; - - if(penType != PEN_NONE) { - cairo_t *cr = cairo_create(DRAWABLE(disp)); - cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE); - cairo_move_to (cr, curX, curY); - cairo_line_to (cr, x,y); - ChoosePen(cr, penType); - cairo_stroke (cr); - cairo_destroy (cr); - } - - if(lastX != NULL) { *lastX = curX; *lastY = curY; } - curX = x; curY = y; -} - -// front-end wrapper for drawing functions to do rectangles -void -DrawRectangle (int left, int top, int right, int bottom, int side, int style) -{ - cairo_t *cr; - - cr = cairo_create (DRAWABLE(disp)); - cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE); - cairo_rectangle (cr, left, top, right-left, bottom-top); - switch(side) - { - case 0: ChoosePen(cr, PEN_BOLDWHITE); break; - case 1: ChoosePen(cr, PEN_BOLDBLACK); break; - case 2: ChoosePen(cr, PEN_BACKGD); break; - } - cairo_fill (cr); - - if(style != FILLED) - { - cairo_rectangle (cr, left, top, right-left-1, bottom-top-1); - ChoosePen(cr, PEN_BLACK); - cairo_stroke (cr); - } - - cairo_destroy(cr); -} - -// front-end wrapper for putting text in graph -void -DrawEvalText (char *buf, int cbBuf, int y) -{ - // the magic constants 8 and 5 should really be derived from the font size somehow - cairo_text_extents_t extents; - cairo_t *cr = cairo_create(DRAWABLE(disp)); - - /* GTK-TODO this has to go into the font-selection */ - cairo_select_font_face (cr, "Sans", - CAIRO_FONT_SLANT_NORMAL, - CAIRO_FONT_WEIGHT_NORMAL); - cairo_set_font_size (cr, 12.0); - - - cairo_text_extents (cr, buf, &extents); - - cairo_move_to (cr, MarginX - 2 - 8*cbBuf, y+5); - cairo_text_path (cr, buf); - cairo_set_source_rgb (cr, 0.0, 0.0, 0); - cairo_fill_preserve (cr); - cairo_set_source_rgb (cr, 0, 1.0, 0); - cairo_set_line_width (cr, 0.1); - cairo_stroke (cr); - - /* free memory */ - cairo_destroy (cr); -} - -static int initDone = FALSE; - -static void -InitializeEvalGraph (Option *opt, int w, int h) -{ - if(w == 0) { - Arg args[10]; - XtSetArg(args[0], XtNwidth, &evalGraphW); - XtSetArg(args[1], XtNheight, &evalGraphH); - XtGetValues(opt->handle, args, 2); - nWidthPB = evalGraphW; nHeightPB = evalGraphH; - } else nWidthPB = w, nHeightPB = h; - - initDone = TRUE; -} - -// The following stuff is really back-end (but too little to bother with a separate file) - -static void -EvalClick (int x, int y) -{ - int index = GetMoveIndexFromPoint( x, y ); - - if( index >= 0 && index < currLast ) ToNrEvent( index + 1 ); -} - -static Option graphOptions[] = { -{ 150, 0x9C, 300, NULL, (void*) &EvalCallback, NULL, NULL, Graph , "" }, -{ 0, 2, 0, NULL, NULL, "", NULL, EndMark , "" } -}; - -static void -DisplayEvalGraph () -{ // back-end painting; calls back front-end primitives for lines, rectangles and text - char *t = MakeEvalTitle(_(title)); - nWidthPB = disp->max; nHeightPB = disp->value; - if(t != title && nWidthPB < 340) t = MakeEvalTitle(nWidthPB < 240 ? "" : _("Eval")); - PaintEvalGraph(); - GraphExpose(graphOptions, 0, 0, nWidthPB, nHeightPB); - SetDialogTitle(EvalGraphDlg, t); -} - -static Option * -EvalCallback (int button, int x, int y) -{ - if(!initDone) return NULL; - - switch(button) { - case 10: // expose event - /* Create or recreate paint box if needed */ - if(x != nWidthPB || y != nHeightPB) { - InitializeEvalGraph(&graphOptions[0], x, y); - } - nWidthPB = x; - nHeightPB = y; - DisplayEvalGraph(); - break; - case 1: EvalClick(x, y); // left button - default: break; // other buttons ignored - } - return NULL; // no context menu! -} - -void -EvalGraphPopUp () -{ - if (GenericPopUp(graphOptions, _(title), EvalGraphDlg, BoardWindow, NONMODAL, 1)) { - InitializeEvalGraph(&graphOptions[0], 0, 0); // first time: add callbacks and initialize pens - disp = graphOptions; - } else { - SetDialogTitle(EvalGraphDlg, _(title)); - SetIconName(EvalGraphDlg, _(title)); - } - - MarkMenu("View.EvaluationGraph", EvalGraphDlg); - -// ShowThinkingEvent(); // [HGM] thinking: might need to prompt engine for thinking output -} - -void -EvalGraphPopDown () -{ - PopDown(EvalGraphDlg); - -// ShowThinkingEvent(); // [HGM] thinking: might need to shut off thinking output -} - -Boolean -EvalGraphIsUp () -{ - return shellUp[EvalGraphDlg]; -} - -int -EvalGraphDialogExists () -{ - return DialogExists(EvalGraphDlg); -} - -void -EvalGraphProc () -{ - if (!PopDown(EvalGraphDlg)) EvalGraphPopUp(); -} - -// This function is the interface to the back-end. - -void -EvalGraphSet (int first, int last, int current, ChessProgramStats_Move * pvInfo) -{ - /* [AS] Danger! For now we rely on the pvInfo parameter being a static variable! */ - - currFirst = first; - currLast = last; - currCurrent = current; - currPvInfo = pvInfo; - - if( DialogExists(EvalGraphDlg) ) { - DisplayEvalGraph(); - } -} - diff --git a/xevalgraph.h b/xevalgraph.h deleted file mode 100644 index e1227c6..0000000 --- a/xevalgraph.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * xevalgraph.h - * - * Copyright 2010, 2011, 2012 Free Software Foundation, Inc. - * - * ------------------------------------------------------------------------ - * - * GNU XBoard is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * GNU XBoard is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see http://www.gnu.org/licenses/. * - * - *------------------------------------------------------------------------ - ** See the file ChangeLog for a revision history. */ - -#ifndef XB_XEVALGRAPH -#define XB_XEVALGRAPH - -void EvalGraphSet P(( int first, int last, int current, ChessProgramStats_Move * pvInfo )); -float Color P((char *col, int n)); -void SetPen P((cairo_t *cr, float w, char *col, int dash)); - -#endif