mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-09 22:00:39 +01:00
invalCellsUnderRect didn't work for rects not intersecting board; fix.
This commit is contained in:
parent
8e2e71a3b7
commit
23b07772c0
2 changed files with 29 additions and 26 deletions
|
@ -1126,21 +1126,23 @@ board_setTrayLoc( BoardCtxt* board, XP_U16 trayLeft, XP_U16 trayTop,
|
||||||
void
|
void
|
||||||
invalCellsUnderRect( BoardCtxt* board, const XP_Rect* rect )
|
invalCellsUnderRect( BoardCtxt* board, const XP_Rect* rect )
|
||||||
{
|
{
|
||||||
XP_Rect lr = *rect;
|
if ( rectsIntersect( rect, &board->boardBounds ) ) {
|
||||||
XP_U16 left, top, right, bottom;
|
XP_Rect lr = *rect;
|
||||||
XP_U16 col, row;
|
XP_U16 left, top, right, bottom;
|
||||||
|
XP_U16 col, row;
|
||||||
|
|
||||||
if ( !coordToCell( board, lr.left, lr.top, &left, &top ) ) {
|
if ( !coordToCell( board, lr.left, lr.top, &left, &top ) ) {
|
||||||
left = top = 0;
|
left = top = 0;
|
||||||
}
|
}
|
||||||
if ( !coordToCell( board, lr.left+lr.width, lr.top+lr.height,
|
if ( !coordToCell( board, lr.left+lr.width, lr.top+lr.height,
|
||||||
&right, &bottom ) ) {
|
&right, &bottom ) ) {
|
||||||
right = bottom = model_numCols( board->model );
|
right = bottom = model_numCols( board->model );
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( row = top; row <= bottom; ++row ) {
|
for ( row = top; row <= bottom; ++row ) {
|
||||||
for ( col = left; col <= right; ++col ) {
|
for ( col = left; col <= right; ++col ) {
|
||||||
invalCell( board, col, row );
|
invalCell( board, col, row );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} /* invalCellsUnderRect */
|
} /* invalCellsUnderRect */
|
||||||
|
@ -1554,18 +1556,19 @@ figureBoardRect( BoardCtxt* board )
|
||||||
} /* figureBoardRect */
|
} /* figureBoardRect */
|
||||||
|
|
||||||
XP_Bool
|
XP_Bool
|
||||||
coordToCell( BoardCtxt* board, XP_U16 x, XP_U16 y, XP_U16* colP, XP_U16* rowP )
|
coordToCell( BoardCtxt* board, XP_S16 xx, XP_S16 yy, XP_U16* colP,
|
||||||
|
XP_U16* rowP )
|
||||||
{
|
{
|
||||||
XP_U16 col, row, max;
|
XP_U16 col, row, max;
|
||||||
XP_Bool onBoard = XP_TRUE;
|
XP_Bool onBoard = XP_TRUE;
|
||||||
|
|
||||||
x -= board->boardBounds.left;
|
xx -= board->boardBounds.left;
|
||||||
|
|
||||||
y -= board->boardBounds.top;
|
yy -= board->boardBounds.top;
|
||||||
y += board->boardVScale * board->yOffset;
|
yy += board->boardVScale * board->yOffset;
|
||||||
|
|
||||||
col = x / board->boardHScale;
|
col = xx / board->boardHScale;
|
||||||
row = y / board->boardVScale;
|
row = yy / board->boardVScale;
|
||||||
|
|
||||||
max = model_numCols( board->model ) - 1;
|
max = model_numCols( board->model ) - 1;
|
||||||
/* I don't deal with non-square boards yet. */
|
/* I don't deal with non-square boards yet. */
|
||||||
|
@ -2710,17 +2713,17 @@ rectContainsPt( const XP_Rect* rect, XP_S16 x, XP_S16 y )
|
||||||
XP_Bool
|
XP_Bool
|
||||||
rectsIntersect( const XP_Rect* rect1, const XP_Rect* rect2 )
|
rectsIntersect( const XP_Rect* rect1, const XP_Rect* rect2 )
|
||||||
{
|
{
|
||||||
|
XP_Bool intersect = XP_TRUE;
|
||||||
if ( rect1->top >= rect2->top + rect2->height ) {
|
if ( rect1->top >= rect2->top + rect2->height ) {
|
||||||
return XP_FALSE;
|
intersect = XP_FALSE;
|
||||||
} else if ( rect1->left >= rect2->left + rect2->width ) {
|
} else if ( rect1->left >= rect2->left + rect2->width ) {
|
||||||
return XP_FALSE;
|
intersect = XP_FALSE;
|
||||||
} else if ( rect2->top >= rect1->top + rect1->height ) {
|
} else if ( rect2->top >= rect1->top + rect1->height ) {
|
||||||
return XP_FALSE;
|
intersect = XP_FALSE;
|
||||||
} else if ( rect2->left >= rect1->left + rect1->width ) {
|
} else if ( rect2->left >= rect1->left + rect1->width ) {
|
||||||
return XP_FALSE;
|
intersect = XP_FALSE;
|
||||||
} else {
|
|
||||||
return XP_TRUE;
|
|
||||||
}
|
}
|
||||||
|
return intersect;
|
||||||
} /* rectsIntersect */
|
} /* rectsIntersect */
|
||||||
|
|
||||||
static XP_Bool
|
static XP_Bool
|
||||||
|
|
|
@ -233,7 +233,7 @@ void flipIf( const BoardCtxt* board, XP_U16 col, XP_U16 row,
|
||||||
XP_U16* fCol, XP_U16* fRow );
|
XP_U16* fCol, XP_U16* fRow );
|
||||||
XP_Bool pointOnSomething( BoardCtxt* board, XP_U16 x, XP_U16 y,
|
XP_Bool pointOnSomething( BoardCtxt* board, XP_U16 x, XP_U16 y,
|
||||||
BoardObjectType* wp );
|
BoardObjectType* wp );
|
||||||
XP_Bool coordToCell( BoardCtxt* board, XP_U16 x, XP_U16 y, XP_U16* colP,
|
XP_Bool coordToCell( BoardCtxt* board, XP_S16 xx, XP_S16 yy, XP_U16* colP,
|
||||||
XP_U16* rowP );
|
XP_U16* rowP );
|
||||||
XP_Bool cellOccupied( const BoardCtxt* board, XP_U16 col, XP_U16 row,
|
XP_Bool cellOccupied( const BoardCtxt* board, XP_U16 col, XP_U16 row,
|
||||||
XP_Bool inclPending );
|
XP_Bool inclPending );
|
||||||
|
|
Loading…
Add table
Reference in a new issue