Coherent UI provides very precise information whether the mouse pointer is over a view. In the case of view used as a HUD, the view may occupy the entire window of the game, but only not transparent (above a predefined threshold) parts are considered part of the view. Mouse queries are supported only for transparent views (created with Coherent::UI::ViewInfo::IsTransparent
set to true). For opaque views the query will always return false. Queries can also be disabled via the Coherent::UI::ViewInfo::SupportClickThrough
flag even on transparent views and this results in slightly increased performance.
Implementing proper click through for a HUD view consists of the following steps:
Coherent::UI::View::IssueMouseOnUIQuery
with the current mouse position.Coherent::UI::View::FetchMouseOnUIQuery
to wait for the result of the query. This is a blocking call, therefore it is important to have as many as possible computations between the two calls.Coherent::UI::View::IsMouseOnView
to get whether the mouse is on part of the view with alpha above the currently set alpha threshold.To change the alpha threshold use Coherent::UI::View::SetClickThroughAlphaThreshold
.
In order to minimize the impact on the performance of client's application, all mouse queries are asynchronous in Coherent UI. The user should strive to put as much computations between the calls to Coherent::UI::View::IssueMouseOnUIQuery
and Coherent::UI::View::FetchMouseOnUIQuery
as possible, in this way the overhead of the call can become virtually zero. Calling Coherent::UI::View::IsMouseOnView
while a query is in-flight produces a warning and the result returned in undefined. Every valid call to Coherent::UI::View::IsMouseOnView
returns the result of the last successful query. Calling Coherent::UI::View::FetchSurfaces
while there is an unfinished query might also result in wrong results.