Change board_zoom to indicate direction only of zoom, not number of

cols.  When figuring internal dimensions zoom out as needed to meet
maxSize value.  This fixes problem where rotating a zoomed portrait
board to landscape leaves cells bigger than they can be made by
zooming, but then the desired zoom has been changed and stored and so
on return to portrait cells are smaller/less zoomed.  Need to see if I
can live with that.
This commit is contained in:
eehouse 2010-06-05 03:40:23 +00:00
parent d0b9f0f7aa
commit f514717428
3 changed files with 28 additions and 9 deletions

View file

@ -72,6 +72,8 @@
# define MAX_BOARD_ZOOM 4
#endif
#define BOARD_ZOOMBY 2
#ifdef CPLUS
extern "C" {
#endif
@ -547,13 +549,20 @@ canZoomIn( const BoardCtxt* board, XP_S16 newCount )
}
XP_Bool
board_zoom( BoardCtxt* board, XP_S16 zoomBy, XP_Bool* canInOut )
board_zoom( BoardCtxt* board, XP_S16 zoomDir, XP_Bool* canInOut )
{
XP_S16 zoomBy = 0;
XP_Bool changed;
XP_S16 zoomCount = board->zoomCount;
ScrollData* hsd = &board->sd[SCROLL_H];
ScrollData* vsd = &board->sd[SCROLL_V];
if ( zoomDir > 0 ) {
zoomBy = BOARD_ZOOMBY;
} else if ( zoomDir < 0 ) {
zoomBy = -BOARD_ZOOMBY;
}
XP_U16 maxCount = model_numCols( board->model ) - MAX_BOARD_ZOOM;
if ( board->boardBounds.width > board->boardBounds.height ) {
XP_U16 ratio = board->boardBounds.width / board->boardBounds.height;
@ -1672,13 +1681,22 @@ figureDims( XP_U16* edges, XP_U16 len, XP_U16 nVisible,
static XP_U16
figureHScale( BoardCtxt* board )
{
XP_U16 nCols = model_numCols( board->model );
XP_U16 nVisCols = nCols - board->zoomCount;
XP_U16 scale = board->boardBounds.width / nVisCols;
XP_U16 spares = board->boardBounds.width % nVisCols;
XP_U16 nCols, nVisCols, scale, spares;
XP_U16 maxOffset;
ScrollData* hsd;
XP_U16 maxOffset = nCols - nVisCols;
ScrollData* hsd = &board->sd[SCROLL_H];
while ( !canZoomIn( board, board->zoomCount ) ) {
XP_ASSERT( board->zoomCount >= BOARD_ZOOMBY );
board->zoomCount -= BOARD_ZOOMBY;
}
nCols = model_numCols( board->model );
nVisCols = nCols - board->zoomCount;
scale = board->boardBounds.width / nVisCols;
spares = board->boardBounds.width % nVisCols;
maxOffset = nCols - nVisCols;
hsd = &board->sd[SCROLL_H];
if ( hsd->offset > maxOffset ) {
hsd->offset = maxOffset;
}

View file

@ -78,6 +78,7 @@ void board_reset( BoardCtxt* board );
XP_Bool board_setYOffset( BoardCtxt* board, XP_U16 newOffset );
XP_U16 board_getYOffset( const BoardCtxt* board );
/* zoomBy: >0: zoom in; < 0: zoom out; 0: query only */
XP_Bool board_zoom( BoardCtxt* board, XP_S16 zoomBy, XP_Bool* canInOut );
void board_setScoreboardLoc( BoardCtxt* board,

View file

@ -1095,7 +1095,7 @@ static void
handle_zoomin_button( GtkWidget* XP_UNUSED(widget), GtkAppGlobals* globals )
{
XP_Bool inOut[2];
if ( board_zoom( globals->cGlobals.game.board, 2, inOut ) ) {
if ( board_zoom( globals->cGlobals.game.board, 1, inOut ) ) {
board_draw( globals->cGlobals.game.board );
setZoomButtons( globals, inOut );
}
@ -1105,7 +1105,7 @@ static void
handle_zoomout_button( GtkWidget* XP_UNUSED(widget), GtkAppGlobals* globals )
{
XP_Bool inOut[2];
if ( board_zoom( globals->cGlobals.game.board, -2, inOut ) ) {
if ( board_zoom( globals->cGlobals.game.board, -1, inOut ) ) {
board_draw( globals->cGlobals.game.board );
setZoomButtons( globals, inOut );
}