myRect.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #include "myRect.h"
  2. void Rect::WhereAmI()
  3. {
  4. std::cout << "Now I am in class Rect" << std::endl;
  5. }
  6. void Rect::WhereAmIVirtual()
  7. {
  8. std::cout << "Now I am in class Rect" << std::endl;
  9. }
  10. //êîíñòðóêòîð ñ ïàðàìåòðàìè äëÿ èíèöèàëèçàöèè ïåðåìåííûõ êëàññà
  11. Rect::Rect(int left, int right, int top, int bottom, colour col, bool contour, double transparency)
  12. :Shape(col,contour, transparency)
  13. {
  14. m_left = left;
  15. m_right = right;
  16. m_top = top;
  17. m_bottom = bottom;
  18. Standarting();
  19. }
  20. //ìåòîä "íîðìàëèçàöèè" ïðÿìîóãîëüíèêà
  21. void Rect::Standarting()
  22. {
  23. if (m_right < m_left)
  24. {
  25. int tmp = m_right;
  26. m_right = m_left;
  27. m_left = tmp;
  28. }
  29. if (m_bottom < m_top)
  30. {
  31. int tmp = m_bottom;
  32. m_bottom = m_top;
  33. m_top = tmp;
  34. }
  35. }
  36. void Rect::Inflate(int inflate)
  37. {
  38. this->InflateRect(inflate / 2, inflate / 2, inflate / 2, inflate / 2);
  39. }
  40. //ìåòîä êîòîðûé óâåëè÷èâàåò ðàçìåðû ïðÿìîóãîëüíèêà íà çàäàííûå ïðèðàùåíèÿ
  41. void Rect::InflateRect(int left, int right, int top, int bottom)
  42. {
  43. m_left -= left;
  44. m_right += right;
  45. m_top -= top;
  46. m_bottom += bottom;
  47. Standarting();
  48. }
  49. //ìåòîä êîòîðûé ïðèíèìàåò äâà àðãóìåíòà, ïî óìîë÷àíèþ ðàâíûõ 1
  50. void Rect::InflateRect(int left, int right)
  51. {
  52. m_left -= left;
  53. m_right += right;
  54. Standarting();
  55. }
  56. //êîíñòðóêòîð êîïèðîâàíèÿ
  57. Rect::Rect(const Rect& other):Shape(other)
  58. {
  59. m_left = other.m_left;
  60. m_right = other.m_right;
  61. m_top = other.m_top;
  62. m_bottom = other.m_bottom;
  63. }
  64. //ìåòîä êîòîðûé ïðèñâàèâàåò ïåðåìåííûì êëàññà ïåðåäàâàåìûå çíà÷åíèÿ
  65. void Rect::SetAll(int left, int right, int top, int bottom)
  66. {
  67. m_left = left;
  68. m_right = right;
  69. m_top = top;
  70. m_bottom = bottom;
  71. Standarting();
  72. }
  73. //ìåòîä êîòîðûé "äîñòàåò" çíà÷åíèÿ private-ïåðåìåííûõ êëàññà.
  74. void Rect::GetAll(int& left, int& right, int& top, int& bottom) const
  75. {
  76. left = m_left;
  77. right = m_right;
  78. top = m_top;
  79. bottom = m_bottom;
  80. }
  81. //ìåòîä êîòîðûé âîçâðàùàåò ïðÿìîóãîëüíèê, â êîòîðûé âïèñàíû çàäàííûå ïðÿìîóãîëüíèêè.
  82. Rect Rect::BoundingRect(const Rect& two)
  83. {
  84. Rect tmp;
  85. (m_left <= two.m_left) ? tmp.m_left = m_left : tmp.m_left = two.m_left;//ÒÅÐÍÀÐÍÛÉ ÎÏÅÐÀÒÎÐ
  86. (m_right >= two.m_right) ? tmp.m_right = m_right : tmp.m_right = two.m_right;
  87. (m_top <= two.m_top) ? tmp.m_top = m_top : tmp.m_top = two.m_top;
  88. (m_bottom >= two.m_bottom) ? tmp.m_bottom = m_bottom : tmp.m_bottom = two.m_bottom;
  89. return tmp;
  90. }
  91. Rect::~Rect()
  92. {
  93. std::cout << "Now I am in Rect's destructor!" << std::endl;
  94. }