diff --git a/xwords4/android/XWords4/jni/drawwrapper.c b/xwords4/android/XWords4/jni/drawwrapper.c index d86a9c03e..2ec44f167 100644 --- a/xwords4/android/XWords4/jni/drawwrapper.c +++ b/xwords4/android/XWords4/jni/drawwrapper.c @@ -33,6 +33,7 @@ typedef struct _AndDraw { JNIEnv** env; jobject jdraw; /* global ref; free it! */ jobject jCache[JCACHE_COUNT]; + XP_UCHAR miniTextBuf[128]; MPSLOT } AndDraw; @@ -404,22 +405,48 @@ and_draw_dictChanged( DrawCtx* dctx, const DictionaryCtxt* dict ) static const XP_UCHAR* and_draw_getMiniWText( DrawCtx* dctx, XWMiniTextType textHint ) { - LOG_FUNC(); - return "hi"; + DRAW_CBK_HEADER( "getMiniWText", "(I)Ljava/lang/String;" ); + jstring jstr = (*env)->CallObjectMethod( env, draw->jdraw, mid, + textHint ); + const char* str = (*env)->GetStringUTFChars( env, jstr, NULL ); + snprintf( draw->miniTextBuf, VSIZE(draw->miniTextBuf), "%s", str ); + (*env)->ReleaseStringUTFChars( env, jstr, str ); + (*env)->DeleteLocalRef( env, jstr ); + return draw->miniTextBuf; } static void and_draw_measureMiniWText( DrawCtx* dctx, const XP_UCHAR* textP, XP_U16* width, XP_U16* height ) { - LOG_FUNC(); + DRAW_CBK_HEADER( "measureMiniWText", "(Ljava/lang/String;[I[I)V" ); + + jintArray widthArray = makeIntArray( env, 1, NULL ); + jintArray heightArray = makeIntArray( env, 1, NULL ); + jstring jstr = (*env)->NewStringUTF( env, textP ); + + (*env)->CallVoidMethod( env, draw->jdraw, mid, + jstr, widthArray, heightArray ); + + (*env)->DeleteLocalRef( env, jstr ); + *width = getIntFromArray( env, widthArray, true ); + *height = getIntFromArray( env, heightArray, true ); } static void and_draw_drawMiniWindow( DrawCtx* dctx, const XP_UCHAR* text, const XP_Rect* rect, void** closure ) { - LOG_FUNC(); + DRAW_CBK_HEADER( "drawMiniWindow", + "(Ljava/lang/String;Landroid/graphics/Rect;)V" ); + + jstring jstr = (*env)->NewStringUTF( env, text ); + jobject jrect = makeJRect( draw, JCACHE_RECT0, rect ); + + (*env)->CallVoidMethod( env, draw->jdraw, mid, + jstr, jrect ); + + (*env)->DeleteLocalRef( env, jstr ); } static XP_Bool diff --git a/xwords4/android/XWords4/res/values/strings.xml b/xwords4/android/XWords4/res/values/strings.xml index b349c3aa8..53fb7a951 100644 --- a/xwords4/android/XWords4/res/values/strings.xml +++ b/xwords4/android/XWords4/res/values/strings.xml @@ -113,7 +113,7 @@ Cumulative score: %d New tiles: %s Passed - + %s:%d %s:%d Lost turn Commit the current move?\n @@ -198,6 +198,7 @@ Triple letter Double word Triple word + Trading tiles.\nSelect \'turn done\' when ready Tile background Focus color Advanced diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardView.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardView.java index 89ae36ca6..ac9d33c38 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardView.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardView.java @@ -20,6 +20,10 @@ import junit.framework.Assert; public class BoardView extends View implements DrawCtx, BoardHandler, SyncedDraw { + private static final int k_miniTextSize = 16; + private static final int k_miniPaddingH = 2; + private static final int k_miniPaddingV = 2; + private Paint m_drawPaint; private Paint m_fillPaint; private Paint m_strokePaint; @@ -433,6 +437,74 @@ public class BoardView extends View implements DrawCtx, BoardHandler, drawCentered( text, rect, null ); } + public String getMiniWText ( int textHint ) + { + int id = 0; + switch( textHint ) { + case BONUS_DOUBLE_LETTER: + id = R.string.bonus_l2x; + break; + case BONUS_DOUBLE_WORD: + id = R.string.bonus_w2x; + break; + case BONUS_TRIPLE_LETTER: + id = R.string.bonus_l3x; + break; + case BONUS_TRIPLE_WORD: + id = R.string.bonus_w3x; + break; + case INTRADE_MW_TEXT: + id = R.string.trading_text; + break; + default: + Assert.fail(); + } + return getResources().getString( id ); + } + + public void measureMiniWText( String str, int[] width, int[] height ) + { + m_fillPaint.setTextSize( k_miniTextSize ); + FontMetricsInt fmi = m_fillPaint.getFontMetricsInt(); + int lineHeight = -fmi.top + fmi.leading; + + String[] lines = str.split("\n"); + height[0] = (lines.length * lineHeight) + (2 * k_miniPaddingV); + + int maxWidth = 0; + for ( String line : lines ) { + m_fillPaint.getTextBounds( line, 0, line.length(), m_boundsScratch ); + int thisWidth = m_boundsScratch.width(); + if ( maxWidth < thisWidth ) { + maxWidth = thisWidth; + } + } + width[0] = maxWidth + (k_miniPaddingH * 2); + } + + public void drawMiniWindow( String text, Rect rect ) + { + clearToBack( rect ); + + m_fillPaint.setTextSize( k_miniTextSize ); + m_fillPaint.setTextAlign( Paint.Align.CENTER ); + m_fillPaint.setColor( BLACK ); + + String[] lines = text.split("\n"); + int lineHt = rect.height() / lines.length; + int bottom = rect.top + lineHt + - m_fillPaint.getFontMetricsInt().descent; + int center = rect.left + (rect.width() / 2); + + for ( String line : lines ) { + m_canvas.drawText( line, center, bottom, m_fillPaint ); + bottom += lineHt; + } + + m_canvas.drawRect( rect, m_strokePaint ); + m_jniThread.handle( JNIThread.JNICmd.CMD_DRAW ); + } + public void objFinished( /*BoardObjectType*/int typ, Rect rect, int dfs ) { if ( DrawCtx.OBJ_SCORE == typ ) { diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/DrawCtx.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/DrawCtx.java index 46a337b39..9463a94f5 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/DrawCtx.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/DrawCtx.java @@ -32,6 +32,7 @@ public interface DrawCtx { void score_drawPlayer( Rect rInner, Rect rOuter, DrawScoreInfo dsi ); void drawTimer( Rect rect, int player, int secondsLeft ); + boolean drawCell( Rect rect, String text, BitmapDrawable[] bitmaps, int tile, int owner, int bonus, int hintAtts, int flags ); void drawBoardArrow ( Rect rect, int bonus, boolean vert, int hintAtts, @@ -46,6 +47,16 @@ public interface DrawCtx { void drawTrayDivider( Rect rect, int flags ); void score_pendingScore( Rect rect, int score, int playerNum, int flags ); + public static final int BONUS_NONE = 0; + public static final int BONUS_DOUBLE_LETTER = 1; + public static final int BONUS_DOUBLE_WORD = 2; + public static final int BONUS_TRIPLE_LETTER = 3; + public static final int BONUS_TRIPLE_WORD = 4; + public static final int INTRADE_MW_TEXT = 5; + String getMiniWText ( int textHint ); + void measureMiniWText( String text, int[] width, int[] height ); + void drawMiniWindow( String text, Rect rect ); + void objFinished( /*BoardObjectType*/int typ, Rect rect, int dfs ); void dictChanged( int dictPtr );