diff --git a/xwords4/android/XWords4/jni/Android.mk b/xwords4/android/XWords4/jni/Android.mk index bd7805855..e09c94f3b 100644 --- a/xwords4/android/XWords4/jni/Android.mk +++ b/xwords4/android/XWords4/jni/Android.mk @@ -37,6 +37,7 @@ local_DEFINES += \ -DRELAY_ROOM_DEFAULT=\"\" \ -D__LITTLE_ENDIAN \ +# -DXWFEATURE_SCOREONEPASS \ local_SRC_FILES += \ xwjni.c \ diff --git a/xwords4/android/XWords4/jni/drawwrapper.c b/xwords4/android/XWords4/jni/drawwrapper.c index 999d0422b..d5e6b51df 100644 --- a/xwords4/android/XWords4/jni/drawwrapper.c +++ b/xwords4/android/XWords4/jni/drawwrapper.c @@ -25,7 +25,12 @@ enum { JCACHE_RECT0 ,JCACHE_RECT1 +#ifdef XWFEATURE_SCOREONEPASS + ,JCACHE_DSIS + ,JCACHE_RECTS +#else ,JCACHE_DSI +#endif ,JCACHE_COUNT }; @@ -69,6 +74,94 @@ makeJRect( AndDraw* draw, int indx, const XP_Rect* rect ) return robj; } /* makeJRect */ +#ifdef XWFEATURE_SCOREONEPASS +static void +readJRect( JNIEnv* env, XP_Rect* rect, jobject jrect ) +{ + rect->left = getInt( env, jrect, "left" ); + rect->top = getInt( env, jrect, "top" ); + rect->width = getInt( env, jrect, "right" ) - rect->left; + rect->height = getInt( env, jrect, "bottom" ) - rect->top; +} + +static jobject +makeJRects( AndDraw* draw, int indx, XP_U16 nPlayers, const XP_Rect rects[] ) +{ + XP_U16 ii; + JNIEnv* env = *draw->env; + jobject jrects = draw->jCache[indx]; + if ( !jrects ) { + jclass rclass = (*env)->FindClass( env, "android/graphics/Rect"); + jrects = (*env)->NewObjectArray( env, nPlayers, rclass, NULL ); + draw->jCache[indx] = (*env)->NewGlobalRef( env, jrects ); + (*env)->DeleteLocalRef( env, jrects ); + jrects = draw->jCache[indx]; + + jmethodID initId = (*env)->GetMethodID( env, rclass, "", + "()V" ); + + for ( ii = 0; ii < nPlayers; ++ii ) { + jobject jrect = (*env)->NewObject( env, rclass, initId ); + (*env)->SetObjectArrayElement( env, jrects, ii, jrect ); + (*env)->DeleteLocalRef( env, jrect ); + } + + (*env)->DeleteLocalRef( env, rclass ); + } + + if ( NULL != rects ) { + XP_ASSERT(0); + /* for ( ii = 0; ii < nPlayers; ++ii ) { */ + /* jobject jrect = (*env)->GetObjectArrayElement( env, jrects, ii ); */ + /* writeJRect( env, jrect, &rects[ii] ); */ + /* } */ + } + + return jrects; +} + +static jobject +makeDSIs( AndDraw* draw, int indx, XP_U16 nPlayers, const DrawScoreInfo dsi[] ) +{ + XP_U16 ii; + JNIEnv* env = *draw->env; + jobject dsiobjs = draw->jCache[indx]; + + if ( !dsiobjs ) { + jclass clas = (*env)->FindClass( env, PKG_PATH("jni/DrawScoreInfo") ); + dsiobjs = (*env)->NewObjectArray( env, nPlayers, clas, NULL ); + draw->jCache[indx] = (*env)->NewGlobalRef( env, dsiobjs ); + (*env)->DeleteLocalRef( env, dsiobjs ); + dsiobjs = draw->jCache[indx]; + + jmethodID initId = (*env)->GetMethodID( env, clas, "", "()V" ); + for ( ii = 0; ii < nPlayers; ++ii ) { + jobject dsiobj = (*env)->NewObject( env, clas, initId ); + (*env)->SetObjectArrayElement( env, dsiobjs, ii, dsiobj ); + (*env)->DeleteLocalRef( env, dsiobj ); + } + + (*env)->DeleteLocalRef( env, clas ); + } + + for ( ii = 0; ii < nPlayers; ++ii ) { + jobject dsiobj = (*env)->GetObjectArrayElement( env, dsiobjs, ii ); + + setInt( env, dsiobj, "playerNum", dsi->playerNum ); + setInt( env, dsiobj, "totalScore", dsi->totalScore ); + setInt( env, dsiobj, "nTilesLeft", dsi->nTilesLeft ); + setInt( env, dsiobj, "flags", dsi->flags ); + setBool( env, dsiobj, "isTurn", dsi->isTurn ); + setBool( env, dsiobj, "selected", dsi->selected ); + setBool( env, dsiobj, "isRemote", dsi->isRemote ); + setBool( env, dsiobj, "isRobot", dsi->isRobot ); + setString( env, dsiobj, "name", dsi->name ); + } + return dsiobjs; +} + +#else + static jobject makeDSI( AndDraw* draw, int indx, const DrawScoreInfo* dsi ) { @@ -98,6 +191,7 @@ makeDSI( AndDraw* draw, int indx, const DrawScoreInfo* dsi ) return dsiobj; } +#endif #define DRAW_CBK_HEADER(nam,sig) \ AndDraw* draw = (AndDraw*)dctx; \ @@ -133,13 +227,33 @@ static void and_draw_drawRemText( DrawCtx* dctx, XP_S16 nTilesLeft, XP_Bool focussed, XP_Rect* rect ) { + DRAW_CBK_HEADER("drawRemText", "(IZLandroid/graphics/Rect;)V" ); + + jobject jrect = makeJRect( draw, JCACHE_RECT0, rect ); + (*env)->CallVoidMethod( env, draw->jdraw, mid, nTilesLeft, focussed, + jrect ); + readJRect( env, rect, jrect ); } static void and_draw_score_drawPlayers( DrawCtx* dctx, const XP_Rect* scoreRect, - XP_U16 nPlayers, DrawScoreInfo playerData[], - XP_Rect playerRects[] ) + XP_U16 nPlayers, DrawScoreInfo playerData[], + XP_Rect playerRects[] ) { + XP_U16 ii; + DRAW_CBK_HEADER("score_drawPlayers", "(Landroid/graphics/Rect;" + "[L" PKG_PATH("jni/DrawScoreInfo;") + "[Landroid/graphics/Rect;)V" ); + + jobject jrect = makeJRect( draw, JCACHE_RECT0, scoreRect ); + jobject jdsis = makeDSIs( draw, JCACHE_DSIS, nPlayers, playerData ); + jobject jrects = makeJRects( draw, JCACHE_RECTS, nPlayers, NULL ); + (*env)->CallVoidMethod( env, draw->jdraw, mid, jrect, jdsis, jrects ); + + for ( ii = 0; ii < nPlayers; ++ii ) { + jobject jrect = (*env)->GetObjectArrayElement( env, jrects, ii ); + readJRect( env, &playerRects[ii], jrect ); + } } #else diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardView.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardView.java index 2a8cfedfd..069b6fb99 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardView.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardView.java @@ -531,6 +531,56 @@ public class BoardView extends View implements DrawCtx, BoardHandler, } } + // public void drawRemText( int nTilesLeft, boolean focussed, Rect rect ) + // { + // int width, height; + // String remText = null; + // if ( 0 >= nTilesLeft ) { + // // make it disappear if useless + // width = height = 0; + // } else { + // // should cache a formatter + // remText = String.format( "%d", nTilesLeft ); + // m_fillPaint.setTextSize( m_mediumFontHt ); + // m_fillPaint.getTextBounds( remText, 0, remText.length(), + // m_boundsScratch ); + + // int minWidth = m_boundsScratch.width(); + // if ( minWidth < 20 ) { + // minWidth = 20; // it's a button; make it bigger + // } + // width = minWidth; + // height = m_boundsScratch.height(); + // } + + // rect.right = rect.left + width; + // // rect.bottom = rect.top + height; + + // if ( 0 < nTilesLeft ) { + // int indx = focussed ? CommonPrefs.COLOR_FOCUS + // : CommonPrefs.COLOR_TILE_BACK; + // fillRectOther( rect, indx ); + + // m_fillPaint.setColor( adjustColor(BLACK) ); + // drawCentered( remText, rect, null ); + // } + // } + + // public void score_drawPlayers( Rect scoreRect, DrawScoreInfo[] playerData, + // Rect[] playerRects ) + // { + // // To measure + + // int width = scoreRect.width() / playerRects.length; + // int left = scoreRect.left; + // for ( int ii = 0; ii < playerRects.length; ++ii ) { + // playerRects[ii].set( left, scoreRect.top, left + width, + // scoreRect.bottom ); + // drawCentered( playerData[ii].name, playerRects[ii], null ); + // left += width; + // } + // } + public void drawTimer( Rect rect, int player, int secondsLeft ) { if ( null != m_canvas && (m_lastSecsLeft != secondsLeft diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/DrawCtx.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/DrawCtx.java index e007984a8..4f39a3419 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/DrawCtx.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/DrawCtx.java @@ -49,6 +49,12 @@ public interface DrawCtx { void drawRemText( Rect rInner, Rect rOuter, int nTilesLeft, boolean focussed ); void score_drawPlayer( Rect rInner, Rect rOuter, int gotPct, DrawScoreInfo dsi ); + + // New way of drawing + // void drawRemText( int nTilesLeft, boolean focussed, Rect rect ); + // void score_drawPlayers( Rect scoreRect, DrawScoreInfo[] playerData, + // Rect[] playerRects ); + void drawTimer( Rect rect, int player, int secondsLeft ); boolean boardBegin( Rect rect, int cellWidth, int cellHeight );