allow board cells to be wider than tall

There are some screen dimensions, especially with dual-pane mode, where
the board is just bit narrower than the screen. Rather than have narrow
white borders, allow the cells to take up the slack. The API takes an
upper bound on the ratio of width to height so things shouldn't get too
odd looking.
This commit is contained in:
Eric House 2016-09-15 20:37:29 -07:00
parent 39c49c3d8d
commit 7994c42691
7 changed files with 70 additions and 53 deletions

View file

@ -40,6 +40,7 @@ LOCAL_DEFINES += \
-DXWFEATURE_DEVID \ -DXWFEATURE_DEVID \
-DXWFEATURE_CHAT \ -DXWFEATURE_CHAT \
-DCOMMON_LAYOUT \ -DCOMMON_LAYOUT \
-DXWFEATURE_WIDER_COLS \
-DNATIVE_NLI \ -DNATIVE_NLI \
-DCOMMS_VERSION=1 \ -DCOMMS_VERSION=1 \
-DINITIAL_CLIENT_VERS=${INITIAL_CLIENT_VERS} \ -DINITIAL_CLIENT_VERS=${INITIAL_CLIENT_VERS} \

View file

@ -1008,7 +1008,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_board_1figureLayout
BoardDims dims; BoardDims dims;
board_figureLayout( state->game.board, gi, left, top, width, height, board_figureLayout( state->game.board, gi, left, top, width, height,
scorePct, trayPct, scoreWidth, 115, scorePct, trayPct, scoreWidth,
fontWidth, fontHt, squareTiles, fontWidth, fontHt, squareTiles,
((!!jdims) ? &dims : NULL) ); ((!!jdims) ? &dims : NULL) );

View file

