X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=draw.c;h=6df1a137266478e2b8251f64da4cd8f032ca90b8;hb=6c09cbad6fd5630f883937303fc5e10a5ef8e3dc;hp=afb639396e11b134dc8feab9a000f2d9caa4bec7;hpb=6bead4fda35db0cb9ec61309ee7cd9c99bb53475;p=xboard.git diff --git a/draw.c b/draw.c index afb6393..6df1a13 100644 --- a/draw.c +++ b/draw.c @@ -5,7 +5,8 @@ * Massachusetts. * * Enhancements Copyright 1992-2001, 2002, 2003, 2004, 2005, 2006, - * 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Free Software Foundation, Inc. + * 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Free + * Software Foundation, Inc. * * The following terms apply to Digital Equipment Corporation's copyright * interest in XBoard: @@ -54,7 +55,6 @@ #include #include #include -#include #include #include #include @@ -109,7 +109,7 @@ cairo_surface_t *csBoardWindow; static cairo_surface_t *pngPieceImages[2][(int)BlackPawn]; // png 256 x 256 images static cairo_surface_t *pngPieceBitmaps[2][(int)BlackPawn]; // scaled pieces as used static cairo_surface_t *pngPieceBitmaps2[2][(int)BlackPawn]; // scaled pieces in store -static RsvgHandle *svgPieces[2][(int)BlackPawn+4]; // vector pieces in store +static RsvgHandle *svgPieces[2][(int)BlackPawn]; // vector pieces in store static cairo_surface_t *pngBoardBitmap[2], *pngOriginalBoardBitmap[2]; int useTexture, textureW[2], textureH[2]; @@ -131,9 +131,34 @@ void SwitchWindow (int main) { currBoard = (main ? &mainOptions[W_BOARD] : &dualOptions[3]); - csBoardWindow = DRAWABLE(currBoard); +// CsBoardWindow = DRAWABLE(currBoard); } + +static void +NewCanvas (Option *graph) +{ + cairo_t *cr; + int w = graph->max, h = graph->value; + if(graph->choice) cairo_surface_destroy((cairo_surface_t *) graph->choice); + graph->choice = (char**) cairo_image_surface_create (CAIRO_FORMAT_ARGB32, w, h); + // paint white, to prevent weirdness when people maximize window and drag pieces over space next to board + cr = cairo_create ((cairo_surface_t *) graph->choice); + cairo_rectangle (cr, 0, 0, w, h); + cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 1.0); + cairo_fill(cr); + cairo_destroy (cr); + graph->min &= ~REPLACE; +} + +static cairo_surface_t * +CsBoardWindow (Option *opt) +{ // test before every draw event if we need to resize the canvas + if(opt->min & REPLACE) NewCanvas(opt); + return DRAWABLE(opt); +} + + void SelectPieces(VariantClass v) { @@ -253,7 +278,7 @@ CreatePNGBoard (char *s, int kind) textureW[kind] = 0; // prevents bitmap from being used if not succesfully loaded if(strstr(s, ".png")) { cairo_surface_t *img = cairo_image_surface_create_from_png (s); - if(img) { + if(cairo_surface_status(img) == CAIRO_STATUS_SUCCESS) { char c, *p = s, *q; int r, f; if(pngOriginalBoardBitmap[kind]) cairo_surface_destroy(pngOriginalBoardBitmap[kind]); @@ -451,7 +476,7 @@ InitDrawingParams (int reloadPieces) { int i, p; if(reloadPieces) - for(i=0; i<2; i++) for(p=0; pmax, opt->value); cairo_set_source_rgba(cr, 0.5, 0.5, 0.5, 1.0); cairo_fill(cr); // paint background in case logo does not exist @@ -759,7 +785,7 @@ DoDrawDot (cairo_surface_t *cs, int marker, int x, int y, int r) void DrawDot (int marker, int x, int y, int r) { // used for atomic captures; no need to draw on backup - DoDrawDot(csBoardWindow, marker, x, y, r); + DoDrawDot(CsBoardWindow(currBoard), marker, x, y, r); GraphExpose(currBoard, x-r, y-r, 2*r, 2*r); } @@ -791,14 +817,14 @@ DrawUnicode (cairo_surface_t *canvas, char *string, int x, int y, char id, int f cairo_destroy(cr); } -static void +void DrawText (char *string, int x, int y, int align) { int xx = x, yy = y; cairo_text_extents_t te; cairo_t *cr; - cr = cairo_create (csBoardWindow); + cr = cairo_create (CsBoardWindow(currBoard)); cairo_select_font_face (cr, "Sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD); @@ -857,10 +883,10 @@ DrawOneSquare (int x, int y, ChessSquare piece, int square_color, int marker, ch // piece, background, coordinate/count, marker dot if (piece == EmptySquare) { - BlankSquare(csBoardWindow, x, y, square_color, piece, 1); + BlankSquare(CsBoardWindow(currBoard), x, y, square_color, piece, 1); } else { - pngDrawPiece(csBoardWindow, piece, square_color, x, y); - if(appData.inscriptions[0]) InscribeKanji(csBoardWindow, piece, x, y); + pngDrawPiece(CsBoardWindow(currBoard), piece, square_color, x, y); + if(appData.inscriptions[0]) InscribeKanji(CsBoardWindow(currBoard), piece, x, y); } if(align) { // square carries inscription (coord or piece count) @@ -869,7 +895,7 @@ DrawOneSquare (int x, int y, ChessSquare piece, int square_color, int marker, ch } if(marker) { // print fat marker dot, if requested - DoDrawDot(csBoardWindow, marker, x + squareSize/4, y+squareSize/4, squareSize/2); + DoDrawDot(CsBoardWindow(currBoard), marker, x + squareSize/4, y+squareSize/4, squareSize/2); } } @@ -888,7 +914,7 @@ InitAnimState (AnimNr anr) { if(c_animBufs[anr]) cairo_surface_destroy (c_animBufs[anr]); if(c_animBufs[anr+2]) cairo_surface_destroy (c_animBufs[anr+2]); - c_animBufs[anr+4] = csBoardWindow; + c_animBufs[anr+4] = CsBoardWindow(currBoard); c_animBufs[anr+2] = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, squareSize, squareSize); c_animBufs[anr] = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, squareSize, squareSize); } @@ -928,13 +954,13 @@ void CopyRectangle (AnimNr anr, int srcBuf, int destBuf, int srcX, int srcY, int width, int height, int destX, int destY) { cairo_t *cr; - c_animBufs[anr+4] = csBoardWindow; + c_animBufs[anr+4] = CsBoardWindow(currBoard); cr = cairo_create (c_animBufs[anr+destBuf]); cairo_set_source_surface (cr, c_animBufs[anr+srcBuf], destX - srcX, destY - srcY); cairo_rectangle (cr, destX, destY, width, height); cairo_fill (cr); cairo_destroy (cr); - if(c_animBufs[anr+destBuf] == csBoardWindow) // suspect that GTK needs this! + if(c_animBufs[anr+destBuf] == CsBoardWindow(currBoard)) // suspect that GTK needs this! GraphExpose(currBoard, destX, destY, width, height); } @@ -970,7 +996,7 @@ DoDrawPolygon (cairo_surface_t *cs, Pnt arrow[], int nr) void DrawPolygon (Pnt arrow[], int nr) { - DoDrawPolygon(csBoardWindow, arrow, nr); + DoDrawPolygon(CsBoardWindow(currBoard), arrow, nr); // if(!dual) DoDrawPolygon(csBoardBackup, arrow, nr); } @@ -1008,7 +1034,7 @@ 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_t *cr = cairo_create(CsBoardWindow(disp)); cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE); cairo_move_to (cr, curX, curY); cairo_line_to (cr, x,y); @@ -1027,7 +1053,7 @@ DrawRectangle (int left, int top, int right, int bottom, int side, int style) { cairo_t *cr; - cr = cairo_create (DRAWABLE(disp)); + cr = cairo_create (CsBoardWindow(disp)); cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE); cairo_rectangle (cr, left, top, right-left, bottom-top); switch(side) @@ -1054,7 +1080,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(DRAWABLE(disp)); + cairo_t *cr = cairo_create(CsBoardWindow(disp)); /* GTK-TODO this has to go into the font-selection */ cairo_select_font_face (cr, "Sans",