3 ms·
A related question, how do GUIs actually resolve quickly on which element under the cursor a click lands? How is the click propagated recursively through every
by protoman3000 6y ago
A related question, how do GUIs actually resolve quickly on which element under the cursor a click lands?
How is the click propagated recursively through every component and is the position compared repeatedly at every step?
- pixel_tracing 6y agoI believe this can be resolved using a quad tree to resolve point locations and map them to a view in a view hierarchy
- badsectoracula 6y agoThey just enumerate all child windows, these events are not frequent enough for this to be a performance bottleneck. The check is something along the lines of Win* GetChildAt(Win* w, int x, int y) { size_t i; if (x >= w->ScreenX1 && y >= w->ScreenY1 && x <= w->ScreenX2 && y <= w->ScreenY2) { for (i=0; i < w->ChildCount; i++) { Win* child = GetChildAt(w->Child[i], x, y); if (child) return child; } return w; } return NULL; } Call this on the root window and you have the deepest child at the given coordinates. (though there is usually a bit extra logic for handling, e.g., invisible and disabled windows)