add board_getActiveRect to jni, and use it to capture a thumbnail

that's smaller.  Scaling is still a problem, though: some but not all
grid lines show up.
This commit is contained in:
Eric House 2013-10-29 07:51:35 -07:00
parent 26f5a0b269
commit 0960e5510c
5 changed files with 59 additions and 7 deletions

View file

@ -275,13 +275,25 @@ getIntFromArray( JNIEnv* env, jintArray arr, bool del )
{ {
jint* ints = (*env)->GetIntArrayElements(env, arr, 0); jint* ints = (*env)->GetIntArrayElements(env, arr, 0);
int result = ints[0]; int result = ints[0];
(*env)->ReleaseIntArrayElements( env, arr, ints, 0); (*env)->ReleaseIntArrayElements( env, arr, ints, 0 );
if ( del ) { if ( del ) {
deleteLocalRef( env, arr ); deleteLocalRef( env, arr );
} }
return result; return result;
} }
void
setIntInArray( JNIEnv* env, jintArray arr, int index, int val )
{
jint* ints = (*env)->GetIntArrayElements( env, arr, 0 );
#ifdef DEBUG
jsize len = (*env)->GetArrayLength( env, arr );
XP_ASSERT( len > index );
#endif
ints[index] = val;
(*env)->ReleaseIntArrayElements( env, arr, ints, 0 );
}
jobjectArray jobjectArray
makeStringArray( JNIEnv *env, int siz, const XP_UCHAR** vals ) makeStringArray( JNIEnv *env, int siz, const XP_UCHAR** vals )
{ {

View file

@ -48,6 +48,7 @@ bool getObject( JNIEnv* env, jobject obj, const char* name, const char* sig,
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 ); int getIntFromArray( JNIEnv* env, jintArray arr, bool del );
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

@ -640,6 +640,29 @@ Java_org_eehouse_android_xw4_jni_XwJNI_board_1setTrayLoc
XWJNI_END(); XWJNI_END();
} }
#ifdef XWFEATURE_ACTIVERECT
JNIEXPORT jboolean JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_board_1getActiveRect
( JNIEnv* env, jclass C, jint gamePtr, jobject jrect, jintArray dims )
{
jboolean result;
XWJNI_START();
XP_Rect rect;
XP_U16 nCols, nRows;
result = board_getActiveRect( state->game.board, &rect, &nCols, &nRows );
if ( result ) {
setInt( env, jrect, "left", rect.left );
setInt( env, jrect, "top", rect.top );
setInt( env, jrect, "right", rect.left + rect.width );
setInt( env, jrect, "bottom", rect.top + rect.height );
setIntInArray( env, dims, 0, nCols );
setIntInArray( env, dims, 1, nRows );
}
XWJNI_END();
return result;
}
#endif
JNIEXPORT jboolean JNICALL JNIEXPORT jboolean JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_board_1handlePenDown Java_org_eehouse_android_xw4_jni_XwJNI_board_1handlePenDown
(JNIEnv *env, jclass C, jint gamePtr, jint xx, jint yy, jbooleanArray barray ) (JNIEnv *env, jclass C, jint gamePtr, jint xx, jint yy, jbooleanArray barray )

View file

@ -940,12 +940,23 @@ public class BoardView extends View implements DrawCtx, BoardHandler,
public Bitmap getScaledBoard() public Bitmap getScaledBoard()
{ {
Bitmap result = null; Bitmap result = null;
int divisor = XWPrefs.getThumbScale( m_context ); if ( GitVersion.THUMBNAIL_SUPPORTED ) {
if ( 0 < divisor ) { int divisor = XWPrefs.getThumbScale( m_context );
result = Bitmap.createScaledBitmap( s_bitmap,
m_layoutWidth / divisor, if ( 0 < divisor ) {
m_layoutHeight / divisor, int[] dims = new int[2];
false ); Rect rect = new Rect();
XwJNI.board_getActiveRect( m_jniGamePtr, rect, dims );
Bitmap tmpb =
Bitmap.createBitmap( s_bitmap, rect.left, rect.top,
1 + rect.width(), 1 + rect.height() );
result = Bitmap.createScaledBitmap( tmpb,
rect.width() / divisor,
rect.height() / divisor,
false );
}
} }
return result; return result;
} }

View file

@ -20,6 +20,9 @@
package org.eehouse.android.xw4.jni; package org.eehouse.android.xw4.jni;
import android.graphics.Rect;
// Collection of native methods // Collection of native methods
public class XwJNI { public class XwJNI {
@ -159,6 +162,8 @@ public class XwJNI {
public static native void board_setTimerLoc( int gamePtr, public static native void board_setTimerLoc( int gamePtr,
int timerLeft, int timerTop, int timerLeft, int timerTop,
int timerWidth, int timerHeight ); int timerWidth, int timerHeight );
public static native boolean board_getActiveRect( int gamePtr, Rect rect,
int[] dims );
public static native boolean board_handlePenDown( int gamePtr, public static native boolean board_handlePenDown( int gamePtr,
int xx, int yy, int xx, int yy,