mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-06 05:24:46 +01:00
more work on single-pass scoreboard drawing. Now the jni stuff is
finished, but disabled via compile-time flag, and there's a commented-out rudimentary implementation on the java side.
This commit is contained in:
parent
b9b58bd0a5
commit
89ffd972bf
4 changed files with 173 additions and 2 deletions
|
@ -37,6 +37,7 @@ local_DEFINES += \
|
|||
-DRELAY_ROOM_DEFAULT=\"\" \
|
||||
-D__LITTLE_ENDIAN \
|
||||
|
||||
# -DXWFEATURE_SCOREONEPASS \
|
||||
|
||||
local_SRC_FILES += \
|
||||
xwjni.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, "<init>",
|
||||
"()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, "<init>", "()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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 );
|
||||
|
||||
|
|
Loading…
Reference in a new issue