Box.js 748 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. "use strict";
  2. function Box(src)
  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.borderColor = "#000000";
  13. }
  14. Box.prototype = Object.create(Object2D.prototype);
  15. Box.prototype.onOver = function(point)
  16. {
  17. this.borderColor = "#FF0000";
  18. };
  19. Box.prototype.isInside = function(point)
  20. {
  21. return this.box.containsPoint(point);
  22. };
  23. Box.prototype.draw = function(context)
  24. {
  25. var width = this.box.max.x - this.box.min.x;
  26. var height = this.box.max.y - this.box.min.y;
  27. context.lineWidth = 2;
  28. context.strokeStyle = this.borderColor;
  29. context.strokeRect(this.box.min.x, this.box.min.y, width, height);
  30. };