MCPcopy Create free account
hub / github.com/eva-engine/eva.js / setCursor

Method setCursor

packages/plugin-worker/lib/events/EventSystem.ts:289–337  ·  view source on GitHub ↗

* Sets the current cursor mode, handling any callbacks or CSS style changes. * @param mode - cursor mode, a key from the cursorStyles dictionary

(mode: string)

Source from the content-addressed store, hash-verified

287 * @param mode - cursor mode, a key from the cursorStyles dictionary
288 */
289 public setCursor(mode: string): void {
290 if (!mode) {
291 mode = 'default';
292 }
293 let applyStyles = true;
294
295 // offscreen canvas does not support setting styles, but cursor modes can be functions,
296 // in order to handle pixi rendered cursors, so we can't bail
297 if (globalThis.OffscreenCanvas && this.domElement instanceof OffscreenCanvas) {
298 applyStyles = false;
299 }
300 // if the mode didn't actually change, bail early
301 if (this._currentCursor === mode) {
302 return;
303 }
304 this._currentCursor = mode;
305 const style = this.cursorStyles[mode];
306
307 // only do things if there is a cursor style for it
308 if (style) {
309 switch (typeof style) {
310 case 'string':
311 // string styles are handled as cursor CSS
312 if (applyStyles) {
313 this.domElement.style.cursor = style;
314 }
315 break;
316 case 'function':
317 // functions are just called, and passed the cursor mode
318 style(mode);
319 break;
320 case 'object':
321 // if it is an object, assume that it is a dictionary of CSS styles,
322 // apply it to the interactionDOMElement
323 if (applyStyles) {
324 Object.assign(this.domElement.style, style);
325 }
326 break;
327 }
328 } else if (
329 applyStyles &&
330 typeof mode === 'string' &&
331 !Object.prototype.hasOwnProperty.call(this.cursorStyles, mode)
332 ) {
333 // if it mode is a string (not a Symbol) and cursorStyles doesn't have any entry
334 // for the mode, then assume that the dev wants it to be CSS for the cursor.
335 this.domElement.style.cursor = mode;
336 }
337 }
338
339 /**
340 * The global pointer event.

Callers 4

_onPointerDownMethod · 0.95
_onPointerMoveMethod · 0.95
_onPointerUpMethod · 0.95
_onPointerOverOutMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected