mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-02 06:20:14 +01:00
implement mini window, jni and java rendering. Works on emulator, but
may not work as well under fat fingers....
This commit is contained in:
parent
a18470e4a2
commit
7d0bd9d50c
4 changed files with 116 additions and 5 deletions
|
@ -33,6 +33,7 @@ typedef struct _AndDraw {
|
||||||
JNIEnv** env;
|
JNIEnv** env;
|
||||||
jobject jdraw; /* global ref; free it! */
|
jobject jdraw; /* global ref; free it! */
|
||||||
jobject jCache[JCACHE_COUNT];
|
jobject jCache[JCACHE_COUNT];
|
||||||
|
XP_UCHAR miniTextBuf[128];
|
||||||
MPSLOT
|
MPSLOT
|
||||||
} AndDraw;
|
} AndDraw;
|
||||||
|
|
||||||
|
@ -404,22 +405,48 @@ and_draw_dictChanged( DrawCtx* dctx, const DictionaryCtxt* dict )
|
||||||
static const XP_UCHAR*
|
static const XP_UCHAR*
|
||||||
and_draw_getMiniWText( DrawCtx* dctx, XWMiniTextType textHint )
|
and_draw_getMiniWText( DrawCtx* dctx, XWMiniTextType textHint )
|
||||||
{
|
{
|
||||||
LOG_FUNC();
|
DRAW_CBK_HEADER( "getMiniWText", "(I)Ljava/lang/String;" );
|
||||||
return "hi";
|
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
|
static void
|
||||||
and_draw_measureMiniWText( DrawCtx* dctx, const XP_UCHAR* textP,
|
and_draw_measureMiniWText( DrawCtx* dctx, const XP_UCHAR* textP,
|
||||||
XP_U16* width, XP_U16* height )
|
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
|
static void
|
||||||
and_draw_drawMiniWindow( DrawCtx* dctx, const XP_UCHAR* text,
|
and_draw_drawMiniWindow( DrawCtx* dctx, const XP_UCHAR* text,
|
||||||
const XP_Rect* rect, void** closure )
|
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
|
static XP_Bool
|
||||||
|
|
|
@ -113,7 +113,7 @@
|
||||||
<string name="strd_cumulative_score">Cumulative score: %d</string>
|
<string name="strd_cumulative_score">Cumulative score: %d</string>
|
||||||
<string name="strs_new_tiles">New tiles: %s</string>
|
<string name="strs_new_tiles">New tiles: %s</string>
|
||||||
<string name="str_passed">Passed</string>
|
<string name="str_passed">Passed</string>
|
||||||
<string name="strsd_summaryscored"></string>
|
<string name="strsd_summaryscored">%s:%d</string>
|
||||||
<string name="strd_traded">%s:%d</string>
|
<string name="strd_traded">%s:%d</string>
|
||||||
<string name="str_lostturn">Lost turn</string>
|
<string name="str_lostturn">Lost turn</string>
|
||||||
<string name="str_commit_confirm">Commit the current move?\n</string>
|
<string name="str_commit_confirm">Commit the current move?\n</string>
|
||||||
|
@ -198,6 +198,7 @@
|
||||||
<string name="bonus_l3x">Triple letter</string>
|
<string name="bonus_l3x">Triple letter</string>
|
||||||
<string name="bonus_w2x">Double word</string>
|
<string name="bonus_w2x">Double word</string>
|
||||||
<string name="bonus_w3x">Triple word</string>
|
<string name="bonus_w3x">Triple word</string>
|
||||||
|
<string name="trading_text">Trading tiles.\nSelect \'turn done\' when ready</string>
|
||||||
<string name="tile_back">Tile background</string>
|
<string name="tile_back">Tile background</string>
|
||||||
<string name="focus">Focus color</string>
|
<string name="focus">Focus color</string>
|
||||||
<string name="advanced">Advanced</string>
|
<string name="advanced">Advanced</string>
|
||||||
|
|
|
@ -20,6 +20,10 @@ import junit.framework.Assert;
|
||||||
|
|
||||||
public class BoardView extends View implements DrawCtx, BoardHandler,
|
public class BoardView extends View implements DrawCtx, BoardHandler,
|
||||||
SyncedDraw {
|
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_drawPaint;
|
||||||
private Paint m_fillPaint;
|
private Paint m_fillPaint;
|
||||||
private Paint m_strokePaint;
|
private Paint m_strokePaint;
|
||||||
|
@ -433,6 +437,74 @@ public class BoardView extends View implements DrawCtx, BoardHandler,
|
||||||
drawCentered( text, rect, null );
|
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 )
|
public void objFinished( /*BoardObjectType*/int typ, Rect rect, int dfs )
|
||||||
{
|
{
|
||||||
if ( DrawCtx.OBJ_SCORE == typ ) {
|
if ( DrawCtx.OBJ_SCORE == typ ) {
|
||||||
|
|
|
@ -32,6 +32,7 @@ public interface DrawCtx {
|
||||||
void score_drawPlayer( Rect rInner, Rect rOuter, DrawScoreInfo dsi );
|
void score_drawPlayer( Rect rInner, Rect rOuter, DrawScoreInfo dsi );
|
||||||
void drawTimer( Rect rect, int player, int secondsLeft );
|
void drawTimer( Rect rect, int player, int secondsLeft );
|
||||||
|
|
||||||
|
|
||||||
boolean drawCell( Rect rect, String text, BitmapDrawable[] bitmaps, int tile,
|
boolean drawCell( Rect rect, String text, BitmapDrawable[] bitmaps, int tile,
|
||||||
int owner, int bonus, int hintAtts, int flags );
|
int owner, int bonus, int hintAtts, int flags );
|
||||||
void drawBoardArrow ( Rect rect, int bonus, boolean vert, int hintAtts,
|
void drawBoardArrow ( Rect rect, int bonus, boolean vert, int hintAtts,
|
||||||
|
@ -46,6 +47,16 @@ public interface DrawCtx {
|
||||||
void drawTrayDivider( Rect rect, int flags );
|
void drawTrayDivider( Rect rect, int flags );
|
||||||
void score_pendingScore( Rect rect, int score, int playerNum, 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 objFinished( /*BoardObjectType*/int typ, Rect rect, int dfs );
|
||||||
|
|
||||||
void dictChanged( int dictPtr );
|
void dictChanged( int dictPtr );
|
||||||
|
|
Loading…
Reference in a new issue