make beginDraw return a boolean so can abort

When a gtk3 window's shutting down it appears we can't get a cairo_t*
for it. This change makes it possible to turn that fact into aborting
the whole draw operation.
This commit is contained in:
Eric House 2016-08-04 15:12:05 -07:00
parent 3c7af0023e
commit df6c1e0d3a
5 changed files with 46 additions and 32 deletions

View file

@ -349,7 +349,7 @@ and_draw_drawTimer( DrawCtx* dctx, const XP_Rect* rect, XP_U16 player,
}
/* Not used on android yet */
static void and_draw_beginDraw( DrawCtx* XP_UNUSED(dctx) ) {}
static XP_Bool and_draw_beginDraw( DrawCtx* XP_UNUSED(dctx) ) {return XP_TRUE;}
static void and_draw_endDraw( DrawCtx* XP_UNUSED(dctx) ) {}
static XP_Bool

View file

@ -624,13 +624,14 @@ XP_Bool
board_draw( BoardCtxt* board )
{
if ( !!board->draw && board->boardBounds.width > 0 ) {
draw_beginDraw( board->draw );
if ( draw_beginDraw( board->draw ) ) {
drawScoreBoard( board );
drawTray( board );
drawBoard( board );
drawScoreBoard( board );
drawTray( board );
drawBoard( board );
draw_endDraw( board->draw );
draw_endDraw( board->draw );
}
}
return !board->needsDrawing && 0 == board->trayInvalBits;
} /* board_draw */

View file

@ -116,7 +116,7 @@ typedef struct DrawCtxVTable {
void DRAW_VTABLE_NAME(dictChanged)( DrawCtx* dctx, XP_S16 playerNum,
const DictionaryCtxt* dict );
void DRAW_VTABLE_NAME(beginDraw) ( DrawCtx* dctx );
XP_Bool DRAW_VTABLE_NAME(beginDraw) ( DrawCtx* dctx );
void DRAW_VTABLE_NAME(endDraw) ( DrawCtx* dctx );
XP_Bool DRAW_VTABLE_NAME(boardBegin) ( DrawCtx* dctx,

View file

@ -78,6 +78,12 @@ curses_draw_dictChanged( DrawCtx* XP_UNUSED(p_dctx),
{
}
static XP_Bool
curses_draw_beginDraw( DrawCtx* XP_UNUSED(p_dctx) )
{
return XP_TRUE;
}
static XP_Bool
curses_draw_boardBegin( DrawCtx* XP_UNUSED(p_dctx),
const XP_Rect* XP_UNUSED(rect),
@ -582,6 +588,7 @@ curses_draw_frameTray( DrawCtx* p_dctx, XP_Rect* rect )
static XP_Bool
draw_doNothing( DrawCtx* XP_UNUSED(dctx), ... )
{
LOG_FUNC();
return XP_FALSE;
} /* draw_doNothing */
@ -593,18 +600,19 @@ cursesDrawCtxtMake( WINDOW* boardWin )
dctx->vtable = malloc( sizeof(*(((CursesDrawCtx*)dctx)->vtable)) );
for ( int ii = 0;
ii < sizeof(*dctx->vtable)/sizeof(draw_doNothing);
ii < sizeof(*dctx->vtable)/sizeof(dctx->vtable->m_draw_destroyCtxt);
++ii ) {
((void**)(dctx->vtable))[ii] = draw_doNothing;
}
SET_VTABLE_ENTRY( dctx->vtable, draw_destroyCtxt, curses );
SET_VTABLE_ENTRY( dctx->vtable, draw_dictChanged, curses );
SET_VTABLE_ENTRY( dctx->vtable, draw_beginDraw, curses );
SET_VTABLE_ENTRY( dctx->vtable, draw_boardBegin, curses );
SET_VTABLE_ENTRY( dctx->vtable, draw_objFinished, curses );
SET_VTABLE_ENTRY( dctx->vtable, draw_trayBegin, curses );
SET_VTABLE_ENTRY( dctx->vtable, draw_scoreBegin, curses );
SET_VTABLE_ENTRY( dctx->vtable, draw_objFinished, curses );
#ifdef XWFEATURE_SCOREONEPASS
SET_VTABLE_ENTRY( dctx->vtable, draw_drawRemText, curses );

View file

@ -82,15 +82,20 @@ gtkInsetRect( XP_Rect* r, short i )
# define GDKCOLORMAP GdkColormap
#endif
static void
static XP_Bool
initCairo( GtkDrawCtx* dctx )
{
/* XP_LOGF( "%s(dctx=%p)", __func__, dctx ); */
XP_ASSERT( !dctx->_cairo );
dctx->_cairo = gdk_cairo_create( gtk_widget_get_window(dctx->drawing_area) );
/* XP_LOGF( "dctx->cairo=%p", dctx->_cairo ); */
cairo_set_line_width( dctx->_cairo, 1.0 );
cairo_set_line_cap( dctx->_cairo, CAIRO_LINE_CAP_SQUARE );
cairo_t* cairo = gdk_cairo_create( gtk_widget_get_window(dctx->drawing_area) );
XP_Bool inited = !!cairo;
if ( inited ) {
dctx->_cairo = cairo;
/* XP_LOGF( "dctx->cairo=%p", dctx->_cairo ); */
cairo_set_line_width( cairo, 1.0 );
cairo_set_line_cap( cairo, CAIRO_LINE_CAP_SQUARE );
}
return inited;
}
static void
@ -435,12 +440,12 @@ gtk_draw_dictChanged( DrawCtx* XP_UNUSED(p_dctx),
{
}
static void
static XP_Bool
gtk_draw_beginDraw( DrawCtx* p_dctx )
{
#ifdef USE_CAIRO
GtkDrawCtx* dctx = (GtkDrawCtx*)p_dctx;
initCairo( dctx );
return initCairo( dctx );
#endif
}
@ -1482,24 +1487,24 @@ gtkDrawCtxtMake( GtkWidget* drawing_area, GtkGameGlobals* globals )
void
draw_gtk_status( GtkDrawCtx* dctx, char ch )
{
initCairo( dctx );
if ( initCairo( dctx ) ) {
GtkGameGlobals* globals = dctx->globals;
GtkGameGlobals* globals = dctx->globals;
XP_Rect rect = {
.left = globals->netStatLeft,
.top = globals->netStatTop,
.width = GTK_NETSTAT_WIDTH,
.height = GTK_HOR_SCORE_HEIGHT
};
gtkEraseRect( dctx, &rect );
XP_Rect rect = {
.left = globals->netStatLeft,
.top = globals->netStatTop,
.width = GTK_NETSTAT_WIDTH,
.height = GTK_HOR_SCORE_HEIGHT
};
gtkEraseRect( dctx, &rect );
const XP_UCHAR str[2] = { ch, '\0' };
draw_string_at( dctx, NULL, str, GTKMIN_W_HT,
&rect, XP_GTK_JUST_CENTER,
&dctx->black, NULL );
const XP_UCHAR str[2] = { ch, '\0' };
draw_string_at( dctx, NULL, str, GTKMIN_W_HT,
&rect, XP_GTK_JUST_CENTER,
&dctx->black, NULL );
destroyCairo( dctx );
destroyCairo( dctx );
}
}
void