From 0c01e9c47c1bb45e9abaa0451f86bfb60d1b15d6 Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Wed, 10 Oct 2012 21:19:25 +0200 Subject: [PATCH] Adapt Eval Graph code to new drawing system The eval graph now triggers an expose after drawing, and gets its size from the Option fields. --- dialogs.c | 1 + xevalgraph.c | 36 +++++++++++++++++------------------- xoptions.c | 1 + 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/dialogs.c b/dialogs.c index ebdd93c..7659f5b 100644 --- a/dialogs.c +++ b/dialogs.c @@ -2073,6 +2073,7 @@ Exp (int n, int x, int y) case 10: sizing = (oldW != x || oldH != y); oldW = x; oldH = y; + InitDrawingHandle(mainOptions + W_BOARD); if(sizing) return NULL; // don't redraw while sizing DrawPosition(True, NULL); default: diff --git a/xevalgraph.c b/xevalgraph.c index 40d0721..f3cac1f 100644 --- a/xevalgraph.c +++ b/xevalgraph.c @@ -78,6 +78,7 @@ extern char *getenv(); #include "xboard.h" #include "evalgraph.h" #include "xevalgraph.h" +#include "draw.h" #include "gettext.h" #ifdef ENABLE_NLS @@ -109,8 +110,7 @@ Dimension evalGraphW, evalGraphH; char *crWhite = "#FFFFB0"; char *crBlack = "#AD5D3D"; -static Window eGraphWindow; -static cairo_surface_t *cs; +Option *disp; static Option *EvalCallback P((int button, int x, int y)); @@ -146,7 +146,7 @@ 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(cs); + 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); @@ -165,7 +165,7 @@ DrawRectangle (int left, int top, int right, int bottom, int side, int style) { cairo_t *cr; - cr = cairo_create (cs); + cr = cairo_create (DRAWABLE(disp)); cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE); cairo_rectangle (cr, left, top, right-left, bottom-top); switch(side) @@ -192,7 +192,7 @@ 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(cs); + cairo_t *cr = cairo_create(DRAWABLE(disp)); /* GTK-TODO this has to go into the font-selection */ cairo_select_font_face (cr, "Sans", @@ -220,8 +220,6 @@ static int initDone = FALSE; static void InitializeEvalGraph (Option *opt, int w, int h) { - eGraphWindow = XtWindow(opt->handle); - if(w == 0) { Arg args[10]; XtSetArg(args[0], XtNwidth, &evalGraphW); @@ -230,24 +228,12 @@ InitializeEvalGraph (Option *opt, int w, int h) nWidthPB = evalGraphW; nHeightPB = evalGraphH; } else nWidthPB = w, nHeightPB = h; - if(cs) cairo_surface_destroy(cs); - cs=cairo_xlib_surface_create(xDisplay, eGraphWindow, DefaultVisual(xDisplay, 0), nWidthPB, nHeightPB); - initDone = TRUE; } // The following stuff is really back-end (but too little to bother with a separate file) static void -DisplayEvalGraph () -{ // back-end painting; calls back front-end primitives for lines, rectangles and text - char *t = MakeEvalTitle(_(title)); - if(t != title && nWidthPB < 340) t = MakeEvalTitle(nWidthPB < 240 ? "" : _("Eval")); - PaintEvalGraph(); - SetDialogTitle(EvalGraphDlg, t); -} - -static void EvalClick (int x, int y) { int index = GetMoveIndexFromPoint( x, y ); @@ -260,6 +246,17 @@ static Option graphOptions[] = { { 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) { @@ -286,6 +283,7 @@ 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)); diff --git a/xoptions.c b/xoptions.c index 6993ab2..2446fb0 100644 --- a/xoptions.c +++ b/xoptions.c @@ -565,6 +565,7 @@ GraphEventProc(Widget widget, caddr_t client_data, XEvent *event) // so only change when size is no longer good if(graph->choice) cairo_surface_destroy((cairo_surface_t *) graph->choice); graph->choice = (char**) cairo_image_surface_create (CAIRO_FORMAT_ARGB32, w, h); + break; } cr = cairo_create((cairo_surface_t *) graph->textValue); cairo_set_source_surface(cr, (cairo_surface_t *) graph->choice, 0, 0); -- 1.7.0.4