fix bug where current player's scoreboard would disappear if other

players' names were too long by giving all a the same proportion of
what they request and passing in the percent given in case draw
implementation wants to use it as a cue to truncate.
This commit is contained in:
Eric House 2012-06-15 06:26:40 -07:00
parent 3d9478744a
commit 405cb23023
7 changed files with 59 additions and 72 deletions

View file

@ -185,20 +185,20 @@ and_draw_drawRemText( DrawCtx* dctx, const XP_Rect* rInner,
}
static void
and_draw_score_drawPlayer( DrawCtx* dctx,
const XP_Rect* rInner,
const XP_Rect* rOuter,
and_draw_score_drawPlayer( DrawCtx* dctx, const XP_Rect* rInner,
const XP_Rect* rOuter, XP_U16 gotPct,
const DrawScoreInfo* dsi )
{
DRAW_CBK_HEADER("score_drawPlayer",
"(Landroid/graphics/Rect;Landroid/graphics/Rect;"
"(Landroid/graphics/Rect;Landroid/graphics/Rect;I"
"L" PKG_PATH("jni/DrawScoreInfo") ";)V" );
jobject jrinner = makeJRect( draw, JCACHE_RECT0, rInner );
jobject jrouter = makeJRect( draw, JCACHE_RECT1, rOuter );
jobject jdsi = makeDSI( draw, JCACHE_DSI, dsi );
(*env)->CallVoidMethod( env, draw->jdraw, mid, jrinner, jrouter, jdsi );
(*env)->CallVoidMethod( env, draw->jdraw, mid, jrinner, jrouter, gotPct,
jdsi );
} /* and_draw_score_drawPlayer */
static void

View file

@ -494,7 +494,8 @@ public class BoardView extends View implements DrawCtx, BoardHandler,
height[0] = r.height();
}
public void score_drawPlayer( Rect rInner, Rect rOuter, DrawScoreInfo dsi )
public void score_drawPlayer( Rect rInner, Rect rOuter,
int gotPct, DrawScoreInfo dsi )
{
if ( 0 != (dsi.flags & CELL_ISCURSOR) ) {
fillRectOther( rOuter, CommonPrefs.COLOR_FOCUS );
@ -506,12 +507,11 @@ public class BoardView extends View implements DrawCtx, BoardHandler,
}
m_fillPaint.setColor( color );
Rect rect = new Rect( rOuter );
int height = rect.height() / texts.length;
rect.bottom = rect.top + height;
int height = rOuter.height() / texts.length;
rOuter.bottom = rOuter.top + height;
for ( String text : texts ) {
drawCentered( text, rect, null );
rect.offset( 0, height );
drawCentered( text, rOuter, null );
rOuter.offset( 0, height );
}
}

View file

