add board_drawSnapshot

Toward something that should work with android: pass a potentially
unique draw context into new method that creates a new board just for
the draw and makes its scoreboard and tray disappear.
This commit is contained in:
Eric House 2016-08-05 10:23:39 -07:00
parent 3c0a128266
commit 0c6283ea63
5 changed files with 50 additions and 25 deletions

View file

@ -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 )
{

View file

@ -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

View file

@ -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 );

View file

@ -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 );

View file

@ -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*