feat(touch): add press/release detection with touch-down tracking

This commit is contained in:
2026-02-18 13:08:56 -08:00
parent 1961631e2c
commit 9f7a383b38
7 changed files with 166 additions and 41 deletions

View File

@@ -143,6 +143,68 @@ public:
_drv->updateHint(x, y, active);
}
/// Show touch feedback - highlights the tile at given coordinates
/// Returns true if a valid tile is being touched
bool showTouchFeedback(int x, int y) {
if(!_drv || _gridCols <= 0) return false;
// Transform touch coordinates
_drv->transformTouch(&x, &y);
int headerH = 30;
if(y < headerH) return false;
// Calculate which cell
int cellW = _drv->width() / _gridCols;
int cellH = (_drv->height() - headerH) / _gridRows;
int col = x / cellW;
int row = (y - headerH) / cellH;
if(col < 0 || col >= _gridCols || row < 0 || row >= _gridRows)
return false;
// Find which tile is at this position
for(int i = 0; i < _tileCount; i++) {
const TileLayout& lay = _layouts[i];
if(lay.col <= col && col < lay.col + lay.cols &&
lay.row <= row && lay.row + lay.rows > row) {
// Found the tile - draw highlight via driver
_drv->updateHint(lay.x, lay.y, true); // active=true means show feedback
return true;
}
}
return false;
}
/// Clear touch feedback
void clearTouchFeedback() {
if(_drv)
_drv->updateHint(0, 0, false); // active=false means clear
}
/// Check if current position is still in same tile as touch-down
bool isSameTile(int downX, int downY, int currentX, int currentY) const {
if(!_drv || _gridCols <= 0 || downX < 0) return false;
int dx = downX, dy = downY;
int cx = currentX, cy = currentY;
_drv->transformTouch(&dx, &dy);
_drv->transformTouch(&cx, &cy);
int headerH = 30;
int cellW = _drv->width() / _gridCols;
int cellH = (_drv->height() - headerH) / _gridRows;
int downCol = dx / cellW;
int downRow = (dy - headerH) / cellH;
int curCol = cx / cellW;
int curRow = (cy - headerH) / cellH;
return downCol == curCol && downRow == curRow;
}
int width() { return _drv ? _drv->width() : 0; }
int height() { return _drv ? _drv->height() : 0; }