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; return array;
} }
int void
getIntFromArray( JNIEnv* env, jintArray arr, bool del ) getIntsFromArray( JNIEnv* env, int dest[], jintArray arr, int count, bool del )
{ {
jint* ints = (*env)->GetIntArrayElements(env, arr, 0); 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 ); (*env)->ReleaseIntArrayElements( env, arr, ints, 0 );
if ( del ) { if ( del ) {
deleteLocalRef( env, arr ); deleteLocalRef( env, arr );
} }
return result;
} }
void void

View file

@ -69,7 +69,7 @@ bool getObject( JNIEnv* env, jobject obj, const char* name, const char* sig,
jobject* ret ); jobject* ret );
jintArray makeIntArray( JNIEnv *env, int size, const jint* vals ); 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 ); void setIntInArray( JNIEnv* env, jintArray arr, int index, int val );
jbyteArray makeByteArray( JNIEnv* env, int size, const jbyte* vals ); 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, nTilesLeft, widthArray,
heightArray ); heightArray );
if ( result ) { if ( result ) {
*width = getIntFromArray( env, widthArray, true ); int tmp;
*height = getIntFromArray( env, heightArray, true ); getIntsFromArray( env, &tmp, widthArray, 1, true );
*width = tmp;
getIntsFromArray( env, &tmp, heightArray, 1, true );
*height = tmp;
} }
returnJRect( draw, JCACHE_RECT0, jrect ); returnJRect( draw, JCACHE_RECT0, jrect );
return result; return result;
@ -337,8 +340,11 @@ and_draw_measureScoreText( DrawCtx* dctx,
widthArray, heightArray ); widthArray, heightArray );
returnJRect( draw, JCACHE_RECT0, jrect ); returnJRect( draw, JCACHE_RECT0, jrect );
*width = getIntFromArray( env, widthArray, true ); int tmp;
*height = getIntFromArray( env, heightArray, true ); getIntsFromArray( env, &tmp, widthArray, 1, true );
*width = tmp;
getIntsFromArray( env, &tmp, heightArray, 1, true );
*height = tmp;
} /* and_draw_measureScoreText */ } /* and_draw_measureScoreText */
static void static void
@ -603,8 +609,12 @@ and_draw_measureMiniWText( DrawCtx* dctx, const XP_UCHAR* textP,
jstr, widthArray, heightArray ); jstr, widthArray, heightArray );
deleteLocalRef( env, jstr ); 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 static void