drawnui-react 0.1.0-preview.3 → 0.1.0-preview.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -1
- package/SKIPPED.md +32 -25
- package/dist/controls/AnimatedFramesRenderer.d.ts +7 -0
- package/dist/controls/AnimatedFramesRenderer.js +16 -1
- package/dist/controls/DrawnGame.d.ts +40 -0
- package/dist/controls/DrawnGame.js +64 -0
- package/dist/controls/GridStructure.d.ts +16 -2
- package/dist/controls/GridStructure.js +40 -4
- package/dist/controls/SkiaBackdrop.d.ts +8 -2
- package/dist/controls/SkiaBackdrop.js +42 -14
- package/dist/controls/SkiaButton.d.ts +15 -1
- package/dist/controls/SkiaButton.js +21 -4
- package/dist/controls/SkiaCarousel.d.ts +21 -2
- package/dist/controls/SkiaCarousel.js +49 -5
- package/dist/controls/SkiaCheckbox.d.ts +0 -1
- package/dist/controls/SkiaCheckbox.js +0 -6
- package/dist/controls/SkiaDrawer.d.ts +2 -0
- package/dist/controls/SkiaDrawer.js +2 -0
- package/dist/controls/SkiaEditor.d.ts +38 -1
- package/dist/controls/SkiaEditor.js +223 -49
- package/dist/controls/SkiaGif.d.ts +3 -0
- package/dist/controls/SkiaGif.js +12 -2
- package/dist/controls/SkiaImage.js +15 -10
- package/dist/controls/SkiaLabel.d.ts +78 -7
- package/dist/controls/SkiaLabel.js +379 -60
- package/dist/controls/SkiaLabelFps.d.ts +16 -0
- package/dist/controls/SkiaLabelFps.js +41 -0
- package/dist/controls/SkiaLayout.d.ts +97 -9
- package/dist/controls/SkiaLayout.js +387 -22
- package/dist/controls/SkiaLottie.js +4 -2
- package/dist/controls/SkiaProgress.d.ts +2 -1
- package/dist/controls/SkiaProgress.js +6 -3
- package/dist/controls/SkiaRadioButton.js +4 -3
- package/dist/controls/SkiaRichLabel.d.ts +1 -1
- package/dist/controls/SkiaRichLabel.js +11 -1
- package/dist/controls/SkiaScroll.d.ts +35 -5
- package/dist/controls/SkiaScroll.js +234 -23
- package/dist/controls/SkiaScrollBar.d.ts +27 -0
- package/dist/controls/SkiaScrollBar.js +51 -2
- package/dist/controls/SkiaShaderCarousel.d.ts +5 -0
- package/dist/controls/SkiaShaderCarousel.js +5 -0
- package/dist/controls/SkiaShape.d.ts +13 -2
- package/dist/controls/SkiaShape.js +50 -10
- package/dist/controls/SkiaSlider.d.ts +20 -2
- package/dist/controls/SkiaSlider.js +59 -5
- package/dist/controls/SkiaSprite.d.ts +1 -0
- package/dist/controls/SkiaSprite.js +4 -0
- package/dist/controls/SkiaSvg.js +1 -1
- package/dist/controls/SkiaSwitch.d.ts +0 -1
- package/dist/controls/SkiaSwitch.js +0 -6
- package/dist/controls/SkiaToggle.d.ts +25 -5
- package/dist/controls/SkiaToggle.js +58 -5
- package/dist/controls/SnappingLayout.d.ts +12 -1
- package/dist/controls/SnappingLayout.js +19 -1
- package/dist/core/Accessibility.d.ts +80 -0
- package/dist/core/Accessibility.js +421 -8
- package/dist/core/Animators.d.ts +37 -1
- package/dist/core/Animators.js +102 -9
- package/dist/core/Canvas.d.ts +108 -7
- package/dist/core/Canvas.js +353 -29
- package/dist/core/Easing.d.ts +12 -1
- package/dist/core/Easing.js +25 -1
- package/dist/core/Gestures.d.ts +34 -2
- package/dist/core/Gestures.js +84 -3
- package/dist/core/Hover.d.ts +47 -0
- package/dist/core/Hover.js +134 -0
- package/dist/core/KeyboardManager.d.ts +13 -0
- package/dist/core/KeyboardManager.js +18 -0
- package/dist/core/ScrollAnimators.js +9 -0
- package/dist/core/Shaping.d.ts +40 -0
- package/dist/core/Shaping.js +224 -0
- package/dist/core/SkiaControl.d.ts +209 -9
- package/dist/core/SkiaControl.js +500 -59
- package/dist/core/SkiaEffect.d.ts +17 -0
- package/dist/core/SkiaEffect.js +43 -8
- package/dist/core/SkiaImageManager.js +1 -1
- package/dist/core/Super.d.ts +22 -2
- package/dist/core/Super.js +47 -3
- package/dist/core/Types.d.ts +11 -1
- package/dist/core/Types.js +32 -1
- package/dist/core/ViewsAdapter.d.ts +7 -2
- package/dist/core/ViewsAdapter.js +10 -3
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/react/SkiaShell.js +33 -14
- package/dist/react/index.d.ts +17 -4
- package/dist/react/index.js +103 -15
- package/dist/react/reconciler.js +33 -13
- package/dist/vite/index.d.ts +9 -0
- package/dist/vite/index.js +36 -3
- package/package.json +41 -3
package/dist/core/SkiaControl.js
CHANGED
|
@@ -22,12 +22,29 @@ export class CachedObject {
|
|
|
22
22
|
this.Picture = Picture;
|
|
23
23
|
this.Image = Image;
|
|
24
24
|
}
|
|
25
|
-
/**
|
|
26
|
-
|
|
25
|
+
/** Canvas.GpuEpoch it was made in: after a WebGL context restore it is remade (a picture may replay old GPU images). */
|
|
26
|
+
Epoch = 0;
|
|
27
|
+
/** A picture recorded to be drawn distorted: the images in it sample smoothly (C# CachedObject.PlaybackDistorted). */
|
|
28
|
+
PlaybackDistorted = false;
|
|
29
|
+
/** A picture holding image blits, whose sampling was fixed when it was recorded (C# CachedObject.HasImageBlits). */
|
|
30
|
+
HasImageBlits = false;
|
|
31
|
+
/** C# PaintRenderObject: the blit paint is antialiased (else a turned bitmap keeps stair steps along its own border), dithered when distorted. */
|
|
32
|
+
static blitPaint;
|
|
33
|
+
static blitPaintDithered;
|
|
34
|
+
static BlitPaint(dither) {
|
|
35
|
+
const CK = Super.CK;
|
|
36
|
+
const make = () => { const p = new CK.Paint(); p.setAntiAlias(true); p.setDither(dither); return p; };
|
|
37
|
+
return dither ? (CachedObject.blitPaintDithered ??= make()) : (CachedObject.blitPaint ??= make());
|
|
38
|
+
}
|
|
39
|
+
/** Replays the cache with its top-left moved to (left, top); `smooth` = an image drawn distorted (linear + mipmaps). */
|
|
40
|
+
Draw(canvas, left, top, smooth = false) {
|
|
27
41
|
const CK = Super.CK;
|
|
28
42
|
if (this.Image) {
|
|
29
|
-
//
|
|
30
|
-
|
|
43
|
+
// nearest keeps a bitmap blitted 1:1 sharp; once scaled, turned or projected it needs smooth sampling (C# 1e4610f6)
|
|
44
|
+
if (smooth)
|
|
45
|
+
canvas.drawImageOptions(this.Image, left, top, CK.FilterMode.Linear, CK.MipmapMode.Linear, CachedObject.BlitPaint(true));
|
|
46
|
+
else
|
|
47
|
+
canvas.drawImageOptions(this.Image, left, top, CK.FilterMode.Nearest, CK.MipmapMode.None, CachedObject.BlitPaint(false));
|
|
31
48
|
}
|
|
32
49
|
else if (this.Picture) {
|
|
33
50
|
const saved = canvas.save();
|
|
@@ -36,9 +53,36 @@ export class CachedObject {
|
|
|
36
53
|
canvas.restoreToCount(saved);
|
|
37
54
|
}
|
|
38
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* C# GetPictureImage: the picture of a picture cache (Operations, OperationsFull) drawn into an image, made on the
|
|
58
|
+
* first call (on `main`'s GPU context when given) and kept as long as this cache lives. Shader effects read it as
|
|
59
|
+
* their input, so on such a control they work on its own content, as on an Image cache.
|
|
60
|
+
*/
|
|
61
|
+
GetPictureImage(main) {
|
|
62
|
+
if (this.pictureImage || !this.Picture)
|
|
63
|
+
return this.pictureImage;
|
|
64
|
+
const w = Math.ceil(this.Bounds.Width), h = Math.ceil(this.Bounds.Height);
|
|
65
|
+
if (w <= 0 || h <= 0)
|
|
66
|
+
return undefined;
|
|
67
|
+
const surface = main?.makeSurface({ ...main.imageInfo(), width: w, height: h }) ?? Super.CK.MakeSurface(w, h);
|
|
68
|
+
if (!surface)
|
|
69
|
+
return undefined;
|
|
70
|
+
const canvas = surface.getCanvas();
|
|
71
|
+
canvas.clear(Super.CK.TRANSPARENT);
|
|
72
|
+
canvas.translate(-this.Bounds.Left, -this.Bounds.Top);
|
|
73
|
+
canvas.drawPicture(this.Picture);
|
|
74
|
+
this.pictureImage = surface.makeImageSnapshot();
|
|
75
|
+
surface.delete();
|
|
76
|
+
return this.pictureImage;
|
|
77
|
+
}
|
|
78
|
+
pictureImage;
|
|
79
|
+
/** The picture drawn into an image, once GetPictureImage made it. */
|
|
80
|
+
get PictureImage() { return this.pictureImage; }
|
|
39
81
|
Dispose() {
|
|
40
82
|
this.Picture?.delete();
|
|
41
83
|
this.Image?.delete();
|
|
84
|
+
this.pictureImage?.delete();
|
|
85
|
+
this.pictureImage = undefined;
|
|
42
86
|
}
|
|
43
87
|
}
|
|
44
88
|
/**
|
|
@@ -66,7 +110,10 @@ export class SkiaControl {
|
|
|
66
110
|
Row = 0;
|
|
67
111
|
ColumnSpan = 1;
|
|
68
112
|
RowSpan = 1;
|
|
69
|
-
|
|
113
|
+
margin = Thickness.Zero;
|
|
114
|
+
/** Space around the control (points); a number is the same on every side, as C# XAML (`Thickness.From`). */
|
|
115
|
+
get Margin() { return this.margin; }
|
|
116
|
+
set Margin(v) { this.margin = Thickness.From(v); }
|
|
70
117
|
/**
|
|
71
118
|
* DrawnUi LockRatio: 0 = off; positive = square of the LARGER of the two sizes (requests or constraints),
|
|
72
119
|
* negative = square of the SMALLER one. Infinite sides are ignored, so WidthRequest=150 + LockRatio=1 = 150x150.
|
|
@@ -87,6 +134,14 @@ export class SkiaControl {
|
|
|
87
134
|
/** Degrees. */
|
|
88
135
|
SkewX = 0;
|
|
89
136
|
SkewY = 0;
|
|
137
|
+
/** Degrees, a 3D turn around the horizontal axis through the pivot, seen with perspective (C# RotationX). */
|
|
138
|
+
RotationX = 0;
|
|
139
|
+
/** Degrees, a 3D turn around the vertical axis through the pivot (C# RotationY). */
|
|
140
|
+
RotationY = 0;
|
|
141
|
+
/** Degrees, a 3D turn around the axis facing the viewer, after RotationX and RotationY (C# RotationZ). */
|
|
142
|
+
RotationZ = 0;
|
|
143
|
+
/** Depth: toward the viewer (+, bigger) or away (−, smaller), turned or flat; draws at 576 / (576 − TranslationZ) (C# TranslationZ). */
|
|
144
|
+
TranslationZ = 0;
|
|
90
145
|
/** Pivot for Rotation/Scale/Skew as a fraction of the box (MAUI default 0.5). */
|
|
91
146
|
AnchorX = 0.5;
|
|
92
147
|
AnchorY = 0.5;
|
|
@@ -114,8 +169,9 @@ export class SkiaControl {
|
|
|
114
169
|
get Scale() { return this.ScaleX; }
|
|
115
170
|
set Scale(v) { this.ScaleX = v; this.ScaleY = v; }
|
|
116
171
|
get HasTransform() {
|
|
117
|
-
return this.TranslationX !== 0 || this.TranslationY !== 0 || this.Left !== 0 || this.Top !== 0 || this.Rotation !== 0 || this.ScaleX !== 1 || this.ScaleY !== 1 || this.SkewX !== 0 || this.SkewY !== 0;
|
|
172
|
+
return this.TranslationX !== 0 || this.TranslationY !== 0 || this.Left !== 0 || this.Top !== 0 || this.Rotation !== 0 || this.ScaleX !== 1 || this.ScaleY !== 1 || this.SkewX !== 0 || this.SkewY !== 0 || this.Has3d;
|
|
118
173
|
}
|
|
174
|
+
get Has3d() { return this.RotationX !== 0 || this.RotationY !== 0 || this.RotationZ !== 0 || this.TranslationZ !== 0; }
|
|
119
175
|
/** Matrix applied at the last render (canvas space), undefined when none; gestures map through its inverse. */
|
|
120
176
|
RenderTransformMatrix;
|
|
121
177
|
/** Generic numeric parameters (DrawnUi Value1/Value2): SkiaShape Arc uses start angle / sweep angle in degrees. */
|
|
@@ -132,6 +188,7 @@ export class SkiaControl {
|
|
|
132
188
|
return;
|
|
133
189
|
this.bindingContext = value;
|
|
134
190
|
this.OnBindingContextChanged();
|
|
191
|
+
this.Superview?.Hover?.RequestCheck(); // a recycled cell under a still mouse now shows another item
|
|
135
192
|
}
|
|
136
193
|
/** Index of the bound item inside its ItemsSource, -1 when not templated. */
|
|
137
194
|
ContextIndex = -1;
|
|
@@ -164,15 +221,52 @@ export class SkiaControl {
|
|
|
164
221
|
compositeSurface;
|
|
165
222
|
/** Own content or structure changed: the next composite record is a full one. */
|
|
166
223
|
compositeFull = true;
|
|
224
|
+
/** Where the kept composite surface starts relative to DrawingRect (the effects margin it was laid out with). */
|
|
225
|
+
compositeInsetX = 0;
|
|
226
|
+
compositeInsetY = 0;
|
|
167
227
|
/** Canvas-pixel bounds this control covered when its parent last recorded it (composite erase region). */
|
|
168
228
|
lastCompositeBounds;
|
|
169
|
-
/**
|
|
170
|
-
|
|
229
|
+
/**
|
|
230
|
+
* What the last composite record did (diagnostics): "full" or "partial", the number of children re-recorded and which
|
|
231
|
+
* ones; Areas: the pixels erased and drawn again for changes deeper than a child (C# Areas), Changed: the controls
|
|
232
|
+
* those areas belong to (C# Changed).
|
|
233
|
+
*/
|
|
234
|
+
LastCompositeRecord = { Mode: "full", Children: 0, Dirty: [], Areas: [], Changed: [] };
|
|
235
|
+
/** C# MaxCompositionAreas: more areas than this in one composite record draw it whole instead. */
|
|
236
|
+
static MaxCompositionAreas = 16;
|
|
237
|
+
/** C# MaxCompositionShare: areas covering more than this share of a composite draw it whole instead. */
|
|
238
|
+
static MaxCompositionShare = 0.5;
|
|
239
|
+
/**
|
|
240
|
+
* Changes deeper than a direct child since the last composite record (drawnui-cross 6m): the control, the direct child
|
|
241
|
+
* it is in, where it was drawn before the change (its own drawn bounds, as drawn) and its rect then.
|
|
242
|
+
*/
|
|
243
|
+
compositeDeep;
|
|
244
|
+
/** Set while an UpdateDraw climbs: the ancestors re-measure but an ImageComposite among them keeps its partial record. */
|
|
245
|
+
static drawOrigin = null;
|
|
171
246
|
/** The children a composite record can re-record individually; layouts return their views. */
|
|
172
247
|
GetCompositeChildren() { return []; }
|
|
173
248
|
/** C# TrackChildAsDirty (DirtyChildrenTracker): the child changed without a remeasure of this control. */
|
|
174
249
|
TrackChildAsDirty(child) { if (this.IsCacheComposite)
|
|
175
250
|
this.DirtyChildrenInternal.add(child); }
|
|
251
|
+
static rejectRect = new Float32Array(4);
|
|
252
|
+
/** Its cache must be recorded before it can be drawn (none, dirty, another type, scale, size or GPU context). */
|
|
253
|
+
CacheStale(scale) {
|
|
254
|
+
const cacheType = this.UsingCacheType;
|
|
255
|
+
if (cacheType === "None")
|
|
256
|
+
return false;
|
|
257
|
+
const o = this.RenderObject, r = cacheType === "Operations" ? this.ExpandedCacheRect(scale) : this.AlignedCacheRect(scale);
|
|
258
|
+
return this.cacheDirty || !o || o.Type !== cacheType || o.Epoch !== (this.Superview?.GpuEpoch ?? 0) || o.Scale !== scale
|
|
259
|
+
|| Math.round(o.Bounds.Width) !== Math.round(r.Width) || Math.round(o.Bounds.Height) !== Math.round(r.Height);
|
|
260
|
+
}
|
|
261
|
+
/** Its rect grown by its effects margin, through the matrix it is drawn with, lies outside the canvas clip. */
|
|
262
|
+
OutsideClip(canvas, scale) {
|
|
263
|
+
const b = SkiaControl.MapRect(this.RenderTransformMatrix, this.ExpandedCacheRect(scale)), q = SkiaControl.rejectRect;
|
|
264
|
+
q[0] = b.Left;
|
|
265
|
+
q[1] = b.Top;
|
|
266
|
+
q[2] = b.Right;
|
|
267
|
+
q[3] = b.Bottom;
|
|
268
|
+
return canvas.quickReject(q);
|
|
269
|
+
}
|
|
176
270
|
/** Drawn bounds in canvas pixels including transforms and effects margins (C# GetTransformedDirtyBounds). */
|
|
177
271
|
GetTransformedDirtyBounds() {
|
|
178
272
|
const r = this.ExpandedCacheRect(this.RenderingScale), m = this.RenderTransformMatrix;
|
|
@@ -191,6 +285,57 @@ export class SkiaControl {
|
|
|
191
285
|
/** Consume every gesture that lands on this control so nothing below (z-order) receives it. */
|
|
192
286
|
BlockGesturesBelow = false;
|
|
193
287
|
LockChildrenGestures = "Disabled";
|
|
288
|
+
// ---- hover (drawnui-cross 6m, C# ReceivesHover / IsHovered / HoverChanged) ----
|
|
289
|
+
receivesHover;
|
|
290
|
+
/**
|
|
291
|
+
* Whether this control takes mouse hover: the canvas sets IsHovered while the mouse is over it. Opt-in: false by
|
|
292
|
+
* default, true by default only in the controls that always had hover (SkiaButton, SkiaSlider, the toggles,
|
|
293
|
+
* SkiaRadioButton, SkiaCarousel, SkiaDrawer), never because a control has a tap handler. A HoverChanged handler turns
|
|
294
|
+
* it on (C# fluent OnHovered) unless it is set.
|
|
295
|
+
*/
|
|
296
|
+
get ReceivesHover() { return this.receivesHover ?? (this.HoverChanged ? true : this.ReceivesHoverByDefault()); }
|
|
297
|
+
set ReceivesHover(value) { this.receivesHover = value; }
|
|
298
|
+
/** The value of ReceivesHover until it is set. */
|
|
299
|
+
ReceivesHoverByDefault() { return false; }
|
|
300
|
+
isHovered = false;
|
|
301
|
+
/**
|
|
302
|
+
* True while the mouse is over this control and it takes hover. Every such control under the pointer is hovered at
|
|
303
|
+
* once (a card and the button inside it, as CSS :hover); it stays as it is while content moves under the pointer and
|
|
304
|
+
* is checked again when that stops. Touch never hovers.
|
|
305
|
+
*/
|
|
306
|
+
get IsHovered() { return this.isHovered; }
|
|
307
|
+
/** IsHovered changed: true when the mouse came over this control, false when it left (C# HoverChanged / OnHovered). */
|
|
308
|
+
HoverChanged;
|
|
309
|
+
/** Set by the canvas's HoverManager. */
|
|
310
|
+
ApplyHover(on) {
|
|
311
|
+
if (this.isHovered === on)
|
|
312
|
+
return;
|
|
313
|
+
this.isHovered = on;
|
|
314
|
+
this.HoverChanged?.(this, on);
|
|
315
|
+
}
|
|
316
|
+
/** A scroll, carousel or drawer moving its content right now: hover waits until it stops (C# IsScrolling / InTransition). */
|
|
317
|
+
MovesContent() { return false; }
|
|
318
|
+
/**
|
|
319
|
+
* Hover hit path (HoverManager): this control is under the point (in its own space), its children under it follow,
|
|
320
|
+
* top-most first, by the routing rules of ProcessGestures. True when this subtree blocks gestures below it, so the
|
|
321
|
+
* controls under it get no hover (a popup over a list).
|
|
322
|
+
*/
|
|
323
|
+
CollectHovered(point, into, xs, ys) {
|
|
324
|
+
into.push(this);
|
|
325
|
+
xs?.push(point.X);
|
|
326
|
+
ys?.push(point.Y);
|
|
327
|
+
if (!this.CheckChildrenGesturesLocked("Pointer")) {
|
|
328
|
+
const listeners = this.GetGestureListeners();
|
|
329
|
+
for (let i = listeners.length - 1; i >= 0; i--) {
|
|
330
|
+
const child = listeners[i];
|
|
331
|
+
if (!child.IsVisible || child.InputTransparent || !this.IsGestureForChild(child, point))
|
|
332
|
+
continue;
|
|
333
|
+
if (child.CollectHovered(child.TransformPointToLocalSpace(point), into, xs, ys))
|
|
334
|
+
return true;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
return this.BlockGesturesBelow;
|
|
338
|
+
}
|
|
194
339
|
// ---- touch feedback (same names as DrawnUi) ----
|
|
195
340
|
TouchEffectColor = Colors.White;
|
|
196
341
|
/** Plays a ripple (from the tap point) when Tapped fires. */
|
|
@@ -199,6 +344,11 @@ export class SkiaControl {
|
|
|
199
344
|
AnimationTappedSpeed = 0;
|
|
200
345
|
/** Overlay effects drawn above this control's content every frame (ripple etc). */
|
|
201
346
|
PostAnimators = [];
|
|
347
|
+
/**
|
|
348
|
+
* C# PendingUnattachedAnimators: animators started while no Canvas was above this control yet (e.g. a game loop
|
|
349
|
+
* started in a constructor). They start on the control's first arrange, where C# starts them in SuperViewChanged.
|
|
350
|
+
*/
|
|
351
|
+
PendingUnattachedAnimators;
|
|
202
352
|
// ---- visual effects (C# VisualEffects: attached SkiaEffect objects) ----
|
|
203
353
|
visualEffects = [];
|
|
204
354
|
/** Post-renderer effects among VisualEffects (C# EffectPostRenderers). */
|
|
@@ -230,10 +380,27 @@ export class SkiaControl {
|
|
|
230
380
|
return [];
|
|
231
381
|
return this.EffectPostRenderers.filter((e) => e.NeedApply);
|
|
232
382
|
}
|
|
233
|
-
/**
|
|
383
|
+
/**
|
|
384
|
+
* C# CachedImage: the cached texture (Image caches only) and the canvas rect it covers NOW. Scrolled content is
|
|
385
|
+
* re-arranged here, not drawn through a translated canvas, so a cache recorded before its control moved is blitted
|
|
386
|
+
* at the control's current aligned rect (RenderContent) and its record-time Bounds are stale: an effect sampling it
|
|
387
|
+
* there (the slides of a SkiaShaderCarousel after the page scrolled) was off by the scroll amount.
|
|
388
|
+
*/
|
|
234
389
|
get CachedImage() {
|
|
235
390
|
const c = this.RenderObject;
|
|
236
|
-
|
|
391
|
+
if (!c)
|
|
392
|
+
return undefined;
|
|
393
|
+
if (c.Image) {
|
|
394
|
+
const r = this.AlignedCacheRect(c.Scale);
|
|
395
|
+
return { Image: c.Image, Bounds: SKRect.Create(r.Left, r.Top, c.Bounds.Width, c.Bounds.Height) };
|
|
396
|
+
}
|
|
397
|
+
// a picture cache: its picture drawn into an image (made in RenderContent), so effects work on this control's
|
|
398
|
+
// content instead of a snapshot of what is behind it (C# caa1c8c1)
|
|
399
|
+
const image = c.PictureImage;
|
|
400
|
+
if (!image)
|
|
401
|
+
return undefined;
|
|
402
|
+
const r = this.ExpandedCacheRect(c.Scale);
|
|
403
|
+
return { Image: image, Bounds: SKRect.Create(r.Left, r.Top, image.width(), image.height()) };
|
|
237
404
|
}
|
|
238
405
|
/** Clip overlay effects to the control's shape (CreateClip). */
|
|
239
406
|
ClipEffects = true;
|
|
@@ -262,6 +429,11 @@ export class SkiaControl {
|
|
|
262
429
|
if (!SkiaStyles.IsEmpty)
|
|
263
430
|
SkiaStyles.Apply(this, atConstruction);
|
|
264
431
|
}
|
|
432
|
+
/**
|
|
433
|
+
* C# IsChildrenItem: added by the app (JSX children or the `Children` list), not a part the control made itself. A new
|
|
434
|
+
* `Children` list drops only these, so a control's own parts keep their place.
|
|
435
|
+
*/
|
|
436
|
+
IsChildrenItem = false;
|
|
265
437
|
AddSubView(_control) { throw new Error(`DrawnUi: ${this.constructor.name} cannot host children`); }
|
|
266
438
|
InsertSubView(_index, control) { this.AddSubView(control); }
|
|
267
439
|
RemoveSubView(_control) { }
|
|
@@ -361,12 +533,37 @@ export class SkiaControl {
|
|
|
361
533
|
const fullW = destination.Width - m.HorizontalThickness * scale, fullH = destination.Height - m.VerticalThickness * scale;
|
|
362
534
|
const x = availL + SkiaControl.Align(this.HorizontalOptions, fullW, w);
|
|
363
535
|
const y = availT + SkiaControl.Align(this.VerticalOptions, fullH, h);
|
|
536
|
+
const old = this.DrawingRect;
|
|
364
537
|
this.DrawingRect = SKRect.Create(x, y, w, h);
|
|
538
|
+
this.FollowMatrix(old);
|
|
365
539
|
this.OnLayoutChanged();
|
|
540
|
+
if (this.PendingUnattachedAnimators)
|
|
541
|
+
this.StartPendingAnimators();
|
|
366
542
|
// DrawnUi OnLayoutReady: an accessible control registers itself on its first layout
|
|
367
543
|
if (!this.registeredWithAccessibility && this.IsAccessibilityElement)
|
|
368
544
|
this.NotifyAccessibility();
|
|
369
545
|
}
|
|
546
|
+
/**
|
|
547
|
+
* A cached ancestor replays its picture where a re-arrange moved it (a scroll) without rendering this control again,
|
|
548
|
+
* so the matrix made at its last Render moves with its rect: taps, hover and the accessibility rect stay on what is
|
|
549
|
+
* drawn (C# offsets the cached render tree instead). A control that renders again gets a fresh matrix there.
|
|
550
|
+
*/
|
|
551
|
+
FollowMatrix(old) {
|
|
552
|
+
const m = this.RenderTransformMatrix, r = this.DrawingRect;
|
|
553
|
+
if (!m || (old.Left === r.Left && old.Top === r.Top))
|
|
554
|
+
return;
|
|
555
|
+
const M = Super.CK.Matrix, dx = r.Left - old.Left, dy = r.Top - old.Top;
|
|
556
|
+
this.RenderTransformMatrix = M.multiply(M.translated(dx, dy), m, M.translated(-dx, -dy));
|
|
557
|
+
}
|
|
558
|
+
/** C# SuperViewChanged: starts the animators queued before this control was attached. */
|
|
559
|
+
StartPendingAnimators() {
|
|
560
|
+
if (!this.Superview)
|
|
561
|
+
return;
|
|
562
|
+
const pending = this.PendingUnattachedAnimators;
|
|
563
|
+
this.PendingUnattachedAnimators = undefined;
|
|
564
|
+
for (const animator of pending)
|
|
565
|
+
animator.Start();
|
|
566
|
+
}
|
|
370
567
|
// ---- accessibility (DrawnUi ISkiaAccessibilityNode) ----
|
|
371
568
|
static nextAccessibilityId = 1;
|
|
372
569
|
/** Stable identity for the DOM overlay. */
|
|
@@ -401,8 +598,12 @@ export class SkiaControl {
|
|
|
401
598
|
this.accessibilityHint = v;
|
|
402
599
|
this.AccessibilityChanged();
|
|
403
600
|
} }
|
|
404
|
-
/**
|
|
405
|
-
|
|
601
|
+
/**
|
|
602
|
+
* Whether keyboard navigation and assistive technology may focus and use this node: the explicit value, else the class
|
|
603
|
+
* default (true when the control handles Tapped), and in both cases only while a tap could reach the control
|
|
604
|
+
* (CanReceiveGesture), so Tab, Enter / Space and screen-reader activation never use a control the pointer cannot.
|
|
605
|
+
*/
|
|
606
|
+
get AccessibilityCanInteract() { return (this.accessibilityCanInteract ?? this.DefaultAccessibilityCanInteract()) && this.CanReceiveGesture("Tapped"); }
|
|
406
607
|
set AccessibilityCanInteract(v) { if (this.accessibilityCanInteract !== v) {
|
|
407
608
|
this.accessibilityCanInteract = v;
|
|
408
609
|
this.AccessibilityChanged();
|
|
@@ -413,6 +614,8 @@ export class SkiaControl {
|
|
|
413
614
|
* host's pointer cursor. Default: the control as a whole (AccessibilityCanInteract); SkiaLabel adds its tappable spans.
|
|
414
615
|
*/
|
|
415
616
|
WantsPointerCursor(_x, _y) { return this.AccessibilityCanInteract; }
|
|
617
|
+
/** A range control's value for screen readers (slider, progress); undefined for everything else (drawnui-cross 6c). */
|
|
618
|
+
get AccessibilityValue() { return undefined; }
|
|
416
619
|
/** aria-pressed for toggles; undefined = not a toggle. */
|
|
417
620
|
get AccessibilityIsPressed() { return this.accessibilityIsPressed; }
|
|
418
621
|
set AccessibilityIsPressed(v) { if (this.accessibilityIsPressed !== v) {
|
|
@@ -487,6 +690,39 @@ export class SkiaControl {
|
|
|
487
690
|
}
|
|
488
691
|
/** Overlay focus arrives on / leaves this node (inputs may activate their sink here). */
|
|
489
692
|
OnAccessibilityFocused(_focused) { }
|
|
693
|
+
/**
|
|
694
|
+
* Keyboard navigation hands this control the keys it may use while it holds keyboard focus (ArrowLeft / Right / Up /
|
|
695
|
+
* Down, Home, End, PageUp, PageDown, DOM `event.code` names). Return true when the key was used; the default uses none,
|
|
696
|
+
* so the key moves focus inside the arrow-key group around the control.
|
|
697
|
+
*/
|
|
698
|
+
OnAccessibilityKey(_key) { return false; }
|
|
699
|
+
/**
|
|
700
|
+
* Whether a pointer gesture of this kind would reach this control, by the rules the gesture dispatch applies: the
|
|
701
|
+
* control and every ancestor draw, none of them is InputTransparent, no ancestor keeps this gesture from its children
|
|
702
|
+
* (LockChildrenGestures, PassNone included) and the control accepts input (AcceptsInput). Opacity does not count, as
|
|
703
|
+
* for the pointer. Keyboard navigation uses it: Tapped for Tab and Enter / Space, Panning for the arrow keys.
|
|
704
|
+
*/
|
|
705
|
+
CanReceiveGesture(gesture) {
|
|
706
|
+
if (!this.IsVisible || this.IsDisposed || this.InputTransparent || !this.AcceptsInput())
|
|
707
|
+
return false;
|
|
708
|
+
for (let p = this.Parent; p; p = p.Parent)
|
|
709
|
+
if (!p.IsVisible || p.IsDisposed || p.InputTransparent || p.CheckChildrenGesturesLocked(gesture))
|
|
710
|
+
return false;
|
|
711
|
+
return true;
|
|
712
|
+
}
|
|
713
|
+
/**
|
|
714
|
+
* False while the control ignores input itself: RespondsToGestures = false on a button, toggle, slider, scroll...
|
|
715
|
+
* Taps, keyboard and the accessibility state (reported disabled) all follow it (drawnui-cross 6w). Default true.
|
|
716
|
+
*/
|
|
717
|
+
AcceptsInput() { return true; }
|
|
718
|
+
/**
|
|
719
|
+
* What a control that takes no input returns for a gesture that reached it (C# BlockedGestureResult): it keeps a
|
|
720
|
+
* press, tap or long press, so nothing under it reacts to them, and lets moves and wheel go on to the controls around
|
|
721
|
+
* it (a scroll behind it still scrolls).
|
|
722
|
+
*/
|
|
723
|
+
BlockedGestureResult(args) {
|
|
724
|
+
return args.Type === "Down" || args.Type === "Tapped" || args.Type === "LongPressing" ? this : null;
|
|
725
|
+
}
|
|
490
726
|
NotifyAccessibilityFocused(focused) { this.Superview?.AccessibilityManager.NotifyFocused(focused ? this : undefined); }
|
|
491
727
|
/** DrawnUi SmartMax: larger of two sizes, an infinite one loses. */
|
|
492
728
|
static SmartMax(a, b) {
|
|
@@ -552,8 +788,25 @@ export class SkiaControl {
|
|
|
552
788
|
const applyOpacity = this.Opacity < 1;
|
|
553
789
|
// C# Left/Top: a cached control is blitted at an offset, no matrix and no save/restore around the subtree
|
|
554
790
|
const offsetOnly = (this.Left !== 0 || this.Top !== 0) && this.UsingCacheType !== "None" && this.TranslationX === 0 && this.TranslationY === 0
|
|
555
|
-
&& this.Rotation === 0 && this.ScaleX === 1 && this.ScaleY === 1 && this.SkewX === 0 && this.SkewY === 0;
|
|
791
|
+
&& this.Rotation === 0 && this.ScaleX === 1 && this.ScaleY === 1 && this.SkewX === 0 && this.SkewY === 0 && !this.Has3d;
|
|
556
792
|
const needTransform = this.HasTransform && !offsetOnly;
|
|
793
|
+
let dx = 0, dy = 0;
|
|
794
|
+
if (needTransform) {
|
|
795
|
+
this.RenderTransformMatrix = this.CreateRenderTransformMatrix(this.DrawingRect, ctx.Scale);
|
|
796
|
+
}
|
|
797
|
+
else if (offsetOnly) {
|
|
798
|
+
dx = this.Left * ctx.Scale;
|
|
799
|
+
dy = this.Top * ctx.Scale;
|
|
800
|
+
this.RenderTransformMatrix = Super.CK.Matrix.translated(dx, dy); // gestures / accessibility still map through it
|
|
801
|
+
}
|
|
802
|
+
else {
|
|
803
|
+
this.RenderTransformMatrix = undefined;
|
|
804
|
+
}
|
|
805
|
+
// drawn entirely outside the clip: skipped with its subtree (C# layout Virtualisation, DrawnUi.Rust); the matrix
|
|
806
|
+
// above stays current for hit tests. A cache that must be recorded is still recorded here, as before, so its cost
|
|
807
|
+
// does not move into the frame where the control scrolls in (DrawnUi.Rust records it then)
|
|
808
|
+
if (this.OutsideClip(canvas, ctx.Scale) && !this.CacheStale(ctx.Scale))
|
|
809
|
+
return;
|
|
557
810
|
let saved = false;
|
|
558
811
|
// same as DrawnUi: opacity = a layer with alpha, transforms = canvas matrix around the whole subtree (cache included)
|
|
559
812
|
if (applyOpacity) {
|
|
@@ -567,19 +820,8 @@ export class SkiaControl {
|
|
|
567
820
|
canvas.save();
|
|
568
821
|
saved = true;
|
|
569
822
|
}
|
|
570
|
-
|
|
571
|
-
if (needTransform) {
|
|
572
|
-
this.RenderTransformMatrix = this.CreateRenderTransformMatrix(this.DrawingRect, ctx.Scale);
|
|
823
|
+
if (needTransform)
|
|
573
824
|
canvas.concat(this.RenderTransformMatrix);
|
|
574
|
-
}
|
|
575
|
-
else if (offsetOnly) {
|
|
576
|
-
dx = this.Left * ctx.Scale;
|
|
577
|
-
dy = this.Top * ctx.Scale;
|
|
578
|
-
this.RenderTransformMatrix = Super.CK.Matrix.translated(dx, dy); // gestures / accessibility still map through it
|
|
579
|
-
}
|
|
580
|
-
else {
|
|
581
|
-
this.RenderTransformMatrix = undefined;
|
|
582
|
-
}
|
|
583
825
|
if (this.IsClippedToBounds) {
|
|
584
826
|
if (!saved) {
|
|
585
827
|
canvas.save();
|
|
@@ -592,11 +834,12 @@ export class SkiaControl {
|
|
|
592
834
|
if (saved)
|
|
593
835
|
canvas.restore();
|
|
594
836
|
}
|
|
595
|
-
/** Port of DrawnUi ApplyTransforms: T(-pivot) · rotation · scale/skew · T(pivot) · translation, in canvas pixels. */
|
|
837
|
+
/** Port of DrawnUi ApplyTransforms: T(-pivot) · rotation · scale/skew · 3D · T(pivot) · translation, in canvas pixels. */
|
|
596
838
|
CreateRenderTransformMatrix(destination, scale) {
|
|
597
839
|
const M = Super.CK.Matrix;
|
|
598
840
|
const moveX = (this.TranslationX + this.Left) * scale, moveY = (this.TranslationY + this.Top) * scale;
|
|
599
|
-
|
|
841
|
+
const has3d = this.Has3d;
|
|
842
|
+
if (this.Rotation === 0 && this.ScaleX === 1 && this.ScaleY === 1 && this.SkewX === 0 && this.SkewY === 0 && !has3d)
|
|
600
843
|
return M.translated(moveX, moveY);
|
|
601
844
|
const px = destination.Left + destination.Width * this.AnchorX;
|
|
602
845
|
const py = destination.Top + destination.Height * this.AnchorY;
|
|
@@ -605,7 +848,36 @@ export class SkiaControl {
|
|
|
605
848
|
const scaleSkew = [this.ScaleX, kx, 0, ky, this.ScaleY, 0, 0, 0, 1];
|
|
606
849
|
const rotation = this.Rotation !== 0 ? M.rotated((Math.PI * this.Rotation) / 180) : M.identity();
|
|
607
850
|
// multiply(a, b, c) = a·b·c, the right-most applies first
|
|
608
|
-
|
|
851
|
+
if (!has3d)
|
|
852
|
+
return M.multiply(M.translated(px + moveX, py + moveY), scaleSkew, rotation, M.translated(-px, -py));
|
|
853
|
+
return M.multiply(M.translated(px + moveX, py + moveY), SkiaControl.Create3dMatrix(this.RotationX, this.RotationY, this.RotationZ, this.TranslationZ), scaleSkew, rotation, M.translated(-px, -py));
|
|
854
|
+
}
|
|
855
|
+
/** C# camera distance of the 3D transforms (Sk3dView.CameraDistance): 8 inches at 72 dpi, in canvas pixels. */
|
|
856
|
+
static CameraDistance = 576;
|
|
857
|
+
/**
|
|
858
|
+
* C# Create3dMatrix (Sk3dView): RotationX, then RotationY, then RotationZ (negated) around the pivot, projected from
|
|
859
|
+
* the camera; TranslationZ is depth, a flat control at depth z draws at camera / (camera − z).
|
|
860
|
+
*/
|
|
861
|
+
static Create3dMatrix(rotationX, rotationY, rotationZ, translationZ) {
|
|
862
|
+
const d = Math.PI / 180, camera = SkiaControl.CameraDistance;
|
|
863
|
+
const sx = Math.sin(rotationX * d), cx = Math.cos(rotationX * d), sy = Math.sin(rotationY * d), cy = Math.cos(rotationY * d);
|
|
864
|
+
const sz = Math.sin(-rotationZ * d), cz = Math.cos(-rotationZ * d);
|
|
865
|
+
return [
|
|
866
|
+
cy * cz, cy * sz, 0,
|
|
867
|
+
sx * sy * cz - cx * sz, sx * sy * sz + cx * cz, 0,
|
|
868
|
+
(cx * sy * cz + sx * sz) / camera, (cx * sy * sz - sx * cz) / camera, Math.max(camera - translationZ, 1) / camera,
|
|
869
|
+
];
|
|
870
|
+
}
|
|
871
|
+
/** C# SkiaSamplingOptions.IsMoveOnly: the matrix only moves (or mirrors), so a bitmap keeps its pixels 1:1. */
|
|
872
|
+
static IsMoveOnly(m) {
|
|
873
|
+
return m[1] === 0 && m[3] === 0 && m[6] === 0 && m[7] === 0 && m[8] === 1 && Math.abs(m[0]) === 1 && Math.abs(m[4]) === 1;
|
|
874
|
+
}
|
|
875
|
+
/**
|
|
876
|
+
* C# WillDrawDistorted: what this control draws here ends up scaled, turned, skewed or projected, by its own transforms
|
|
877
|
+
* or a live ancestor's (both in the canvas matrix) or by the picture it is recorded into. Images then sample smoothly.
|
|
878
|
+
*/
|
|
879
|
+
WillDrawDistorted(ctx) {
|
|
880
|
+
return !!ctx.Context.PlaybackDistorted || !SkiaControl.IsMoveOnly(ctx.Context.Canvas.getTotalMatrix());
|
|
609
881
|
}
|
|
610
882
|
/** Maps a point given in the parent's space into this control's untransformed space (DrawnUi TransformPointToLocalSpace). */
|
|
611
883
|
TransformPointToLocalSpace(point) {
|
|
@@ -641,26 +913,39 @@ export class SkiaControl {
|
|
|
641
913
|
}
|
|
642
914
|
else {
|
|
643
915
|
const r = cacheType === "Operations" ? this.ExpandedCacheRect(ctx.Scale) : this.AlignedCacheRect(ctx.Scale);
|
|
644
|
-
const
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
916
|
+
const epoch = this.Superview?.GpuEpoch ?? 0;
|
|
917
|
+
if (this.RenderObjectPrevious && this.RenderObjectPrevious.Epoch !== epoch)
|
|
918
|
+
this.DisposePrevious(); // made on a lost GPU context
|
|
919
|
+
// a picture replays its image blits with the sampling chosen when it was recorded: recorded again once its
|
|
920
|
+
// playback turns distorted or straight (C# SamplingMismatch), else a cached child of a turning card stays jagged
|
|
921
|
+
const o = this.RenderObject;
|
|
922
|
+
if (this.CacheStale(ctx.Scale) || (o?.Picture && o.HasImageBlits && o.PlaybackDistorted !== this.WillDrawDistorted(ctx)))
|
|
648
923
|
this.CreateRenderingObject({ ...ctx, Destination: this.DrawingRect }, cacheType);
|
|
649
924
|
if (this.RenderObject) {
|
|
650
|
-
// C# DrawRenderObject: with post renderers
|
|
651
|
-
//
|
|
652
|
-
|
|
653
|
-
|
|
925
|
+
// C# DrawRenderObject: with post renderers a cache is not blitted, the effects sample it (CachedImage) and paint
|
|
926
|
+
// the result, so the shader replaces the control; a picture cache hands them its picture drawn into an image
|
|
927
|
+
// (made once per cache, C# GetPictureImage); drawn as before only when that image could not be made
|
|
928
|
+
const cache = this.RenderObject;
|
|
929
|
+
if (post.length > 0 && cache.Picture)
|
|
930
|
+
cache.GetPictureImage(ctx.Context.Surface);
|
|
931
|
+
if (post.length === 0 || !(cache.Image ?? cache.PictureImage))
|
|
932
|
+
this.DrawCache(cache, ctx, r.Left + dx, r.Top + dy);
|
|
654
933
|
for (const e of post)
|
|
655
934
|
e.Render(own);
|
|
656
935
|
}
|
|
657
936
|
else if (this.RenderObjectPrevious)
|
|
658
|
-
this.
|
|
937
|
+
this.DrawCache(this.RenderObjectPrevious, ctx, r.Left + dx, r.Top + dy); // double buffer: last good frame
|
|
659
938
|
else
|
|
660
939
|
this.DrawPlaceholder(own);
|
|
661
940
|
}
|
|
662
941
|
this.ExecutePostAnimators(own);
|
|
663
942
|
}
|
|
943
|
+
/** Blits a cache: an image samples smoothly when drawn distorted; a picture being recorded learns it holds image blits. */
|
|
944
|
+
DrawCache(cache, ctx, left, top) {
|
|
945
|
+
if (cache.Image || cache.HasImageBlits)
|
|
946
|
+
ctx.Context.HasImageBlits = true;
|
|
947
|
+
cache.Draw(ctx.Context.Canvas, left, top, !!cache.Image && this.WillDrawDistorted(ctx));
|
|
948
|
+
}
|
|
664
949
|
/** Background + Paint(): the part of the control that a cache captures. */
|
|
665
950
|
PaintContent(ctx) {
|
|
666
951
|
if (this.BackgroundColor || (this.FillGradient && this.FillGradientPaintsBackground()) || this.PaintsBackgroundWithoutColor())
|
|
@@ -695,11 +980,16 @@ export class SkiaControl {
|
|
|
695
980
|
}
|
|
696
981
|
if (cacheType === "Operations") {
|
|
697
982
|
const recorder = new CK.PictureRecorder();
|
|
983
|
+
const playbackDistorted = this.WillDrawDistorted(ctx);
|
|
698
984
|
const canvas = recorder.beginRecording(CK.LTRBRect(r.Left, r.Top, r.Right, r.Bottom));
|
|
699
|
-
|
|
985
|
+
const recording = { ...ctx.Context, Canvas: canvas, Recording: true, PlaybackDistorted: playbackDistorted, HasImageBlits: false };
|
|
986
|
+
this.PaintContent({ ...ctx, Context: recording });
|
|
700
987
|
const picture = recorder.finishRecordingAsPicture();
|
|
701
988
|
recorder.delete();
|
|
702
989
|
this.RenderObject = new CachedObject("Operations", r, ctx.Scale, picture);
|
|
990
|
+
this.RenderObject.Epoch = this.Superview?.GpuEpoch ?? 0;
|
|
991
|
+
this.RenderObject.PlaybackDistorted = playbackDistorted;
|
|
992
|
+
this.RenderObject.HasImageBlits = recording.HasImageBlits;
|
|
703
993
|
}
|
|
704
994
|
else if (cacheType === "ImageComposite") {
|
|
705
995
|
this.CreateCompositeRenderingObject(ctx, r, w, h);
|
|
@@ -723,6 +1013,7 @@ export class SkiaControl {
|
|
|
723
1013
|
const image = offscreen.makeImageSnapshot();
|
|
724
1014
|
offscreen.delete();
|
|
725
1015
|
this.RenderObject = new CachedObject(cacheType, r, ctx.Scale, undefined, image);
|
|
1016
|
+
this.RenderObject.Epoch = this.Superview?.GpuEpoch ?? 0;
|
|
726
1017
|
}
|
|
727
1018
|
this.cacheDirty = false;
|
|
728
1019
|
}
|
|
@@ -741,7 +1032,9 @@ export class SkiaControl {
|
|
|
741
1032
|
}
|
|
742
1033
|
let surface = this.compositeSurface;
|
|
743
1034
|
const prev = this.RenderObject;
|
|
744
|
-
const
|
|
1035
|
+
const epoch = this.Superview?.GpuEpoch ?? 0;
|
|
1036
|
+
// the kept surface belongs to the GPU context it was made on: after a context restore it is made again
|
|
1037
|
+
const sameGeometry = !!surface && !!prev && prev.Type === "ImageComposite" && prev.Scale === ctx.Scale && prev.Epoch === epoch
|
|
745
1038
|
&& Math.round(prev.Bounds.Width) === w && Math.round(prev.Bounds.Height) === h;
|
|
746
1039
|
if (!sameGeometry) {
|
|
747
1040
|
surface?.delete();
|
|
@@ -754,14 +1047,46 @@ export class SkiaControl {
|
|
|
754
1047
|
}
|
|
755
1048
|
const canvas = surface.getCanvas();
|
|
756
1049
|
const children = this.GetCompositeChildren();
|
|
757
|
-
const
|
|
1050
|
+
const deep = this.compositeDeep;
|
|
1051
|
+
// the same size with another effects margin moves the content inside the surface: record whole (C# 97683f19)
|
|
1052
|
+
const insetX = r.Left - this.DrawingRect.Left, insetY = r.Top - this.DrawingRect.Top;
|
|
1053
|
+
const sameInset = insetX === this.compositeInsetX && insetY === this.compositeInsetY;
|
|
1054
|
+
this.compositeInsetX = insetX;
|
|
1055
|
+
this.compositeInsetY = insetY;
|
|
1056
|
+
let partial = sameGeometry && sameInset && !this.compositeFull && children.length > 0 && (this.DirtyChildrenInternal.size > 0 || !!deep?.length);
|
|
1057
|
+
// changes deeper than a child: only their areas, the child they are in drawn clipped to them (drawnui-cross 6m)
|
|
1058
|
+
const areas = [], changed = [], inside = new Set();
|
|
1059
|
+
if (partial && deep?.length) {
|
|
1060
|
+
let covered = 0;
|
|
1061
|
+
for (const d of deep) {
|
|
1062
|
+
if (!children.includes(d.Child) || this.DirtyChildrenInternal.has(d.Child))
|
|
1063
|
+
continue;
|
|
1064
|
+
const area = SkiaControl.DeepArea(d, this, ctx.Scale);
|
|
1065
|
+
if (area === null) {
|
|
1066
|
+
partial = false;
|
|
1067
|
+
break;
|
|
1068
|
+
}
|
|
1069
|
+
if (!area) {
|
|
1070
|
+
this.DirtyChildrenInternal.add(d.Child);
|
|
1071
|
+
continue;
|
|
1072
|
+
}
|
|
1073
|
+
areas.push(area);
|
|
1074
|
+
changed.push(d.Origin);
|
|
1075
|
+
inside.add(d.Child);
|
|
1076
|
+
covered += area.Width * area.Height;
|
|
1077
|
+
}
|
|
1078
|
+
if (areas.length > SkiaControl.MaxCompositionAreas || covered > r.Width * r.Height * SkiaControl.MaxCompositionShare)
|
|
1079
|
+
partial = false;
|
|
1080
|
+
}
|
|
1081
|
+
if (deep)
|
|
1082
|
+
deep.length = 0;
|
|
758
1083
|
const offset = prev && sameGeometry ? { X: r.Left - prev.Bounds.Left, Y: r.Top - prev.Bounds.Top } : { X: 0, Y: 0 };
|
|
759
1084
|
const saved = canvas.save();
|
|
760
1085
|
canvas.translate(-r.Left, -r.Top);
|
|
761
1086
|
if (partial) {
|
|
762
1087
|
// dirty = reported children + siblings intersecting their old or new bounds (C# makes intersecting children dirty too)
|
|
763
1088
|
const dirty = new Set();
|
|
764
|
-
const rects = [];
|
|
1089
|
+
const rects = [...areas];
|
|
765
1090
|
const boundsOf = (c) => {
|
|
766
1091
|
const out = [c.GetTransformedDirtyBounds()];
|
|
767
1092
|
if (c.lastCompositeBounds)
|
|
@@ -777,7 +1102,7 @@ export class SkiaControl {
|
|
|
777
1102
|
while (grew) {
|
|
778
1103
|
grew = false;
|
|
779
1104
|
for (const c of children) {
|
|
780
|
-
if (dirty.has(c) || !c.IsVisible)
|
|
1105
|
+
if (dirty.has(c) || inside.has(c) || !c.IsVisible)
|
|
781
1106
|
continue;
|
|
782
1107
|
const own = boundsOf(c);
|
|
783
1108
|
if (rects.some((d) => own.some((o) => o.Left < d.Right && d.Left < o.Right && o.Top < d.Bottom && d.Top < o.Bottom))) {
|
|
@@ -804,14 +1129,18 @@ export class SkiaControl {
|
|
|
804
1129
|
this.DirtyChildrenInternal.clear();
|
|
805
1130
|
for (const c of dirty)
|
|
806
1131
|
this.DirtyChildrenInternal.add(c);
|
|
1132
|
+
for (const c of inside)
|
|
1133
|
+
this.DirtyChildrenInternal.add(c);
|
|
1134
|
+
// children entirely outside the redrawn areas are skipped by their own clip check (Render)
|
|
807
1135
|
this.PaintContent({ ...ctx, Context: { Canvas: canvas, Surface: surface, Origin: { X: r.Left, Y: r.Top } } });
|
|
808
1136
|
this.IsRenderingWithComposition = false;
|
|
809
|
-
|
|
1137
|
+
const redrawn = children.filter((c) => this.DirtyChildrenInternal.has(c));
|
|
1138
|
+
this.LastCompositeRecord = { Mode: "partial", Children: redrawn.length, Dirty: redrawn, Areas: areas, Changed: changed };
|
|
810
1139
|
}
|
|
811
1140
|
else {
|
|
812
1141
|
canvas.clear(CK.TRANSPARENT);
|
|
813
1142
|
this.PaintContent({ ...ctx, Context: { Canvas: canvas, Surface: surface, Origin: { X: r.Left, Y: r.Top } } });
|
|
814
|
-
this.LastCompositeRecord = { Mode: "full", Children: children.length, Dirty: children };
|
|
1143
|
+
this.LastCompositeRecord = { Mode: "full", Children: children.length, Dirty: children, Areas: [], Changed: [] };
|
|
815
1144
|
}
|
|
816
1145
|
canvas.restoreToCount(saved);
|
|
817
1146
|
for (const c of children)
|
|
@@ -821,6 +1150,7 @@ export class SkiaControl {
|
|
|
821
1150
|
const image = surface.makeImageSnapshot();
|
|
822
1151
|
const old = this.RenderObject;
|
|
823
1152
|
this.RenderObject = new CachedObject("ImageComposite", r, ctx.Scale, undefined, image);
|
|
1153
|
+
this.RenderObject.Epoch = epoch;
|
|
824
1154
|
if (old) {
|
|
825
1155
|
const sv = this.Superview;
|
|
826
1156
|
if (sv)
|
|
@@ -856,7 +1186,11 @@ export class SkiaControl {
|
|
|
856
1186
|
/** Marks the cache stale; re-recorded on the next frame (a composite records fully: its own content changed). */
|
|
857
1187
|
InvalidateCache() { this.cacheDirty = true; this.compositeFull = true; }
|
|
858
1188
|
/** Effects margin recomputed on the next use (C# InvalidateEffectsMargin). */
|
|
859
|
-
InvalidateEffectsMargin() {
|
|
1189
|
+
InvalidateEffectsMargin() {
|
|
1190
|
+
// a layout's margin aggregates what its children paint outside it: every ancestor recomputes too (C# 97683f19)
|
|
1191
|
+
for (let c = this; c; c = c.Parent)
|
|
1192
|
+
c.effectsMarginCache = undefined;
|
|
1193
|
+
}
|
|
860
1194
|
/** Draws PostAnimators above content; an effect returning true asks for another frame. */
|
|
861
1195
|
ExecutePostAnimators(ctx) {
|
|
862
1196
|
if (this.PostAnimators.length === 0)
|
|
@@ -1038,6 +1372,7 @@ export class SkiaControl {
|
|
|
1038
1372
|
this.ownAnimations.clear();
|
|
1039
1373
|
for (const e of [...this.PostAnimators])
|
|
1040
1374
|
e.Stop?.();
|
|
1375
|
+
this.PendingUnattachedAnimators = undefined;
|
|
1041
1376
|
this.PostAnimators.length = 0;
|
|
1042
1377
|
this.DestroyRenderingObject();
|
|
1043
1378
|
this.compositeSurface?.delete();
|
|
@@ -1066,32 +1401,134 @@ export class SkiaControl {
|
|
|
1066
1401
|
}
|
|
1067
1402
|
/** Redraw without remeasure and WITHOUT dropping caches (position/overlay changes). */
|
|
1068
1403
|
Repaint() {
|
|
1069
|
-
this.
|
|
1404
|
+
if (!this.UnderHiddenParent())
|
|
1405
|
+
this.Superview?.Update();
|
|
1406
|
+
}
|
|
1407
|
+
/**
|
|
1408
|
+
* A parent (not the control itself) is hidden: a change here asks for no frame and the latest state shows when the
|
|
1409
|
+
* parent is shown again (C# 329f6c44 HiddenUpdateTests, DrawnUi.Rust hidden_updates). The control's own visibility
|
|
1410
|
+
* change still draws: it is the one that hides or shows it.
|
|
1411
|
+
*/
|
|
1412
|
+
UnderHiddenParent() {
|
|
1413
|
+
for (let p = this.Parent; p; p = p.Parent)
|
|
1414
|
+
if (!p.IsVisible)
|
|
1415
|
+
return true;
|
|
1416
|
+
return false;
|
|
1070
1417
|
}
|
|
1418
|
+
/** The control or a parent is hidden: its animators pause until it shows again. */
|
|
1419
|
+
HiddenInTree() { return !this.IsVisible || this.UnderHiddenParent(); }
|
|
1420
|
+
/** The control an invalidation started at while it climbs (InvalidateMeasure): a hidden parent of it wakes no frame. */
|
|
1421
|
+
static invalidateOrigin = null;
|
|
1071
1422
|
/**
|
|
1072
1423
|
* Transform / Opacity changed: this control's own cache is still valid (content unchanged) but every ancestor
|
|
1073
1424
|
* cache holds its composited output, so those are staled before redrawing (DrawnUi RedrawCanvas + parent invalidation).
|
|
1074
1425
|
*/
|
|
1075
1426
|
RepaintComposition() {
|
|
1076
|
-
|
|
1077
|
-
|
|
1427
|
+
this.ReportToComposites();
|
|
1428
|
+
for (let p = this.Parent; p; p = p.Parent)
|
|
1078
1429
|
p.cacheDirty = true;
|
|
1079
|
-
p.TrackChildAsDirty(child);
|
|
1080
|
-
child = p;
|
|
1081
|
-
p = p.Parent;
|
|
1082
|
-
}
|
|
1083
1430
|
this.Repaint();
|
|
1084
1431
|
}
|
|
1432
|
+
/**
|
|
1433
|
+
* Update() for a change of how this control looks, not of its size (a color set through props, C# NeedDraw): the same
|
|
1434
|
+
* re-measure and cache invalidation, but an ImageComposite above redraws only this control's area instead of
|
|
1435
|
+
* recording whole (drawnui-cross 6m). The record still goes whole when the control's rect changed after all.
|
|
1436
|
+
*/
|
|
1437
|
+
UpdateDraw() {
|
|
1438
|
+
this.ReportToComposites();
|
|
1439
|
+
const outer = SkiaControl.drawOrigin;
|
|
1440
|
+
SkiaControl.drawOrigin = this;
|
|
1441
|
+
try {
|
|
1442
|
+
this.InvalidateMeasure();
|
|
1443
|
+
}
|
|
1444
|
+
finally {
|
|
1445
|
+
SkiaControl.drawOrigin = outer;
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
/**
|
|
1449
|
+
* A change of this control that keeps its layout, to every ImageComposite above: a direct child is drawn again whole
|
|
1450
|
+
* (C# TrackChildAsDirty), a deeper control by its area, read now as it was drawn (its last matrix and effects margin).
|
|
1451
|
+
*/
|
|
1452
|
+
ReportToComposites() {
|
|
1453
|
+
let before;
|
|
1454
|
+
let child = this;
|
|
1455
|
+
for (let p = this.Parent; p; child = p, p = p.Parent) {
|
|
1456
|
+
if (!p.IsCacheComposite)
|
|
1457
|
+
continue;
|
|
1458
|
+
if (child === this) {
|
|
1459
|
+
p.TrackChildAsDirty(child);
|
|
1460
|
+
continue;
|
|
1461
|
+
}
|
|
1462
|
+
const deep = p.compositeDeep ??= [];
|
|
1463
|
+
if (deep.some((d) => d.Origin === this))
|
|
1464
|
+
continue;
|
|
1465
|
+
before ??= this.GetTransformedDirtyBounds();
|
|
1466
|
+
const r = this.DrawingRect;
|
|
1467
|
+
deep.push({ Origin: this, Child: child, Before: before, Rect: new SKRect(r.Left, r.Top, r.Right, r.Bottom) });
|
|
1468
|
+
}
|
|
1469
|
+
}
|
|
1470
|
+
/** The matrix this control will be drawn with (Render), from its current properties; undefined when none. */
|
|
1471
|
+
CurrentMatrix(scale) {
|
|
1472
|
+
return this.HasTransform ? this.CreateRenderTransformMatrix(this.DrawingRect, scale) : undefined;
|
|
1473
|
+
}
|
|
1474
|
+
/** Where this control will be drawn: its rect grown by its effects margin, through its current matrix. */
|
|
1475
|
+
DrawnBoundsNow(scale) { return SkiaControl.MapRect(this.CurrentMatrix(scale), this.ExpandedCacheRect(scale)); }
|
|
1476
|
+
static MapRect(m, r) {
|
|
1477
|
+
if (!m)
|
|
1478
|
+
return r;
|
|
1479
|
+
const pts = Super.CK.Matrix.mapPoints(m, [r.Left, r.Top, r.Right, r.Top, r.Right, r.Bottom, r.Left, r.Bottom]);
|
|
1480
|
+
return new SKRect(Math.min(pts[0], pts[2], pts[4], pts[6]), Math.min(pts[1], pts[3], pts[5], pts[7]), Math.max(pts[0], pts[2], pts[4], pts[6]), Math.max(pts[1], pts[3], pts[5], pts[7]));
|
|
1481
|
+
}
|
|
1482
|
+
/** Its output depends on all of its content (a visual effect; a backdrop samples below): a change inside redraws it whole. */
|
|
1483
|
+
get SamplesContent() { return !this.DisableEffects && this.visualEffects.length > 0; }
|
|
1484
|
+
/**
|
|
1485
|
+
* Where a deep change shows inside the composite (drawnui-cross 6m rule b): the control as drawn before and as drawn
|
|
1486
|
+
* now, then through the transform of every ancestor up to the composite. undefined: draw the child whole (an effect
|
|
1487
|
+
* or a backdrop on the way, the control gone from the child); null: the layout changed, record whole.
|
|
1488
|
+
*/
|
|
1489
|
+
static DeepArea(d, composite, scale) {
|
|
1490
|
+
const o = d.Origin, r = o.DrawingRect;
|
|
1491
|
+
if (r.Left !== d.Rect.Left || r.Top !== d.Rect.Top || r.Right !== d.Rect.Right || r.Bottom !== d.Rect.Bottom)
|
|
1492
|
+
return null;
|
|
1493
|
+
if (!o.IsVisible)
|
|
1494
|
+
return undefined;
|
|
1495
|
+
const now = o.DrawnBoundsNow(scale);
|
|
1496
|
+
let area = new SKRect(Math.min(now.Left, d.Before.Left), Math.min(now.Top, d.Before.Top), Math.max(now.Right, d.Before.Right), Math.max(now.Bottom, d.Before.Bottom));
|
|
1497
|
+
let p = o.Parent, child = o;
|
|
1498
|
+
for (; p && p !== composite; child = p, p = p.Parent) {
|
|
1499
|
+
if (p.SamplesContent || !p.IsVisible)
|
|
1500
|
+
return undefined;
|
|
1501
|
+
area = SkiaControl.MapRect(p.CurrentMatrix(scale), area);
|
|
1502
|
+
}
|
|
1503
|
+
return p === composite && child === d.Child ? area : undefined;
|
|
1504
|
+
}
|
|
1505
|
+
/**
|
|
1506
|
+
* DrawnUi IsParentIndependent: this control's size never changes the layout around it, so its own invalidation
|
|
1507
|
+
* stops here (ancestors composite again, nothing above re-measures). The parent re-measures it on draw when
|
|
1508
|
+
* NeedMeasure is set. Used by SkiaScroll for its scroll bars.
|
|
1509
|
+
*/
|
|
1510
|
+
IsParentIndependent = false;
|
|
1085
1511
|
/** Size or content may have changed: this control and all ancestors remeasure and re-record. */
|
|
1086
1512
|
InvalidateMeasure() {
|
|
1087
1513
|
this.NeedMeasure = true;
|
|
1088
1514
|
this.cacheDirty = true;
|
|
1089
|
-
|
|
1515
|
+
// structure may change: a composite cannot patch it; a draw-only change (UpdateDraw) reported its area instead
|
|
1516
|
+
if (SkiaControl.drawOrigin === null || SkiaControl.drawOrigin === this)
|
|
1517
|
+
this.compositeFull = true;
|
|
1090
1518
|
this.effectsMarginCache = undefined;
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
this.
|
|
1519
|
+
const outer = SkiaControl.invalidateOrigin;
|
|
1520
|
+
SkiaControl.invalidateOrigin ??= this;
|
|
1521
|
+
try {
|
|
1522
|
+
if (this.Parent && this.IsParentIndependent)
|
|
1523
|
+
this.RepaintComposition();
|
|
1524
|
+
else if (this.Parent)
|
|
1525
|
+
this.Parent.InvalidateMeasure();
|
|
1526
|
+
else if (!SkiaControl.invalidateOrigin.UnderHiddenParent())
|
|
1527
|
+
this.Superview?.Update();
|
|
1528
|
+
}
|
|
1529
|
+
finally {
|
|
1530
|
+
SkiaControl.invalidateOrigin = outer;
|
|
1531
|
+
}
|
|
1095
1532
|
}
|
|
1096
1533
|
// ---- gestures (same names as DrawnUi) ----
|
|
1097
1534
|
/** Hit rect in pixels (no transforms in this port, so it is DrawingRect). */
|
|
@@ -1150,15 +1587,19 @@ export class SkiaControl {
|
|
|
1150
1587
|
if (this.ConsumeGestures) {
|
|
1151
1588
|
const sent = new SkiaGesturesInfo(args, apply);
|
|
1152
1589
|
this.ConsumeGestures(this, sent);
|
|
1153
|
-
if (args.Type !== "Up" && sent.Consumed)
|
|
1590
|
+
if (args.Type !== "Up" && sent.Consumed) {
|
|
1591
|
+
args.Event.Handled = true;
|
|
1154
1592
|
return this;
|
|
1593
|
+
}
|
|
1155
1594
|
}
|
|
1156
1595
|
// C# EffectsGestureProcessors: attached effects that process gestures (ISkiaGestureProcessor) see them first
|
|
1157
1596
|
if (!this.DisableEffects)
|
|
1158
1597
|
for (const e of this.visualEffects) {
|
|
1159
1598
|
const p = e.ProcessGestures;
|
|
1160
|
-
if (typeof p === "function" && p.call(e, args, apply) && args.Type !== "Up")
|
|
1599
|
+
if (typeof p === "function" && p.call(e, args, apply) && args.Type !== "Up") {
|
|
1600
|
+
args.Event.Handled = true;
|
|
1161
1601
|
return this;
|
|
1602
|
+
}
|
|
1162
1603
|
}
|
|
1163
1604
|
if (this.CheckChildrenGesturesLocked(args.Type))
|
|
1164
1605
|
return consumedDefault;
|