Rectangle.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. namespace Grafika\DrawingObject;
  3. use Grafika\Color;
  4. /**
  5. * Base class
  6. * @package Grafika
  7. */
  8. abstract class Rectangle
  9. {
  10. /**
  11. * Image width in pixels
  12. * @var int
  13. */
  14. protected $width;
  15. /**
  16. * Image height in pixels
  17. * @var int
  18. */
  19. protected $height;
  20. /**
  21. * X and Y position in an array.
  22. * @var array
  23. */
  24. protected $pos;
  25. /**
  26. * @var int
  27. */
  28. protected $borderSize;
  29. /**
  30. * @var Color
  31. */
  32. protected $fillColor;
  33. /**
  34. * @var Color
  35. */
  36. protected $borderColor;
  37. /**
  38. * Creates a rectangle.
  39. *
  40. * @param int $width Width of rectangle in pixels.
  41. * @param int $height Height in pixels.
  42. * @param array $pos Array of X and Y position. X is the distance in pixels from the left of the canvass to the left of the rectangle. Y is the distance from the top of the canvass to the top of the rectangle. Defaults to array(0,0).
  43. * @param int $borderSize Size of the border in pixels. Defaults to 1 pixel. Set to 0 for no border.
  44. * @param Color|string|null $borderColor Border color. Defaults to black. Set to null for no color.
  45. * @param Color|string|null $fillColor Fill color. Defaults to white. Set to null for no color.
  46. */
  47. public function __construct(
  48. $width,
  49. $height,
  50. $pos = array(0, 0),
  51. $borderSize = 1,
  52. $borderColor = '#000000',
  53. $fillColor = '#FFFFFF'
  54. ) {
  55. if (is_string($borderColor)) {
  56. $borderColor = new Color($borderColor);
  57. }
  58. if (is_string($fillColor)) {
  59. $fillColor = new Color($fillColor);
  60. }
  61. $this->width = $width;
  62. $this->height = $height;
  63. $this->pos = $pos;
  64. $this->borderSize = $borderSize;
  65. $this->borderColor = $borderColor;
  66. $this->fillColor = $fillColor;
  67. }
  68. /**
  69. * @return int
  70. */
  71. public function getWidth()
  72. {
  73. return $this->width;
  74. }
  75. /**
  76. * @return int
  77. */
  78. public function getHeight()
  79. {
  80. return $this->height;
  81. }
  82. /**
  83. * @return array
  84. */
  85. public function getPos()
  86. {
  87. return $this->pos;
  88. }
  89. /**
  90. * @return int
  91. */
  92. public function getBorderSize()
  93. {
  94. return $this->borderSize;
  95. }
  96. /**
  97. * @return Color
  98. */
  99. public function getFillColor()
  100. {
  101. return $this->fillColor;
  102. }
  103. /**
  104. * @return Color
  105. */
  106. public function getBorderColor()
  107. {
  108. return $this->borderColor;
  109. }
  110. }