@awayjs/scene 0.13.237 → 0.13.240

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.
@@ -3,6 +3,7 @@ import { Point, Vector3D, EventBase } from '@awayjs/core';
3
3
  import { EntityNode, ContainerNode, INode, ITraversable, View } 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) {
282
+ if (!dispatcher.isMouseDisabled()) {
283
+ dispatcher.container.dispatchEvent(this);
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;
@@ -219,29 +223,35 @@ 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);
245
255
  }
246
256
  return;
247
257
  }
@@ -250,10 +260,8 @@ export class MouseManager {
250
260
  if (event.commonAncestor && dispatcher == event.commonAncestor) {
251
261
  return;
252
262
  }
253
- if (!dispatcher.isMouseDisabled()) {
254
- dispatcher.container.dispatchEvent(event);
255
- FrameScriptManager.execute_queue();
256
- }
263
+ event._dispatchEvent(dispatcher);
264
+
257
265
  if (!event._iAllowedToPropagate) {
258
266
  dispatcher = null;
259
267
  } else {
@@ -324,20 +332,10 @@ export class MouseManager {
324
332
  } else if (this._eventBubbling)
325
333
  this._stage.dispatchEvent(event);
326
334
 
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)
335
+ if (this._mouseDragCollision) {
336
+ this.setFocus(this._mouseDragCollision?.rootNode);
340
337
  this.setupAndDispatchEvent(this._dragStart, event, this._mouseDragCollision);
338
+ }
341
339
 
342
340
  } else if (event.type == AwayMouseEvent.MOUSE_UP) {
343
341
 
@@ -736,16 +734,25 @@ export class MouseManager {
736
734
 
737
735
  //console.log("Keydown", event);
738
736
  if (this.allowKeyInput) {
739
- //event.preventDefault();
740
- if (this._focusContainer || this._stage) {
741
- //console.log("dispatch keydown on ", this._focusContainer);
737
+ switch (event.keyCode) {
738
+ case 37: // left
739
+ case 39: // right
740
+ case 38: // up
741
+ case 40: // down
742
+ event.preventDefault();
743
+ break;
744
+ default:
745
+ break;
746
+ }
747
+ if (this._focusNode || this._stage) {
748
+ //console.log("dispatch keydown on ", this._focusNode);
742
749
  const newEvent: KeyboardEvent = new KeyboardEvent(KeyboardEvent.KEYDOWN, event.key, event.code);
743
750
  newEvent.isShift = event.shiftKey;
744
751
  newEvent.isCTRL = event.ctrlKey;
745
752
  newEvent.isAlt = event.altKey;
746
753
  (<any>newEvent).keyCode = event.keyCode;
747
- if (this._focusContainer)
748
- this._focusContainer.dispatchEvent(newEvent);
754
+ if (this._focusNode)
755
+ this._focusNode.container.dispatchEvent(newEvent);
749
756
  if (this._stage)
750
757
  this._stage.dispatchEvent(newEvent);
751
758
  }
@@ -758,17 +765,26 @@ export class MouseManager {
758
765
 
759
766
  //console.log("Keyup", event);
760
767
  if (this.allowKeyInput) {
761
- //event.preventDefault();
768
+ switch (event.keyCode) {
769
+ case 37: // left
770
+ case 39: // right
771
+ case 38: // up
772
+ case 40: // down
773
+ event.preventDefault();
774
+ break;
775
+ default:
776
+ break;
777
+ }
762
778
 
763
- if (this._focusContainer || this._stage) {
764
- //console.log("dispatch keydown on ", this._focusContainer);
779
+ if (this._focusNode || this._stage) {
780
+ //console.log("dispatch keydown on ", this._focusNode);
765
781
  const newEvent: KeyboardEvent = new KeyboardEvent(KeyboardEvent.KEYUP, event.key, event.code);
766
782
  newEvent.isShift = event.shiftKey;
767
783
  newEvent.isCTRL = event.ctrlKey;
768
784
  newEvent.isAlt = event.altKey;
769
785
  (<any>newEvent).keyCode = event.keyCode;
770
- if (this._focusContainer)
771
- this._focusContainer.dispatchEvent(newEvent);
786
+ if (this._focusNode)
787
+ this._focusNode.container.dispatchEvent(newEvent);
772
788
  if (this._stage)
773
789
  this._stage.dispatchEvent(newEvent);
774
790
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awayjs/scene",
3
- "version": "0.13.237",
3
+ "version": "0.13.240",
4
4
  "description": "AwayJS scene classes",
5
5
  "main": "bundle/awayjs-scene.umd.js",
6
6
  "module": "dist/index.js",