Finds the rectangle at the cursor position. @return focused rectangle
()
| 243 | * @return focused rectangle |
| 244 | */ |
| 245 | private boolean focus() { |
| 246 | if(gui.updating || mainRects == null) return false; |
| 247 | |
| 248 | /* |
| 249 | * Loop through all rectangles. As the rectangles are sorted by PRE order |
| 250 | * and small rectangles are descendants of bigger ones, the focused |
| 251 | * rectangle can be found by simply parsing the array backwards. |
| 252 | */ |
| 253 | int r = mainRects.size; |
| 254 | while(--r >= 0) { |
| 255 | final MapRect rect = mainRects.get(r); |
| 256 | if(rect.contains(mouseX, mouseY)) break; |
| 257 | } |
| 258 | // don't focus top rectangles |
| 259 | final MapRect fr = r >= 0 ? mainRects.get(r) : null; |
| 260 | |
| 261 | // find focused rectangle |
| 262 | final boolean nf = focused != fr || fr != null && fr.thumb; |
| 263 | focused = fr; |
| 264 | |
| 265 | if(nf) gui.notify.focus(focused != null ? focused.pre : -1, this); |
| 266 | return nf; |
| 267 | } |
| 268 | |
| 269 | /** |
| 270 | * Initializes the calculation of the main map. |
no test coverage detected