mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-16 15:41:16 +01:00
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:
parent
3d9478744a
commit
405cb23023
7 changed files with 59 additions and 72 deletions
|
@ -185,20 +185,20 @@ and_draw_drawRemText( DrawCtx* dctx, const XP_Rect* rInner,
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
and_draw_score_drawPlayer( DrawCtx* dctx,
|
and_draw_score_drawPlayer( DrawCtx* dctx, const XP_Rect* rInner,
|
||||||
const XP_Rect* rInner,
|
const XP_Rect* rOuter, XP_U16 gotPct,
|
||||||
const XP_Rect* rOuter,
|
|
||||||
const DrawScoreInfo* dsi )
|
const DrawScoreInfo* dsi )
|
||||||
{
|
{
|
||||||
DRAW_CBK_HEADER("score_drawPlayer",
|
DRAW_CBK_HEADER("score_drawPlayer",
|
||||||
"(Landroid/graphics/Rect;Landroid/graphics/Rect;"
|
"(Landroid/graphics/Rect;Landroid/graphics/Rect;I"
|
||||||
"L" PKG_PATH("jni/DrawScoreInfo") ";)V" );
|
"L" PKG_PATH("jni/DrawScoreInfo") ";)V" );
|
||||||
|
|
||||||
jobject jrinner = makeJRect( draw, JCACHE_RECT0, rInner );
|
jobject jrinner = makeJRect( draw, JCACHE_RECT0, rInner );
|
||||||
jobject jrouter = makeJRect( draw, JCACHE_RECT1, rOuter );
|
jobject jrouter = makeJRect( draw, JCACHE_RECT1, rOuter );
|
||||||
jobject jdsi = makeDSI( draw, JCACHE_DSI, dsi );
|
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 */
|
} /* and_draw_score_drawPlayer */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
@ -494,7 +494,8 @@ public class BoardView extends View implements DrawCtx, BoardHandler,
|
||||||
height[0] = r.height();
|
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) ) {
|
if ( 0 != (dsi.flags & CELL_ISCURSOR) ) {
|
||||||
fillRectOther( rOuter, CommonPrefs.COLOR_FOCUS );
|
fillRectOther( rOuter, CommonPrefs.COLOR_FOCUS );
|
||||||
|
@ -506,12 +507,11 @@ public class BoardView extends View implements DrawCtx, BoardHandler,
|
||||||
}
|
}
|
||||||
m_fillPaint.setColor( color );
|
m_fillPaint.setColor( color );
|
||||||
|
|
||||||
Rect rect = new Rect( rOuter );
|
int height = rOuter.height() / texts.length;
|
||||||
int height = rect.height() / texts.length;
|
rOuter.bottom = rOuter.top + height;
|
||||||
rect.bottom = rect.top + height;
|
|
||||||
for ( String text : texts ) {
|
for ( String text : texts ) {
|
||||||
drawCentered( text, rect, null );
|
drawCentered( text, rOuter, null );
|
||||||
rect.offset( 0, height );
|
rOuter.offset( 0, height );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,8 @@ public interface DrawCtx {
|
||||||
void measureRemText( Rect r, int nTilesLeft, int[] width, int[] height );
|
void measureRemText( Rect r, int nTilesLeft, int[] width, int[] height );
|
||||||
void measureScoreText( Rect r, DrawScoreInfo dsi, 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 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 );
|
void drawTimer( Rect rect, int player, int secondsLeft );
|
||||||
boolean boardBegin( Rect rect, int cellWidth, int cellHeight );
|
boolean boardBegin( Rect rect, int cellWidth, int cellHeight );
|
||||||
|
|
||||||
|
|
|
@ -149,6 +149,7 @@ typedef struct DrawCtxVTable {
|
||||||
void DRAW_VTABLE_NAME(score_drawPlayer) ( DrawCtx* dctx,
|
void DRAW_VTABLE_NAME(score_drawPlayer) ( DrawCtx* dctx,
|
||||||
const XP_Rect* rInner,
|
const XP_Rect* rInner,
|
||||||
const XP_Rect* rOuter,
|
const XP_Rect* rOuter,
|
||||||
|
XP_U16 gotPct,
|
||||||
const DrawScoreInfo* dsi );
|
const DrawScoreInfo* dsi );
|
||||||
|
|
||||||
void DRAW_VTABLE_NAME(score_pendingScore) ( DrawCtx* dctx,
|
void DRAW_VTABLE_NAME(score_pendingScore) ( DrawCtx* dctx,
|
||||||
|
@ -276,8 +277,8 @@ struct DrawCtx {
|
||||||
CALL_DRAW_NAME4(drawRemText, (dc), (ri), (ro), (n), (f) )
|
CALL_DRAW_NAME4(drawRemText, (dc), (ri), (ro), (n), (f) )
|
||||||
#define draw_measureScoreText(dc,r,dsi,wp,hp) \
|
#define draw_measureScoreText(dc,r,dsi,wp,hp) \
|
||||||
CALL_DRAW_NAME4(measureScoreText,(dc),(r),(dsi),(wp),(hp))
|
CALL_DRAW_NAME4(measureScoreText,(dc),(r),(dsi),(wp),(hp))
|
||||||
#define draw_score_drawPlayer(dc, ri, ro, dsi) \
|
#define draw_score_drawPlayer(dc, ri, ro, gp, dsi) \
|
||||||
CALL_DRAW_NAME3(score_drawPlayer,(dc),(ri),(ro),(dsi))
|
CALL_DRAW_NAME4(score_drawPlayer,(dc),(ri),(ro),(gp),(dsi))
|
||||||
#define draw_score_pendingScore(dc, r, s, p, f ) \
|
#define draw_score_pendingScore(dc, r, s, p, f ) \
|
||||||
CALL_DRAW_NAME4(score_pendingScore,(dc), (r), (s), (p), (f))
|
CALL_DRAW_NAME4(score_pendingScore,(dc), (r), (s), (p), (f))
|
||||||
#define draw_drawTimer( dc, r, plyr, sec ) \
|
#define draw_drawTimer( dc, r, plyr, sec ) \
|
||||||
|
|
|
@ -70,13 +70,11 @@ drawScoreBoard( BoardCtxt* board )
|
||||||
XP_Rect scoreRect = board->scoreBdBounds;
|
XP_Rect scoreRect = board->scoreBdBounds;
|
||||||
XP_S16* adjustDim;
|
XP_S16* adjustDim;
|
||||||
XP_S16* adjustPt;
|
XP_S16* adjustPt;
|
||||||
XP_U16 totalDim; /* don't really need this */
|
XP_U16 remWidth, remHeight, remDim;
|
||||||
XP_U16 extra, remWidth, remHeight, remDim;
|
|
||||||
DrawScoreData* dp;
|
DrawScoreData* dp;
|
||||||
DrawScoreData datum[MAX_NUM_PLAYERS];
|
DrawScoreData datum[MAX_NUM_PLAYERS];
|
||||||
ScoresArray scores;
|
ScoresArray scores;
|
||||||
XP_Bool isVertical = !board->scoreSplitHor;
|
XP_Bool isVertical = !board->scoreSplitHor;
|
||||||
XP_Bool skipCurTurn; /* skip the guy whose turn it is this pass? */
|
|
||||||
XP_Bool remFocussed = XP_FALSE;
|
XP_Bool remFocussed = XP_FALSE;
|
||||||
XP_Bool focusAll = XP_FALSE;
|
XP_Bool focusAll = XP_FALSE;
|
||||||
#ifdef KEYBOARD_NAV
|
#ifdef KEYBOARD_NAV
|
||||||
|
@ -106,6 +104,8 @@ drawScoreBoard( BoardCtxt* board )
|
||||||
if ( draw_scoreBegin( board->draw, &board->scoreBdBounds, nPlayers,
|
if ( draw_scoreBegin( board->draw, &board->scoreBdBounds, nPlayers,
|
||||||
scores.arr, nTilesInPool,
|
scores.arr, nTilesInPool,
|
||||||
dfsFor( board, OBJ_SCORE ) ) ) {
|
dfsFor( board, OBJ_SCORE ) ) ) {
|
||||||
|
XP_U16 totalDim = 0; /* not counting rem */
|
||||||
|
XP_U16 gotPct;
|
||||||
|
|
||||||
/* Let platform decide whether the rem: string should be given
|
/* Let platform decide whether the rem: string should be given
|
||||||
any space once there are no tiles left. On Palm that space
|
any space once there are no tiles left. On Palm that space
|
||||||
|
@ -125,8 +125,6 @@ drawScoreBoard( BoardCtxt* board )
|
||||||
}
|
}
|
||||||
*adjustDim -= remDim;
|
*adjustDim -= remDim;
|
||||||
|
|
||||||
totalDim = remDim;
|
|
||||||
|
|
||||||
/* Give as much room as possible to the entry for the player
|
/* Give as much room as possible to the entry for the player
|
||||||
whose turn it is so name can be drawn. Do that by
|
whose turn it is so name can be drawn. Do that by
|
||||||
formatting that player's score last, and passing each time
|
formatting that player's score last, and passing each time
|
||||||
|
@ -136,64 +134,49 @@ drawScoreBoard( BoardCtxt* board )
|
||||||
|
|
||||||
/* figure spacing for each scoreboard entry */
|
/* figure spacing for each scoreboard entry */
|
||||||
XP_MEMSET( &datum, 0, sizeof(datum) );
|
XP_MEMSET( &datum, 0, sizeof(datum) );
|
||||||
for ( skipCurTurn = XP_TRUE; ; skipCurTurn = XP_FALSE ) {
|
totalDim = 0;
|
||||||
for ( dp = datum, ii = 0; ii < nPlayers; ++ii, ++dp ) {
|
for ( dp = datum, ii = 0; ii < nPlayers; ++ii, ++dp ) {
|
||||||
LocalPlayer* lp;
|
LocalPlayer* lp = &board->gi->players[ii];
|
||||||
XP_U16 dim;
|
|
||||||
|
|
||||||
if ( skipCurTurn == (ii == curTurn) ) {
|
/* This is a hack! */
|
||||||
continue;
|
dp->dsi.lsc = board_ScoreCallback;
|
||||||
}
|
dp->dsi.lscClosure = model;
|
||||||
|
|
||||||
lp = &board->gi->players[ii];
|
|
||||||
|
|
||||||
/* This is a hack! */
|
|
||||||
dp->dsi.lsc = board_ScoreCallback;
|
|
||||||
dp->dsi.lscClosure = model;
|
|
||||||
#ifdef KEYBOARD_NAV
|
#ifdef KEYBOARD_NAV
|
||||||
if ( (ii == cursorIndex) || focusAll ) {
|
if ( (ii == cursorIndex) || focusAll ) {
|
||||||
dp->dsi.flags |= CELL_ISCURSOR;
|
dp->dsi.flags |= CELL_ISCURSOR;
|
||||||
}
|
|
||||||
#endif
|
|
||||||
dp->dsi.playerNum = ii;
|
|
||||||
dp->dsi.totalScore = scores.arr[ii];
|
|
||||||
dp->dsi.isTurn = (ii == curTurn);
|
|
||||||
dp->dsi.name = emptyStringIfNull(lp->name);
|
|
||||||
dp->dsi.selected = board->trayVisState != TRAY_HIDDEN
|
|
||||||
&& ii==selPlayer;
|
|
||||||
dp->dsi.isRobot = LP_IS_ROBOT(lp);
|
|
||||||
dp->dsi.isRemote = !lp->isLocal;
|
|
||||||
dp->dsi.nTilesLeft = (nTilesInPool > 0)? -1:
|
|
||||||
model_getNumTilesTotal( model, ii );
|
|
||||||
|
|
||||||
draw_measureScoreText( board->draw, &scoreRect,
|
|
||||||
&dp->dsi, &dp->width,
|
|
||||||
&dp->height );
|
|
||||||
|
|
||||||
XP_ASSERT( dp->width <= scoreRect.width );
|
|
||||||
XP_ASSERT( dp->height <= scoreRect.height );
|
|
||||||
dim = isVertical ? dp->height : dp->width;
|
|
||||||
totalDim += dim;
|
|
||||||
*adjustDim -= dim;
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
dp->dsi.playerNum = ii;
|
||||||
|
dp->dsi.totalScore = scores.arr[ii];
|
||||||
|
dp->dsi.isTurn = (ii == curTurn);
|
||||||
|
dp->dsi.name = emptyStringIfNull(lp->name);
|
||||||
|
dp->dsi.selected = board->trayVisState != TRAY_HIDDEN
|
||||||
|
&& ii==selPlayer;
|
||||||
|
dp->dsi.isRobot = LP_IS_ROBOT(lp);
|
||||||
|
dp->dsi.isRemote = !lp->isLocal;
|
||||||
|
dp->dsi.nTilesLeft = (nTilesInPool > 0)? -1:
|
||||||
|
model_getNumTilesTotal( model, ii );
|
||||||
|
|
||||||
if ( !skipCurTurn ) { /* exit 2nd time through */
|
draw_measureScoreText( board->draw, &scoreRect,
|
||||||
break;
|
&dp->dsi, &dp->width,
|
||||||
|
&dp->height );
|
||||||
|
|
||||||
|
XP_ASSERT( dp->width <= scoreRect.width );
|
||||||
|
XP_ASSERT( dp->height <= scoreRect.height );
|
||||||
|
totalDim += isVertical ? dp->height : dp->width;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 */
|
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
|
/* at this point, the scoreRect should be anchored at the
|
||||||
scoreboard rect's upper left. */
|
scoreboard rect's upper left. */
|
||||||
|
|
||||||
|
@ -218,11 +201,11 @@ drawScoreBoard( BoardCtxt* board )
|
||||||
for ( dp = datum, ii = 0; ii < nPlayers; ++dp, ++ii ) {
|
for ( dp = datum, ii = 0; ii < nPlayers; ++dp, ++ii ) {
|
||||||
XP_Rect innerRect;
|
XP_Rect innerRect;
|
||||||
XP_U16 dim = isVertical? dp->height:dp->width;
|
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 );
|
centerIn( &innerRect, &scoreRect, dp->width, dp->height );
|
||||||
draw_score_drawPlayer( board->draw, &innerRect, &scoreRect,
|
draw_score_drawPlayer( board->draw, &innerRect, &scoreRect,
|
||||||
&dp->dsi );
|
gotPct, &dp->dsi );
|
||||||
#ifdef KEYBOARD_NAV
|
#ifdef KEYBOARD_NAV
|
||||||
XP_MEMCPY( &board->pti[ii].scoreRects, &scoreRect,
|
XP_MEMCPY( &board->pti[ii].scoreRects, &scoreRect,
|
||||||
sizeof(scoreRect) );
|
sizeof(scoreRect) );
|
||||||
|
|
|
@ -277,7 +277,8 @@ curses_draw_objFinished( DrawCtx* p_dctx, BoardObjectType XP_UNUSED(typ),
|
||||||
|
|
||||||
static void
|
static void
|
||||||
curses_draw_score_drawPlayer( DrawCtx* p_dctx, const XP_Rect* rInner,
|
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;
|
CursesDrawCtx* dctx = (CursesDrawCtx*)p_dctx;
|
||||||
char buf[100];
|
char buf[100];
|
||||||
|
|
|
@ -1013,7 +1013,8 @@ gtk_draw_measureScoreText( DrawCtx* p_dctx, const XP_Rect* bounds,
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gtk_draw_score_drawPlayer( DrawCtx* p_dctx, const XP_Rect* rInner,
|
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;
|
GtkDrawCtx* dctx = (GtkDrawCtx*)p_dctx;
|
||||||
XP_Bool hasCursor = (dsi->flags & CELL_ISCURSOR) != 0;
|
XP_Bool hasCursor = (dsi->flags & CELL_ISCURSOR) != 0;
|
||||||
|
|
Loading…
Reference in a new issue