From 224ed6301ed95439f1fe5b8b678d671cbeeaa2dc Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Sat, 6 Oct 2012 13:40:12 +0200 Subject: [PATCH] Some cleanup --- dialogs.h | 2 +- draw.c | 31 ++++++++++++++++--------------- draw.h | 4 +++- xboard.c | 10 +++++++++- 4 files changed, 29 insertions(+), 18 deletions(-) diff --git a/dialogs.h b/dialogs.h index 95dd442..9bd7515 100644 --- a/dialogs.h +++ b/dialogs.h @@ -129,7 +129,7 @@ extern void *userLogo; extern WindowPlacement wpComment, wpTags, wpMoveHistory, wpMain; extern char *marked[]; extern Boolean shellUp[]; -extern Option textOptions[], typeOptions[]; +extern Option textOptions[], typeOptions[], dualOptions[], mainOptions[]; int DialogExists P((DialogClass n)); diff --git a/draw.c b/draw.c index ca5c706..e79851f 100644 --- a/draw.c +++ b/draw.c @@ -84,7 +84,6 @@ extern char *getenv(); #include "frontend.h" #include "backend.h" -#include "xboard.h" #include "xevalgraph.h" #include "board.h" #include "menus.h" @@ -126,16 +125,19 @@ struct { int x1, x2, y1, y2; } gridSegments[BOARD_RANKS + BOARD_FILES + 2]; +static int dual = 0; + void SwitchWindow () { cairo_surface_t *cstmp = csBoardWindow; csBoardWindow = csDualBoard; - if(!csDualBoard && cstmp) { - int boardWidth = lineGap + BOARD_WIDTH * (squareSize + lineGap); - int boardHeight = lineGap + BOARD_HEIGHT * (squareSize + lineGap); - csBoardWindow = cairo_xlib_surface_create(xDisplay, xBoardWindow, DefaultVisual(xDisplay, 0), boardWidth, boardHeight); + dual = !dual; + if(!csDualBoard) { + csBoardWindow = GetOutputSurface(&dualOptions[3], 0, 0); + dual = 1; } + csDualBoard = cstmp; } void @@ -154,9 +156,10 @@ InitDrawingSizes (BoardSize boardSize, int flags) { // [HGM] resize is functional now, but for board format changes only (nr of ranks, files) int boardWidth, boardHeight; int i; - static Dimension oldWidth, oldHeight; + static int oldWidth, oldHeight; static VariantClass oldVariant; static int oldMono = -1, oldTwoBoards = 0; + extern Widget formWidget; if(!formWidget) return; @@ -273,7 +276,7 @@ CreatePNGPieces () } } -int +void CreateAnyPieces () { // [HGM] taken out of main if (appData.pngDirectory[0] != NULLCHAR) { @@ -281,9 +284,6 @@ CreateAnyPieces () } CreatePNGBoard(appData.liteBackTextureFile, 1); CreatePNGBoard(appData.darkBackTextureFile, 0); - cairoAnimate = *appData.pngDirectory && useTexture == 3 - && strstr(appData.liteBackTextureFile, ".png") && strstr(appData.darkBackTextureFile, ".png"); - return cairoAnimate; } void @@ -392,7 +392,7 @@ DrawSeekOpen () int boardWidth = lineGap + BOARD_WIDTH * (squareSize + lineGap); int boardHeight = lineGap + BOARD_HEIGHT * (squareSize + lineGap); if(!csBoardWindow) { - csBoardWindow = cairo_xlib_surface_create(xDisplay, xBoardWindow, DefaultVisual(xDisplay, 0), boardWidth, boardHeight); + csBoardWindow = GetOutputSurface(&mainOptions[W_BOARD], 0, 0); csBoardBackup = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, boardWidth, boardHeight); } } @@ -460,7 +460,7 @@ void DrawGrid() { DoDrawGrid(csBoardWindow); - DoDrawGrid(csBoardBackup); + if(!dual) DoDrawGrid(csBoardBackup); } void @@ -486,7 +486,7 @@ void DrawBorder (int x, int y, int type) { DoDrawBorder(csBoardWindow, x, y, type); - DoDrawBorder(csBoardBackup, x, y, type); + if(!dual) DoDrawBorder(csBoardBackup, x, y, type); } static int @@ -515,7 +515,7 @@ DrawLogo (void *handle, void *logo) int w, h; if(!logo || !handle) return; - cs = cairo_xlib_surface_create(xDisplay, XtWindow(handle), DefaultVisual(xDisplay, 0), appData.logoSize, appData.logoSize/2); + cs = GetOutputSurface(handle, appData.logoSize, appData.logoSize/2); img = cairo_image_surface_create_from_png (logo); w = cairo_image_surface_get_width (img); h = cairo_image_surface_get_height (img); @@ -656,6 +656,7 @@ DrawOneSquare (int x, int y, ChessSquare piece, int square_color, int marker, ch { DrawSeekOpen(); DoDrawOneSquare (csBoardWindow, x, y, piece, square_color, marker, string, align); + if(!dual) DoDrawOneSquare (csBoardBackup, x, y, piece, square_color, marker, string, align); } @@ -764,7 +765,7 @@ void DrawPolygon (Pnt arrow[], int nr) { DoDrawPolygon(csBoardWindow, arrow, nr); - DoDrawPolygon(csBoardBackup, arrow, nr); + if(!dual) DoDrawPolygon(csBoardBackup, arrow, nr); } diff --git a/draw.h b/draw.h index 233c85e..2cb0fe8 100644 --- a/draw.h +++ b/draw.h @@ -57,17 +57,19 @@ void CreateGCs P((int redo)); void DelayedDrag P((void)); void ReadBitmap P((Pixmap *pm, String name, unsigned char bits[], u_int wreq, u_int hreq)); +cairo_surface_t *GetOutputSurface P((Option *opt, int w, int h)); extern XFontStruct *coordFontStruct, *countFontStruct; extern Font coordFontID, countFontID; extern int xScreen; +extern int lineGap, squareSize; extern Pixel lightSquareColor, darkSquareColor, whitePieceColor, blackPieceColor, highlightSquareColor, premoveHighlightColor; // defined in draw.c void CreateGCs P((int redo)); void NewSurfaces P((void)); -int CreateAnyPieces P((void)); +void CreateAnyPieces P((void)); void CreatePNGPieces P((void)); void CreateGrid P((void)); diff --git a/xboard.c b/xboard.c index 3b97fca..4d8b3f2 100644 --- a/xboard.c +++ b/xboard.c @@ -1315,12 +1315,13 @@ main (int argc, char **argv) XtGetValues(shellWidget, shellArgs, 2); shellArgs[4].value = shellArgs[2].value = w; shellArgs[5].value = shellArgs[3].value = h; - if(!CreateAnyPieces()) XtSetValues(shellWidget, &shellArgs[2], 4); +// XtSetValues(shellWidget, &shellArgs[2], 4); marginW = w - boardWidth; // [HGM] needed to set new shellWidget size when we resize board marginH = h - boardHeight; CatchDeleteWindow(shellWidget, "QuitProc"); + CreateAnyPieces(); CreateGrid(); if(appData.logoSize) @@ -1668,6 +1669,13 @@ SetupDropMenu () } } +cairo_surface_t * +GetOutputSurface(Option *opt, int w, int h) +{ + if(w == 0) w = lineGap + BOARD_WIDTH * (squareSize + lineGap); + if(h == 0) h = lineGap + BOARD_HEIGHT * (squareSize + lineGap); + return cairo_xlib_surface_create(xDisplay, XtWindow(opt->handle), DefaultVisual(xDisplay, 0), w, h); +} static void do_flash_delay (unsigned long msec) -- 1.7.0.4