From 52d02f04ddb17bcafd8625ff415765083413ea54 Mon Sep 17 00:00:00 2001 From: Andy2 Date: Fri, 2 Dec 2011 18:58:52 -0800 Subject: [PATCH] pass tile value into drawCell(). Java code doesn't use it yet, but I want to play with drawing cells tray-tile-style when they're big enough. --- xwords4/android/XWords4/jni/drawwrapper.c | 9 +++++---- .../src/org/eehouse/android/xw4/BoardView.java | 8 +++++--- .../src/org/eehouse/android/xw4/jni/DrawCtx.java | 2 +- xwords4/common/boarddrw.c | 11 +++++++---- xwords4/common/draw.h | 15 ++++++++++----- xwords4/linux/cursesdraw.c | 6 +++--- xwords4/linux/gtkdraw.c | 4 ++-- 7 files changed, 33 insertions(+), 22 deletions(-) diff --git a/xwords4/android/XWords4/jni/drawwrapper.c b/xwords4/android/XWords4/jni/drawwrapper.c index 20c7b6927..ac62259b3 100644 --- a/xwords4/android/XWords4/jni/drawwrapper.c +++ b/xwords4/android/XWords4/jni/drawwrapper.c @@ -232,11 +232,12 @@ and_draw_boardBegin( DrawCtx* dctx, const XP_Rect* rect, static XP_Bool and_draw_drawCell( DrawCtx* dctx, const XP_Rect* rect, const XP_UCHAR* text, - const XP_Bitmaps* bitmaps, Tile tile, XP_S16 owner, - XWBonusType bonus, HintAtts hintAtts, CellFlags flags ) + const XP_Bitmaps* bitmaps, Tile tile, XP_U16 value, + XP_S16 owner, XWBonusType bonus, HintAtts hintAtts, + CellFlags flags ) { DRAW_CBK_HEADER("drawCell", - "(Landroid/graphics/Rect;Ljava/lang/String;IIIII)Z" ); + "(Landroid/graphics/Rect;Ljava/lang/String;IIIIII)Z" ); jobject jrect = makeJRect( draw, JCACHE_RECT0, rect ); jstring jtext = NULL; if ( !!text ) { @@ -247,7 +248,7 @@ and_draw_drawCell( DrawCtx* dctx, const XP_Rect* rect, const XP_UCHAR* text, } jboolean result = (*env)->CallBooleanMethod( env, draw->jdraw, mid, - jrect, jtext, tile, + jrect, jtext, tile, value, owner, bonus, hintAtts, flags ); if ( !!jtext ) { 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 6f7ae697c..ad091a2ff 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardView.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardView.java @@ -529,8 +529,9 @@ public class BoardView extends View implements DrawCtx, BoardHandler, return true; } - public boolean drawCell( final Rect rect, String text, int tile, int owner, - int bonus, int hintAtts, final int flags ) + public boolean drawCell( final Rect rect, String text, int tile, int value, + int owner, int bonus, int hintAtts, + final int flags ) { boolean canDraw = figureFontDims(); if ( canDraw ) { @@ -819,7 +820,8 @@ public class BoardView extends View implements DrawCtx, BoardHandler, if ( val >= 0 ) { if ( null == m_valRect ) { - m_valRect = new Rect( 0, 0, rect.width() / 4, rect.height() / 4 ); + m_valRect = new Rect( 0, 0, rect.width() / 4, + rect.height() / 4 ); m_valRect.inset( 2, 2 ); } m_valRect.offsetTo( rect.right - (rect.width() / 4), 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 41740544f..8148aa3d3 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 @@ -51,7 +51,7 @@ public interface DrawCtx { void drawTimer( Rect rect, int player, int secondsLeft ); boolean boardBegin( Rect rect, int cellWidth, int cellHeight ); - boolean drawCell( Rect rect, String text, int tile, + boolean drawCell( Rect rect, String text, int tile, int value, int owner, int bonus, int hintAtts, int flags ); void drawBoardArrow ( Rect rect, int bonus, boolean vert, int hintAtts, int flags ); diff --git a/xwords4/common/boarddrw.c b/xwords4/common/boarddrw.c index 88570fa13..0bec5e916 100644 --- a/xwords4/common/boarddrw.c +++ b/xwords4/common/boarddrw.c @@ -397,6 +397,7 @@ drawCell( BoardCtxt* board, XP_U16 col, XP_U16 row, XP_Bool skipBlanks ) HintAtts hintAtts; CellFlags flags = CELL_NONE; XP_Bool isOrigin; + XP_U16 value = 0; isEmpty = !model_getTile( model, modelCol, modelRow, showPending, selPlayer, &tile, &isBlank, @@ -416,6 +417,9 @@ drawCell( BoardCtxt* board, XP_U16 col, XP_U16 row, XP_Bool skipBlanks ) } else if ( isBlank && skipBlanks ) { break; } else { + Tile valTile = isBlank? dict_getBlankTile( dict ) : tile; + value = dict_getTileValue( dict, valTile ); + if ( board->showColors ) { owner = (XP_S16)model_getCellOwner( model, modelCol, modelRow ); @@ -424,9 +428,7 @@ drawCell( BoardCtxt* board, XP_U16 col, XP_U16 row, XP_Bool skipBlanks ) invert = showPending? pending : recent; if ( board->showCellValues ) { - Tile valTile = isBlank? dict_getBlankTile( dict ) : tile; - XP_U16 val = dict_getTileValue( dict, valTile ); - XP_SNPRINTF( ch, VSIZE(ch), "%d", val ); + XP_SNPRINTF( ch, VSIZE(ch), "%d", value ); textP = ch; } else { if ( dict_faceIsBitmap( dict, tile ) ) { @@ -458,7 +460,8 @@ drawCell( BoardCtxt* board, XP_U16 col, XP_U16 row, XP_Bool skipBlanks ) #endif success = draw_drawCell( board->draw, &cellRect, textP, bptr, - tile, owner, bonus, hintAtts, flags ); + tile, value, owner, bonus, hintAtts, + flags ); break; } } diff --git a/xwords4/common/draw.h b/xwords4/common/draw.h index d66546bb0..4c63f00b3 100644 --- a/xwords4/common/draw.h +++ b/xwords4/common/draw.h @@ -165,7 +165,7 @@ typedef struct DrawCtxVTable { null */ const XP_UCHAR* text, const XP_Bitmaps* bitmaps, - Tile tile, + Tile tile, XP_U16 value, XP_S16 owner, /* -1 means don't use */ XWBonusType bonus, HintAtts hintAtts, CellFlags flags ); @@ -229,6 +229,8 @@ struct DrawCtx { linked##_draw_##name(dc,(p1),(p2),(p3),(p4),(p5),(p6)) # define CALL_DRAW_NAME8(name,dc,p1,p2,p3,p4,p5,p6,p7,p8) \ linked##_draw_##name(dc,(p1),(p2),(p3),(p4),(p5),(p6),(p7),(p8)) +# define CALL_DRAW_NAME9(name,dc,p1,p2,p3,p4,p5,p6,p7,p8,p9) \ + linked##_draw_##name(dc,(p1),(p2),(p3),(p4),(p5),(p6),(p7),(p8),(p9)) # define CALL_DRAW_NAME10(name,dc,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10) \ linked##_draw_##name(dc,(p1),(p2),(p3),(p4),(p5),(p6),(p7),\ (p8),(p9),(p10)) @@ -246,8 +248,11 @@ struct DrawCtx { # define CALL_DRAW_NAME6(name,dc,p1,p2,p3,p4,p5,p6) \ ((dc)->vtable->m_draw_##name)(dc,(p1),(p2),(p3),(p4),(p5),(p6)) # define CALL_DRAW_NAME8(name,dc,p1,p2,p3,p4,p5,p6,p7,p8) \ - ((dc)->vtable->m_draw_##name)(dc,(p1),(p2),(p3),(p4),(p5),(p6),(p7),\ - (p8)) + ((dc)->vtable->m_draw_##name)(dc,(p1),(p2),(p3),(p4),(p5),(p6),(p7), \ + (p8)) +# define CALL_DRAW_NAME9(name,dc,p1,p2,p3,p4,p5,p6,p7,p8,p9) \ + ((dc)->vtable->m_draw_##name)(dc,(p1),(p2),(p3),(p4),(p5),(p6),(p7), \ + (p8),(p9)) # define CALL_DRAW_NAME10(name,dc,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10) \ ((dc)->vtable->m_draw_##name)(dc,(p1),(p2),(p3),(p4),(p5),(p6),(p7),\ (p8),(p9),(p10)) @@ -277,8 +282,8 @@ struct DrawCtx { CALL_DRAW_NAME4(score_pendingScore,(dc), (r), (s), (p), (f)) #define draw_drawTimer( dc, r, plyr, sec ) \ CALL_DRAW_NAME3(drawTimer,(dc),(r),(plyr),(sec)) -#define draw_drawCell( dc, rect, txt, bmap, t, o, bon, hi, f ) \ - CALL_DRAW_NAME8(drawCell,(dc),(rect),(txt),(bmap),(t),(o),(bon),(hi),\ +#define draw_drawCell( dc, rect, txt, bmap, t, v,o, bon, hi, f ) \ + CALL_DRAW_NAME9(drawCell,(dc),(rect),(txt),(bmap),(t),(v),(o),(bon),(hi), \ (f)) #define draw_invertCell( dc, rect ) CALL_DRAW_NAME1(invertCell,(dc),(rect)) #define draw_drawTile( dc, rect, text, bmp, val, hil ) \ diff --git a/xwords4/linux/cursesdraw.c b/xwords4/linux/cursesdraw.c index b6a35beb6..8ae097bf3 100644 --- a/xwords4/linux/cursesdraw.c +++ b/xwords4/linux/cursesdraw.c @@ -298,9 +298,9 @@ static XP_Bool curses_draw_drawCell( DrawCtx* p_dctx, const XP_Rect* rect, const XP_UCHAR* letter, const XP_Bitmaps* XP_UNUSED(bitmaps), - Tile XP_UNUSED(tile), XP_S16 XP_UNUSED(owner), - XWBonusType bonus, HintAtts XP_UNUSED(hintAtts), - CellFlags flags ) + Tile XP_UNUSED(tile), XP_U16 XP_UNUSED(value), + XP_S16 XP_UNUSED(owner), XWBonusType bonus, + HintAtts XP_UNUSED(hintAtts), CellFlags flags ) { CursesDrawCtx* dctx = (CursesDrawCtx*)p_dctx; XP_Bool highlight = (flags & (CELL_HIGHLIGHT|CELL_ISCURSOR)) != 0; diff --git a/xwords4/linux/gtkdraw.c b/xwords4/linux/gtkdraw.c index 5d8326361..6451b5c15 100644 --- a/xwords4/linux/gtkdraw.c +++ b/xwords4/linux/gtkdraw.c @@ -506,8 +506,8 @@ drawCrosshairs( GtkDrawCtx* dctx, const XP_Rect* rect, CellFlags flags ) static XP_Bool gtk_draw_drawCell( DrawCtx* p_dctx, const XP_Rect* rect, const XP_UCHAR* letter, const XP_Bitmaps* bitmaps, Tile XP_UNUSED(tile), - XP_S16 owner, XWBonusType bonus, HintAtts hintAtts, - CellFlags flags ) + XP_U16 XP_UNUSED(value), XP_S16 owner, XWBonusType bonus, + HintAtts hintAtts, CellFlags flags ) { GtkDrawCtx* dctx = (GtkDrawCtx*)p_dctx; XP_Rect rectInset = *rect;