@ -407,7 +407,7 @@ board_drawSnapshot( const BoardCtxt* curBoard, DrawCtx* dctx,
board_setDraw( newBoard, dctx ); /* so draw_dictChanged() will get called */ board_setDraw( newBoard, dctx ); /* so draw_dictChanged() will get called */
XP_U16 fontWidth = width / curBoard->gi->boardSize; XP_U16 fontWidth = width / curBoard->gi->boardSize;
board_figureLayout( newBoard, curBoard->gi, 0, 0, width, height, board_figureLayout( newBoard, curBoard->gi, 0, 0, width, height,
0, 0, 0, fontWidth, width, XP_FALSE, NULL ); 100, 0, 0, 0, fontWidth, width, XP_FALSE, NULL );
newBoard->showColors = curBoard->showColors; newBoard->showColors = curBoard->showColors;
newBoard->showGrid = curBoard->showGrid; newBoard->showGrid = curBoard->showGrid;
@ -447,10 +447,11 @@ printDims( const BoardDims* dimsp )
void void
board_figureLayout( BoardCtxt* board, const CurGameInfo* gi, board_figureLayout( BoardCtxt* board, const CurGameInfo* gi,
XP_U16 bLeft, XP_U16 bTop, XP_U16 bWidth, XP_U16 bHeight, XP_U16 bLeft, XP_U16 bTop,
XP_U16 scorePct, XP_U16 trayPct, XP_U16 scoreWidth, const XP_U16 bWidth, const XP_U16 bHeight,
XP_U16 fontWidth, XP_U16 fontHt, XP_Bool squareTiles, XP_U16 colPctMax, XP_U16 scorePct, XP_U16 trayPct,
BoardDims* dimsp ) XP_U16 scoreWidth, XP_U16 fontWidth, XP_U16 fontHt,
XP_Bool squareTiles, BoardDims* dimsp )
{ {
BoardDims ldims; BoardDims ldims;
XP_MEMSET( &ldims, 0, sizeof(ldims) ); XP_MEMSET( &ldims, 0, sizeof(ldims) );
@ -461,14 +462,13 @@ board_figureLayout( BoardCtxt* board, const CurGameInfo* gi,
XP_U16 scoreHt; XP_U16 scoreHt;
XP_U16 wantHt; XP_U16 wantHt;
XP_U16 nToScroll; XP_U16 nToScroll;
XP_Bool firstPass;
ldims.left = bLeft; ldims.left = bLeft;
ldims.top = bTop; ldims.top = bTop;
ldims.width = bWidth; ldims.width = bWidth;
ldims.boardWidth = bWidth; ldims.boardWidth = bWidth;
for ( firstPass = XP_TRUE; ; ) { for ( XP_Bool firstPass = XP_TRUE; ; ) {
XP_U16 cellSize = ldims.boardWidth / nCells; XP_U16 cellSize = ldims.boardWidth / nCells;
if ( cellSize > maxCellSize ) { if ( cellSize > maxCellSize ) {
cellSize = maxCellSize; cellSize = maxCellSize;
@ -560,6 +560,15 @@ board_figureLayout( BoardCtxt* board, const CurGameInfo* gi,
break; break;
} }
#ifdef XWFEATURE_WIDER_COLS
ldims.boardWidth = (ldims.boardWidth * colPctMax) / 100;
if ( ldims.boardWidth > bWidth ) {
ldims.boardWidth = bWidth;
}
#else
XP_USE(colPctMax);
#endif
printDims( &ldims ); printDims( &ldims );
if ( !!dimsp ) { if ( !!dimsp ) {
@ -2164,37 +2173,46 @@ figureDims( XP_U16* edges, XP_U16 len, XP_U16 nVisible,
} /* figureDims */ } /* figureDims */
static XP_U16 static XP_U16
figureHScale( BoardCtxt* board ) figureScale( BoardCtxt* board, XP_U16 count, XP_U16 dimension, ScrollData* sd )
{ {
XP_U16 nCols, nVisCols, scale, spares; XP_U16 nVis = count - board->zoomCount;
XP_U16 maxOffset; XP_U16 scale = dimension / nVis;
ScrollData* hsd; XP_U16 spares = dimension % nVis;
XP_U16 maxOffset = count - nVis;
if ( sd->offset > maxOffset ) {
sd->offset = maxOffset;
}
sd->lastVisible = count - board->zoomCount + sd->offset - 1;
if ( figureDims( sd->dims, VSIZE(sd->dims), nVis,
scale, spares ) ) {
board_invalAll( board );
}
return scale;
}
static void
figureScales( BoardCtxt* board, XP_U16* scaleHP, XP_U16* scaleVP )
{
while ( !canZoomIn( board, board->zoomCount ) ) { while ( !canZoomIn( board, board->zoomCount ) ) {
XP_ASSERT( board->zoomCount >= 1 ); XP_ASSERT( board->zoomCount >= 1 );
--board->zoomCount; --board->zoomCount;
} }
nCols = model_numCols( board->model ); /* Horizontal scale */
nVisCols = nCols - board->zoomCount; *scaleHP = figureScale( board, model_numCols( board->model ),
scale = board->boardBounds.width / nVisCols; board->boardBounds.width, &board->sd[SCROLL_H] );
spares = board->boardBounds.width % nVisCols;
maxOffset = nCols - nVisCols; #ifdef XWFEATURE_WIDER_COLS
hsd = &board->sd[SCROLL_H]; *scaleVP = figureScale( board, model_numCols( board->model ),
if ( hsd->offset > maxOffset ) { board->boardBounds.height,
hsd->offset = maxOffset; &board->sd[SCROLL_V] );
} #else
*scaleVP = *scaleHP;
hsd->lastVisible = nCols - board->zoomCount + hsd->offset - 1; #endif
} /* figureScales */
if ( figureDims( hsd->dims, VSIZE(hsd->dims), nVisCols,
scale, spares ) ) {
board_invalAll( board );
}
return scale;
} /* figureHScale */
static void static void
figureBoardRect( BoardCtxt* board ) figureBoardRect( BoardCtxt* board )
@ -2203,13 +2221,14 @@ figureBoardRect( BoardCtxt* board )
XP_Rect boardBounds = board->boardBounds; XP_Rect boardBounds = board->boardBounds;
XP_U16 nVisible; XP_U16 nVisible;
XP_U16 nRows = model_numRows( board->model ); XP_U16 nRows = model_numRows( board->model );
XP_U16 boardScale = figureHScale( board );
ScrollData* hsd = &board->sd[SCROLL_H]; ScrollData* hsd = &board->sd[SCROLL_H];
ScrollData* vsd = &board->sd[SCROLL_V]; ScrollData* vsd = &board->sd[SCROLL_V];
XP_U16 boardHScale, boardVScale;
figureScales( board, &boardHScale, &boardVScale );
if ( boardScale != hsd->scale ) { if ( boardHScale != hsd->scale ) {
board_invalAll( board ); board_invalAll( board );
hsd->scale = boardScale; hsd->scale = boardHScale;
} }
/* Figure height of board. Max height is with all rows visible and /* Figure height of board. Max height is with all rows visible and
@ -2217,7 +2236,7 @@ figureBoardRect( BoardCtxt* board )
if it's visible, or the bottom of the board as set in board_setPos. if it's visible, or the bottom of the board as set in board_setPos.
So we check those two possibilities. */ So we check those two possibilities. */
XP_U16 maxHeight, wantHeight = nRows * boardScale; XP_U16 maxHeight, wantHeight = nRows * boardVScale;
XP_Bool trayHidden = board->trayVisState == TRAY_HIDDEN; XP_Bool trayHidden = board->trayVisState == TRAY_HIDDEN;
if ( trayHidden ) { if ( trayHidden ) {
maxHeight = board->heightAsSet; maxHeight = board->heightAsSet;
@ -2237,10 +2256,10 @@ figureBoardRect( BoardCtxt* board )
XP_S16 maxYOffset; XP_S16 maxYOffset;
/* Need to hide rows etc. */ /* Need to hide rows etc. */
boardBounds.height = maxHeight; boardBounds.height = maxHeight;
vsd->scale = boardScale; vsd->scale = boardVScale;
nVisible = maxHeight / boardScale; nVisible = maxHeight / boardVScale;
extra = maxHeight % boardScale; extra = maxHeight % boardVScale;
maxYOffset = nRows - nVisible; maxYOffset = nRows - nVisible;
if ( vsd->offset > maxYOffset ) { if ( vsd->offset > maxYOffset ) {
@ -2337,16 +2356,18 @@ getCellRect( const BoardCtxt* board, XP_U16 col, XP_U16 row, XP_Rect* rect )
XP_Bool onBoard = col >= hsd->offset && row >= vsd->offset XP_Bool onBoard = col >= hsd->offset && row >= vsd->offset
&& col <= hsd->lastVisible && row <= vsd->lastVisible; && col <= hsd->lastVisible && row <= vsd->lastVisible;
rect->left = board->boardBounds.left; XP_U16 left = board->boardBounds.left;
for ( cur = hsd->offset; cur < col; ++cur ) { for ( cur = hsd->offset; cur < col; ++cur ) {
rect->left += hsd->dims[cur]; left += hsd->dims[cur];
} }
rect->left = left;
rect->width = hsd->dims[col]; rect->width = hsd->dims[col];
rect->top = board->boardBounds.top; XP_U16 top = board->boardBounds.top;
for ( cur = vsd->offset; cur < row; ++cur ) { for ( cur = vsd->offset; cur < row; ++cur ) {
rect->top += vsd->dims[cur]; top += vsd->dims[cur];
} }
rect->top = top;
rect->height = vsd->dims[row]; rect->height = vsd->dims[row];
return onBoard; return onBoard;

View file

@ -101,9 +101,9 @@ typedef struct _BoardDims {
void board_figureLayout( BoardCtxt* board, const CurGameInfo* gi, XP_U16 bLeft, void board_figureLayout( BoardCtxt* board, const CurGameInfo* gi, XP_U16 bLeft,
XP_U16 bTop, XP_U16 bWidth, XP_U16 bHeight, XP_U16 bTop, XP_U16 bWidth, XP_U16 bHeight,
XP_U16 scorePct, XP_U16 trayPct, XP_U16 scoreWidth, XP_U16 colPctMax, XP_U16 scorePct, XP_U16 trayPct,
XP_U16 fontWidth, XP_U16 fontHt, XP_Bool squareTiles, XP_U16 scoreWidth, XP_U16 fontWidth, XP_U16 fontHt,
/* out */ BoardDims* dimsp ); XP_Bool squareTiles, /* out */ BoardDims* dimsp );
void board_applyLayout( BoardCtxt* board, const BoardDims* dims ); void board_applyLayout( BoardCtxt* board, const BoardDims* dims );
#endif #endif

View file

@ -124,6 +124,7 @@ DEFINES += -DXWFEATURE_CHANGEDICT
DEFINES += -DXWFEATURE_DEVID DEFINES += -DXWFEATURE_DEVID
DEFINES += -DXWFEATURE_COMMSACK DEFINES += -DXWFEATURE_COMMSACK
#DEFINES += -DXWFEATURE_ACTIVERECT #DEFINES += -DXWFEATURE_ACTIVERECT
DEFINES += -DXWFEATURE_WIDER_COLS
DEFINES += -DCOMMS_XPORT_FLAGSPROC DEFINES += -DCOMMS_XPORT_FLAGSPROC
DEFINES += -DINITIAL_CLIENT_VERS=3 DEFINES += -DINITIAL_CLIENT_VERS=3
DEFINES += -DCOMMON_LAYOUT DEFINES += -DCOMMON_LAYOUT

View file

@ -1532,7 +1532,7 @@ positionSizeStuff( CursesAppGlobals* globals, int width, int height )
BoardDims dims; BoardDims dims;
board_figureLayout( board, cGlobals->gi, board_figureLayout( board, cGlobals->gi,
0, 0, width, height, 0, 0, width, height, 100,
150, 200, /* percents */ 150, 200, /* percents */
width*75/100, 2, 1, width*75/100, 2, 1,
XP_FALSE, &dims ); XP_FALSE, &dims );

View file

@ -719,13 +719,7 @@ configure_event( GtkWidget* widget, GdkEventConfigure* XP_UNUSED(event),
BoardDims dims; BoardDims dims;
board_figureLayout( board, cGlobals->gi, board_figureLayout( board, cGlobals->gi,
GTK_BOARD_LEFT, GTK_HOR_SCORE_TOP, bdWidth, bdHeight, GTK_BOARD_LEFT, GTK_HOR_SCORE_TOP, bdWidth, bdHeight,
#if 1 110, 150, 200, bdWidth-25, 16, 16, XP_FALSE, &dims );
150, 200,
#else
0, 0,
#endif
bdWidth-25, 16, 16,
XP_FALSE, &dims );
board_applyLayout( board, &dims ); board_applyLayout( board, &dims );
#else #else