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

View file

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

View file

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

View file

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

View file

@ -151,10 +151,12 @@ public class XwJNI {
// Only if COMMON_LAYOUT defined // Only if COMMON_LAYOUT defined
public static native void board_figureLayout( int gamePtr, CurGameInfo gi, 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, int fontWidth, int fontHt,
boolean squareTiles, boolean squareTiles,
Rect bounds, BoardDims dims ); BoardDims dims );
// Only if COMMON_LAYOUT defined // Only if COMMON_LAYOUT defined
public static native void board_applyLayout( int gamePtr, BoardDims dims ); public static native void board_applyLayout( int gamePtr, BoardDims dims );

View file

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

View file

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

View file

@ -613,18 +613,16 @@ configure_event( GtkWidget* widget, GdkEventConfigure* XP_UNUSED(event),
#ifdef COMMON_LAYOUT #ifdef COMMON_LAYOUT
XP_ASSERT( !cGlobals->params->verticalScore ); /* not supported */ 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; BoardDims dims;
board_figureLayout( board, cGlobals->gi, board_figureLayout( board, cGlobals->gi,
GTK_BOARD_LEFT, GTK_HOR_SCORE_TOP, bdWidth, bdHeight,
#if 1 #if 1
150, 200, 150, 200,
#else #else
0, 0, 0, 0,
#endif #endif
16, 16, bdWidth-100, 16, 16,
XP_FALSE, &rect, &dims ); XP_FALSE, &dims );
board_applyLayout( board, &dims ); board_applyLayout( board, &dims );
#else #else