Modify layout code to keep cells close to square when possible,

leaving significant border space on highly rectangular screens.
This commit is contained in:
ehouse 2008-10-08 04:42:16 +00:00
parent a8fb37504d
commit 190c0aca88
4 changed files with 104 additions and 93 deletions

View file

@ -25,10 +25,10 @@
#define TRAY_BORDER 7 #define TRAY_BORDER 7
#define CELL_BORDER 3 #define CELL_BORDER 3
#define MIN_CELL_WIDTH 12 #define MIN_CELL_WIDTH 10
#define MIN_CELL_HEIGHT 13 #define MIN_CELL_HEIGHT 13
/* 1 below for what's subtracted from bparms->trayHeight */ /* 1 below for what's subtracted from bparms->trayHeight */
#define MIN_TILE_HEIGHT (((MIN_CELL_HEIGHT) + (TRAY_BORDER - CELL_BORDER)) + 1) #define MIN_TRAY_HEIGHT (((MIN_CELL_HEIGHT) + (TRAY_BORDER - CELL_BORDER)) + 1)
/* Favor the tray over the scoreboard. */ /* Favor the tray over the scoreboard. */
#define SCORE_TWEAK 2 #define SCORE_TWEAK 2

View file

@ -1129,8 +1129,8 @@ DRAW_FUNC_NAME(measureRemText)( DrawCtx* p_dctx, const XP_Rect* xprect,
formatRemText( nTilesLeft, dctx->scoreIsVertical, buf ); formatRemText( nTilesLeft, dctx->scoreIsVertical, buf );
height = xprect->height-2; height = xprect->height-2;
if ( height > globals->cellHt ) { if ( height > globals->cellHt - CELL_BORDER ) {
height = globals->cellHt; height = globals->cellHt - CELL_BORDER;
} }
fce = ceGetSizedFont( dctx, height, RFONTS_REM ); fce = ceGetSizedFont( dctx, height, RFONTS_REM );
oldFont = SelectObject( hdc, fce->setFont ); oldFont = SelectObject( hdc, fce->setFont );

View file

@ -57,7 +57,7 @@
#define MAX_LOADSTRING 100 #define MAX_LOADSTRING 100
#define PPC_SCROLLBAR_WIDTH 12 #define MAX_SCROLLBAR_WIDTH 12
#define MIN_SCROLLBAR_WIDTH 6 #define MIN_SCROLLBAR_WIDTH 6
#define SCROLLBARID 0x4321 /* needs to be unique! */ #define SCROLLBARID 0x4321 /* needs to be unique! */
@ -443,7 +443,10 @@ makeScrollbar( CEAppGlobals* globals, XP_U16 nHidden, XP_U16 xx, XP_U16 yy,
XP_MEMCPY( &globals->scrollRects[1], &tmp, sizeof(globals->scrollRects[1]) ); XP_MEMCPY( &globals->scrollRects[1], &tmp, sizeof(globals->scrollRects[1]) );
yy += rectHt; yy += rectHt;
height -= rectHt * 2; /* above and below */ height -= rectHt * 2; /* above and below */
width -= 2; /* make narrower: on CE will erase cell border */
++xx;
#endif #endif
/* Need to destroy it, or resize it, because board size may be changing /* Need to destroy it, or resize it, because board size may be changing
in case where portrait display's been flipped. */ in case where portrait display's been flipped. */
@ -487,6 +490,9 @@ removeScrollbar( CEAppGlobals* globals )
typedef struct CEBoardParms { typedef struct CEBoardParms {
XP_U16 scrnWidth; XP_U16 scrnWidth;
XP_U16 scrnHeight;
XP_U16 adjLeft;
XP_U16 adjTop;
XP_U16 boardHScale; XP_U16 boardHScale;
XP_U16 boardVScale; XP_U16 boardVScale;
@ -509,17 +515,18 @@ typedef struct CEBoardParms {
} CEBoardParms; } CEBoardParms;
static void static void
figureBoardParms( CEAppGlobals* globals, XP_U16 nRows, CEBoardParms* bparms ) figureBoardParms( CEAppGlobals* globals, const XP_U16 nRows,
CEBoardParms* bparms )
{ {
RECT rc; RECT rc;
XP_U16 scrnWidth, scrnHeight; XP_U16 scrnWidth, scrnHeight;
XP_U16 trayVScale, scoreWidth, boardLeft, scoreHeight; XP_U16 trayHeight, scoreWidth, scoreHeight;
XP_U16 hScale, vScale, nVisibleRows; XP_U16 hScale, vScale, nVisibleRows;
XP_U16 trayTop; XP_U16 tmp, rowsToUse, nRowsPossible;
XP_Bool horiz; XP_Bool horiz;
XP_U16 scrollWidth = 0; XP_U16 scrollWidth = 0;
XP_U16 numUnits;
XP_S16 num2Scroll; XP_S16 num2Scroll;
XP_U16 adjLeft, adjTop;
GetClientRect( globals->hWnd, &rc ); GetClientRect( globals->hWnd, &rc );
#ifndef _WIN32_WCE #ifndef _WIN32_WCE
@ -541,88 +548,68 @@ figureBoardParms( CEAppGlobals* globals, XP_U16 nRows, CEBoardParms* bparms )
scrnWidth = (XP_U16)(rc.right - rc.left); scrnWidth = (XP_U16)(rc.right - rc.left);
scrnHeight = (XP_U16)(rc.bottom - rc.top); scrnHeight = (XP_U16)(rc.bottom - rc.top);
XP_LOGF( "%s: scrnWidth: %d, scrnHeight: %d", __func__, XP_LOGF( "%s: scrnWidth: %d, scrnHeight: %d", __func__,
scrnWidth, scrnHeight ); scrnWidth, scrnHeight );
horiz = (scrnHeight/* - CE_SCORE_HEIGHT*/) /* Figure layout style based on proportion UNLESS there's just no room
>= (scrnWidth/* - CE_MIN_SCORE_WIDTH*/); for anything but 15 columns on the board -- because vertically is the
nVisibleRows = nRows; only dimension in which we can scroll. */
if ( scrnWidth <= (MIN_CELL_WIDTH * (nRows+2)) ) {
horiz = XP_TRUE;
} else {
horiz = scrnHeight >= scrnWidth;
}
/* Scoreboard is same height as cells (less SCORE_TWEAK) */ /* Scoreboard is same height as cells (less SCORE_TWEAK) */
numUnits = (scrnHeight-MIN_TILE_HEIGHT) / MIN_CELL_HEIGHT; nRowsPossible = (scrnHeight-MIN_TRAY_HEIGHT) / MIN_CELL_HEIGHT;
num2Scroll = (nRows + 1) - numUnits; /* 1: scoreboard */ num2Scroll = (nRows + (horiz?1:0)) - nRowsPossible; /* 1: scoreboard */
if ( num2Scroll < 0 ) { if ( num2Scroll < 0 ) {
num2Scroll = 0; num2Scroll = 0;
} }
#ifdef FORCE_SCROLL #ifdef FORCE_SCROLL
if ( num2Scroll < FORCE_SCROLL ) { if ( num2Scroll < FORCE_SCROLL ) { num2Scroll = FORCE_SCROLL; }
num2Scroll = FORCE_SCROLL;
}
#endif #endif
nVisibleRows = nRows - num2Scroll;
rowsToUse = nVisibleRows + (horiz? 1:0); /* 1: scoreboard */
vScale = (scrnHeight-MIN_TRAY_HEIGHT) / rowsToUse;
nVisibleRows -= num2Scroll; tmp = nRows + (horiz ? 0 : 2);
hScale = scrnWidth / tmp;
/* apportion the extra pixels */ if ( vScale > hScale ) {
vScale = (scrnHeight-MIN_TILE_HEIGHT) / (nVisibleRows + (horiz? 1:0)); vScale = XP_MAX( MIN_CELL_HEIGHT, hScale );
XP_LOGF( "%s: vScale: %d", __func__, vScale ); } else if ( hScale > vScale ) {
hScale = XP_MAX( MIN_CELL_WIDTH, vScale );
trayTop = (vScale * (nVisibleRows+(horiz? 1:0))); /* 1 for scoreboard */
if ( horiz ) {
trayTop -= SCORE_TWEAK;
}
trayVScale = scrnHeight - trayTop;
/* If we have the space, make tiles 2* the size of cells */
if ( nVisibleRows == nRows ) {
XP_U16 nRowsIncSbrd = nRows + (horiz?1:0);
while ( (vScale > MIN_CELL_HEIGHT) && (trayVScale < (2 * vScale)) ) {
trayVScale += nRowsIncSbrd;
trayTop -= nRowsIncSbrd;
--vScale;
}
} }
globals->cellHt = vScale; /* Figure out tray size */
tmp = vScale * rowsToUse;
XP_LOGF( "vScale: %d; target: %d", vScale, MIN_CELL_HEIGHT ); trayHeight = XP_MIN( vScale * 2, scrnHeight - tmp );
XP_LOGF( "trayVScale: %d; target: %d", trayVScale, MIN_TILE_HEIGHT );
#ifdef CEFEATURE_CANSCROLL #ifdef CEFEATURE_CANSCROLL
if ( nVisibleRows < nRows ) { /* Does this need to be in a loop? */
scrollWidth = PPC_SCROLLBAR_WIDTH; while ( nVisibleRows < nRows && hScale > MIN_CELL_WIDTH ) { /* need scroller? (while allows break) */
scrollWidth = scrnWidth - (tmp * hScale);
if ( scrollWidth >= MIN_SCROLLBAR_WIDTH ) {
break;
}
--hScale;
}
if ( scrollWidth > MAX_SCROLLBAR_WIDTH ) {
scrollWidth = MAX_SCROLLBAR_WIDTH;
} }
#endif #endif
if ( horiz ) { if ( horiz ) {
/* don't let scrollbar be wide out of proportion */ scoreWidth = scrollWidth + (hScale * nRows);
for ( ; ; ) { scoreHeight = vScale - SCORE_TWEAK;
hScale = (scrnWidth - scrollWidth) / nRows; trayHeight += SCORE_TWEAK;
XP_LOGF( "1: scrollWidth: %d; hScale:%d", scrollWidth, hScale );
if ( scrollWidth > 0 ) {
boardLeft = 0;
scrollWidth = scrnWidth - (nRows * hScale);
} else {
boardLeft = (scrnWidth - scrollWidth - (hScale*nRows)) / 2;
}
XP_LOGF( "NOW: scrollWidth: %d; hScale:%d", scrollWidth, hScale );
if ( (hScale < scrollWidth)
&& (scrollWidth-nRows > MIN_SCROLLBAR_WIDTH) ) {
scrollWidth -= nRows;
} else {
break;
}
}
scoreWidth = scrnWidth;
} else { } else {
hScale = (scrnWidth - scrollWidth) / (nRows + 2); /* double width? */ scoreWidth = XP_MIN( 2*hScale, scrnWidth - (hScale * nRows) );
boardLeft = scrnWidth - scrollWidth - (hScale * nRows); scoreHeight = (nVisibleRows * vScale) + trayHeight;
scoreWidth = boardLeft/* + scrollWidth*/;
} }
scoreHeight = horiz? vScale - SCORE_TWEAK : scrnHeight;
if ( globals->gameInfo.timerEnabled ) { if ( globals->gameInfo.timerEnabled ) {
if ( horiz ) { if ( horiz ) {
bparms->timerWidth = scoreWidth / 6; /* arbitrarily, one sixth */ bparms->timerWidth = scoreWidth / 6; /* arbitrarily, one sixth */
@ -640,22 +627,33 @@ figureBoardParms( CEAppGlobals* globals, XP_U16 nRows, CEBoardParms* bparms )
} }
} }
globals->cellHt = vScale;
/* figure actual width and height */
tmp = scrollWidth + (hScale * nRows) + (horiz ? 0 : scoreWidth);
adjLeft = (scrnWidth - tmp)/2;
tmp = trayHeight + (vScale * nVisibleRows) + (horiz?scoreHeight:0);
adjTop = (scrnHeight - tmp)/2;
bparms->scrnWidth = scrnWidth; bparms->scrnWidth = scrnWidth;
bparms->scrnHeight = scrnHeight;
bparms->adjLeft = adjLeft;
bparms->adjTop = adjTop;
bparms->boardHScale = hScale; bparms->boardHScale = hScale;
bparms->boardVScale = vScale; bparms->boardVScale = vScale;
bparms->boardTop = horiz? scoreHeight : 0; bparms->boardTop = adjTop + (horiz? scoreHeight : 0);
bparms->trayTop = trayTop; bparms->trayTop = bparms->boardTop + (nVisibleRows * vScale);
bparms->trayHeight = trayVScale; bparms->trayHeight = trayHeight;
bparms->trayWidth = horiz? scrnWidth: scrnWidth - scoreWidth; bparms->trayWidth = (hScale * nRows) + scrollWidth;
bparms->boardLeft = boardLeft; bparms->boardLeft = adjLeft + (horiz ? 0 : scoreWidth);
bparms->trayLeft = horiz? 0 : scoreWidth; bparms->trayLeft = bparms->boardLeft;//horiz? 0 : scoreWidth;
bparms->scoreWidth = scoreWidth; bparms->scoreWidth = scoreWidth;
bparms->scoreHeight = scoreHeight; bparms->scoreHeight = scoreHeight;
bparms->scrollWidth = scrollWidth; bparms->scrollWidth = scrollWidth;
bparms->horiz = horiz; bparms->horiz = horiz;
#ifdef CEFEATURE_CANSCROLL #ifdef CEFEATURE_CANSCROLL
bparms->needsScroller = nVisibleRows < nRows; bparms->needsScroller = scrollWidth > 0;
if ( bparms->needsScroller ) { if ( bparms->needsScroller ) {
XP_U16 boardRight; XP_U16 boardRight;
boardRight = bparms->boardLeft + (nRows * hScale); boardRight = bparms->boardLeft + (nRows * hScale);
@ -673,25 +671,35 @@ static void
setOwnedRects( CEAppGlobals* globals, XP_U16 nRows, setOwnedRects( CEAppGlobals* globals, XP_U16 nRows,
const CEBoardParms* bparms ) const CEBoardParms* bparms )
{ {
if ( bparms->horiz ) { RECT tmp;
RECT tmp; XP_U16 scrollWidth = bparms->scrollWidth;
XP_U16 scrollWidth = bparms->scrollWidth;
tmp.top = bparms->scoreHeight; /* Same for both */ XP_MEMSET( &globals->ownedRects, 0, sizeof(globals->ownedRects) );
tmp.bottom = bparms->trayTop; /* Same for both */
tmp.left = 0; tmp.top = bparms->adjTop; /* Same for both */
tmp.right = bparms->boardLeft; tmp.bottom = bparms->trayTop + bparms->trayHeight; /* Same for both */
XP_MEMCPY( &globals->ownedRects[OWNED_RECT_LEFT], &tmp,
sizeof(globals->ownedRects[OWNED_RECT_LEFT]) );
tmp.left = tmp.right + (bparms->boardHScale * nRows) + scrollWidth; tmp.left = 0;
tmp.right = bparms->scrnWidth; tmp.right = bparms->adjLeft;
XP_MEMCPY( &globals->ownedRects[OWNED_RECT_RIGHT], &tmp, XP_MEMCPY( &globals->ownedRects[OWNED_RECT_LEFT], &tmp,
sizeof(globals->ownedRects[OWNED_RECT_RIGHT]) ); sizeof(globals->ownedRects[OWNED_RECT_LEFT]) );
} else {
XP_MEMSET( &globals->ownedRects, 0, sizeof(globals->ownedRects) ); tmp.left = tmp.right + (bparms->boardHScale * nRows) + scrollWidth;
} tmp.right = bparms->scrnWidth;
XP_MEMCPY( &globals->ownedRects[OWNED_RECT_RIGHT], &tmp,
sizeof(globals->ownedRects[OWNED_RECT_RIGHT]) );
tmp.left = 0;
tmp.top = 0;
tmp.right = bparms->scrnWidth;
tmp.bottom = bparms->adjTop;
XP_MEMCPY( &globals->ownedRects[OWNED_RECT_TOP], &tmp,
sizeof(globals->ownedRects[OWNED_RECT_TOP]) );
tmp.top = bparms->trayTop + bparms->trayHeight;
tmp.bottom = bparms->scrnHeight;
XP_MEMCPY( &globals->ownedRects[OWNED_RECT_BOTTOM], &tmp,
sizeof(globals->ownedRects[OWNED_RECT_BOTTOM]) );
} /* setOwnedRects */ } /* setOwnedRects */
@ -724,7 +732,8 @@ cePositionBoard( CEAppGlobals* globals )
board_setScale( globals->game.board, bparms.boardHScale, board_setScale( globals->game.board, bparms.boardHScale,
bparms.boardVScale ); bparms.boardVScale );
board_setScoreboardLoc( globals->game.board, 0, 0, bparms.scoreWidth, board_setScoreboardLoc( globals->game.board, bparms.adjLeft, bparms.adjTop,
bparms.scoreWidth,
bparms.scoreHeight, bparms.horiz ); bparms.scoreHeight, bparms.horiz );
board_setShowColors( globals->game.board, globals->appPrefs.showColors ); board_setShowColors( globals->game.board, globals->appPrefs.showColors );
board_setYOffset( globals->game.board, 0 ); board_setYOffset( globals->game.board, 0 );

View file

@ -89,6 +89,8 @@ typedef struct CEAppPrefs {
enum { OWNED_RECT_LEFT enum { OWNED_RECT_LEFT
,OWNED_RECT_RIGHT ,OWNED_RECT_RIGHT
,OWNED_RECT_TOP
,OWNED_RECT_BOTTOM
,N_OWNED_RECTS ,N_OWNED_RECTS
}; };