Skip to content

Commit 7c284ee

Browse files
myrootrookiejava
authored andcommitted
Implements WindowOverlay and VisualDiagnosticsOverlay (#294)
* Implements WindowOverlay and VisualDiagnosticsOverlay * Apply code review
1 parent f044413 commit 7c284ee

File tree

5 files changed

+78
-34
lines changed

5 files changed

+78
-34
lines changed

src/Core/src/Handlers/Window/WindowHandler.Tizen.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ public static void MapContent(WindowHandler handler, IWindow window)
1414

1515
var nativeContent = window.Content.ToContainerView(handler.MauiContext);
1616
handler.MauiContext.Context.SetContent(nativeContent);
17+
18+
if (window.VisualDiagnosticsOverlay != null)
19+
window.VisualDiagnosticsOverlay.Initialize();
1720
}
1821
}
1922
}

src/Core/src/Platform/Tizen/CoreUIAppContext.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ public void SetContent(EvasObject content)
8787
ModalStack.Push(content);
8888
}
8989

90+
public void SetOverlay(EvasObject? content)
91+
{
92+
content?.SetAlignment(-1, -1);
93+
content?.SetWeight(1, 1);
94+
content?.Show();
95+
MainWindow.AddResizeObject(content);
96+
}
97+
9098
public void SetBackButtonPressedHandler(Func<bool> handler)
9199
{
92100
_handleBackButtonPressed = handler;
@@ -130,11 +138,6 @@ void InitializeMainWindow()
130138
BaseCircleSurface = new CircleSurface(conformant);
131139
}
132140
conformant.SetContent(BaseLayout);
133-
134-
if (DeviceType == DeviceType.Watch)
135-
{
136-
BaseCircleSurface = new CircleSurface(conformant);
137-
}
138141
}
139142

140143
MainWindow.Active();

src/Core/src/Platform/Tizen/ViewExtensions.cs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,7 @@ internal static Rectangle GetNativeViewBounds(this EvasObject nativeView)
163163
if (nativeView == null)
164164
return new Rectangle();
165165

166-
return new Rectangle(
167-
nativeView.Geometry.X,
168-
nativeView.Geometry.Y,
169-
nativeView.Geometry.Width,
170-
nativeView.Geometry.Height);
166+
return nativeView.Geometry.ToDP();
171167
}
172168

173169
internal static Matrix4x4 GetViewTransform(this IView view)
@@ -179,7 +175,7 @@ internal static Matrix4x4 GetViewTransform(this IView view)
179175
}
180176

181177
internal static Matrix4x4 GetViewTransform(this EvasObject nativeView)
182-
=> nativeView.GetViewTransform();
178+
=> new Matrix4x4();
183179

184180
internal static Graphics.Rectangle GetBoundingBox(this IView view)
185181
=> view.GetNative(true).GetBoundingBox();
@@ -189,14 +185,7 @@ internal static Graphics.Rectangle GetBoundingBox(this EvasObject? nativeView)
189185
if (nativeView == null)
190186
return new Rectangle();
191187

192-
var rect = nativeView.Geometry;
193-
194-
var nvb = nativeView.GetNativeViewBounds();
195-
var transform = nativeView.GetViewTransform();
196-
var radians = transform.ExtractAngleInRadians();
197-
//TODO: Need to impl
198-
199-
return new Rectangle(nvb.X, nvb.Y, nvb.Width, nvb.Height);
188+
return nativeView.Geometry.ToDP();
200189
}
201190
}
202191
}

src/Core/src/VisualDiagnostics/VisualDiagnosticsOverlay.Tizen.cs

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
using System.Collections.Generic;
2-
using Microsoft.Maui.Graphics;
3-
using Microsoft.Maui.Graphics.Skia.Views;
1+
using System;
2+
using System.Collections.Generic;
43
using ElmSharp;
54

