CheckBox.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /************************************************************************
  2. * CheckBox.js
  3. ************************************************************************
  4. * Copyright (c) 2021 Pedro Tonini Rosenberg Schneider.
  5. *
  6. * This file is part of Pandora.
  7. *
  8. * Pandora is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * Pandora is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with Pandora. If not, see <https://www.gnu.org/licenses/>.
  20. *************************************************************************/
  21. class CheckBox extends UIObject
  22. {
  23. constructor(name, label = "checkbox", val = false)
  24. {
  25. super(name);
  26. this.label = label;
  27. this.P5Element = createCheckbox(label, val);
  28. this.P5Element.position(0, 0);
  29. this.setStyle(STYLE.DEFAULT_STYLE);
  30. this.connectCallbacks();
  31. this.P5Element.changed(this.onChanged);
  32. }
  33. setLabel(label)
  34. {
  35. this.label = label;
  36. this.P5Element.html(label);
  37. }
  38. _onChanged()
  39. {
  40. console.log(this.P5Element.checked());
  41. }
  42. initSignals()
  43. {
  44. this.addSignal("mousePressed");
  45. this.addSignal("doubleClicked");
  46. this.addSignal("mouseWheel");
  47. this.addSignal("mouseReleased");
  48. this.addSignal("mouseClicked");
  49. this.addSignal("mouseMoved");
  50. this.addSignal("mouseOver");
  51. this.addSignal("mouseOut");
  52. this.addSignal("touchStarted");
  53. this.addSignal("touchMoved");
  54. this.addSignal("touchEnded");
  55. this.addSignal("dragOver");
  56. this.addSignal("dragLeave");
  57. this.addSignal("changed")
  58. this._initSignals();
  59. }
  60. onChanged()
  61. {
  62. this.pandoraObject.emitSignal("changed");
  63. this.pandoraObject._onChanged();
  64. }
  65. }