From c91847f56f1f7ef1683e419988637b6ed64215ee Mon Sep 17 00:00:00 2001 From: ehouse Date: Thu, 9 Nov 2006 06:05:40 +0000 Subject: [PATCH] When moving focus through tray, skip empty space; when through board, skip cells with tiles permanently played. Space char raises focus but does not move it laterally. --- common/board.c | 13 +++++++------ common/board.h | 2 +- common/dbgutil.c | 2 +- common/tray.c | 26 ++++++++++++++++++-------- linux/cursesmain.c | 12 +++++++----- palm/palmmain.c | 8 +------- 6 files changed, 35 insertions(+), 28 deletions(-) diff --git a/common/board.c b/common/board.c index 4d9c14bed..5f041dcdf 100644 --- a/common/board.c +++ b/common/board.c @@ -2735,9 +2735,11 @@ board_handleKey( BoardCtxt* board, XP_Key key ) break; #ifdef KEYBOARD_NAV - case XP_FOCUSCHANGE_KEY: - if ( board->focussed != OBJ_NONE ) { - shiftFocusUp( board, XP_CURSOR_KEY_RIGHT ); + case XP_RAISEFOCUS_KEY: + if ( board->focussed != OBJ_NONE && board->focusHasDived ) { + invalFocusOwner( board ); + board->focusHasDived = XP_FALSE; + invalFocusOwner( board ); result = XP_TRUE; } break; @@ -2939,7 +2941,7 @@ advanceArrow( BoardCtxt* board ) static XP_Bool figureNextLoc( BoardCtxt* board, XP_Key cursorKey, XP_Bool canShiftFocus, - XP_Bool avoidOccupied, XP_U16* colP, XP_U16* rowP ) + XP_Bool inclPending, XP_U16* colP, XP_U16* rowP ) { XP_S16 max; XP_S16* useWhat; @@ -2997,8 +2999,7 @@ figureNextLoc( BoardCtxt* board, XP_Key cursorKey, XP_Bool canShiftFocus, } result = XP_TRUE; *useWhat += incr; - if ( !avoidOccupied - || !cellOccupied( board, *colP, *rowP, XP_TRUE ) ) { + if ( !cellOccupied( board, *colP, *rowP, inclPending ) ) { break; } } diff --git a/common/board.h b/common/board.h index 1a073abf6..164d63138 100644 --- a/common/board.h +++ b/common/board.h @@ -42,7 +42,7 @@ typedef enum { XP_CURSOR_KEY_UP, XP_CURSOR_KEY_LEFT, XP_CURSOR_KEY_DEL, - XP_FOCUSCHANGE_KEY, + XP_RAISEFOCUS_KEY, XP_RETURN_KEY, XP_KEY_LAST diff --git a/common/dbgutil.c b/common/dbgutil.c index 078f689ad..4008a2297 100644 --- a/common/dbgutil.c +++ b/common/dbgutil.c @@ -35,7 +35,7 @@ XP_Key_2str( XP_Key key ) CASESTR(XP_CURSOR_KEY_UP); CASESTR(XP_CURSOR_KEY_LEFT); CASESTR(XP_CURSOR_KEY_DEL); - CASESTR(XP_FOCUSCHANGE_KEY); + CASESTR(XP_RAISEFOCUS_KEY); CASESTR(XP_RETURN_KEY); CASESTR(XP_KEY_LAST ); default: return FUNC(__FUNCTION__) " unknown"; diff --git a/common/tray.c b/common/tray.c index 8478e0e6d..9d4fbe54a 100644 --- a/common/tray.c +++ b/common/tray.c @@ -1,6 +1,6 @@ /* -*-mode: C; fill-column: 78; c-basic-offset: 4; -*- */ /* - * Copyright 1997 - 2000 by Eric House (xwords@eehouse.org). All rights reserved. + * Copyright 1997 - 2006 by Eric House (xwords@eehouse.org). All rights reserved. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -628,14 +628,24 @@ tray_moveCursor( BoardCtxt* board, XP_Key cursorKey ) board_invalTrayTiles( board, 1 << board->trayCursorLoc[selPlayer] ); pos = board->trayCursorLoc[selPlayer]; - pos += cursorKey == XP_CURSOR_KEY_RIGHT ? 1 : -1; - if ( pos < 0 || pos >= MAX_TRAY_TILES ) { - shiftFocusUp( board, cursorKey ); - } else { - board->trayCursorLoc[selPlayer] = pos; - board_invalTrayTiles( board, 1 << pos ); + /* Loop in order to skip all empty tile slots but one */ + for ( ; ; ) { + pos += cursorKey == XP_CURSOR_KEY_RIGHT ? 1 : -1; + if ( pos < 0 || pos >= MAX_TRAY_TILES ) { + shiftFocusUp( board, cursorKey ); + } else { + if ( board->trayVisState == TRAY_REVEALED ) { + XP_U16 count = model_getNumTilesInTray( board->model, + selPlayer ); + if ( (pos > count) && (pos < MAX_TRAY_TILES-1) ) { + continue; + } + } + board->trayCursorLoc[selPlayer] = pos; + board_invalTrayTiles( board, 1 << pos ); + } + break; } - board_invalTrayTiles( board, 1 << board->trayCursorLoc[selPlayer] ); result = XP_TRUE; } diff --git a/linux/cursesmain.c b/linux/cursesmain.c index b538032d9..4749226a6 100644 --- a/linux/cursesmain.c +++ b/linux/cursesmain.c @@ -1,6 +1,7 @@ /* -*-mode: C; fill-column: 78; c-basic-offset: 4; compile-command: "make MEMDEBUG=TRUE"; -*- */ /* - * Copyright 2000 by Eric House (xwords@eehouse.org). All rights reserved. + * Copyright 2000-2006 by Eric House (xwords@eehouse.org). All rights + * reserved. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -357,14 +358,14 @@ checkAssignFocus( BoardCtxt* board ) } static XP_Bool -handleTab( CursesAppGlobals* globals ) +handleSpace( CursesAppGlobals* globals ) { checkAssignFocus( globals->cGlobals.game.board ); globals->doDraw = board_handleKey( globals->cGlobals.game.board, - XP_FOCUSCHANGE_KEY ); + XP_RAISEFOCUS_KEY ); return XP_TRUE; -} /* handleTab */ +} /* handleSpace */ static XP_Bool handleRet( CursesAppGlobals* globals ) @@ -453,7 +454,8 @@ handleReplace( CursesAppGlobals* globals ) MenuList sharedMenuList[] = { { handleQuit, "Quit", "Q", 'Q' }, - { handleTab, "Change focus", "", '\t' }, + { handleRight, "Tab right", "", '\t' }, + { handleSpace, "Raise focus", "", ' ' }, { handleRet, "Click/tap", "", '\r' }, { handleHint, "Hint", "?", '?' }, diff --git a/palm/palmmain.c b/palm/palmmain.c index 11d193e07..aa00675ff 100644 --- a/palm/palmmain.c +++ b/palm/palmmain.c @@ -2559,7 +2559,7 @@ mainViewHandleEvent( EventPtr event ) xpkey = XP_CURSOR_KEY_DOWN; break; case chrSpace: - xpkey = XP_FOCUSCHANGE_KEY; + xpkey = XP_RAISEFOCUS_KEY; break; #endif default: @@ -2578,12 +2578,6 @@ mainViewHandleEvent( EventPtr event ) } if ( xpkey != XP_KEY_NONE ) { draw = board_handleKey( globals->game.board, xpkey ); -#ifdef XWFEATURE_FIVEWAY - if ( xpkey == XP_FOCUSCHANGE_KEY ) { - checkSetFocus( globals, - board_getFocusOwner( globals->game.board ) ); - } -#endif } handled = draw; }