-
Notifications
You must be signed in to change notification settings - Fork 416
/
Copy pathPopupOverlay.windows.cs
52 lines (43 loc) · 1.4 KB
/
PopupOverlay.windows.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
namespace CommunityToolkit.Maui.Core.Views;
/// <summary>
/// Displays Overlay in the Popup background.
/// </summary>
class PopupOverlay : WindowOverlay
{
readonly IWindowOverlayElement popupOverlayElement;
/// <summary>
/// Instantiates a new instance of <see cref="PopupOverlay"/>.
/// </summary>
/// <param name="window">An instance of <see cref="IWindow"/>.</param>
/// <param name="overlayColor">Popup overlay color</param>
public PopupOverlay(IWindow window, Color? overlayColor = null) : base(window)
{
popupOverlayElement = new PopupOverlayElement(this, overlayColor);
AddWindowElement(popupOverlayElement);
EnableDrawableTouchHandling = true;
}
class PopupOverlayElement : IWindowOverlayElement
{
readonly IWindowOverlay overlay;
readonly Color overlayColor = Color.FromRgba(255, 255, 255, 153); // 60% Opacity
RectF overlayRect = new();
public PopupOverlayElement(IWindowOverlay overlay, Color? overlayColor = null)
{
this.overlay = overlay;
if (overlayColor is not null)
{
this.overlayColor = overlayColor;
}
}
public bool Contains(Point point)
{
return overlayRect.Contains(new Point(point.X / overlay.Density, point.Y / overlay.Density));
}
public void Draw(ICanvas canvas, RectF dirtyRect)
{
overlayRect = dirtyRect;
canvas.FillColor = overlayColor;
canvas.FillRectangle(dirtyRect.X, dirtyRect.Y, dirtyRect.Width, dirtyRect.Height);
}
}
}