pass scoreWidth separately into formatting code so space can be left

for network status icon.
This commit is contained in:
Eric House 2013-11-09 05:34:23 -08:00
parent 57c887b8cd
commit dfdbd9a8a2
8 changed files with 50 additions and 52 deletions

View file

@ -165,6 +165,7 @@ static const SetInfo bd_ints[] = {
,ARR_MEMBER( BoardDims, width )
,ARR_MEMBER( BoardDims, height )
,ARR_MEMBER( BoardDims, scoreHt )
,ARR_MEMBER( BoardDims, scoreWidth )
,ARR_MEMBER( BoardDims, boardHt )
,ARR_MEMBER( BoardDims, trayTop )
,ARR_MEMBER( BoardDims, trayHt )
@ -182,9 +183,7 @@ dimsJToC( JNIEnv* env, BoardDims* out, jobject jdims )
static void
dimsCtoJ( JNIEnv* env, jobject jdims, const BoardDims* in )
{
LOG_FUNC();
setInts( env, jdims, (void*)in, bd_ints, VSIZE(bd_ints) );
LOG_RETURN_VOID();
}
#endif
@ -638,23 +637,18 @@ Java_org_eehouse_android_xw4_jni_XwJNI_board_1draw
#ifdef COMMON_LAYOUT
JNIEXPORT void JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_board_1figureLayout
( JNIEnv* env, jclass C, jint gamePtr, jobject jgi,
jint scorePct, jint trayPct, jint fontWidth, jint fontHt,
jboolean squareTiles, jobject jbounds, jobject jdims )
( JNIEnv* env, jclass C, jint gamePtr, jobject jgi, jint left, jint top,
jint width, jint height, jint scorePct, jint trayPct, jint scoreWidth,
jint fontWidth, jint fontHt, jboolean squareTiles, jobject jdims )
{
LOG_FUNC();
XWJNI_START();
CurGameInfo* gi = makeGI( MPPARM(mpool) env, jgi );
XP_Rect bounds;
bounds.left = getInt( env, jbounds, "left" );
bounds.top = getInt( env, jbounds, "top" );
bounds.width = getInt( env, jbounds, "right" ) - bounds.left;
bounds.height = getInt( env, jbounds, "bottom" ) - bounds.top;
BoardDims dims;
board_figureLayout( state->game.board, gi, scorePct, trayPct,
fontWidth, fontHt, squareTiles, &bounds,
board_figureLayout( state->game.board, gi, left, top, width, height,
scorePct, trayPct, scoreWidth,
fontWidth, fontHt, squareTiles,
((!!jdims) ? &dims : NULL) );
destroyGI( MPPARM(mpool) &gi );

View file

@ -2084,9 +2084,8 @@ public class BoardActivity extends XWActivity
}
thumb = Bitmap.createBitmap( size, size, Bitmap.Config.ARGB_8888 );
Rect bounds = new Rect( 0, 0, size, size );
XwJNI.board_figureLayout( m_jniGamePtr, m_gi, 0, 0, 20, 20, false,
bounds, null );
XwJNI.board_figureLayout( m_jniGamePtr, m_gi, 0, 0, size, size,
0, 0, 0, 20, 20, false, null );
ThumbCanvas canvas = new ThumbCanvas( this, thumb );
XwJNI.board_setDraw( m_jniGamePtr, canvas );
@ -2103,7 +2102,7 @@ public class BoardActivity extends XWActivity
}
DBUtils.saveThumbnail( this, m_gameLock, thumb );
}
}
} // takeSnapshot
private void warnIfNoTransport()
{

View file

@ -25,7 +25,7 @@ package org.eehouse.android.xw4;
public class BoardDims {
public int left, top;
public int width, height; // of the bitmap
public int scoreHt;
public int scoreWidth, scoreHt;
public int boardHt;
public int trayTop, trayHt;
public int cellSize, maxCellSize;
@ -38,6 +38,7 @@ public class BoardDims {
// + " left: " + left
// + " top: " + top
// + " scoreHt: " + scoreHt
// + " scoreWidth: " + scoreWidth
// + " boardHt: " + boardHt
// + " trayTop: " + trayTop
// + " trayHt: " + trayHt

View file

@ -240,14 +240,15 @@ public class JNIThread extends Thread {
BoardDims dims = new BoardDims();
boolean squareTiles = XWPrefs.getSquareTiles( m_context );
Rect bounds = new Rect( 0, 0, width, height );
XwJNI.board_figureLayout( m_jniGamePtr, m_gi, 150, 200,
fontWidth, fontHeight, squareTiles,
bounds, dims );
int statusWidth = width / 15;
int scoreWidth = width - statusWidth;
XwJNI.board_figureLayout( m_jniGamePtr, m_gi, 0, 0, width, height,
150, 200, scoreWidth, fontWidth,
fontHeight, squareTiles, dims );
int scoreWidth = dims.width - dims.cellSize;
ConnStatusHandler.setRect( scoreWidth, 0, scoreWidth + dims.cellSize,
dims.scoreHt );
ConnStatusHandler.setRect( dims.left + scoreWidth, dims.top,
dims.left + scoreWidth + statusWidth,
dims.top + dims.scoreHt );
XwJNI.board_applyLayout( m_jniGamePtr, dims );

View file

@ -151,10 +151,12 @@ public class XwJNI {
// Only if COMMON_LAYOUT defined
public static native void board_figureLayout( int gamePtr, CurGameInfo gi,
int scorePct, int trayPct,
int left, int top, int width,
int height, int scorePct,
int trayPct, int scoreWidth,
int fontWidth, int fontHt,
boolean squareTiles,
Rect bounds, BoardDims dims );
BoardDims dims );
// Only if COMMON_LAYOUT defined
public static native void board_applyLayout( int gamePtr, BoardDims dims );

View file

@ -392,9 +392,10 @@ board_reset( BoardCtxt* board )
#ifdef COMMON_LAYOUT
void
board_figureLayout( BoardCtxt* board, const CurGameInfo* gi,
XP_U16 scorePct, XP_U16 trayPct,
XP_U16 bLeft, XP_U16 bTop, XP_U16 bWidth, XP_U16 bHeight,
XP_U16 scorePct, XP_U16 trayPct, XP_U16 scoreWidth,
XP_U16 fontWidth, XP_U16 fontHt, XP_Bool squareTiles,
const XP_Rect* bounds, BoardDims* dimsp )
BoardDims* dimsp )
{
BoardDims ldims;
XP_MEMSET( &ldims, 0, sizeof(ldims) );
@ -407,13 +408,13 @@ board_figureLayout( BoardCtxt* board, const CurGameInfo* gi,
XP_U16 nToScroll;
XP_Bool firstPass;
ldims.left = bounds->left;
ldims.top = bounds->top;
ldims.left = bLeft;
ldims.top = bTop;
for ( firstPass = XP_TRUE; ; ) {
ldims.width = bounds->width;
ldims.width = bWidth;
XP_U16 cellSize = bounds->width / nCells;
XP_U16 cellSize = bWidth / nCells;
if ( cellSize > maxCellSize ) {
cellSize = maxCellSize;
@ -430,24 +431,24 @@ board_figureLayout( BoardCtxt* board, const CurGameInfo* gi,
scoreHt = (scorePct * cellSize) / 100;
trayHt = (trayPct * cellSize) / 100;
wantHt = trayHt + scoreHt + (cellSize * nCells);
if ( wantHt <= bounds->height ) {
if ( wantHt <= bHeight ) {
nToScroll = 0;
} else {
// Scrolling's required if we use cell width sufficient to
// fill the screen. But perhaps we don't need to.
int cellWidth = 2 * (bounds->height / ( 4 + 3 + (2*nCells)));
int cellWidth = 2 * (bHeight / ( 4 + 3 + (2*nCells)));
if ( firstPass && cellWidth >= fontHt ) {
firstPass = XP_FALSE;
ldims.width = nCells * cellWidth;
continue;
} else {
nToScroll = nCells -
((bounds->height - trayHt - scoreHt) / cellSize);
((bHeight - trayHt - scoreHt) / cellSize);
}
}
XP_U16 heightUsed = trayHt + scoreHt + (nCells - nToScroll) * cellSize;
XP_U16 heightLeft = bounds->height - heightUsed;
XP_U16 heightLeft = bHeight - heightUsed;
if ( 0 < heightLeft ) {
if ( heightLeft > (cellSize * 3 / 2) ) {
heightLeft = cellSize * 3 / 2;
@ -460,14 +461,15 @@ board_figureLayout( BoardCtxt* board, const CurGameInfo* gi,
if ( 0 < trayPct ) {
trayHt += heightLeft * 2;
}
if ( squareTiles && trayHt > (bounds->width / 7) ) {
trayHt = bounds->width / 7;
if ( squareTiles && trayHt > (bWidth / 7) ) {
trayHt = bWidth / 7;
}
heightUsed = trayHt + scoreHt + ((nCells - nToScroll) * cellSize);
}
ldims.trayHt = trayHt;
ldims.scoreHt = scoreHt;
ldims.scoreWidth = scoreWidth;
ldims.boardHt = cellSize * nCells;
ldims.trayTop = scoreHt + (cellSize * (nCells-nToScroll));
@ -476,6 +478,7 @@ board_figureLayout( BoardCtxt* board, const CurGameInfo* gi,
if ( gi->timerEnabled ) {
ldims.timerWidth = fontWidth * XP_STRLEN("-00:00");
ldims.scoreWidth -= ldims.timerWidth;
}
break;
}
@ -495,10 +498,10 @@ board_applyLayout( BoardCtxt* board, const BoardDims* dims )
dims->maxCellSize, XP_FALSE );
board_setScoreboardLoc( board, dims->left, dims->top,
dims->width - dims->timerWidth,
dims->scoreWidth,
dims->scoreHt, XP_TRUE );
board_setTimerLoc( board, dims->left + dims->width - dims->timerWidth,
board_setTimerLoc( board, dims->left + dims->scoreWidth,
dims->top, dims->timerWidth, dims->scoreHt );
board_setTrayLoc( board, dims->left, dims->trayTop,

View file

@ -78,18 +78,18 @@ void board_reset( BoardCtxt* board );
typedef struct _BoardDims {
XP_U16 left, top;
XP_U16 width, height;
XP_U16 scoreHt;
XP_U16 scoreWidth, scoreHt;
XP_U16 boardHt;
XP_U16 trayTop, trayHt;
XP_U16 cellSize, maxCellSize;
XP_U16 timerWidth;
} BoardDims;
void board_figureLayout( BoardCtxt* board, const CurGameInfo* gi,
XP_U16 scorePct, XP_U16 trayPct,
XP_U16 fontWidth, XP_U16 fontHt,
XP_Bool squareTiles, const XP_Rect* bounds,
/* out */ BoardDims* dims );
void board_figureLayout( BoardCtxt* board, const CurGameInfo* gi, XP_U16 bLeft,
XP_U16 bTop, XP_U16 bWidth, XP_U16 bHeight,
XP_U16 scorePct, XP_U16 trayPct, XP_U16 scoreWidth,
XP_U16 fontWidth, XP_U16 fontHt, XP_Bool squareTiles,
/* out */ BoardDims* dimsp );
void board_applyLayout( BoardCtxt* board, const BoardDims* dims );
#endif

View file

@ -613,18 +613,16 @@ configure_event( GtkWidget* widget, GdkEventConfigure* XP_UNUSED(event),
#ifdef COMMON_LAYOUT
XP_ASSERT( !cGlobals->params->verticalScore ); /* not supported */
XP_Rect rect = { .left = GTK_BOARD_LEFT, .top = GTK_HOR_SCORE_TOP,
.width = bdWidth, .height = bdHeight
};
BoardDims dims;
board_figureLayout( board, cGlobals->gi,
GTK_BOARD_LEFT, GTK_HOR_SCORE_TOP, bdWidth, bdHeight,
#if 1
150, 200,
#else
0, 0,
#endif
16, 16,
XP_FALSE, &rect, &dims );
bdWidth-100, 16, 16,
XP_FALSE, &dims );
board_applyLayout( board, &dims );
#else