Box.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. /**
  16. * Box object containing the size of the object.
  17. */
  18. this.box = new Box2(new Vector2(-50, -35), new Vector2(50, 35));
  19. /**
  20. * Color of the box border line.
  21. */
  22. this.strokeStyle = "#000000";
  23. /**
  24. * Line width.
  25. */
  26. this.lineWidth = 1;
  27. /**
  28. * Background color of the box.
  29. */
  30. this.fillStyle = "#FFFFFF";
  31. }
  32. Box.prototype = Object.create(Object2D.prototype);
  33. Box.prototype.onPointerEnter = function(pointer, viewport)
  34. {
  35. this.fillStyle = "#CCCCCC";
  36. };
  37. Box.prototype.onPointerLeave = function(pointer, viewport)
  38. {
  39. this.fillStyle = "#FFFFFF";
  40. };
  41. Box.prototype.isInside = function(point)
  42. {
  43. return this.box.containsPoint(point);
  44. };
  45. Box.prototype.draw = function(context, viewport, canvas)
  46. {
  47. var width = this.box.max.x - this.box.min.x;
  48. var height = this.box.max.y - this.box.min.y;
  49. context.fillStyle = this.fillStyle;
  50. context.fillRect(this.box.min.x, this.box.min.y, width, height);
  51. context.lineWidth = this.lineWidth;
  52. context.strokeStyle = this.strokeStyle;
  53. context.strokeRect(this.box.min.x, this.box.min.y, width, height);
  54. };
  55. export {Box};