Box.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. "use strict";
  2. import {Object2D} from "../Object2D.js";
  3. import {Vector2} from "../math/Vector2.js";
  4. import {Box2} from "../math/Box2.js";
  5. import {Helpers} from "../utils/Helpers.js";
  6. import {Circle} from "./Circle.js";
  7. /**
  8. * Box object draw a box.
  9. *
  10. * @class
  11. */
  12. function Box()
  13. {
  14. Object2D.call(this);
  15. var self = this;
  16. /**
  17. * Box object containing the size of the object.
  18. */
  19. this.box = new Box2(new Vector2(-50, -35), new Vector2(50, 35));
  20. /**
  21. * Color of the box border line.
  22. */
  23. this.strokeStyle = "#000000";
  24. /**
  25. * Background color of the box.
  26. */
  27. this.fillStyle = "#FFFFFF";
  28. }
  29. Box.prototype = Object.create(Object2D.prototype);
  30. Box.prototype.onPointerEnter = function(pointer, viewport)
  31. {
  32. this.fillStyle = "#CCCCCC";
  33. };
  34. Box.prototype.onPointerLeave = function(pointer, viewport)
  35. {
  36. this.fillStyle = "#FFFFFF";
  37. };
  38. Box.prototype.isInside = function(point)
  39. {
  40. return this.box.containsPoint(point);
  41. };
  42. Box.prototype.draw = function(context, viewport, canvas)
  43. {
  44. var width = this.box.max.x - this.box.min.x;
  45. var height = this.box.max.y - this.box.min.y;
  46. context.fillStyle = this.fillStyle;
  47. context.fillRect(this.box.min.x, this.box.min.y, width, height);
  48. context.lineWidth = 1;
  49. context.strokeStyle = this.strokeStyle;
  50. context.strokeRect(this.box.min.x, this.box.min.y, width, height);
  51. };
  52. export {Box};