widget_base.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. function widget_base (instance, widget) {
  2. "use strict";
  3. widget.Base = instance.Widget.extend({
  4. size: {
  5. width: 0,
  6. height: 0
  7. },
  8. position: {
  9. x: 0,
  10. y: 0
  11. },
  12. init: function (parent, size, position) {
  13. this._super(parent);
  14. this.size = size || this.size;
  15. this.position = position || this.position;
  16. },
  17. start: function () {
  18. console.log('Widget started');
  19. },
  20. getSize: function () {
  21. return this.size;
  22. },
  23. getWidth: function () {
  24. return this.getSize().width;
  25. },
  26. getHeight: function () {
  27. return this.getSize().height;
  28. },
  29. getPosition: function () {
  30. return this.position;
  31. },
  32. getPositionX: function () {
  33. return this.getPosition().x;
  34. },
  35. getPositionY: function () {
  36. return this.getPosition().y;
  37. },
  38. setSize: function (width, height) {
  39. this.size.width = width;
  40. this.size.height = height;
  41. },
  42. setWidth: function (width) {
  43. this.size.width = width;
  44. },
  45. setHeight: function (height) {
  46. this.size.height = height;
  47. },
  48. setPosition: function (x, y) {
  49. this.position.x = x;
  50. this.position.y = y;
  51. },
  52. setPositionX: function (x) {
  53. this.position.x = x;
  54. },
  55. setPositionY: function (y) {
  56. this.position.y = y;
  57. }
  58. });
  59. }