From 42ad517e5296ff8b095c467f8d982c910f4f992f Mon Sep 17 00:00:00 2001 From: ehouse Date: Sat, 27 Sep 2008 15:07:48 +0000 Subject: [PATCH] When moving cursor within board, scroll board if it's possible to do so, and only if it is not move the cursor (or if needed to keep it visible after scroll.) This makes it easier for users to scroll -- but may not be needed if focussing scrolbar works. --- common/board.c | 65 ++++++++++++++++++++++++++++++++++++++----------- common/boardp.h | 2 +- 2 files changed, 52 insertions(+), 15 deletions(-) diff --git a/common/board.c b/common/board.c index 1f9513b95..7ab0f2692 100644 --- a/common/board.c +++ b/common/board.c @@ -1965,7 +1965,8 @@ moveSelTileToBoardXY( BoardCtxt* board, XP_U16 col, XP_U16 row ) } /* moveSelTileToBoardXY */ XP_Bool -cellOccupied( BoardCtxt* board, XP_U16 col, XP_U16 row, XP_Bool inclPending ) +cellOccupied( const BoardCtxt* board, XP_U16 col, XP_U16 row, + XP_Bool inclPending ) { Tile tile; XP_Bool ignr; @@ -2487,7 +2488,7 @@ advanceArrow( BoardCtxt* board ) } /* advanceArrow */ static XP_Bool -figureNextLoc( BoardCtxt* board, XP_Key cursorKey, +figureNextLoc( const BoardCtxt* board, XP_Key cursorKey, XP_Bool inclPending, XP_Bool forceFirst, XP_U16* colP, XP_U16* rowP, XP_Bool* XP_UNUSED_KEYBOARD_NAV(pUp) ) @@ -2597,28 +2598,64 @@ stripAlt( XP_Key key, XP_Bool* wasAlt ) return key; } /* stripAlt */ +static XP_Bool +scrollTrumpsMove( const BoardCtxt* board, XP_Key cursorKey, XP_S16* moveBy ) +{ + XP_Bool scroll = XP_FALSE; + if ( XP_CURSOR_KEY_DOWN == cursorKey ) { + scroll = (board->lastVisibleRow+1) < model_numRows( board->model ); + if ( scroll ) { + *moveBy = -1; + } + } else if ( XP_CURSOR_KEY_UP == cursorKey ) { + scroll = board->yOffset > 0; + if ( scroll ) { + *moveBy = 1; + } + } + return scroll; +} + static XP_Bool board_moveCursor( BoardCtxt* board, XP_Key cursorKey, XP_Bool preflightOnly, XP_Bool* up ) { PerTurnInfo* pti = board->selInfo; - BdCursorLoc loc = pti->bdCursor; - XP_U16 col = loc.col; - XP_U16 row = loc.row; + BdCursorLoc loc; + XP_S16 moveBy; XP_Bool changed; + XP_Bool needMove = XP_FALSE; XP_Bool altSet; cursorKey = stripAlt( cursorKey, &altSet ); - changed = figureNextLoc( board, cursorKey, XP_FALSE, altSet, - &col, &row, up ); - if ( changed && !preflightOnly ) { - invalCell( board, loc.col, loc.row ); - invalCell( board, col, row ); - loc.col = col; - loc.row = row; - pti->bdCursor = loc; - checkScrollCell( board, col, row ); + changed = !preflightOnly + && scrollTrumpsMove( board, cursorKey, &moveBy ); + if ( changed ) { + if ( adjustYOffset( board, moveBy ) ) { + /* need to move the cursor too? */ + XP_Rect ignore; + loc = pti->bdCursor; + needMove = !getCellRect( board, loc.col, loc.row, &ignore ); + } + } + + /* PENDING: Is it a problem that needMove will only get set if + preflightOnly is false? */ + if ( !changed || needMove ) { + XP_U16 col, row; + loc = pti->bdCursor; + col = loc.col; + row = loc.row; + changed = figureNextLoc( board, cursorKey, XP_FALSE, altSet, + &col, &row, up ); + if ( changed && !preflightOnly ) { + invalCell( board, loc.col, loc.row ); + invalCell( board, col, row ); + loc.col = col; + loc.row = row; + pti->bdCursor = loc; + } } return changed; } /* board_moveCursor */ diff --git a/common/boardp.h b/common/boardp.h index b0b07e1ce..68aba1573 100644 --- a/common/boardp.h +++ b/common/boardp.h @@ -230,7 +230,7 @@ XP_Bool pointOnSomething( BoardCtxt* board, XP_U16 x, XP_U16 y, BoardObjectType* wp ); XP_Bool coordToCell( BoardCtxt* board, XP_U16 x, XP_U16 y, XP_U16* colP, XP_U16* rowP ); -XP_Bool cellOccupied( BoardCtxt* board, XP_U16 col, XP_U16 row, +XP_Bool cellOccupied( const BoardCtxt* board, XP_U16 col, XP_U16 row, XP_Bool inclPending ); XP_Bool holdsPendingTile( BoardCtxt* board, XP_U16 pencol, XP_U16 penrow );