65
namespace Microsoft.Maui
@@ -18,19 +17,39 @@ public void AddScrollableElementHandler(IScrollView scrollBar)
1817
if (nativeScroll != null)
1918
{
2019
_scrollViews.Add(scrollBar, nativeScroll);
20+
if (nativeScroll is Scroller scroller)
21+
{
22+
scroller.Scrolled += OnScrolled;
23+
}
2124
}
22-
//TODO : Need to impl
25+
}
26+
27+
public override void HandleUIChange()
28+
{
29+
base.HandleUIChange();
30+
31+
if (WindowElements.Count > 0)
32+
RemoveAdorners();
33+
34+
Invalidate();
2335
}
2436

2537
/// <inheritdoc/>
2638
public void RemoveScrollableElementHandler()
2739
{
2840
foreach (var scroll in _scrollViews.Values)
2941
{
30-
//TODO : Need to impl
42+
if (scroll is Scroller scroller)
43+
{
44+
scroller.Scrolled -= OnScrolled;
45+
}
3146
}
32-
3347
_scrollViews.Clear();
3448
}
49+
50+
void OnScrolled(object? sender, EventArgs e)
51+
{
52+
Invalidate();
53+
}
3554
}
3655
}
Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
using System.Linq;
2-
using Microsoft.Maui.Graphics;
1+
using ElmSharp;
32
using Microsoft.Maui.Graphics.Skia.Views;
4-
using Microsoft.Maui.Handlers;
5-
using ElmSharp;
63
using Point = Microsoft.Maui.Graphics.Point;
74

85
namespace Microsoft.Maui
96
{
107
public partial class WindowOverlay
118
{
129
SkiaGraphicsView? _graphicsView;
10+
GestureLayer? _touchLayer;
1311

1412
public virtual bool Initialize()
1513
{
@@ -19,16 +17,30 @@ public virtual bool Initialize()
1917
if (Window == null)
2018
return false;
2119

22-
var nativeWindow = Window?.Content?.GetNative(true);
20+
var nativeWindow = Window.Content?.GetNative(true);
2321
if (nativeWindow == null)
2422
return false;
2523

26-
var handler = Window?.Handler as WindowHandler;
24+
var handler = Window.Handler as WindowHandler;
2725
if (handler?.MauiContext == null)
2826
return false;
2927

30-
//TODO: Need to impl
31-
return false;
28+
_graphicsView = new SkiaGraphicsView(handler.MauiContext.Context!.BaseLayout);
29+
_graphicsView.Drawable = this;
30+
_graphicsView.RepeatEvents = !DisableUITouchEventPassthrough;
31+
32+
_touchLayer = new GestureLayer(handler.MauiContext.Context!.BaseLayout);
33+
_touchLayer.Attach(_graphicsView);
34+
_touchLayer.SetTapCallback(GestureLayer.GestureType.Tap, GestureLayer.GestureState.Start, (data) =>
35+
{
36+
var x = _touchLayer.EvasCanvas.Pointer.X;
37+
var y = _touchLayer.EvasCanvas.Pointer.Y;
38+
OnTappedInternal(new Point(DPExtensions.ConvertToScaledDP(x), DPExtensions.ConvertToScaledDP(y)));
39+
});
40+
41+
handler.MauiContext.Context.SetOverlay(_graphicsView);
42+
IsNativeViewInitialized = true;
43+
return IsNativeViewInitialized;
3244
}
3345

3446
public void Invalidate()
@@ -38,10 +50,28 @@ public void Invalidate()
3850

3951
void DeinitializeNativeDependencies()
4052
{
41-
//TODO: Need to impl
53+
if (Window == null)
54+
return;
55+
56+
var nativeWindow = Window?.Content?.GetNative(true);
57+
if (nativeWindow == null)
58+
return;
59+
60+
var handler = Window?.Handler as WindowHandler;
61+
if (handler?.MauiContext == null)
62+
return;
4263

64+
_graphicsView?.Unrealize();
4365
_graphicsView = null;
4466
IsNativeViewInitialized = false;
4567
}
68+
69+
partial void OnDisableUITouchEventPassthroughSet()
70+
{
71+
if (_graphicsView != null)
72+
{
73+
_graphicsView.RepeatEvents = !DisableUITouchEventPassthrough;
74+
}
75+
}
4676
}
4777
}

0 commit comments

Comments
 (0)