mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-29 08:34:37 +01:00
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:
parent
39c49c3d8d
commit
7994c42691
7 changed files with 70 additions and 53 deletions
|
@ -40,6 +40,7 @@ LOCAL_DEFINES += \
|
|||
-DXWFEATURE_DEVID \
|
||||
-DXWFEATURE_CHAT \
|
||||
-DCOMMON_LAYOUT \
|
||||
-DXWFEATURE_WIDER_COLS \
|
||||
-DNATIVE_NLI \
|
||||
-DCOMMS_VERSION=1 \
|
||||
-DINITIAL_CLIENT_VERS=${INITIAL_CLIENT_VERS} \
|
||||
|
|
|
@ -1008,7 +1008,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_board_1figureLayout
|
|||
|
||||
BoardDims dims;
|
||||
board_figureLayout( state->game.board, gi, left, top, width, height,
|
||||
scorePct, trayPct, scoreWidth,
|
||||
115, scorePct, trayPct, scoreWidth,
|
||||
fontWidth, fontHt, squareTiles,
|
||||
((!!jdims) ? &dims : NULL) );
|
||||
|
||||
|
|
|
@ -407,7 +407,7 @@ board_drawSnapshot( const BoardCtxt* curBoard, DrawCtx* dctx,
|
|||
board_setDraw( newBoard, dctx ); /* so draw_dictChanged() will get called */
|
||||
XP_U16 fontWidth = width / curBoard->gi->boardSize;
|
||||
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->showGrid = curBoard->showGrid;
|
||||
|
@ -447,10 +447,11 @@ printDims( const BoardDims* dimsp )
|
|||
|
||||
void
|
||||
board_figureLayout( BoardCtxt* board, const CurGameInfo* gi,
|
||||
XP_U16 bLeft, XP_U16 bTop, XP_U16 bWidth, XP_U16 bHeight,
|
||||
XP_U16 scorePct, XP_U16 trayPct, XP_U16 scoreWidth,
|
||||
XP_U16 fontWidth, XP_U16 fontHt, XP_Bool squareTiles,
|
||||
BoardDims* dimsp )
|
||||
XP_U16 bLeft, XP_U16 bTop,
|
||||
const XP_U16 bWidth, const XP_U16 bHeight,
|
||||
XP_U16 colPctMax, XP_U16 scorePct, XP_U16 trayPct,
|
||||
XP_U16 scoreWidth, XP_U16 fontWidth, XP_U16 fontHt,
|
||||
XP_Bool squareTiles, BoardDims* dimsp )
|
||||
{
|
||||
BoardDims ldims;
|
||||
XP_MEMSET( &ldims, 0, sizeof(ldims) );
|
||||
|
@ -461,14 +462,13 @@ board_figureLayout( BoardCtxt* board, const CurGameInfo* gi,
|
|||
XP_U16 scoreHt;
|
||||
XP_U16 wantHt;
|
||||
XP_U16 nToScroll;
|
||||
XP_Bool firstPass;
|
||||
|
||||
ldims.left = bLeft;
|
||||
ldims.top = bTop;
|
||||
ldims.width = bWidth;
|
||||
|
||||
ldims.boardWidth = bWidth;
|
||||
for ( firstPass = XP_TRUE; ; ) {
|
||||
for ( XP_Bool firstPass = XP_TRUE; ; ) {
|
||||
XP_U16 cellSize = ldims.boardWidth / nCells;
|
||||
if ( cellSize > maxCellSize ) {
|
||||
cellSize = maxCellSize;
|
||||
|
@ -560,6 +560,15 @@ board_figureLayout( BoardCtxt* board, const CurGameInfo* gi,
|
|||
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 );
|
||||
|
||||
if ( !!dimsp ) {
|
||||
|
@ -2164,37 +2173,46 @@ figureDims( XP_U16* edges, XP_U16 len, XP_U16 nVisible,
|
|||
} /* figureDims */
|
||||
|
||||
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 maxOffset;
|
||||
ScrollData* hsd;
|
||||
XP_U16 nVis = count - board->zoomCount;
|
||||
XP_U16 scale = dimension / nVis;
|
||||
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 ) ) {
|
||||
XP_ASSERT( board->zoomCount >= 1 );
|
||||
--board->zoomCount;
|
||||
}
|
||||
|
||||
nCols = model_numCols( board->model );
|
||||
nVisCols = nCols - board->zoomCount;
|
||||
scale = board->boardBounds.width / nVisCols;
|
||||
spares = board->boardBounds.width % nVisCols;
|
||||
/* Horizontal scale */
|
||||
*scaleHP = figureScale( board, model_numCols( board->model ),
|
||||
board->boardBounds.width, &board->sd[SCROLL_H] );
|
||||
|
||||
maxOffset = nCols - nVisCols;
|
||||
hsd = &board->sd[SCROLL_H];
|
||||
if ( hsd->offset > maxOffset ) {
|
||||
hsd->offset = maxOffset;
|
||||
}
|
||||
|
||||
hsd->lastVisible = nCols - board->zoomCount + hsd->offset - 1;
|
||||
|
||||
if ( figureDims( hsd->dims, VSIZE(hsd->dims), nVisCols,
|
||||
scale, spares ) ) {
|
||||
board_invalAll( board );
|
||||
}
|
||||
|
||||
return scale;
|
||||
} /* figureHScale */
|
||||
#ifdef XWFEATURE_WIDER_COLS
|
||||
*scaleVP = figureScale( board, model_numCols( board->model ),
|
||||
board->boardBounds.height,
|
||||
&board->sd[SCROLL_V] );
|
||||
#else
|
||||
*scaleVP = *scaleHP;
|
||||
#endif
|
||||
} /* figureScales */
|
||||
|
||||
static void
|
||||
figureBoardRect( BoardCtxt* board )
|
||||
|
@ -2203,13 +2221,14 @@ figureBoardRect( BoardCtxt* board )
|
|||
XP_Rect boardBounds = board->boardBounds;
|
||||
XP_U16 nVisible;
|
||||
XP_U16 nRows = model_numRows( board->model );
|
||||
XP_U16 boardScale = figureHScale( board );
|
||||
ScrollData* hsd = &board->sd[SCROLL_H];
|
||||
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 );
|
||||
hsd->scale = boardScale;
|
||||
hsd->scale = boardHScale;
|
||||
}
|
||||
|
||||
/* 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.
|
||||
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;
|
||||
if ( trayHidden ) {
|
||||
maxHeight = board->heightAsSet;
|
||||
|
@ -2237,10 +2256,10 @@ figureBoardRect( BoardCtxt* board )
|
|||
XP_S16 maxYOffset;
|
||||
/* Need to hide rows etc. */
|
||||
boardBounds.height = maxHeight;
|
||||
vsd->scale = boardScale;
|
||||
vsd->scale = boardVScale;
|
||||
|
||||
nVisible = maxHeight / boardScale;
|
||||
extra = maxHeight % boardScale;
|
||||
nVisible = maxHeight / boardVScale;
|
||||
extra = maxHeight % boardVScale;
|
||||
|
||||
maxYOffset = nRows - nVisible;
|
||||
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
|
||||
&& col <= hsd->lastVisible && row <= vsd->lastVisible;
|
||||
|
||||
rect->left = board->boardBounds.left;
|
||||
XP_U16 left = board->boardBounds.left;
|
||||
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->top = board->boardBounds.top;
|
||||
XP_U16 top = board->boardBounds.top;
|
||||
for ( cur = vsd->offset; cur < row; ++cur ) {
|
||||
rect->top += vsd->dims[cur];
|
||||
top += vsd->dims[cur];
|
||||
}
|
||||
rect->top = top;
|
||||
rect->height = vsd->dims[row];
|
||||
|
||||
return onBoard;
|
||||
|
|
|
@ -101,9 +101,9 @@ typedef struct _BoardDims {
|
|||
|
||||
void board_figureLayout( BoardCtxt* board, const CurGameInfo* gi, XP_U16 bLeft,
|
||||
XP_U16 bTop, XP_U16 bWidth, XP_U16 bHeight,
|
||||
XP_U16 scorePct, XP_U16 trayPct, XP_U16 scoreWidth,
|
||||
XP_U16 fontWidth, XP_U16 fontHt, XP_Bool squareTiles,
|
||||
/* out */ BoardDims* dimsp );
|
||||
XP_U16 colPctMax, XP_U16 scorePct, XP_U16 trayPct,
|
||||
XP_U16 scoreWidth, XP_U16 fontWidth, XP_U16 fontHt,
|
||||
XP_Bool squareTiles, /* out */ BoardDims* dimsp );
|
||||
void board_applyLayout( BoardCtxt* board, const BoardDims* dims );
|
||||
|
||||
#endif
|
||||
|
|
|
@ -124,6 +124,7 @@ DEFINES += -DXWFEATURE_CHANGEDICT
|
|||
DEFINES += -DXWFEATURE_DEVID
|
||||
DEFINES += -DXWFEATURE_COMMSACK
|
||||
#DEFINES += -DXWFEATURE_ACTIVERECT
|
||||
DEFINES += -DXWFEATURE_WIDER_COLS
|
||||
DEFINES += -DCOMMS_XPORT_FLAGSPROC
|
||||
DEFINES += -DINITIAL_CLIENT_VERS=3
|
||||
DEFINES += -DCOMMON_LAYOUT
|
||||
|
|
|
@ -1532,7 +1532,7 @@ positionSizeStuff( CursesAppGlobals* globals, int width, int height )
|
|||
|
||||
BoardDims dims;
|
||||
board_figureLayout( board, cGlobals->gi,
|
||||
0, 0, width, height,
|
||||
0, 0, width, height, 100,
|
||||
150, 200, /* percents */
|
||||
width*75/100, 2, 1,
|
||||
XP_FALSE, &dims );
|
||||
|
|
|
@ -719,13 +719,7 @@ configure_event( GtkWidget* widget, GdkEventConfigure* XP_UNUSED(event),
|
|||
BoardDims dims;
|
||||
board_figureLayout( board, cGlobals->gi,
|
||||
GTK_BOARD_LEFT, GTK_HOR_SCORE_TOP, bdWidth, bdHeight,
|
||||
#if 1
|
||||
150, 200,
|
||||
#else
|
||||
0, 0,
|
||||
#endif
|
||||
bdWidth-25, 16, 16,
|
||||
XP_FALSE, &dims );
|
||||
110, 150, 200, bdWidth-25, 16, 16, XP_FALSE, &dims );
|
||||
board_applyLayout( board, &dims );
|
||||
|
||||
#else
|
||||
|
|
Loading…
Add table
Reference in a new issue