@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
106 lines (105 loc) • 4.58 kB
JavaScript
"use strict";
import { EventConnectionPoint, EventConnectionPointType } from "../utils/io/connections/Event";
import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig";
import { TypedInputEventNode, EVENT_PARAM_OPTIONS } from "./_BaseInput";
import { isBooleanTrue } from "../../../core/BooleanValue";
import { EventInputType } from "../../poly/registers/nodes/types/Event";
import { CoreEventEmitter, EVENT_EMITTERS, EVENT_EMITTER_PARAM_MENU_OPTIONS } from "../../../core/event/CoreEventEmitter";
import { ACCEPTED_MOUSE_EVENT_TYPES } from "../../../core/event/MouseEventType";
class MouseEventParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
/** @param toggle on to allow any event to be listened to */
this.active = ParamConfig.BOOLEAN(true, {
callback: (node) => {
MouseEventNode.PARAM_CALLBACK_updateRegister(node);
},
separatorAfter: true
});
/** @param set which element triggers the event */
this.element = ParamConfig.INTEGER(EVENT_EMITTERS.indexOf(CoreEventEmitter.CANVAS), {
...EVENT_EMITTER_PARAM_MENU_OPTIONS,
separatorAfter: true
});
/** @param toggle on to listen to auxclick events */
this.auxclick = ParamConfig.BOOLEAN(0, EVENT_PARAM_OPTIONS);
/** @param toggle on to listen to click events */
this.click = ParamConfig.BOOLEAN(0, EVENT_PARAM_OPTIONS);
/** @param toggle on to listen to contextmenu events */
this.contextmenu = ParamConfig.BOOLEAN(0, EVENT_PARAM_OPTIONS);
/** @param toggle on to listen to dblclick events */
this.dblclick = ParamConfig.BOOLEAN(0, EVENT_PARAM_OPTIONS);
/** @param toggle on to listen to mousedown events */
this.mousedown = ParamConfig.BOOLEAN(1, EVENT_PARAM_OPTIONS);
/** @param toggle on to listen to mouseenter events */
this.mouseenter = ParamConfig.BOOLEAN(0, EVENT_PARAM_OPTIONS);
/** @param toggle on to listen to mouseleave events */
this.mouseleave = ParamConfig.BOOLEAN(0, EVENT_PARAM_OPTIONS);
/** @param toggle on to listen to mousemove events */
this.mousemove = ParamConfig.BOOLEAN(1, EVENT_PARAM_OPTIONS);
/** @param toggle on to listen to mouseover events */
this.mouseover = ParamConfig.BOOLEAN(0, EVENT_PARAM_OPTIONS);
/** @param toggle on to listen to mouseout events */
this.mouseout = ParamConfig.BOOLEAN(0, EVENT_PARAM_OPTIONS);
/** @param toggle on to listen to mouseup events */
this.mouseup = ParamConfig.BOOLEAN(1, EVENT_PARAM_OPTIONS);
/** @param toggle on to listen to pointerlockchange events */
this.pointerlockchange = ParamConfig.BOOLEAN(0, EVENT_PARAM_OPTIONS);
/** @param toggle on to listen to pointerlockerror events */
this.pointerlockerror = ParamConfig.BOOLEAN(0, EVENT_PARAM_OPTIONS);
/** @param toggle on to listen to select events */
this.select = ParamConfig.BOOLEAN(0, EVENT_PARAM_OPTIONS);
/** @param toggle on to listen to wheel events */
this.wheel = ParamConfig.BOOLEAN(0, EVENT_PARAM_OPTIONS);
/** @param requires ctrlKey */
this.ctrlKey = ParamConfig.BOOLEAN(0, { ...EVENT_PARAM_OPTIONS, separatorBefore: true });
/** @param requires altKey */
this.altKey = ParamConfig.BOOLEAN(0, EVENT_PARAM_OPTIONS);
/** @param requires shiftKey */
this.shiftKey = ParamConfig.BOOLEAN(0, EVENT_PARAM_OPTIONS);
/** @param requires metaKey */
this.metaKey = ParamConfig.BOOLEAN(0, EVENT_PARAM_OPTIONS);
}
}
const ParamsConfig = new MouseEventParamsConfig();
export class MouseEventNode extends TypedInputEventNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return EventInputType.MOUSE;
}
acceptedEventTypes() {
return /* @__PURE__ */ new Set([...ACCEPTED_MOUSE_EVENT_TYPES]);
}
initializeNode() {
this.io.outputs.setNamedOutputConnectionPoints(
ACCEPTED_MOUSE_EVENT_TYPES.map((event_type) => {
return new EventConnectionPoint(event_type, EventConnectionPointType.MOUSE);
})
);
}
processEvent(eventContext) {
if (!this.pv.active) {
return;
}
const event = eventContext.event;
if (!event) {
return;
}
if (event.ctrlKey != isBooleanTrue(this.pv.ctrlKey)) {
return;
}
if (event.shiftKey != isBooleanTrue(this.pv.shiftKey)) {
return;
}
if (event.altKey != isBooleanTrue(this.pv.altKey)) {
return;
}
if (event.metaKey != isBooleanTrue(this.pv.metaKey)) {
return;
}
this.dispatchEventToOutput(event.type, eventContext);
}
}