| 213 | } |
| 214 | |
| 215 | GridCell UIGrid::GetGridCellAt(float x, float y, float* clickHeight, float* clickWidth) |
| 216 | { |
| 217 | if (mFlip) |
| 218 | y = (mHeight - 1) - y; |
| 219 | |
| 220 | float xsize = float(mWidth) / mCols; |
| 221 | float ysize = float(mHeight) / mRows; |
| 222 | |
| 223 | int col = ofClamp(x / xsize, 0, mCols - 1); |
| 224 | int row = ofClamp(y / ysize, 0, mRows - 1); |
| 225 | |
| 226 | if (clickHeight) |
| 227 | { |
| 228 | *clickHeight = ofClamp(1 - (y / ysize - ofClamp((int)(y / ysize), 0, mRows - 1)), 0, 1); |
| 229 | if (mFlip) |
| 230 | *clickHeight = 1 - *clickHeight; |
| 231 | } |
| 232 | |
| 233 | if (clickWidth) |
| 234 | { |
| 235 | *clickWidth = ofClamp(x / xsize - ofClamp((int)(x / xsize), 0, mCols - 1), 0, 1); |
| 236 | } |
| 237 | |
| 238 | return GridCell(col, row); |
| 239 | } |
| 240 | |
| 241 | ofVec2f UIGrid::GetCellPosition(int col, int row) |
| 242 | { |