123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- class UIObject extends GameObject
- {
- constructor(name)
- {
- super(name);
- this.P5Element = null;
- this.visible = true;
- }
- connectCallbacks()
- {
- this.P5Element.mousePressed(this.onMousePressed);
- this.P5Element.doubleClicked(this.onDoubleClicked);
- this.P5Element.mouseWheel(this.onMouseWheel);
- this.P5Element.mouseReleased(this.onMouseReleased);
- this.P5Element.mouseClicked(this.onMouseClicked);
- this.P5Element.mouseMoved(this.onMouseMoved);
- this.P5Element.mouseOver(this.onMouseOver);
- this.P5Element.mouseOut(this.onMouseOut);
- this.P5Element.touchStarted(this.onTouchStarted);
- this.P5Element.touchMoved(this.onTouchMoved);
- this.P5Element.touchEnded(this.onTouchEnded);
- this.P5Element.dragOver(this.onDragOver);
- this.P5Element.dragLeave(this.onDragLeave);
- this.P5Element.pandoraObject = this;
- }
-
- setPosition(x, y)
- {
- this.P5Element.position(x, y);
- }
- setSize(w, h)
- {
- this.P5Element.size(w, h);
- }
- setVisibility(vis)
- {
- if (vis) this.P5Element.show();
- else this.P5Element.hide();
- this.visible = !this.visible;
- }
- setValue(val)
- {
- this.P5Element.value(val)
- }
- setStyle(style)
- {
- for (const [key, value] of Object.entries(style))
- {
- this.P5Element.style(`${key}`, value);
- }
- }
-
- getPosition()
- {
- return this.P5Element.position();
- }
- getVisibility()
- {
- return this.visible;
- }
- getValue()
- {
- return this.P5Element.value();
- }
-
- toggleVisibility()
- {
- this.setVisibility(!this.visible);
- }
- addChild(child)
- {
- child.parent = this;
- child.parented = true;
- this.children.push(child);
- child.P5Element.parent(this.P5Element);
- }
-
- _onMousePressed()
- {
- }
- _onDoubleClicked()
- {
- }
- _onMouseWheel()
- {
- }
- _onMouseReleased()
- {
- }
- _onMouseClicked()
- {
- }
- _onMouseMoved()
- {
- }
- _onMouseOver()
- {
- }
- _onMouseOut()
- {
- }
- _onTouchStarted()
- {
- }
- _onTouchMoved()
- {
- }
- _onTouchEnded()
- {
- }
- _onDragOver()
- {
- }
- _onDragLeave()
- {
- }
-
- onMousePressed()
- {
- this.pandoraObject._onMousePressed();
- }
- onDoubleClicked()
- {
- this.pandoraObject._onDoubleClicked();
- }
- onMouseWheel()
- {
- this.pandoraObject._onMouseWheel();
- }
- onMouseReleased()
- {
- this.pandoraObject._onMouseReleased();
- }
- onMouseClicked()
- {
- this.pandoraObject._onMouseClicked();
- }
- onMouseMoved()
- {
- this.pandoraObject._onMouseMoved();
- }
- onMouseOver()
- {
- this.pandoraObject._onMouseOver();
- }
- onMouseOut()
- {
- this.pandoraObject._onMouseOut();
- }
- onTouchStarted()
- {
- this.pandoraObject._onTouchStarted();
- }
- onTouchMoved()
- {
- this.pandoraObject._onTouchMoved();
- }
- onTouchEnded()
- {
- this.pandoraObject._onTouchEnded();
- }
- onDragOver()
- {
- this.pandoraObject._onDragOver();
- }
- onDragLeave()
- {
- this.pandoraObject._onDragLeave();
- }
- }
|