Finish scrollbar work by passing number of visible rows to

util_trayHiddenChange, which means an API change.  In board, calculate
bottom of board based on bottom of tray when tray is hidden, and round
so that it's an exact multiple of cell height.  In wince, take
advantage of the new parameter to fix the scrollbar so that very
constrained boards can be scrolled even when the tray is hidden.
This commit is contained in:
ehouse 2006-05-19 13:44:05 +00:00
parent f69d433b7c
commit 19414ae505
9 changed files with 56 additions and 44 deletions

View file

@ -1044,11 +1044,11 @@ board_draw( BoardCtxt* board )
board->focussed == OBJ_BOARD ) ) {
XP_Bool allDrawn = XP_TRUE;
XP_S16 lastCol, lastRow, i;
XP_S16 lastCol, i;
XP_U16 row;
ModelCtxt* model = board->model;
BlankQueue bq;
scrollIfCan( board ); /* this must happen before we count blanks
since it invalidates squares */
@ -1056,22 +1056,21 @@ board_draw( BoardCtxt* board )
board->trayVisState == TRAY_REVEALED, &bq );
invalBlanksWithNeighbors( board, &bq );
lastRow = model_numRows( model );
while ( lastRow-- ) {
XP_U16 rowFlags = board->redrawFlags[lastRow];
for ( row = board->yOffset; row < board->lastVisibleRow; ++row ) {
XP_U16 rowFlags = board->redrawFlags[row];
if ( rowFlags != 0 ) {
XP_U16 colMask;
XP_U16 failedBits = 0;
lastCol = model_numCols( model );
for ( colMask = 1<<(lastCol-1); lastCol--; colMask >>= 1 ) {
if ( (rowFlags & colMask) != 0 ) {
if ( !drawCell( board, lastCol, lastRow, XP_TRUE )) {
if ( !drawCell( board, lastCol, row, XP_TRUE )) {
failedBits |= colMask;
allDrawn = XP_FALSE;
}
}
}
board->redrawFlags[lastRow] = failedBits;
board->redrawFlags[row] = failedBits;
}
}
@ -1455,6 +1454,7 @@ setTrayVisState( BoardCtxt* board, XW_TrayVisState newState )
if ( changed ) {
XP_Bool nowHidden = newState == TRAY_HIDDEN;
XP_U16 selPlayer = board->selPlayer;
XP_U16 nVisible;
/* redraw cells that are pending; whether tile is visible may
change */
@ -1495,7 +1495,8 @@ setTrayVisState( BoardCtxt* board, XW_TrayVisState newState )
invalCurHintRect( board, selPlayer, XP_FALSE );
#endif
util_trayHiddenChange( board->util, board->trayVisState );
nVisible = board->lastVisibleRow - board->yOffset;
util_trayHiddenChange( board->util, board->trayVisState, nVisible );
}
return changed;
} /* setTrayVisState */
@ -1686,7 +1687,6 @@ drawCell( BoardCtxt* board, XP_U16 col, XP_U16 row, XP_Bool skipBlanks )
XP_Bool showPending = board->trayVisState == TRAY_REVEALED
&& curCount > 0;
if ( dict != NULL && getCellRect( board, col, row, &cellRect ) ) {
/* This 'while' is only here so I can 'break' below */
@ -1741,22 +1741,30 @@ drawCell( BoardCtxt* board, XP_U16 col, XP_U16 row, XP_Bool skipBlanks )
static void
figureBoardRect( BoardCtxt* board )
{
XP_Rect boardBounds = board->boardBounds;
XP_U16 boardVScale = board->boardVScale;
if ( boardVScale > 0 ) {
XP_Rect boardBounds = board->boardBounds;
XP_U16 nVisible;
boardBounds.width = model_numCols( board->model ) * board->boardHScale;
boardBounds.height = (model_numRows( board->model ) - board->yOffset)
* board->boardVScale;
boardBounds.width = model_numCols( board->model ) * board->boardHScale;
boardBounds.height = (model_numRows( board->model ) - board->yOffset)
* board->boardVScale;
if ( board->trayVisState != TRAY_HIDDEN && board->boardObscuresTray ) {
boardBounds.height = board->trayBounds.top - boardBounds.top - 1;
} else {
XP_U16 trayBottom = board->trayBounds.top + board->trayBounds.height;
if ( trayBottom < boardBounds.top + boardBounds.height ) {
boardBounds.height = trayBottom - boardBounds.top;
if ( board->trayVisState != TRAY_HIDDEN && board->boardObscuresTray ) {
boardBounds.height = board->trayBounds.top - boardBounds.top;
} else {
XP_U16 trayBottom = board->trayBounds.top + board->trayBounds.height;
if ( trayBottom < boardBounds.top + boardBounds.height ) {
boardBounds.height = trayBottom - boardBounds.top;
}
}
}
/* round down */
nVisible = boardBounds.height / boardVScale;
boardBounds.height = nVisible * boardVScale;
board->lastVisibleRow = nVisible + board->yOffset;
board->boardBounds = boardBounds;
board->boardBounds = boardBounds;
}
} /* figureBoardRect */
static XP_Bool

View file

@ -82,6 +82,7 @@ struct BoardCtxt {
XP_U16 boardHScale;
XP_U16 boardVScale;
XP_U16 yOffset;
XP_U16 lastVisibleRow;
XP_U16 preHideYOffset;
XP_U16 prevYScrollOffset; /* represents where the last draw took place;
used to see if bit scrolling can be used */

View file

@ -117,7 +117,8 @@ typedef struct UtilVtable {
XP_UCHAR* buf, XP_U16* len );
void (*m_util_trayHiddenChange)(XW_UtilCtxt* uc,
XW_TrayVisState newState );
XW_TrayVisState newState,
XP_U16 nVisibleRows );
void (*m_util_yOffsetChange)(XW_UtilCtxt* uc, XP_U16 oldOffset,
XP_U16 newOffset );
@ -186,8 +187,8 @@ struct XW_UtilCtxt {
#define util_askPassword( uc, n, b, lp ) \
(uc)->vtable->m_util_askPassword( (uc), (n), (b), (lp) )
#define util_trayHiddenChange( uc, b ) \
(uc)->vtable->m_util_trayHiddenChange((uc), (b))
#define util_trayHiddenChange( uc, b, n ) \
(uc)->vtable->m_util_trayHiddenChange((uc), (b), (n))
#define util_yOffsetChange( uc, o, n ) \
(uc)->vtable->m_util_yOffsetChange((uc), (o), (n) )

View file

@ -160,7 +160,8 @@ curses_util_userQuery( XW_UtilCtxt* uc, UtilQueryID id, XWStreamCtxt* stream )
} /* curses_util_userQuery */
static void
curses_util_trayHiddenChange( XW_UtilCtxt* uc, XW_TrayVisState state )
curses_util_trayHiddenChange( XW_UtilCtxt* uc, XW_TrayVisState state,
XP_U16 nVisibleRows )
{
/* nothing to do if we don't have a scrollbar */
} /* curses_util_trayHiddenChange */
@ -695,7 +696,7 @@ blocking_gotEvent( CursesAppGlobals* globals, int* ch )
if ( numEvents > 0 &&
(globals->fdArray[fdIndex].revents & POLLIN) != 0 ) {
int nBytes;
XP_U8 buf[256];
XP_UCHAR buf[256];
struct sockaddr_in addr_sock;
--numEvents;

View file

@ -1,4 +1,4 @@
/* -*-mode: C; fill-column: 78; c-basic-offset: 4; -*- */
/* -*-mode: C; fill-column: 78; c-basic-offset: 4; compile-command: "make MEMDEBUG=TRUE"; -*- */
/*
* Copyright 2000-2003 by Eric House (xwords@eehouse.org). All rights reserved.
*
@ -334,7 +334,7 @@ configure_event( GtkWidget* widget, GdkEventConfigure* event,
boardTop += HOR_SCORE_HEIGHT;
}
trayTop = boardTop + (vscale * NUM_ROWS) + BOTTOM_MARGIN + 1;
trayTop = boardTop + (vscale * NUM_ROWS);
/* move tray up if part of board's meant to be hidden */
trayTop -= vscale * globals->cGlobals.params->nHidden;
board_setPos( globals->cGlobals.game.board, BOARD_LEFT, boardTop,
@ -964,7 +964,8 @@ setCtrlsForTray( GtkAppGlobals* globals )
} /* setCtrlsForTray */
static void
gtk_util_trayHiddenChange( XW_UtilCtxt* uc, XW_TrayVisState state )
gtk_util_trayHiddenChange( XW_UtilCtxt* uc, XW_TrayVisState state,
XP_U16 nVisibleRows )
{
GtkAppGlobals* globals = (GtkAppGlobals*)uc->closure;
setCtrlsForTray( globals );
@ -1598,11 +1599,6 @@ gtkmain( XP_Bool isServer, LaunchParams* params, int argc, char *argv[] )
globals.drawing_area = drawing_area;
gtk_widget_show( drawing_area );
#if 0
width = (MAX_COLS * MIN_SCALE) + LEFT_MARGIN + RIGHT_MARGIN;
height = (MAX_ROWS * MIN_SCALE) + TOP_MARGIN + BOTTOM_MARGIN
+ MIN_TRAY_SCALE + BOTTOM_MARGIN;
#else
width = HOR_SCORE_WIDTH + TIMER_WIDTH + TIMER_PAD;
if ( globals.cGlobals.params->verticalScore ) {
width += VERT_SCORE_WIDTH;
@ -1611,7 +1607,7 @@ gtkmain( XP_Bool isServer, LaunchParams* params, int argc, char *argv[] )
if ( globals.cGlobals.params->nHidden == 0 ) {
height += MIN_SCALE * TRAY_HT_ROWS;
}
#endif
gtk_widget_set_size_request( GTK_WIDGET(drawing_area), width, height );
hbox = gtk_hbox_new( FALSE, 0 );

View file

@ -350,7 +350,7 @@ linux_close_socket( CommonGlobals* cGlobals )
}
int
linux_receive( CommonGlobals* cGlobals, unsigned char* buf, int bufSize )
linux_receive( CommonGlobals* cGlobals, XP_UCHAR* buf, int bufSize )
{
int sock = cGlobals->socket;
unsigned short tmp;

View file

@ -40,7 +40,7 @@ int initListenerSocket( int port );
XP_S16 linux_tcp_send( XP_U8* buf, XP_U16 buflen, const CommsAddrRec* addrRec,
void* closure );
int linux_init_socket( CommonGlobals* cGlobals );
int linux_receive( CommonGlobals* cGlobals, unsigned char* buf, int bufSize );
int linux_receive( CommonGlobals* cGlobals, XP_UCHAR* buf, int bufSize );
void linuxFireTimer( CommonGlobals* cGlobals, XWTimerReason why );

View file

@ -133,7 +133,8 @@ static XP_S16 palm_util_userPickTile( XW_UtilCtxt* uc, const PickInfo* pi,
static XP_Bool palm_util_askPassword( XW_UtilCtxt* uc, const XP_UCHAR* name,
XP_UCHAR* buf, XP_U16* len );
static void palm_util_trayHiddenChange( XW_UtilCtxt* uc,
XW_TrayVisState newState );
XW_TrayVisState newState,
XP_U16 nVisibleRows );
static void palm_util_yOffsetChange( XW_UtilCtxt* uc, XP_U16 oldOffset,
XP_U16 newOffset );
static void palm_util_notifyGameOver( XW_UtilCtxt* uc );
@ -3289,7 +3290,8 @@ palm_util_askPassword( XW_UtilCtxt* uc, const XP_UCHAR* name, XP_UCHAR* buf,
} /* palm_util_askPassword */
static void
palm_util_trayHiddenChange( XW_UtilCtxt* uc, XW_TrayVisState newState )
palm_util_trayHiddenChange( XW_UtilCtxt* uc, XW_TrayVisState newState,
XP_U16 nVisibleRows )
{
PalmAppGlobals* globals = (PalmAppGlobals*)uc->closure;
palmSetCtrlsForTray( globals );

View file

@ -103,7 +103,8 @@ static XP_S16 ce_util_userPickTile( XW_UtilCtxt* uc, const PickInfo* pi,
static XP_Bool ce_util_askPassword( XW_UtilCtxt* uc, const XP_UCHAR* name,
XP_UCHAR* buf, XP_U16* len );
static void ce_util_trayHiddenChange( XW_UtilCtxt* uc,
XW_TrayVisState newState );
XW_TrayVisState newState,
XP_U16 nVisibleRows );
static void ce_util_yOffsetChange( XW_UtilCtxt* uc, XP_U16 oldOffset,
XP_U16 newOffset );
static void ce_util_notifyGameOver( XW_UtilCtxt* uc );
@ -455,7 +456,6 @@ hideScroller( CEAppGlobals* globals )
# define MIN_TRAY_HEIGHT 40
# define CE_MIN_SCORE_WIDTH 36
#endif
#define TRAY_PADDING 1
typedef struct CEBoardParms {
XP_U16 boardHScale;
@ -565,7 +565,7 @@ figureBoardParms( CEAppGlobals* globals, XP_U16 nRows, CEBoardParms* bparms )
}
trayWidth = boardWidth + scrollWidth;
trayTop = boardHt + scoreHeight + TRAY_PADDING;
trayTop = boardHt + scoreHeight;
trayVScale = scrnHeight - trayTop;
if ( !horiz ) {
@ -2516,15 +2516,18 @@ ce_util_askPassword( XW_UtilCtxt* uc, const XP_UCHAR* name,
} /* ce_util_askPassword */
static void
ce_util_trayHiddenChange( XW_UtilCtxt* uc, XW_TrayVisState newState )
ce_util_trayHiddenChange( XW_UtilCtxt* uc, XW_TrayVisState newState,
XP_U16 nVisibleRows )
{
CEAppGlobals* globals = (CEAppGlobals*)uc->closure;
#ifdef CEFEATURE_CANSCROLL
/* If there's a scrollbar, hide/show it. It wants to be
active/visible only when the tray is NOT hidden */
if ( !!globals->scrollHandle ) {
EnableWindow( globals->scrollHandle, TRAY_HIDDEN != newState );
updateScrollInfo( globals->scrollHandle,
model_numRows( globals->game.model ) - nVisibleRows );
}
#endif