18 internal System.Drawing.Point ToScreenPx(
double x,
double y)
20 ??
new System.Drawing.Point((
int)Math.Floor(x), (
int)Math.Floor(y));
22 private const string DefaultCanvasStyle =
23 "width: 100%; height: 100%; display: block; outline: none;";
25 internal event Action<KeyboardEventArgs>? KeyDown;
26 internal event Action<KeyboardEventArgs>? KeyUp;
27 internal event Action<MouseEventArgs>? MouseMove;
28 internal event Action<MouseEventArgs>? MouseDown;
29 internal event Action<MouseEventArgs>? MouseUp;
30 internal event Action<WheelEventArgs>? Wheel;
31 internal event Action<TouchEventArgs>? TouchStart;
32 internal event Action<TouchEventArgs>? TouchMove;
33 internal event Action<TouchEventArgs>? TouchEnd;
34 internal event Action<TouchEventArgs>? TouchCancel;
39 [Parameter(CaptureUnmatchedValues =
true)]
50 protected string CanvasStyle {
get;
private set; } = DefaultCanvasStyle;
66 var attributes =
new Dictionary<string, object>(
68 StringComparer.OrdinalIgnoreCase);
69 attributes.Remove(
"style");
75 protected void HandleKeyDown(KeyboardEventArgs e) => KeyDown?.Invoke(e);
79 protected void HandleKeyUp(KeyboardEventArgs e) => KeyUp?.Invoke(e);
95 protected void HandleWheel(WheelEventArgs e) => Wheel?.Invoke(e);
97 internal readonly record
struct CanvasOffset(float Left, float Top);
98 internal virtual ValueTask<CanvasOffset> GetCanvasOffsetAsync() => ValueTask.FromResult(
default(CanvasOffset));
100 private async Task ForwardTouch(TouchEventArgs args, Action<TouchEventArgs>? handler)
102 if (handler is
null)
return;
103 var offset = await GetCanvasOffsetAsync();
104 foreach (var point
in args.ChangedTouches)
106 point.ClientX -= offset.Left;
107 point.ClientY -= offset.Top;