From 09bc83429e45ec77def81d14bdb73d41bcae0766 Mon Sep 17 00:00:00 2001 From: Andy2 Date: Wed, 11 Aug 2010 18:50:16 -0700 Subject: [PATCH 1/4] add and set new flags for crosshairs so platforms can do better than fill cells as is done for focus. --- xwords4/common/boarddrw.c | 29 +++++++++++++++++++++-------- xwords4/common/dragdrpp.c | 16 +++++++++------- xwords4/common/dragdrpp.h | 4 +++- xwords4/common/draw.h | 4 +++- 4 files changed, 36 insertions(+), 17 deletions(-) diff --git a/xwords4/common/boarddrw.c b/xwords4/common/boarddrw.c index 0a9480adf..aa0873044 100644 --- a/xwords4/common/boarddrw.c +++ b/xwords4/common/boarddrw.c @@ -231,6 +231,23 @@ makeMiniWindowForTrade( BoardCtxt* board ) makeMiniWindowForText( board, text, MINIWINDOW_TRADING ); } /* makeMiniWindowForTrade */ +#ifdef XWFEATURE_CROSSHAIRS +static CellFlags +flagsForCrosshairs( const BoardCtxt* board, XP_U16 col, XP_U16 row ) +{ + CellFlags flags = 0; + XP_Bool inHor, inVert; + dragDropInCrosshairs( board, col, row, &inHor, &inVert ); + if ( inHor ) { + flags |= CELL_CROSSHOR; + } + if ( inVert ) { + flags |= CELL_CROSSVERT; + } + return flags; +} +#endif + static void drawBoard( BoardCtxt* board ) { @@ -310,16 +327,14 @@ drawBoard( BoardCtxt* board ) CellFlags flags = CELL_NONE; bonus = util_getSquareBonus( board->util, model, col, row ); hintAtts = figureHintAtts( board, col, row ); - if ( 0 ) { #ifdef KEYBOARD_NAV - } else if ( cellFocused( board, col, row ) ) { + if ( cellFocused( board, col, row ) ) { flags |= CELL_ISCURSOR; + } #endif #ifdef XWFEATURE_CROSSHAIRS - } else if ( dragDropInCrosshairs( board, col, row ) ) { - flags |= CELL_ISCURSOR; + flags |= flagsForCrosshairs( board, col, row ); #endif - } draw_drawBoardArrow( board->draw, &arrowRect, bonus, arrow->vert, hintAtts, flags ); @@ -433,9 +448,7 @@ drawCell( BoardCtxt* board, XP_U16 col, XP_U16 row, XP_Bool skipBlanks ) } #endif #ifdef XWFEATURE_CROSSHAIRS - if ( dragDropInCrosshairs( board, col, row ) ) { - flags |= CELL_ISCURSOR; - } + flags |= flagsForCrosshairs( board, col, row ); #endif success = draw_drawCell( board->draw, &cellRect, textP, bptr, diff --git a/xwords4/common/dragdrpp.c b/xwords4/common/dragdrpp.c index 92a39686b..7bdad2e73 100644 --- a/xwords4/common/dragdrpp.c +++ b/xwords4/common/dragdrpp.c @@ -659,16 +659,18 @@ startScrollTimerIf( BoardCtxt* board ) } /* startScrollTimerIf */ #ifdef XWFEATURE_CROSSHAIRS -XP_Bool -dragDropInCrosshairs( const BoardCtxt* board, XP_U16 col, XP_U16 row ) +void +dragDropInCrosshairs( const BoardCtxt* board, XP_U16 col, XP_U16 row, + XP_Bool* inHor, XP_Bool* inVert ) { - XP_Bool result = dragDropInProgress( board ); - if ( result ) { + + if ( dragDropInProgress( board ) ) { const DragState* ds = &board->dragState; - result = ds->crosshairs.col == col - || ds->crosshairs.row == row; + *inHor = ds->crosshairs.row == row; + *inVert = ds->crosshairs.col == col; + } else { + *inHor = *inVert = XP_FALSE; } - return result; } /* dragDropInCrosshairs */ static void diff --git a/xwords4/common/dragdrpp.h b/xwords4/common/dragdrpp.h index 73f3368c4..e93de9de0 100644 --- a/xwords4/common/dragdrpp.h +++ b/xwords4/common/dragdrpp.h @@ -58,7 +58,9 @@ XP_Bool dragDropGetHintLimits( const BoardCtxt* board, BdHintLimits* limits ); void dragDropTileInfo( const BoardCtxt* board, Tile* tile, XP_Bool* isBlank ); #ifdef XWFEATURE_CROSSHAIRS -XP_Bool dragDropInCrosshairs( const BoardCtxt* board, XP_U16 col, XP_U16 row ); +void dragDropInCrosshairs( const BoardCtxt* board, XP_U16 col, XP_U16 row, + XP_Bool* inHor, XP_Bool* inVert ); + #endif #ifdef CPLUS diff --git a/xwords4/common/draw.h b/xwords4/common/draw.h index cf2ade55d..10774614a 100644 --- a/xwords4/common/draw.h +++ b/xwords4/common/draw.h @@ -41,7 +41,9 @@ typedef enum { , CELL_VALHIDDEN = 0x20 /* show letter only, not value */ , CELL_DRAGSRC = 0x40 /* where drag originated */ , CELL_DRAGCUR = 0x80 /* where drag is now */ - , CELL_ALL = 0xFF + , CELL_CROSSVERT = 0x100 /* vertical component of crosshair */ + , CELL_CROSSHOR = 0x200 /* horizontal component of crosshair */ + , CELL_ALL = 0x3FF } CellFlags; typedef struct DrawScoreInfo { From 2d69d8f2b0f84cbc48ca20a19781eb6fa1593599 Mon Sep 17 00:00:00 2001 From: Andy2 Date: Wed, 11 Aug 2010 18:51:09 -0700 Subject: [PATCH 2/4] use new crosshairs flags to draw a cross in the middle third of cells --- xwords4/linux/gtkdraw.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/xwords4/linux/gtkdraw.c b/xwords4/linux/gtkdraw.c index a236079ad..b8c34cfae 100644 --- a/xwords4/linux/gtkdraw.c +++ b/xwords4/linux/gtkdraw.c @@ -420,6 +420,28 @@ drawHintBorders( GtkDrawCtx* dctx, const XP_Rect* rect, HintAtts hintAtts) } } +#ifdef XWFEATURE_CROSSHAIRS +static void +drawCrosshairs( GtkDrawCtx* dctx, const XP_Rect* rect, CellFlags flags ) +{ + XP_Rect hairRect; + if ( 0 != (flags & CELL_CROSSHOR) ) { + hairRect = *rect; + hairRect.height /= 3; + hairRect.top += hairRect.height; + gtkFillRect( dctx, &hairRect, &dctx->cursor ); + } + if ( 0 != (flags & CELL_CROSSVERT) ) { + hairRect = *rect; + hairRect.width /= 3; + hairRect.left += hairRect.width; + gtkFillRect( dctx, &hairRect, &dctx->cursor ); + } +} +#else +# define drawCrosshairs( a, b, c ) +#endif + 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), @@ -504,6 +526,7 @@ gtk_draw_drawCell( DrawCtx* p_dctx, const XP_Rect* rect, const XP_UCHAR* letter, } drawHintBorders( dctx, rect, hintAtts ); + drawCrosshairs( dctx, rect, flags ); return XP_TRUE; } /* gtk_draw_drawCell */ From d44b08b60985140928b7468cac3cd69313bba5fa Mon Sep 17 00:00:00 2001 From: Andy2 Date: Wed, 11 Aug 2010 18:51:33 -0700 Subject: [PATCH 3/4] remove unused and confusing duplicate flags. --- .../org/eehouse/android/xw4/jni/DrawScoreInfo.java | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/DrawScoreInfo.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/DrawScoreInfo.java index d5bdeeb7d..2c6f9a830 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/DrawScoreInfo.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/DrawScoreInfo.java @@ -20,20 +20,6 @@ package org.eehouse.android.xw4.jni; public class DrawScoreInfo { - - public static final int CELL_NONE = 0x00; - public static final int CELL_ISBLANK = 0x01; - public static final int CELL_HIGHLIGHT = 0x02; - public static final int CELL_ISSTAR = 0x04; - public static final int CELL_ISCURSOR = 0x08; - public static final int CELL_ISEMPTY = 0x10; /* of a tray tile slot */ - public static final int CELL_VALHIDDEN = 0x20; /* show letter only, not value */ - public static final int CELL_DRAGSRC = 0x40; /* where drag originated */ - public static final int CELL_DRAGCUR = 0x80; /* where drag is now */ - public static final int CELL_ALL = 0xFF; - - // LastScoreCallback lsc; - // void* lscClosure; public String name; public int playerNum; public int totalScore; From ac022ea5a58760e304c39333dd75ba9d000c6a18 Mon Sep 17 00:00:00 2001 From: Andy2 Date: Wed, 11 Aug 2010 18:53:12 -0700 Subject: [PATCH 4/4] add java version of new crosshairs flags; draw crosshairs 1/3 width/height of cells instead of reusing focus code to color background. --- .../org/eehouse/android/xw4/BoardView.java | 21 +++++++++++++++++-- .../org/eehouse/android/xw4/jni/DrawCtx.java | 4 +++- 2 files changed, 22 insertions(+), 3 deletions(-) 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 a088c1651..4c501e6e0 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardView.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardView.java @@ -445,8 +445,8 @@ public class BoardView extends View implements DrawCtx, BoardHandler, } } - public boolean drawCell( Rect rect, String text, int tile, int owner, - int bonus, int hintAtts, int flags ) + public boolean drawCell( final Rect rect, String text, int tile, int owner, + int bonus, int hintAtts, final int flags ) { int backColor; boolean empty = 0 != (flags & (CELL_DRAGSRC|CELL_ISEMPTY)); @@ -500,6 +500,8 @@ public class BoardView extends View implements DrawCtx, BoardHandler, } // frame the cell m_canvas.drawRect( rect, m_strokePaint ); + + drawCrosshairs( rect, flags ); return true; } // drawCell @@ -779,6 +781,21 @@ public class BoardView extends View implements DrawCtx, BoardHandler, } } + private void drawCrosshairs( final Rect rect, final int flags ) + { + int color = m_otherColors[CommonPrefs.COLOR_FOCUS]; + if ( 0 != (flags & CELL_CROSSHOR) ) { + Rect hairRect = new Rect( rect ); + hairRect.inset( 0, hairRect.height() / 3 ); + fillRect( hairRect, color ); + } + if ( 0 != (flags & CELL_CROSSVERT) ) { + Rect hairRect = new Rect( rect ); + hairRect.inset( hairRect.width() / 3, 0 ); + fillRect( hairRect, color ); + } + } + private void fillRect( Rect rect, int color ) { m_fillPaint.setColor( color ); 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 098479507..3ec984e5d 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 @@ -31,7 +31,9 @@ public interface DrawCtx { static final int CELL_VALHIDDEN = 0x20; /* show letter only, not value */ static final int CELL_DRAGSRC = 0x40; /* where drag originated */ static final int CELL_DRAGCUR = 0x80; /* where drag is now */ - static final int CELL_ALL = 0xFF; + static final int CELL_CROSSVERT = 0x100; + static final int CELL_CROSSHOR = 0x200; + static final int CELL_ALL = 0x3FF; /* BoardObjectType */ static final int OBJ_NONE = 0;