@awayjs/scene 0.13.239 → 0.13.242

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.
@@ -1,8 +1,9 @@
1
1
  import { Point, Vector3D, EventBase } from '@awayjs/core';
2
2
 
3
- import { EntityNode, ContainerNode, INode, ITraversable, View } from '@awayjs/view';
3
+ import { EntityNode, ContainerNode, INode, ITraversable, View, IPartitionContainer } from '@awayjs/view';
4
4
 
5
5
  import { IMaterial } from '@awayjs/renderer';
6
+ import FrameScriptManager from '../managers/FrameScriptManager';
6
7
 
7
8
  /**
8
9
  * A MouseEvent is dispatched when a mouse event occurs over a mouseEnabled object in View.
@@ -276,4 +277,11 @@ export class MouseEvent extends EventBase {
276
277
 
277
278
  return sceneNormal;
278
279
  }
280
+
281
+ public _dispatchEvent(dispatcher: ContainerNode, target: IPartitionContainer) {
282
+ if (!dispatcher.isMouseDisabled()) {
283
+ dispatcher.container.dispatchEvent(this, target);
284
+ FrameScriptManager.execute_queue();
285
+ }
286
+ }
279
287
  }
@@ -2,6 +2,7 @@ import { Vector3D } from '@awayjs/core';
2
2
  import { Stage } from '@awayjs/stage';
3
3
 
4
4
  import { PickingCollision, RaycastPicker, ContainerNode, IPartitionContainer, EntityNode } from '@awayjs/view';
5
+ import { FocusEvent } from '../events/FocusEvent';
5
6
 
6
7
  import { KeyboardEvent } from '../events/KeyboardEvent';
7
8
  import { MouseEvent as AwayMouseEvent } from '../events/MouseEvent';
@@ -26,7 +27,7 @@ export class MouseManager {
26
27
 
27
28
  private _mouseDragCollision: PickingCollision; // entity hit on mouse-down
28
29
  private _mouseDragging: boolean; // true while mosue is dragged
29
- private _focusContainer: IPartitionContainer; // entity currently in focus
30
+ private _focusNode: ContainerNode; // entity currently in focus
30
31
 
31
32
  public allowKeyInput: boolean=true;
32
33
 
@@ -60,6 +61,9 @@ export class MouseManager {
60
61
  private _dragStart: AwayMouseEvent = new AwayMouseEvent(AwayMouseEvent.DRAG_START);
61
62
  private _dragStop: AwayMouseEvent = new AwayMouseEvent(AwayMouseEvent.DRAG_STOP);
62
63
 
64
+ private _focusIn: FocusEvent = new FocusEvent(FocusEvent.FOCUS_IN);
65
+ private _focusOut: FocusEvent = new FocusEvent(FocusEvent.FOCUS_OUT);
66
+
63
67
  private _useSoftkeyboard: boolean = false;
64
68
 
65
69
  public buttonEnabledDirty: boolean;
@@ -121,7 +125,7 @@ export class MouseManager {
121
125
  this.onKeyUp = this.onKeyUp.bind(this);
122
126
 
123
127
  this.buttonEnabledDirty = false;
124
- this._isTouch = (('ontouchstart' in self) || navigator.msMaxTouchPoints > 0);
128
+ this._isTouch = (('ontouchstart' in self) || navigator['msMaxTouchPoints'] > 0);
125
129
  this._showCursor = true;
126
130
  this._mouseDragging = false;
127
131
 
@@ -219,41 +223,47 @@ export class MouseManager {
219
223
 
220
224
  }
221
225
 
222
- public setFocus(obj: IPartitionContainer) {
223
- if (this._focusContainer == obj) {
226
+ public setFocus(node: ContainerNode) {
227
+ if (this._focusNode == node)
224
228
  return;
225
- }
226
- if (this._focusContainer) {
227
- this._focusContainer.setFocus(false, false);
228
- }
229
- this._focusContainer = obj;
230
229
 
231
- if (this._focusContainer) {
232
- this._focusContainer.setFocus(true, false);
230
+ // in FP6, a mouseclick on non focus-able object still steal the focus
231
+ // in newer FP they only steal the focus if the the new hit is focusable
232
+ if (this._allowFocusOnUnfocusable || this._focusNode.container.tabEnabled) {
233
+ if (this._focusNode) {
234
+ this.dispatchEvent(this._focusOut, this._focusNode);
235
+ this._focusNode.container.setFocus(false, true);
236
+ }
237
+
238
+ this._focusNode = node;
239
+
240
+ if (this._focusNode) {
241
+ this.dispatchEvent(this._focusIn, this._focusNode);
242
+ this._focusNode.container.setFocus(true, true);
243
+ }
233
244
  }
234
245
  }
235
246
 
236
247
  public getFocus() {
237
- return this._focusContainer;
248
+ return this._focusNode;
238
249
  }
239
250
 
240
- private dispatchEvent(event: AwayMouseEvent, dispatcher: ContainerNode) {
251
+ private dispatchEvent(event: AwayMouseEvent | FocusEvent, dispatcher: ContainerNode) {
241
252
  if (!this._eventBubbling) {
242
253
  if (dispatcher) {
243
- dispatcher.container.dispatchEvent(event);
244
- FrameScriptManager.execute_queue();
254
+ event._dispatchEvent(dispatcher, dispatcher.container);
245
255
  }
246
256
  return;
247
257
  }
248
258
 
259
+ const target = dispatcher?.container;
260
+
249
261
  while (dispatcher) {
250
262
  if (event.commonAncestor && dispatcher == event.commonAncestor) {
251
263
  return;
252
264
  }
253
- if (!dispatcher.isMouseDisabled()) {
254
- dispatcher.container.dispatchEvent(event);
255
- FrameScriptManager.execute_queue();
256
- }
265
+ event._dispatchEvent(dispatcher, target);
266
+
257
267
  if (!event._iAllowedToPropagate) {
258
268
  dispatcher = null;
259
269
  } else {
@@ -324,20 +334,10 @@ export class MouseManager {
324
334
  } else if (this._eventBubbling)
325
335
  this._stage.dispatchEvent(event);
326
336
 
327
- // in FP6, a mouseclick on non focus-able object still steal the focus
328
- // in newer FP they only steal the focus if the the new hit is focusable
329
- if (this._allowFocusOnUnfocusable || this._mouseDragCollision?.rootNode.container.tabEnabled) {
330
- if (this._focusContainer)
331
- this._focusContainer.setFocus(false, true);
332
-
333
- this._focusContainer = this._mouseDragCollision?.rootNode?.container;
334
-
335
- if (this._focusContainer)
336
- this._focusContainer.setFocus(true, true);
337
- }
338
-
339
- if (this._mouseDragCollision)
337
+ if (this._mouseDragCollision) {
338
+ this.setFocus(this._mouseDragCollision?.rootNode);
340
339
  this.setupAndDispatchEvent(this._dragStart, event, this._mouseDragCollision);
340
+ }
341
341
 
342
342
  } else if (event.type == AwayMouseEvent.MOUSE_UP) {
343
343
 
@@ -746,15 +746,15 @@ export class MouseManager {
746
746
  default:
747
747
  break;
748
748
  }
749
- if (this._focusContainer || this._stage) {
750
- //console.log("dispatch keydown on ", this._focusContainer);
749
+ if (this._focusNode || this._stage) {
750
+ //console.log("dispatch keydown on ", this._focusNode);
751
751
  const newEvent: KeyboardEvent = new KeyboardEvent(KeyboardEvent.KEYDOWN, event.key, event.code);
752
752
  newEvent.isShift = event.shiftKey;
753
753
  newEvent.isCTRL = event.ctrlKey;
754
754
  newEvent.isAlt = event.altKey;
755
755
  (<any>newEvent).keyCode = event.keyCode;
756
- if (this._focusContainer)
757
- this._focusContainer.dispatchEvent(newEvent);
756
+ if (this._focusNode)
757
+ this._focusNode.container.dispatchEvent(newEvent);
758
758
  if (this._stage)
759
759
  this._stage.dispatchEvent(newEvent);
760
760
  }
@@ -778,15 +778,15 @@ export class MouseManager {
778
778
  break;
779
779
  }
780
780
 
781
- if (this._focusContainer || this._stage) {
782
- //console.log("dispatch keydown on ", this._focusContainer);
781
+ if (this._focusNode || this._stage) {
782
+ //console.log("dispatch keydown on ", this._focusNode);
783
783
  const newEvent: KeyboardEvent = new KeyboardEvent(KeyboardEvent.KEYUP, event.key, event.code);
784
784
  newEvent.isShift = event.shiftKey;
785
785
  newEvent.isCTRL = event.ctrlKey;
786
786
  newEvent.isAlt = event.altKey;
787
787
  (<any>newEvent).keyCode = event.keyCode;
788
- if (this._focusContainer)
789
- this._focusContainer.dispatchEvent(newEvent);
788
+ if (this._focusNode)
789
+ this._focusNode.container.dispatchEvent(newEvent);
790
790
  if (this._stage)
791
791
  this._stage.dispatchEvent(newEvent);
792
792
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awayjs/scene",
3
- "version": "0.13.239",
3
+ "version": "0.13.242",
4
4
  "description": "AwayJS scene classes",
5
5
  "main": "bundle/awayjs-scene.umd.js",
6
6
  "module": "dist/index.js",