modify function to be more useful

This commit is contained in:
Eric House 2017-03-09 19:35:07 -08:00
parent 618f9cf20a
commit 70b3aaa263
3 changed files with 22 additions and 11 deletions

View file

@ -371,16 +371,17 @@ makeBooleanArray( JNIEnv *env, int siz, const jboolean* vals )
return array;
}
int
getIntFromArray( JNIEnv* env, jintArray arr, bool del )
void
getIntsFromArray( JNIEnv* env, int dest[], jintArray arr, int count, bool del )
{
jint* ints = (*env)->GetIntArrayElements(env, arr, 0);
int result = ints[0];
for ( int ii = 0; ii < count; ++ii ) {
dest[ii] = ints[ii];
}
(*env)->ReleaseIntArrayElements( env, arr, ints, 0 );
if ( del ) {
deleteLocalRef( env, arr );
}
return result;
}
void

View file

@ -69,7 +69,7 @@ bool getObject( JNIEnv* env, jobject obj, const char* name, const char* sig,
jobject* ret );
jintArray makeIntArray( JNIEnv *env, int size, const jint* vals );
int getIntFromArray( JNIEnv* env, jintArray arr, bool del );
void getIntsFromArray( JNIEnv* env, int dest[], jintArray arr, int count, bool del );
void setIntInArray( JNIEnv* env, jintArray arr, int index, int val );
jbyteArray makeByteArray( JNIEnv* env, int size, const jbyte* vals );

View file

@ -293,8 +293,11 @@ and_draw_measureRemText( DrawCtx* dctx, const XP_Rect* rect,
nTilesLeft, widthArray,
heightArray );
if ( result ) {
*width = getIntFromArray( env, widthArray, true );
*height = getIntFromArray( env, heightArray, true );
int tmp;
getIntsFromArray( env, &tmp, widthArray, 1, true );
*width = tmp;
getIntsFromArray( env, &tmp, heightArray, 1, true );
*height = tmp;
}
returnJRect( draw, JCACHE_RECT0, jrect );
return result;
@ -337,8 +340,11 @@ and_draw_measureScoreText( DrawCtx* dctx,
widthArray, heightArray );
returnJRect( draw, JCACHE_RECT0, jrect );
*width = getIntFromArray( env, widthArray, true );
*height = getIntFromArray( env, heightArray, true );
int tmp;
getIntsFromArray( env, &tmp, widthArray, 1, true );
*width = tmp;
getIntsFromArray( env, &tmp, heightArray, 1, true );
*height = tmp;
} /* and_draw_measureScoreText */
static void
@ -603,8 +609,12 @@ and_draw_measureMiniWText( DrawCtx* dctx, const XP_UCHAR* textP,
jstr, widthArray, heightArray );
deleteLocalRef( env, jstr );
*width = getIntFromArray( env, widthArray, true );
*height = getIntFromArray( env, heightArray, true );
int tmp;
getIntsFromArray( env, &tmp, widthArray, 1, true );
*width = tmp;
getIntsFromArray( env, &tmp, heightArray, 1, true );
*height = tmp;
}
static void