line.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. define(function(require, exports, module) {
  2. return require('../core/class').createClass('Line', {
  3. base: require('./path'),
  4. constructor: function(x1, y1, x2, y2) {
  5. this.callBase();
  6. this.point1 = {
  7. x: x1 || 0,
  8. y: y1 || 0
  9. };
  10. this.point2 = {
  11. x: x2 || 0,
  12. y: y2 || 0
  13. };
  14. this.update();
  15. },
  16. setPoint1: function(x, y) {
  17. this.point1.x = x;
  18. this.point1.y = y;
  19. return this.update();
  20. },
  21. setPoint2: function(x, y) {
  22. this.point2.x = x;
  23. this.point2.y = y;
  24. return this.update();
  25. },
  26. getPoint1: function() {
  27. return {
  28. x: this.point1.x,
  29. y: this.point1.y
  30. };
  31. },
  32. getPoint2: function() {
  33. return {
  34. x: this.point2.x,
  35. y: this.point2.y
  36. };
  37. },
  38. update: function() {
  39. var drawer = this.getDrawer();
  40. drawer.clear();
  41. drawer.moveTo(this.point1.x, this.point1.y);
  42. drawer.lineTo(this.point2.x, this.point2.y);
  43. return this;
  44. }
  45. });
  46. });