hide focus when pen used, but remember where it was (don't set to

OBJ_NONE) so can replace it when focus keys used again.
This commit is contained in:
ehouse 2008-11-22 16:37:29 +00:00
parent 46b574b4e7
commit 542e441b69
5 changed files with 55 additions and 35 deletions

View file

@ -167,9 +167,9 @@ board_make( MPFORMAL ModelCtxt* model, ServerCtxt* server, DrawCtx* draw,
#ifdef KEYBOARD_NAV #ifdef KEYBOARD_NAV
{ {
/* set up some useful initial values */ /* set up some useful initial values */
XP_U16 i; XP_U16 ii;
for ( i = 0; i < MAX_NUM_PLAYERS; ++i ) { for ( ii = 0; ii < MAX_NUM_PLAYERS; ++ii ) {
PerTurnInfo* pti = result->pti + i; PerTurnInfo* pti = result->pti + ii;
pti->trayCursorLoc = 1; pti->trayCursorLoc = 1;
pti->bdCursor.col = 5; pti->bdCursor.col = 5;
pti->bdCursor.row = 7; pti->bdCursor.row = 7;
@ -1266,17 +1266,11 @@ setTrayVisState( BoardCtxt* board, XW_TrayVisState newState )
board->trayVisState = newState; board->trayVisState = newState;
invalSelTradeWindow( board ); invalSelTradeWindow( board );
invalFocusOwner( board ); /* must be done before and after rect (void)invalFocusOwner( board ); /* must be done before and after rect
recalculated */ recalculated */
figureBoardRect( board ); /* comes before setYOffset since that figureBoardRect( board ); /* comes before setYOffset since that
uses rects to calc scroll */ uses rects to calc scroll */
(void)invalFocusOwner( board );
/* This is sometimes the wrong thing to do, and seems not to be
needed at all. */
/* if ( (board->focussed == OBJ_TRAY) && board->focusHasDived ) { */
/* board->focusHasDived = XP_FALSE; */
/* } */
invalFocusOwner( board );
if ( board->boardObscuresTray ) { if ( board->boardObscuresTray ) {
if ( nowHidden && !trayOnTop(board) ) { if ( nowHidden && !trayOnTop(board) ) {
@ -1921,8 +1915,7 @@ board_handlePenDown( BoardCtxt* board, XP_U16 x, XP_U16 y, XP_Bool* handled )
#ifdef KEYBOARD_NAV #ifdef KEYBOARD_NAV
/* clear focus as soon as pen touches board */ /* clear focus as soon as pen touches board */
result = invalFocusOwner( board ); result = invalFocusOwner( board );
board->focussed = OBJ_NONE; board->hideFocus = XP_TRUE;
board->focusHasDived = XP_FALSE;
if ( board->boardObscuresTray ) { if ( board->boardObscuresTray ) {
figureBoardRect( board ); figureBoardRect( board );
} }
@ -2241,9 +2234,9 @@ handleFocusKeyUp( BoardCtxt* board, XP_Key key, XP_Bool preflightOnly,
} }
if ( up ) { if ( up ) {
if ( !preflightOnly ) { if ( !preflightOnly ) {
invalFocusOwner( board ); (void)invalFocusOwner( board );
board->focusHasDived = XP_FALSE; board->focusHasDived = XP_FALSE;
invalFocusOwner( board ); (void)invalFocusOwner( board );
} }
} else { } else {
*pHandled = redraw; *pHandled = redraw;
@ -2271,6 +2264,17 @@ board_handleKeyRepeat( BoardCtxt* board, XP_Key key, XP_Bool* handled )
} }
return draw; return draw;
} }
static XP_Bool
unhideFocus( BoardCtxt* board )
{
XP_Bool changing = board->hideFocus;
if ( changing ) {
board->hideFocus = XP_FALSE;
(void)invalFocusOwner( board );
}
return changing;
}
#endif /* KEYBOARD_NAV */ #endif /* KEYBOARD_NAV */
#ifdef KEY_SUPPORT #ifdef KEY_SUPPORT
@ -2318,7 +2322,12 @@ board_handleKeyUp( BoardCtxt* board, XP_Key key, XP_Bool* pHandled )
case XP_CURSOR_KEY_ALTLEFT: case XP_CURSOR_KEY_ALTLEFT:
case XP_CURSOR_KEY_RIGHT: case XP_CURSOR_KEY_RIGHT:
case XP_CURSOR_KEY_ALTRIGHT: case XP_CURSOR_KEY_ALTRIGHT:
redraw = handleFocusKeyUp( board, key, XP_FALSE, &handled ); /* If focus is hidden, all we do is show it */
if ( unhideFocus( board ) ) {
redraw = handled = XP_TRUE;
} else {
redraw = handleFocusKeyUp( board, key, XP_FALSE, &handled );
}
break; break;
#endif #endif
@ -2330,26 +2339,34 @@ board_handleKeyUp( BoardCtxt* board, XP_Key key, XP_Bool* pHandled )
#ifdef KEYBOARD_NAV #ifdef KEYBOARD_NAV
case XP_RAISEFOCUS_KEY: case XP_RAISEFOCUS_KEY:
if ( board->focussed != OBJ_NONE && board->focusHasDived ) { if ( unhideFocus( board ) ) {
invalFocusOwner( board ); /* do nothing */
} else if ( board->focussed != OBJ_NONE && board->focusHasDived ) {
(void)invalFocusOwner( board );
board->focusHasDived = XP_FALSE; board->focusHasDived = XP_FALSE;
invalFocusOwner( board ); (void)invalFocusOwner( board );
handled = redraw = XP_TRUE; } else {
break; /* skip setting handled */
} }
handled = redraw = XP_TRUE;
break; break;
case XP_RETURN_KEY: case XP_RETURN_KEY:
if ( board->focusHasDived ) { if ( unhideFocus( board ) ) {
XP_U16 x, y; handled = XP_TRUE;
if ( focusToCoords( board, &x, &y ) ) { } else if ( board->focussed != OBJ_NONE ) {
redraw = handlePenUpInternal( board, x, y, XP_FALSE ); if ( board->focusHasDived ) {
XP_U16 xx, yy;
if ( focusToCoords( board, &xx, &yy ) ) {
redraw = handlePenUpInternal( board, xx, yy, XP_FALSE );
handled = XP_TRUE;
}
} else {
(void)invalFocusOwner( board );
board->focusHasDived = XP_TRUE;
redraw = invalFocusOwner( board );
handled = XP_TRUE; handled = XP_TRUE;
} }
} else if ( board->focussed != OBJ_NONE ) {
redraw = invalFocusOwner( board );
board->focusHasDived = XP_TRUE;
redraw = invalFocusOwner( board );
handled = XP_TRUE;
} }
break; break;
#endif #endif

View file

@ -420,7 +420,7 @@ DrawFocusState
dfsFor( BoardCtxt* board, BoardObjectType obj ) dfsFor( BoardCtxt* board, BoardObjectType obj )
{ {
DrawFocusState dfs; DrawFocusState dfs;
if ( board->focussed == obj ) { if ( (board->focussed == obj) && !board->hideFocus ) {
if ( board->focusHasDived ) { if ( board->focusHasDived ) {
dfs = DFS_DIVED; dfs = DFS_DIVED;
} else { } else {
@ -437,7 +437,7 @@ cellFocused( const BoardCtxt* board, XP_U16 col, XP_U16 row )
{ {
XP_Bool focussed = XP_FALSE; XP_Bool focussed = XP_FALSE;
if ( board->focussed == OBJ_BOARD ) { if ( (board->focussed == OBJ_BOARD) && !board->hideFocus ) {
if ( board->focusHasDived ) { if ( board->focusHasDived ) {
if ( (col == board->selInfo->bdCursor.col) if ( (col == board->selInfo->bdCursor.col)
&& (row == board->selInfo->bdCursor.row) ) { && (row == board->selInfo->bdCursor.row) ) {
@ -501,7 +501,9 @@ scrollIfCan( BoardCtxt* board )
XP_S16 dist; XP_S16 dist;
#ifdef PERIMETER_FOCUS #ifdef PERIMETER_FOCUS
if ( (board->focussed == OBJ_BOARD) && !board->focusHasDived ) { if ( (board->focussed == OBJ_BOARD)
&& !board->focusHasDived
&& !board->hideFocus ) {
invalOldPerimeter( board ); invalOldPerimeter( board );
} }
#endif #endif

View file

@ -169,6 +169,7 @@ struct BoardCtxt {
#ifdef KEYBOARD_NAV #ifdef KEYBOARD_NAV
XP_Bool focusHasDived; XP_Bool focusHasDived;
XP_Bool hideFocus; /* not saved */
XP_Rect remRect; /* on scoreboard */ XP_Rect remRect; /* on scoreboard */
#endif #endif

View file

@ -71,7 +71,7 @@ drawScoreBoard( BoardCtxt* board )
XP_Bool remFocussed = XP_FALSE; XP_Bool remFocussed = XP_FALSE;
XP_S16 cursorIndex = -1; XP_S16 cursorIndex = -1;
if ( board->focussed == OBJ_SCORE ) { if ( (board->focussed == OBJ_SCORE) && !board->hideFocus ) {
focusAll = !board->focusHasDived; focusAll = !board->focusHasDived;
if ( !focusAll ) { if ( !focusAll ) {
cursorIndex = board->scoreCursorLoc; cursorIndex = board->scoreCursorLoc;

View file

@ -136,7 +136,7 @@ drawTray( BoardCtxt* board )
XP_Bool cursorOnDivider = XP_FALSE; XP_Bool cursorOnDivider = XP_FALSE;
#ifdef KEYBOARD_NAV #ifdef KEYBOARD_NAV
XP_S16 cursorTile = pti->trayCursorLoc; XP_S16 cursorTile = pti->trayCursorLoc;
if ( board->focussed == OBJ_TRAY ) { if ( (board->focussed == OBJ_TRAY) && !board->hideFocus ) {
cursorOnDivider = pti->dividerLoc == cursorTile; cursorOnDivider = pti->dividerLoc == cursorTile;
if ( board->focusHasDived ) { if ( board->focusHasDived ) {
if ( !cursorOnDivider ) { if ( !cursorOnDivider ) {