Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 21 additions & 19 deletions samples/TestApp/Views/MainView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using System.Collections.ObjectModel;
using System.Collections.Generic;
using System.Linq;
using ShimSkiaSharp;
using SkiaSharp;
using Svg.Skia;
using Svg.Model.Drawables;
using Svg.Model.Services;
Expand All @@ -18,6 +20,10 @@ public partial class MainView : UserControl
{
private readonly ObservableCollection<string> _hitResults = new();
private SKSvg? _currentSkSvg;
private bool _showHitBounds;
private SKColor _hitBoundsColor = SKColors.Cyan;
private readonly IList<SKPoint> _hitTestPoints = new List<SKPoint>();
private readonly IList<SKRect> _hitTestRects = new List<SKRect>();

public MainView()
{
Expand Down Expand Up @@ -96,13 +102,9 @@ private void FileItem_OnDoubleTapped(object? sender, TappedEventArgs e)

private void ShowHitBoundsToggle_OnToggled(object? sender, RoutedEventArgs e)
{
var svg = Svg.SkSvg;
if (svg is { })
{
svg.Settings.ShowHitBounds = ShowHitBoundsToggle.IsChecked == true;
SubscribeOnDraw();
Svg.InvalidateVisual();
}
_showHitBounds = ShowHitBoundsToggle.IsChecked == true;
SubscribeOnDraw();
Svg.InvalidateVisual();
}

private void Svg_OnPointerPressed(object? sender, PointerPressedEventArgs e)
Expand All @@ -111,13 +113,13 @@ private void Svg_OnPointerPressed(object? sender, PointerPressedEventArgs e)

_hitResults.Clear();

if (Svg.SkSvg is { } skSvg)
if (Svg.SkSvg is { })
{
skSvg.Settings.HitTestPoints.Clear();
_hitTestPoints.Clear();

if (Svg.TryGetPicturePoint(pt, out var skPoint))
{
skSvg.Settings.HitTestPoints.Add(skPoint);
_hitTestPoints.Add(skPoint);

// foreach (var element in Svg.HitTestElements(pt))
// {
Expand All @@ -139,10 +141,10 @@ private void SelectingItemsControl_OnSelectionChanged(object? sender, SelectionC
{
_hitResults.Clear();

if (Svg.SkSvg is { } skSvg)
if (Svg.SkSvg is { })
{
skSvg.Settings.HitTestPoints.Clear();
skSvg.Settings.ShowHitBounds = ShowHitBoundsToggle.IsChecked == true;
_hitTestPoints.Clear();
_showHitBounds = ShowHitBoundsToggle.IsChecked == true;
SubscribeOnDraw();
}

Expand All @@ -156,16 +158,16 @@ private void SkSvg_OnDraw(object? sender, SKSvgDrawEventArgs e)
return;
}

if (!skSvg.Settings.ShowHitBounds)
if (!_showHitBounds)
{
return;
}

var hits = new HashSet<DrawableBase>();

if (skSvg.Settings.HitTestPoints is { })
if (_hitTestPoints is { })
{
foreach (var pt in skSvg.Settings.HitTestPoints)
foreach (var pt in _hitTestPoints)
{
foreach (var d in HitTestService.HitTest(drawable, pt))
{
Expand All @@ -174,9 +176,9 @@ private void SkSvg_OnDraw(object? sender, SKSvgDrawEventArgs e)
}
}

if (skSvg.Settings.HitTestRects is { })
if (_hitTestRects is { })
{
foreach (var r in skSvg.Settings.HitTestRects)
foreach (var r in _hitTestRects)
{
foreach (var d in HitTestService.HitTest(drawable, r))
{
Expand All @@ -188,7 +190,7 @@ private void SkSvg_OnDraw(object? sender, SKSvgDrawEventArgs e)
using var paint = new SkiaSharp.SKPaint();
paint.IsAntialias = true;
paint.Style = SkiaSharp.SKPaintStyle.Stroke;
paint.Color = skSvg.Settings.HitBoundsColor;
paint.Color = _hitBoundsColor;

foreach (var hit in hits.Take(1))
{
Expand Down
13 changes: 0 additions & 13 deletions src/Svg.Skia/SKSvgSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT license. See LICENSE file in the project root for details.
using System.Collections.Generic;
using Svg.Skia.TypefaceProviders;
using ShimSkiaSharp;

namespace Svg.Skia;

Expand All @@ -18,13 +17,6 @@ public class SKSvgSettings

public IList<ITypefaceProvider>? TypefaceProviders { get; set; }

public bool ShowHitBounds { get; set; }

public SkiaSharp.SKColor HitBoundsColor { get; set; }

public IList<ShimSkiaSharp.SKPoint> HitTestPoints { get; set; }

public IList<ShimSkiaSharp.SKRect> HitTestRects { get; set; }

public SKSvgSettings()
{
Expand All @@ -41,10 +33,5 @@ public SKSvgSettings()
new FontManagerTypefaceProvider(),
new DefaultTypefaceProvider()
};

ShowHitBounds = false;
HitBoundsColor = SkiaSharp.SKColors.Cyan;
HitTestPoints = new List<ShimSkiaSharp.SKPoint>();
HitTestRects = new List<ShimSkiaSharp.SKRect>();
}
}
Loading