Skip to content

Commit 19aac5b

Browse files
committed
Original event is passed to bounds and slot callbacks.
1 parent ef005ab commit 19aac5b

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

spine-ts/spine-webgl/example/webcomponent-tutorial.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -3223,7 +3223,7 @@
32233223
await widgetButton.loadingPromise;
32243224

32253225
widgetButton.skeleton.color.set(.85, .85, .85, 1);
3226-
widgetButton.cursorBoundsEventCallback = (event) => {
3226+
widgetButton.cursorBoundsEventCallback = (event, originalEvent) => {
32273227
if (event === "enter") {
32283228
widgetButton.state.setAnimation(0, "enhance-in", false);
32293229
widgetButton.state.setAnimation(1, "shadow-in", false);
@@ -3236,6 +3236,7 @@
32363236
};
32373237
if (event === "down") {
32383238
widgetButton.state.setAnimation(0, "enhance-in", false).timeScale = 2;
3239+
originalEvent.preventDefault();
32393240
if (form.reportValidity()) {
32403241
if (passwordInput.value === "password") {
32413242
widget.state.setAnimation(0, "interactive/pwd/hooray", 0);

spine-ts/spine-webgl/src/SpineWebComponentWidget.ts

+19-20
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ export class SpineWebComponentWidget extends HTMLElement implements Disposable,
551551
* By default, the function does nothing.
552552
* This is an experimental property and might be removed in the future.
553553
*/
554-
public cursorBoundsEventCallback = (event: CursorEventTypes) => {}
554+
public cursorBoundsEventCallback = (event: CursorEventTypes, originalEvent?: UIEvent) => {}
555555

556556
/**
557557
* This methods allows to associate to a Slot a callback. For these slots, if the widget is interactive,
@@ -1105,39 +1105,39 @@ export class SpineWebComponentWidget extends HTMLElement implements Disposable,
11051105
* @internal
11061106
*/
11071107
public cursorSlotEventCallbacks: Map<Slot, {
1108-
slotFunction: (slot: Slot, event: CursorEventTypes ) => void,
1108+
slotFunction: (slot: Slot, event: CursorEventTypes, originalEvent?: UIEvent) => void,
11091109
inside: boolean,
11101110
}> = new Map();
11111111

11121112
/**
11131113
* @internal
11141114
*/
1115-
public cursorEventUpdate (type: CursorEventTypesInput) {
1115+
public cursorEventUpdate (type: CursorEventTypesInput, originalEvent?: UIEvent) {
11161116
if (!this.isInteractive) return;
11171117

1118-
this.checkBoundsInteraction(type);
1119-
this.checkSlotInteraction(type);
1118+
this.checkBoundsInteraction(type, originalEvent);
1119+
this.checkSlotInteraction(type, originalEvent);
11201120
}
11211121

1122-
private checkBoundsInteraction (type: CursorEventTypesInput) {
1122+
private checkBoundsInteraction (type: CursorEventTypesInput, originalEvent?: UIEvent) {
11231123
if ((type === "down"|| type === "up") && this.cursorInsideBounds) {
1124-
this.cursorBoundsEventCallback(type);
1124+
this.cursorBoundsEventCallback(type, originalEvent);
11251125
return;
11261126
}
11271127

11281128
if (this.checkCursorInsideBounds()) {
11291129

11301130
if (!this.cursorInsideBounds) {
1131-
this.cursorBoundsEventCallback("enter");
1131+
this.cursorBoundsEventCallback("enter", originalEvent);
11321132
}
11331133
this.cursorInsideBounds = true;
11341134

1135-
this.cursorBoundsEventCallback(type);
1135+
this.cursorBoundsEventCallback(type, originalEvent);
11361136

11371137
} else {
11381138

11391139
if (this.cursorInsideBounds) {
1140-
this.cursorBoundsEventCallback("leave");
1140+
this.cursorBoundsEventCallback("leave", originalEvent);
11411141
}
11421142
this.cursorInsideBounds = false;
11431143

@@ -1158,7 +1158,7 @@ export class SpineWebComponentWidget extends HTMLElement implements Disposable,
11581158
return inside(this.pointTemp, this.bounds);
11591159
}
11601160

1161-
private checkSlotInteraction(type: CursorEventTypesInput) {
1161+
private checkSlotInteraction(type: CursorEventTypesInput, originalEvent?: UIEvent) {
11621162
for (let [slot, interactionState] of this.cursorSlotEventCallbacks) {
11631163
if (!slot.bone.active) continue;
11641164
let attachment = slot.getAttachment();
@@ -1169,7 +1169,7 @@ export class SpineWebComponentWidget extends HTMLElement implements Disposable,
11691169

11701170
if (type === "down" || type === "up") {
11711171
if (inside) {
1172-
slotFunction(slot, type);
1172+
slotFunction(slot, type, originalEvent);
11731173
}
11741174
return;
11751175
}
@@ -1192,7 +1192,7 @@ export class SpineWebComponentWidget extends HTMLElement implements Disposable,
11921192

11931193
if (!inside) {
11941194
interactionState.inside = true;
1195-
slotFunction(slot, "enter");
1195+
slotFunction(slot, "enter", originalEvent);
11961196
}
11971197

11981198
slotFunction(slot, type);
@@ -1201,7 +1201,7 @@ export class SpineWebComponentWidget extends HTMLElement implements Disposable,
12011201

12021202
if (inside) {
12031203
interactionState.inside = false;
1204-
slotFunction(slot, "leave");
1204+
slotFunction(slot, "leave", originalEvent);
12051205
}
12061206

12071207
}
@@ -1982,18 +1982,17 @@ class SpineWebComponentOverlay extends HTMLElement implements OverlayAttributes,
19821982
this.skeletonList.forEach(widget => {
19831983
if (!this.cursorWidgetUpdate(widget) || !widget.onScreen) return;
19841984

1985-
widget.cursorEventUpdate("move");
1985+
widget.cursorEventUpdate("move", ev);
19861986
});
19871987
},
19881988
down: (x, y, ev) => {
19891989
const input = getInput(ev);
19901990
this.skeletonList.forEach(widget => {
19911991
if (!widget.onScreen && widget.dragX === 0 && widget.dragY === 0) return;
19921992

1993-
widget.cursorEventUpdate("down");
1993+
widget.cursorEventUpdate("down", ev);
19941994

19951995
if ((widget.isInteractive && widget.cursorInsideBounds) || (!widget.isInteractive && widget.checkCursorInsideBounds())) {
1996-
19971996
if (!widget.isDraggable) return;
19981997

19991998
widget.dragging = true;
@@ -2016,7 +2015,7 @@ class SpineWebComponentOverlay extends HTMLElement implements OverlayAttributes,
20162015
this.skeletonList.forEach(widget => {
20172016
if (!this.cursorWidgetUpdate(widget) || !widget.onScreen && widget.dragX === 0 && widget.dragY === 0) return;
20182017

2019-
widget.cursorEventUpdate("drag");
2018+
widget.cursorEventUpdate("drag", ev);
20202019

20212020
if (!widget.dragging) return;
20222021

@@ -2030,12 +2029,12 @@ class SpineWebComponentOverlay extends HTMLElement implements OverlayAttributes,
20302029
prevX = input.x;
20312030
prevY = input.y;
20322031
},
2033-
up: () => {
2032+
up: (x, y, ev) => {
20342033
this.skeletonList.forEach(widget => {
20352034
widget.dragging = false;
20362035

20372036
if (widget.cursorInsideBounds) {
2038-
widget.cursorEventUpdate("up");
2037+
widget.cursorEventUpdate("up", ev);
20392038
}
20402039
});
20412040
}

0 commit comments

Comments
 (0)