Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XR input sources interact with Elements #1988

Merged
merged 9 commits into from
Apr 16, 2020
3 changes: 3 additions & 0 deletions src/framework/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,9 @@ Object.assign(pc, function () {
this.vr = null;
this.xr = new pc.XrManager(this);

if (this.elementInput)
this.elementInput.attachSelectEvents();

this._inTools = false;

this._skyboxLast = 0;
Expand Down
68 changes: 68 additions & 0 deletions src/framework/components/button/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Object.assign(pc, function () {

this._visualState = VisualState.DEFAULT;
this._isHovering = false;
this._hoveringCounter = 0;
this._isPressed = false;

this._defaultTint = new pc.Color(1, 1, 1, 1);
Expand Down Expand Up @@ -150,6 +151,10 @@ Object.assign(pc, function () {
this.entity.element[onOrOff]('touchend', this._onTouchEnd, this);
this.entity.element[onOrOff]('touchleave', this._onTouchLeave, this);
this.entity.element[onOrOff]('touchcancel', this._onTouchCancel, this);
this.entity.element[onOrOff]('selectstart', this._onSelectStart, this);
this.entity.element[onOrOff]('selectend', this._onSelectEnd, this);
this.entity.element[onOrOff]('selectenter', this._onSelectEnter, this);
this.entity.element[onOrOff]('selectleave', this._onSelectLeave, this);
this.entity.element[onOrOff]('click', this._onClick, this);

this._hasHitElementListeners = isAdding;
Expand Down Expand Up @@ -278,6 +283,41 @@ Object.assign(pc, function () {
this._fireIfActive('touchcancel', event);
},

_onSelectStart: function (event) {
this._isPressed = true;
this._updateVisualState();
this._fireIfActive('selectstart', event);
},

_onSelectEnd: function (event) {
this._isPressed = false;
this._updateVisualState();
this._fireIfActive('selectend', event);
},

_onSelectEnter: function (event) {
this._hoveringCounter++;

if (this._hoveringCounter === 1) {
this._isHovering = true;
this._updateVisualState();
}

this._fireIfActive('selectenter', event);
},

_onSelectLeave: function (event) {
this._hoveringCounter--;

if (this._hoveringCounter === 0) {
this._isHovering = false;
this._isPressed = false;
this._updateVisualState();
}

this._fireIfActive('selectleave', event);
},

_onClick: function (event) {
this._fireIfActive('click', event);
},
Expand Down Expand Up @@ -524,6 +564,34 @@ Object.assign(pc, function () {
* @param {pc.ElementTouchEvent} event - The event.
*/

/**
* @event
* @name pc.ButtonComponent#selectstart
* @description Fired when a xr select starts on the component.
* @param {pc.ElementSelectEvent} event - The event.
*/

/**
* @event
* @name pc.ButtonComponent#selectend
* @description Fired when a xr select ends on the component.
* @param {pc.ElementSelectEvent} event - The event.
*/

/**
* @event
* @name pc.ButtonComponent#selectenter
* @description Fired when a xr select now hovering over the component.
* @param {pc.ElementSelectEvent} event - The event.
*/

/**
* @event
* @name pc.ButtonComponent#selectleave
* @description Fired when a xr select not hovering over the component.
* @param {pc.ElementSelectEvent} event - The event.
*/

/**
* @event
* @name pc.ButtonComponent#hoverstart
Expand Down
Loading