Box.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. "use strict";
  2. function Box()
  3. {
  4. Object2D.call(this);
  5. /**
  6. * Box object containing the size of the object.
  7. */
  8. this.box = new Box2(new Vector2(-50, -35), new Vector2(50, 35));
  9. /**
  10. * Color of the box border line.
  11. */
  12. this.strokeStyle = "#000000";
  13. /**
  14. * Background color of the box.
  15. */
  16. this.fillStyle = "#FFFFFF";
  17. }
  18. Box.prototype = Object.create(Object2D.prototype);
  19. Box.prototype.onPointerDrag = function(mouse, viewport, delta)
  20. {
  21. this.position.x += delta.x;
  22. this.position.y += delta.y;
  23. };
  24. Box.prototype.onPointerEnter = function(mouse, viewport)
  25. {
  26. this.fillStyle = "#CCCCCC";
  27. };
  28. Box.prototype.onPointerLeave = function(mouse, viewport)
  29. {
  30. this.fillStyle = "#FFFFFF";
  31. };
  32. Box.prototype.isInside = function(point)
  33. {
  34. return this.box.containsPoint(point);
  35. };
  36. Box.prototype.draw = function(context)
  37. {
  38. var width = this.box.max.x - this.box.min.x;
  39. var height = this.box.max.y - this.box.min.y;
  40. context.fillStyle = this.fillStyle;
  41. context.fillRect(this.box.min.x, this.box.min.y, width, height);
  42. context.setLineDash([]);
  43. context.lineWidth = 3;
  44. context.strokeStyle = this.strokeStyle;
  45. context.strokeRect(this.box.min.x, this.box.min.y, width, height);
  46. };