Skip to content

Commit c22590e

Browse files
Added Panning example.
1 parent 33f1a4e commit c22590e

File tree

11 files changed

+384
-164
lines changed

11 files changed

+384
-164
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using AngleSharp.Dom;
2+
using KristofferStrube.Blazor.SVGEditor;
3+
4+
namespace KristofferStrube.Blazor.WebAudio.WasmExample.AudioPannerEditor;
5+
6+
public class ListenerShape : Circle
7+
{
8+
public ListenerShape(IElement element, SVGEditor.SVGEditor svg) : base(element, svg)
9+
{
10+
}
11+
12+
public static ListenerShape AddNew(SVGEditor.SVGEditor SVG, double x, double y)
13+
{
14+
IElement element = SVG.Document.CreateElement("CIRCLE");
15+
16+
ListenerShape circle = new(element, SVG)
17+
{
18+
Changed = SVG.UpdateInput,
19+
Fill = "lightgrey",
20+
Cx = x,
21+
Cy = y,
22+
R = 1
23+
};
24+
25+
SVG.AddElement(circle);
26+
27+
return circle;
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
@using KristofferStrube.Blazor.SVGEditor
2+
@using KristofferStrube.Blazor.SVGEditor.ShapeEditors
3+
@using KristofferStrube.Blazor.SVGEditor.Extensions
4+
@inherits ShapeEditor<Circle>
5+
6+
<g transform="translate(@SVGElement.SVG.Translate.x.AsString() @SVGElement.SVG.Translate.y.AsString()) scale(@SVGElement.SVG.Scale.AsString())">
7+
<circle @ref=ElementReference
8+
@onfocusin="FocusElement"
9+
@onfocusout="UnfocusElement"
10+
@onpointerdown="SelectAsync"
11+
@onkeyup="KeyUp" tabindex="@(SVGElement.IsChildElement ? -1 : 0)"
12+
cx=@SVGElement.Cx.AsString()
13+
cy=@SVGElement.Cy.AsString()
14+
r=@SVGElement.R.AsString()
15+
fill="@SVGElement.Fill">
16+
</circle>
17+
<circle @onfocusin="FocusElement"
18+
@onfocusout="UnfocusElement"
19+
@onpointerdown="SelectAsync"
20+
@onkeyup="KeyUp" tabindex="@(SVGElement.IsChildElement ? -1 : 0)"
21+
cx=@((SVGElement.Cx - SVGElement.R).AsString())
22+
cy=@SVGElement.Cy.AsString()
23+
r=@((SVGElement.R / 2).AsString())
24+
fill="@SVGElement.Fill">
25+
</circle>
26+
<circle @onfocusin="FocusElement"
27+
@onfocusout="UnfocusElement"
28+
@onpointerdown="SelectAsync"
29+
@onkeyup="KeyUp" tabindex="@(SVGElement.IsChildElement ? -1 : 0)"
30+
cx=@((SVGElement.Cx + SVGElement.R).AsString())
31+
cy=@SVGElement.Cy.AsString()
32+
r=@((SVGElement.R / 2).AsString())
33+
fill="@SVGElement.Fill">
34+
</circle>
35+
</g>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
using AngleSharp.Dom;
2+
using KristofferStrube.Blazor.SVGEditor;
3+
using Microsoft.AspNetCore.Components.Web;
4+
5+
namespace KristofferStrube.Blazor.WebAudio.WasmExample.AudioPannerEditor;
6+
7+
public class PannerNodeShape : Rect
8+
{
9+
public PannerNodeShape(IElement element, SVGEditor.SVGEditor svg) : base(element, svg)
10+
{
11+
}
12+
13+
public override Type Presenter => typeof(PannerNodeShapeEditor);
14+
15+
public double Rotation { get; set; }
16+
17+
public override string StateRepresentation => base.StateRepresentation + Rotation;
18+
19+
public override void HandlePointerMove(PointerEventArgs eventArgs)
20+
{
21+
if (SVG.CurrentAnchor is not 4 || SVG.EditMode is not EditMode.MoveAnchor)
22+
{
23+
base.HandlePointerMove(eventArgs);
24+
return;
25+
}
26+
27+
(double x, double y) = SVG.LocalDetransform((eventArgs.OffsetX, eventArgs.OffsetY));
28+
29+
(double x, double y) rotationVector =
30+
(
31+
x - (X + (Width / 2)),
32+
y - (Y + (Height / 2))
33+
);
34+
35+
Rotation = (-Math.Atan(rotationVector.x / rotationVector.y) * 180 / Math.PI) + (rotationVector.y < 0 ? 180 : 0);
36+
}
37+
38+
public static PannerNodeShape AddNew(SVGEditor.SVGEditor SVG, double x, double y, double rotation, string color)
39+
{
40+
IElement element = SVG.Document.CreateElement("RECT");
41+
42+
PannerNodeShape pannerNode = new(element, SVG)
43+
{
44+
Changed = SVG.UpdateInput,
45+
StrokeWidth = "0",
46+
Fill = color,
47+
Rotation = rotation
48+
};
49+
(pannerNode.X, pannerNode.Y) = (x, y);
50+
(pannerNode.Width, pannerNode.Height) = (2, 2);
51+
52+
SVG.AddElement(pannerNode);
53+
54+
return pannerNode;
55+
}
56+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
@using KristofferStrube.Blazor.SVGEditor
2+
@using KristofferStrube.Blazor.SVGEditor.ShapeEditors
3+
@using KristofferStrube.Blazor.SVGEditor.Extensions
4+
@inherits ShapeEditor<PannerNodeShape>
5+
6+
<g transform="translate(@SVGElement.SVG.Translate.x.AsString() @SVGElement.SVG.Translate.y.AsString()) scale(@SVGElement.SVG.Scale.AsString())">
7+
<rect @ref=ElementReference
8+
@onfocusin="FocusElement"
9+
@onfocusout="UnfocusElement"
10+
@onpointerdown="SelectAsync"
11+
@onkeyup="KeyUp"
12+
tabindex="@(SVGElement.IsChildElement ? -1 : 0)"
13+
x=@SVGElement.X.AsString()
14+
y=@SVGElement.Y.AsString()
15+
width=@SVGElement.Width.AsString()
16+
height=@SVGElement.Height.AsString()
17+
fill="@SVGElement.Fill"
18+
transform="rotate(@(SVGElement.Rotation.AsString()) @((SVGElement.X + SVGElement.Width / 2).AsString()) @((SVGElement.Y + SVGElement.Height / 2).AsString()))">
19+
</rect>
20+
</g>
21+
@if (SVGElement.Selected && SVGElement.SVG.EditMode is not EditMode.Add)
22+
{
23+
<Anchor OnPointerDown="() => AnchorSelect(4)" Position="anchorPosition" />
24+
}
25+
26+
@code {
27+
private (double x, double y) anchorPosition =>
28+
(
29+
x: SVGElement.X + SVGElement.Width / 2 + Math.Sin(-SVGElement.Rotation / 180 * Math.PI) * SVGElement.Height,
30+
y: SVGElement.Y + SVGElement.Height / 2 + Math.Cos(-SVGElement.Rotation / 180 * Math.PI) * SVGElement.Height
31+
);
32+
}

samples/KristofferStrube.Blazor.WebAudio.WasmExample/Pages/DotNetBot.razor

-162
This file was deleted.

0 commit comments

Comments
 (0)