From 628f8d9cf3ece1a2a25b23f44aed3032cfdc3072 Mon Sep 17 00:00:00 2001 From: eehouse Date: Thu, 3 Jun 2010 04:57:11 +0000 Subject: [PATCH] don't zoom in if doing so will make cells larger than the limit passed in. --- xwords4/common/board.c | 16 +++++++++++++--- xwords4/common/boardp.h | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/xwords4/common/board.c b/xwords4/common/board.c index 95d4a024a..2fb6a5e0d 100644 --- a/xwords4/common/board.c +++ b/xwords4/common/board.c @@ -360,7 +360,7 @@ board_reset( BoardCtxt* board ) void board_setPos( BoardCtxt* board, XP_U16 left, XP_U16 top, - XP_U16 width, XP_U16 height, XP_U16 maxWidth, + XP_U16 width, XP_U16 height, XP_U16 maxCellSz, XP_Bool leftHanded ) { XP_LOGF( "%s(%d,%d,%d,%d)", __func__, left, top, width, height ); @@ -369,7 +369,7 @@ board_setPos( BoardCtxt* board, XP_U16 left, XP_U16 top, board->boardBounds.top = top; board->boardBounds.width = width; board->heightAsSet = height; - board->maxWidth = maxWidth; + board->maxCellSz = maxCellSz; board->leftHanded = leftHanded; figureBoardRect( board ); @@ -556,6 +556,16 @@ board_zoom( BoardCtxt* board, XP_S16 zoomBy, XP_Bool* canIn, XP_Bool* canOut ) } changed = zoomCount != board->zoomCount; + + /* If we're zooming in, make sure we'll stay inside the limit */ + if ( changed && zoomBy > 0 ) { + XP_U16 nVisCols = model_numCols( board->model ) - zoomCount; + XP_U16 scale = board->boardBounds.width / nVisCols; + if ( scale > board->maxCellSz ) { + changed = XP_FALSE; + } + } + if ( changed ) { /* Try to distribute the zoom */ hsd->offset = adjustOffset( hsd->offset, zoomBy ); @@ -567,7 +577,7 @@ board_zoom( BoardCtxt* board, XP_S16 zoomBy, XP_Bool* canIn, XP_Bool* canOut ) } if ( !!canIn ) { - *canIn = maxCount > zoomCount && hsd->scale < board->maxWidth; + *canIn = maxCount > zoomCount && hsd->scale < board->maxCellSz; } if ( !!canOut ) { *canOut = zoomCount > 0; diff --git a/xwords4/common/boardp.h b/xwords4/common/boardp.h index 4476333b7..b8163ea32 100644 --- a/xwords4/common/boardp.h +++ b/xwords4/common/boardp.h @@ -151,7 +151,7 @@ struct BoardCtxt { XP_Rect boardBounds; XP_U16 heightAsSet; - XP_U16 maxWidth; + XP_U16 maxCellSz; BoardObjectType penDownObject;