diff --git a/xwords4/common/board.c b/xwords4/common/board.c index dcace69ef..14435a0ca 100644 --- a/xwords4/common/board.c +++ b/xwords4/common/board.c @@ -105,7 +105,6 @@ static void invalTradeWindow( BoardCtxt* board, XP_S16 turn, XP_Bool redraw ); static XP_Bool invalCellsWithTiles( BoardCtxt* board ); static void setTimerIf( BoardCtxt* board ); -static void clearTimerIf( const BoardCtxt* board ); static XP_Bool p_board_timerFired( void* closure, XWTimerReason why ); @@ -174,14 +173,6 @@ board_make( MPFORMAL ModelCtxt* model, ServerCtxt* server, DrawCtx* draw, result->star_row = (XP_U16)(model_numRows(model) / 2); - model_setBoardListener( model, boardCellChanged, result ); - model_setTrayListener( model, boardTilesChanged, result ); - model_setDictListener( model, dictChanged, result ); - server_setTurnChangeListener( server, boardTurnChanged, result ); - server_setGameOverListener( server, boardGameOver, result ); - - setTimerIf( result ); - #ifdef KEYBOARD_NAV { /* set up some useful initial values */ @@ -202,7 +193,7 @@ board_make( MPFORMAL ModelCtxt* model, ServerCtxt* server, DrawCtx* draw, void board_destroy( BoardCtxt* board ) { - clearTimerIf( board ); + util_clearTimer( board->util, TIMER_TIMERTICK ); XP_FREE( board->mpool, board ); } /* board_destroy */ @@ -222,6 +213,7 @@ board_makeFromStream( MPFORMAL XWStreamCtxt* stream, ModelCtxt* model, #endif board = board_make( MPPARM(mpool) model, server, draw, util ); + board_setCallbacks( board ); if ( version >= STREAM_VERS_4YOFFSET) { board->sd[SCROLL_H].offset = (XP_U16)stream_getBits( stream, 4 ); @@ -405,6 +397,21 @@ board_reset( BoardCtxt* board ) setTimerIf( board ); } /* board_reset */ +void +board_drawSnapshot( const BoardCtxt* curBoard, DrawCtx* dctx, + XP_U16 width, XP_U16 height ) +{ + BoardCtxt* newBoard = board_make( MPPARM(curBoard->mpool) + curBoard->model, + curBoard->server, dctx, curBoard->util ); + + XP_U16 fontWidth = width / curBoard->gi->boardSize; + board_figureLayout( newBoard, curBoard->gi, 0, 0, width, height, + 0, 0, 0, fontWidth, width, XP_TRUE, NULL ); + board_draw( newBoard ); + board_destroy( newBoard ); +} + #ifdef COMMON_LAYOUT # if 0 static void @@ -577,6 +584,18 @@ board_applyLayout( BoardCtxt* board, const BoardDims* dims ) } #endif +void +board_setCallbacks( BoardCtxt* board ) +{ + model_setBoardListener( board->model, boardCellChanged, board ); + model_setTrayListener( board->model, boardTilesChanged, board ); + model_setDictListener( board->model, dictChanged, board ); + server_setTurnChangeListener( board->server, boardTurnChanged, board ); + server_setGameOverListener( board->server, boardGameOver, board ); + + setTimerIf( board ); +} + void board_setPos( BoardCtxt* board, XP_U16 left, XP_U16 top, XP_U16 width, XP_U16 height, XP_U16 maxCellSz, @@ -1290,12 +1309,6 @@ setTimerIf( BoardCtxt* board ) } } /* setTimerIf */ -static void -clearTimerIf( const BoardCtxt* board ) -{ - util_clearTimer( board->util, TIMER_TIMERTICK ); -} - static void timerFiredForTimer( BoardCtxt* board ) { diff --git a/xwords4/common/board.h b/xwords4/common/board.h index 885037fc5..e65b0c7c9 100644 --- a/xwords4/common/board.h +++ b/xwords4/common/board.h @@ -64,6 +64,7 @@ BoardCtxt* board_makeFromStream( MPFORMAL XWStreamCtxt* stream, ModelCtxt* model, ServerCtxt* server, DrawCtx* draw, XW_UtilCtxt* util, XP_U16 nPlayers ); +void board_setCallbacks( BoardCtxt* board ); void board_setDraw( BoardCtxt* board, DrawCtx* draw ); DrawCtx* board_getDraw( const BoardCtxt* board ); @@ -73,6 +74,9 @@ void board_writeToStream( const BoardCtxt* board, XWStreamCtxt* stream ); void board_reset( BoardCtxt* board ); +void board_drawSnapshot( const BoardCtxt* board, DrawCtx* dctx, + XP_U16 width, XP_U16 height ); + /* Layout. Either done internally or by client */ #ifdef COMMON_LAYOUT diff --git a/xwords4/common/game.c b/xwords4/common/game.c index ab09bc859..affc7be27 100644 --- a/xwords4/common/game.c +++ b/xwords4/common/game.c @@ -131,6 +131,7 @@ game_makeNewGame( MPFORMAL XWGame* game, CurGameInfo* gi, util ); game->board = board_make( MPPARM(mpool) game->model, game->server, NULL, util ); + board_setCallbacks( game->board ); server_prefsChanged( game->server, cp ); board_prefsChanged( game->board, cp ); diff --git a/xwords4/linux/gamesdb.c b/xwords4/linux/gamesdb.c index c4ccf059e..be1780984 100644 --- a/xwords4/linux/gamesdb.c +++ b/xwords4/linux/gamesdb.c @@ -24,6 +24,9 @@ #include "linuxutl.h" #include "main.h" +#define SNAP_WIDTH 200 +#define SNAP_HEIGHT 200 + static void getColumnText( sqlite3_stmt *ppStmt, int iCol, XP_UCHAR* buf, int len ); #ifdef DEBUG @@ -173,10 +176,8 @@ addSnap( CommonGlobals* cGlobals ) BoardCtxt* board = cGlobals->game.board; GtkDrawCtx* dctx = (GtkDrawCtx*)board_getDraw( board ); - addSurface( dctx, 100, 100 ); - board_invalAll( board ); - board_draw( board ); - board_invalAll( board ); + addSurface( dctx, SNAP_WIDTH, SNAP_HEIGHT ); + board_drawSnapshot( board, (DrawCtx*)dctx, SNAP_WIDTH, SNAP_HEIGHT ); XWStreamCtxt* stream = make_simple_stream( cGlobals ); getImage( dctx, stream ); diff --git a/xwords4/linux/gtkdraw.c b/xwords4/linux/gtkdraw.c index dbc48100a..90eb8c304 100644 --- a/xwords4/linux/gtkdraw.c +++ b/xwords4/linux/gtkdraw.c @@ -703,8 +703,11 @@ gtk_draw_trayBegin( DrawCtx* p_dctx, const XP_Rect* XP_UNUSED(rect), DrawFocusState XP_UNUSED(dfs) ) { GtkDrawCtx* dctx = (GtkDrawCtx*)p_dctx; - dctx->trayOwner = owner; - return XP_TRUE; + XP_Bool doDraw = !dctx->surface; + if ( doDraw ) { + dctx->trayOwner = owner; + } + return doDraw; } /* gtk_draw_trayBegin */ static XP_Bool @@ -873,9 +876,12 @@ gtk_draw_scoreBegin( DrawCtx* p_dctx, const XP_Rect* rect, DrawFocusState XP_UNUSED(dfs) ) { GtkDrawCtx* dctx = (GtkDrawCtx*)p_dctx; - gtkEraseRect( dctx, rect ); - dctx->scoreIsVertical = rect->height > rect->width; - return XP_TRUE; + XP_Bool doDraw = !dctx->surface; + if ( doDraw ) { + gtkEraseRect( dctx, rect ); + dctx->scoreIsVertical = rect->height > rect->width; + } + return doDraw; } /* gtk_draw_scoreBegin */ static PangoLayout*