@ -47,7 +47,8 @@ public interface DrawCtx {
void measureRemText( Rect r, int nTilesLeft, int[] width, int[] height );
void measureScoreText( Rect r, DrawScoreInfo dsi, int[] width, int[] height );
void drawRemText( Rect rInner, Rect rOuter, int nTilesLeft, boolean focussed );
void score_drawPlayer( Rect rInner, Rect rOuter, DrawScoreInfo dsi );
void score_drawPlayer( Rect rInner, Rect rOuter, int gotPct,
DrawScoreInfo dsi );
void drawTimer( Rect rect, int player, int secondsLeft );
boolean boardBegin( Rect rect, int cellWidth, int cellHeight );

View file

@ -149,6 +149,7 @@ typedef struct DrawCtxVTable {
void DRAW_VTABLE_NAME(score_drawPlayer) ( DrawCtx* dctx,
const XP_Rect* rInner,
const XP_Rect* rOuter,
XP_U16 gotPct,
const DrawScoreInfo* dsi );
void DRAW_VTABLE_NAME(score_pendingScore) ( DrawCtx* dctx,
@ -276,8 +277,8 @@ struct DrawCtx {
CALL_DRAW_NAME4(drawRemText, (dc), (ri), (ro), (n), (f) )
#define draw_measureScoreText(dc,r,dsi,wp,hp) \
CALL_DRAW_NAME4(measureScoreText,(dc),(r),(dsi),(wp),(hp))
#define draw_score_drawPlayer(dc, ri, ro, dsi) \
CALL_DRAW_NAME3(score_drawPlayer,(dc),(ri),(ro),(dsi))
#define draw_score_drawPlayer(dc, ri, ro, gp, dsi) \
CALL_DRAW_NAME4(score_drawPlayer,(dc),(ri),(ro),(gp),(dsi))
#define draw_score_pendingScore(dc, r, s, p, f ) \
CALL_DRAW_NAME4(score_pendingScore,(dc), (r), (s), (p), (f))
#define draw_drawTimer( dc, r, plyr, sec ) \

View file

@ -70,13 +70,11 @@ drawScoreBoard( BoardCtxt* board )
XP_Rect scoreRect = board->scoreBdBounds;
XP_S16* adjustDim;
XP_S16* adjustPt;
XP_U16 totalDim; /* don't really need this */
XP_U16 extra, remWidth, remHeight, remDim;
XP_U16 remWidth, remHeight, remDim;
DrawScoreData* dp;
DrawScoreData datum[MAX_NUM_PLAYERS];
ScoresArray scores;
XP_Bool isVertical = !board->scoreSplitHor;
XP_Bool skipCurTurn; /* skip the guy whose turn it is this pass? */
XP_Bool remFocussed = XP_FALSE;
XP_Bool focusAll = XP_FALSE;
#ifdef KEYBOARD_NAV
@ -106,6 +104,8 @@ drawScoreBoard( BoardCtxt* board )
if ( draw_scoreBegin( board->draw, &board->scoreBdBounds, nPlayers,
scores.arr, nTilesInPool,
dfsFor( board, OBJ_SCORE ) ) ) {
XP_U16 totalDim = 0; /* not counting rem */
XP_U16 gotPct;
/* Let platform decide whether the rem: string should be given
any space once there are no tiles left. On Palm that space
@ -125,8 +125,6 @@ drawScoreBoard( BoardCtxt* board )
}
*adjustDim -= remDim;
totalDim = remDim;
/* Give as much room as possible to the entry for the player
whose turn it is so name can be drawn. Do that by
formatting that player's score last, and passing each time
@ -136,16 +134,9 @@ drawScoreBoard( BoardCtxt* board )
/* figure spacing for each scoreboard entry */
XP_MEMSET( &datum, 0, sizeof(datum) );
for ( skipCurTurn = XP_TRUE; ; skipCurTurn = XP_FALSE ) {
totalDim = 0;
for ( dp = datum, ii = 0; ii < nPlayers; ++ii, ++dp ) {
LocalPlayer* lp;
XP_U16 dim;
if ( skipCurTurn == (ii == curTurn) ) {
continue;
}
lp = &board->gi->players[ii];
LocalPlayer* lp = &board->gi->players[ii];
/* This is a hack! */
dp->dsi.lsc = board_ScoreCallback;
@ -172,28 +163,20 @@ drawScoreBoard( BoardCtxt* board )
XP_ASSERT( dp->width <= scoreRect.width );
XP_ASSERT( dp->height <= scoreRect.height );
dim = isVertical ? dp->height : dp->width;
totalDim += dim;
*adjustDim -= dim;
totalDim += isVertical ? dp->height : dp->width;
}
if ( !skipCurTurn ) { /* exit 2nd time through */
break;
gotPct = (*adjustDim * 100) / totalDim;
for ( dp = datum, ii = 0; ii < nPlayers; ++ii, ++dp ) {
if ( isVertical ) {
dp->height = (dp->height * gotPct) / 100;
} else {
dp->width = (dp->width * gotPct) / 100;
}
}
scoreRect = board->scoreBdBounds; /* reset */
/* break extra space into chunks, one to follow REM and
another to preceed the timer, and then one for each player.
Generally the player's score will be centered in the rect
it's given, so in effect we're putting half the chunk on
either side. The goal here is for the scores to be closer
to each other than they are to the rem: string and timer on
the ends. */
XP_ASSERT( *adjustDim >= totalDim ); /* ???? */
extra = (*adjustDim - totalDim) / nPlayers;
/* at this point, the scoreRect should be anchored at the
scoreboard rect's upper left. */
@ -218,11 +201,11 @@ drawScoreBoard( BoardCtxt* board )
for ( dp = datum, ii = 0; ii < nPlayers; ++dp, ++ii ) {
XP_Rect innerRect;
XP_U16 dim = isVertical? dp->height:dp->width;
*adjustDim = board->pti[ii].scoreDims = dim + extra;
*adjustDim = board->pti[ii].scoreDims = dim;
centerIn( &innerRect, &scoreRect, dp->width, dp->height );
draw_score_drawPlayer( board->draw, &innerRect, &scoreRect,
&dp->dsi );
gotPct, &dp->dsi );
#ifdef KEYBOARD_NAV
XP_MEMCPY( &board->pti[ii].scoreRects, &scoreRect,
sizeof(scoreRect) );

View file

@ -277,7 +277,8 @@ curses_draw_objFinished( DrawCtx* p_dctx, BoardObjectType XP_UNUSED(typ),
static void
curses_draw_score_drawPlayer( DrawCtx* p_dctx, const XP_Rect* rInner,
const XP_Rect* rOuter, const DrawScoreInfo* dsi )
const XP_Rect* rOuter,
XP_U16 XP_UNUSED(gotPct), const DrawScoreInfo* dsi )
{
CursesDrawCtx* dctx = (CursesDrawCtx*)p_dctx;
char buf[100];

View file

@ -1013,7 +1013,8 @@ gtk_draw_measureScoreText( DrawCtx* p_dctx, const XP_Rect* bounds,
static void
gtk_draw_score_drawPlayer( DrawCtx* p_dctx, const XP_Rect* rInner,
const XP_Rect* rOuter, const DrawScoreInfo* dsi )
const XP_Rect* rOuter,
XP_U16 XP_UNUSED(gotPct), const DrawScoreInfo* dsi )
{
GtkDrawCtx* dctx = (GtkDrawCtx*)p_dctx;
XP_Bool hasCursor = (dsi->flags & CELL_ISCURSOR) != 0;