mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 06:37:43 +00:00
WindowServer: Add support for alpha channel based hit testing
This enables implementing non-rectangular window shapes, including non-rectangular window frames.
This commit is contained in:
parent
b3f0a5c917
commit
d590e0c946
12 changed files with 107 additions and 12 deletions
|
@ -873,4 +873,20 @@ bool Window::is_descendant_of(Window& window) const
|
|||
return false;
|
||||
}
|
||||
|
||||
bool Window::hit_test(const Gfx::IntPoint& point, bool include_frame) const
|
||||
{
|
||||
if (!frame().rect().contains(point))
|
||||
return false;
|
||||
if (!rect().contains(point)) {
|
||||
if (include_frame)
|
||||
return frame().hit_test(point);
|
||||
return false;
|
||||
}
|
||||
u8 threshold = alpha_hit_threshold() * 255;
|
||||
if (threshold == 0 || !m_backing_store || !m_backing_store->has_alpha_channel())
|
||||
return true;
|
||||
auto color = m_backing_store->get_pixel(point.translated(-rect().location()));
|
||||
return color.alpha() >= threshold;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue