@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
55 lines (54 loc) • 1.82 kB
JavaScript
;
import { EventConnectionPoint, EventConnectionPointType } from "../utils/io/connections/Event";
import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig";
import { TypedInputEventNode, EVENT_PARAM_OPTIONS } from "./_BaseInput";
import { EventInputType } from "../../poly/registers/nodes/types/Event";
import { ACCEPTED_WINDOW_EVENT_TYPES } from "../../../core/event/WindowEventType";
class WindowEventParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
/** @param toggle on to allow any event to be listened to */
this.active = ParamConfig.BOOLEAN(true, {
callback: (node) => {
WindowEventNode.PARAM_CALLBACK_updateRegister(node);
},
separatorAfter: true
});
/** @param set which element triggers the event */
this.element = ParamConfig.INTEGER(0, {
hidden: true
});
/** @param toggle on to listen to resize events */
this.resize = ParamConfig.BOOLEAN(1, EVENT_PARAM_OPTIONS);
}
}
const ParamsConfig = new WindowEventParamsConfig();
export class WindowEventNode extends TypedInputEventNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return EventInputType.WINDOW;
}
acceptedEventTypes() {
return /* @__PURE__ */ new Set([...ACCEPTED_WINDOW_EVENT_TYPES]);
}
initializeNode() {
this.io.outputs.setNamedOutputConnectionPoints(
ACCEPTED_WINDOW_EVENT_TYPES.map((event_type) => {
return new EventConnectionPoint(event_type, EventConnectionPointType.POINTER);
})
);
}
processEvent(eventContext) {
if (!this.pv.active) {
return;
}
const event = eventContext.event;
if (!event) {
return;
}
this.dispatchEventToOutput(event.type, eventContext);
}
}