From 184ac28ebc140474956bb31c0403687c1746148e Mon Sep 17 00:00:00 2001 From: Eric House Date: Sun, 3 Nov 2013 12:15:53 -0800 Subject: [PATCH] fix to compile, and in gtk case to work, when COMMON_LAYOUT defined --- xwords4/linux/cursesmain.c | 8 +++-- xwords4/linux/gtkboard.c | 69 +++++++++++++++++++++++--------------- xwords4/linux/linuxmain.c | 5 ++- 3 files changed, 52 insertions(+), 30 deletions(-) diff --git a/xwords4/linux/cursesmain.c b/xwords4/linux/cursesmain.c index 239e9c291..2810c8d8a 100644 --- a/xwords4/linux/cursesmain.c +++ b/xwords4/linux/cursesmain.c @@ -1635,8 +1635,12 @@ passKeyToBoard( CursesAppGlobals* globals, char ch ) static void positionSizeStuff( CursesAppGlobals* globals, int width, int height ) { - XP_U16 cellWidth, cellHt, scoreLeft, scoreWidth; BoardCtxt* board = globals->cGlobals.game.board; +#ifdef COMMON_LAYOUT + XP_USE( width ); + XP_USE( height ); +#else + XP_U16 cellWidth, cellHt, scoreLeft, scoreWidth; int remWidth = width; int nRows = globals->cGlobals.gi->boardSize; @@ -1680,7 +1684,7 @@ positionSizeStuff( CursesAppGlobals* globals, int width, int height ) /* no divider -- yet */ /* board_setTrayVisible( globals.board, XP_TRUE, XP_FALSE ); */ - +#endif board_invalAll( board ); } /* positionSizeStuff */ diff --git a/xwords4/linux/gtkboard.c b/xwords4/linux/gtkboard.c index e180f228d..d46b71c28 100644 --- a/xwords4/linux/gtkboard.c +++ b/xwords4/linux/gtkboard.c @@ -598,7 +598,29 @@ static gboolean configure_event( GtkWidget* widget, GdkEventConfigure* XP_UNUSED(event), GtkGameGlobals* globals ) { - short bdWidth, bdHeight; + if ( globals->draw == NULL ) { + createOrLoadObjects( globals ); + } + + CommonGlobals* cGlobals = &globals->cGlobals; + BoardCtxt* board = cGlobals->game.board; + + short bdWidth = widget->allocation.width - (GTK_RIGHT_MARGIN + + GTK_BOARD_LEFT_MARGIN); + short bdHeight = widget->allocation.height - (GTK_TOP_MARGIN + GTK_BOTTOM_MARGIN) + - GTK_MIN_TRAY_SCALEV - GTK_BOTTOM_MARGIN; + +#ifdef COMMON_LAYOUT + XP_ASSERT( !cGlobals->params->verticalScore ); /* not supported */ + + XP_Rect rect = { .left = GTK_BOARD_LEFT, .top = GTK_HOR_SCORE_TOP, + .width = bdWidth, .height = bdHeight + }; + BoardDims dims; + board_figureLayout( board, cGlobals->gi, 16, 16, XP_FALSE, &rect, &dims ); + board_applyLayout( board, &dims ); + +#else short timerLeft, timerTop; gint hscale, vscale; gint trayTop; @@ -607,48 +629,39 @@ configure_event( GtkWidget* widget, GdkEventConfigure* XP_UNUSED(event), gint nCols; gint nRows; - if ( globals->draw == NULL ) { - createOrLoadObjects( globals ); - } - - nCols = globals->cGlobals.gi->boardSize; + nCols = cGlobals->gi->boardSize; nRows = nCols; - bdWidth = widget->allocation.width - (GTK_RIGHT_MARGIN - + GTK_BOARD_LEFT_MARGIN); - if ( globals->cGlobals.params->verticalScore ) { + if ( cGlobals->params->verticalScore ) { bdWidth -= GTK_VERT_SCORE_WIDTH; } - bdHeight = widget->allocation.height - (GTK_TOP_MARGIN + GTK_BOTTOM_MARGIN) - - GTK_MIN_TRAY_SCALEV - GTK_BOTTOM_MARGIN; hscale = bdWidth / nCols; - if ( 0 != globals->cGlobals.params->nHidden ) { + if ( 0 != cGlobals->params->nHidden ) { vscale = hscale; } else { vscale = (bdHeight / (nCols + GTK_TRAY_HT_ROWS)); /* makd tray height 3x cell height */ } - if ( !globals->cGlobals.params->verticalScore ) { + if ( !cGlobals->params->verticalScore ) { boardTop += GTK_HOR_SCORE_HEIGHT; } trayTop = boardTop + (vscale * nRows); /* move tray up if part of board's meant to be hidden */ - trayTop -= vscale * globals->cGlobals.params->nHidden; - board_setPos( globals->cGlobals.game.board, GTK_BOARD_LEFT, boardTop, + trayTop -= vscale * cGlobals->params->nHidden; + board_setPos( board, GTK_BOARD_LEFT, boardTop, hscale * nCols, vscale * nRows, hscale * 4, XP_FALSE ); - /* board_setScale( globals->cGlobals.game.board, hscale, vscale ); */ - globals->gridOn = XP_TRUE; + /* board_setScale( board, hscale, vscale ); */ - if ( !!globals->cGlobals.game.comms ) { + if ( !!cGlobals->game.comms ) { netStatWidth = GTK_NETSTAT_WIDTH; } timerTop = GTK_TIMER_TOP; - if ( globals->cGlobals.params->verticalScore ) { + if ( cGlobals->params->verticalScore ) { timerLeft = GTK_BOARD_LEFT + (hscale*nCols) + 1; - board_setScoreboardLoc( globals->cGlobals.game.board, + board_setScoreboardLoc( board, timerLeft, GTK_VERT_SCORE_TOP, GTK_VERT_SCORE_WIDTH, @@ -658,7 +671,7 @@ configure_event( GtkWidget* widget, GdkEventConfigure* XP_UNUSED(event), } else { timerLeft = GTK_BOARD_LEFT + (hscale*nCols) - GTK_TIMER_WIDTH - netStatWidth; - board_setScoreboardLoc( globals->cGlobals.game.board, + board_setScoreboardLoc( board, GTK_BOARD_LEFT, GTK_HOR_SCORE_TOP, timerLeft-GTK_BOARD_LEFT, GTK_HOR_SCORE_HEIGHT, @@ -667,24 +680,26 @@ configure_event( GtkWidget* widget, GdkEventConfigure* XP_UNUSED(event), } /* Still pending: do this for the vertical score case */ - if ( globals->cGlobals.game.comms ) { + if ( cGlobals->game.comms ) { globals->netStatLeft = timerLeft + GTK_TIMER_WIDTH; globals->netStatTop = 0; } - board_setTimerLoc( globals->cGlobals.game.board, timerLeft, timerTop, + board_setTimerLoc( board, timerLeft, timerTop, GTK_TIMER_WIDTH, GTK_HOR_SCORE_HEIGHT ); - board_setTrayLoc( globals->cGlobals.game.board, GTK_TRAY_LEFT, trayTop, + board_setTrayLoc( board, GTK_TRAY_LEFT, trayTop, hscale * nCols, vscale * GTK_TRAY_HT_ROWS + 10, GTK_DIVIDER_WIDTH ); +#endif + globals->gridOn = XP_TRUE; + setCtrlsForTray( globals ); - - board_invalAll( globals->cGlobals.game.board ); + board_invalAll( board ); XP_Bool inOut[2]; - board_zoom( globals->cGlobals.game.board, 0, inOut ); + board_zoom( board, 0, inOut ); setZoomButtons( globals, inOut ); return TRUE; diff --git a/xwords4/linux/linuxmain.c b/xwords4/linux/linuxmain.c index a568c3d86..5ee2b1161 100644 --- a/xwords4/linux/linuxmain.c +++ b/xwords4/linux/linuxmain.c @@ -989,7 +989,10 @@ send_or_close( CommonGlobals* cGlobals, const XP_U8* buf, size_t len ) cGlobals->socket = -1; /* delete all pending packets since the socket's bad */ - g_slist_free_full( cGlobals->packetQueue, free_elem_proc ); + for ( GSList* iter = cGlobals->packetQueue; !!iter; iter = iter->next ) { + free_elem_proc( iter->data ); + } + g_slist_free( cGlobals->packetQueue ); cGlobals->packetQueue = NULL; } LOG_RETURNF( "%d", success );