implement board_getFocusOwner, board_focusChanged and board_handleKey,

and utils needed.
This commit is contained in:
eehouse 2010-02-27 18:05:39 +00:00
parent 397d0df573
commit cb6b19f0aa
3 changed files with 68 additions and 14 deletions

View file

@ -190,16 +190,23 @@ makeByteArray( JNIEnv *env, int siz, const jbyte* vals )
return array;
}
void
setBoolArray( JNIEnv* env, jbooleanArray jarr, int count,
const jboolean* vals )
{
jboolean* elems = (*env)->GetBooleanArrayElements( env, jarr, NULL );
XP_ASSERT( !!elems );
XP_MEMCPY( elems, vals, count * sizeof(*elems) );
(*env)->ReleaseBooleanArrayElements( env, jarr, elems, 0 );
}
jbooleanArray
makeBooleanArray( JNIEnv *env, int siz, const jboolean* vals )
{
jbooleanArray array = (*env)->NewBooleanArray( env, siz );
XP_ASSERT( !!array );
if ( !!vals ) {
jboolean* elems = (*env)->GetBooleanArrayElements( env, array, NULL );
XP_ASSERT( !!elems );
XP_MEMCPY( elems, vals, siz * sizeof(*elems) );
(*env)->ReleaseBooleanArrayElements( env, array, elems, 0 );
setBoolArray( env, array, siz, vals );
}
return array;
}
@ -351,9 +358,7 @@ jenumFieldToInt( JNIEnv* env, jobject j_gi, const char* field,
XP_ASSERT( !!fid );
jobject jenum = (*env)->GetObjectField( env, j_gi, fid );
XP_ASSERT( !!jenum );
jmethodID mid = getMethodID( env, jenum, "ordinal", "()I" );
jint result = (*env)->CallIntMethod( env, jenum, mid );
jint result = jEnumToInt( env, jenum );
(*env)->DeleteLocalRef( env, clazz );
(*env)->DeleteLocalRef( env, jenum );
@ -398,10 +403,6 @@ intToJEnum( JNIEnv* env, int val, const char* enumSig )
jobject jenum = NULL;
jclass clazz = (*env)->FindClass( env, enumSig );
XP_ASSERT( !!clazz );
/* jmethodID mid = getMethodID( env, clazz, "<init>", "()V" ); */
/* XP_ASSERT( !!mid ); */
/* jenum = (*env)->NewObject( env, clazz, mid ); */
/* XP_ASSERT( !!jenum ); */
char buf[128];
snprintf( buf, sizeof(buf), "()[L%s;", enumSig );
@ -420,6 +421,14 @@ intToJEnum( JNIEnv* env, int val, const char* enumSig )
return jenum;
} /* intToJEnum */
jint
jEnumToInt( JNIEnv* env, jobject jenum )
{
jmethodID mid = getMethodID( env, jenum, "ordinal", "()I" );
XP_ASSERT( !!mid );
return (*env)->CallIntMethod( env, jenum, mid );
}
XWStreamCtxt*
and_empty_stream( MPFORMAL AndGlobals* globals )
{

View file

@ -32,6 +32,8 @@ int getIntFromArray( JNIEnv* env, jintArray arr, bool del );
jbyteArray makeByteArray( JNIEnv* env, int size, const jbyte* vals );
jbooleanArray makeBooleanArray( JNIEnv* env, int size, const jboolean* vals );
void setBoolArray( JNIEnv* env, jbooleanArray jarr, int count,
const jboolean* vals );
jobjectArray makeStringArray( JNIEnv *env, int size, const XP_UCHAR** vals );
jstring streamToJString( MPFORMAL JNIEnv* env, XWStreamCtxt* stream );
@ -49,4 +51,5 @@ jint jenumFieldToInt( JNIEnv* env, jobject j_gi, const char* field,
void intToJenumField( JNIEnv* env, jobject j_gi, int val, const char* field,
const char* fieldSig );
jobject intToJEnum( JNIEnv* env, int val, const char* enumSig );
jint jEnumToInt( JNIEnv* env, jobject jenum );
#endif

View file

@ -698,9 +698,8 @@ Java_org_eehouse_android_xw4_jni_XwJNI_board_1requestHint
&tmpbool );
/* If passed need to do workRemains[0] = tmpbool */
if ( workRemains ) {
jboolean* jelems = (*env)->GetBooleanArrayElements(env, workRemains, NULL );
*jelems = tmpbool;
(*env)->ReleaseBooleanArrayElements( env, workRemains, jelems, 0 );
jboolean jbool = tmpbool;
setBoolArray( env, workRemains, 1, &jbool );
}
XWJNI_END();
return result;
@ -890,6 +889,49 @@ Java_org_eehouse_android_xw4_jni_XwJNI_board_1prefsChanged
return result;
}
JNIEXPORT jint JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_board_1getFocusOwner
( JNIEnv* env, jclass C, jint gamePtr )
{
jint result;
XWJNI_START();
result = board_getFocusOwner( state->game.board );
XWJNI_END();
return result;
}
JNIEXPORT jboolean JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_board_1focusChanged
( JNIEnv* env, jclass C, jint gamePtr, jint typ )
{
jboolean result;
XWJNI_START();
result = board_focusChanged( state->game.board, typ, XP_TRUE );
XWJNI_END();
return result;
}
JNIEXPORT jboolean JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_board_1handleKey
( JNIEnv* env, jclass C, jint gamePtr, jobject jkey, jboolean jup,
jbooleanArray jhandled )
{
jboolean result;
XWJNI_START();
XP_Bool tmpbool;
XP_Key key = jEnumToInt( env, jkey );
if ( jup ) {
result = board_handleKeyUp( state->game.board, key, &tmpbool );
} else {
result = board_handleKeyDown( state->game.board, key, &tmpbool );
}
jboolean jbool = tmpbool;
setBoolArray( env, jhandled, 1, &jbool );
XWJNI_END();
return result;
}
JNIEXPORT jboolean JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_game_1hasComms
( JNIEnv* env, jclass C, jint gamePtr )