FlRect.cpp
上传用户:lj3531212
上传日期:2007-06-18
资源大小:346k
文件大小:2k
源码类别:

绘图程序

开发平台:

Visual C++

  1. // FlRect.cpp: implementation of the CFlRect class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "graphsoft.h"
  6. #include "FlRect.h"
  7. #ifdef _DEBUG
  8. #undef THIS_FILE
  9. static char THIS_FILE[]=__FILE__;
  10. #define new DEBUG_NEW
  11. #endif
  12. //////////////////////////////////////////////////////////////////////
  13. // Construction/Destruction
  14. //////////////////////////////////////////////////////////////////////
  15. CFlRect::CFlRect()
  16. {
  17. left=0;
  18. top=0;
  19. right=0;
  20. bottom=0;
  21. }
  22. CFlRect::CFlRect(CRect rect)
  23. {
  24. left=rect.left;
  25. top=rect.top;
  26. right=rect.right;
  27. bottom=rect.bottom;  
  28. }
  29. CFlRect::CFlRect(CPoint topLeft,CPoint bottomRight)
  30. {
  31. left=topLeft.x;
  32. top=topLeft.y;
  33. right=bottomRight.x;
  34. bottom=bottomRight.y;
  35. }
  36. CFlRect::CFlRect(float lf,float tp,float rt,float bm)
  37. {
  38. left=lf;
  39. top=tp;
  40. right=rt;
  41. bottom=bm;
  42. }
  43. CFlRect::~CFlRect()
  44. {
  45. }
  46. CRect CFlRect::GetRect()
  47. {
  48. CRect rect(left,top,right,bottom);
  49. return rect;
  50. }
  51. void  CFlRect::OffsetRect(float cx,float cy)
  52. {
  53. left=left+cx;
  54. right=right+cx;
  55. top=top+cy;
  56. bottom=bottom+cy;
  57. }
  58. CPoint CFlRect::LeftTop()
  59. {
  60. CPoint point(left,top);
  61. return point;
  62. }
  63. CPoint CFlRect::BottomRight()
  64. {
  65. CPoint point(right,bottom);
  66. return point;
  67. }  
  68. CPoint CFlRect::CenterPoint()
  69. {
  70. CPoint point((left+right)/2,(top+bottom)/2);
  71. return point;
  72. }
  73. float CFlRect::Width()
  74. {
  75.  return fabs(right-left);
  76. }
  77. float CFlRect::Height()
  78. {
  79. return fabs(bottom-top);
  80. }
  81. bool CFlRect::PtInRect(CPoint pt)
  82. {
  83. if(pt.x<left || pt.x>right)
  84. return false;
  85. if(pt.y<top || pt.y>bottom)
  86. return false;
  87. return true;
  88. }
  89. bool CFlRect::PtInRect(float x,float y)
  90. {
  91. if(x<left || x>right)
  92. return false;
  93. if(y<top || y>bottom)
  94. return false;
  95. return true;
  96. }
  97. void CFlRect::InflateRect(float cx,float cy)
  98. {
  99. left=left-cx;
  100. right=right+cx;
  101. top=top-cy;
  102. bottom=bottom+cy;
  103. }
  104. void CFlRect::DeflateRect(float cx,float cy)
  105. {
  106. left=left+cx;
  107. right=right-cx;
  108. top=top+cy;
  109. bottom=bottom-cy;
  110. }
  111. void CFlRect::NormalizeRect()
  112. {
  113. left = min(left,right);
  114. right = max(left,right);
  115. top = min(top,bottom);
  116. bottom = max(top,bottom);
  117. }
  118. CFlRect::operator CRect( )
  119. {
  120. return CRect(left,top,right,bottom);  
  121. }
  122. bool  operator !=(CFlRect& rtA,CFlRect& rtB)
  123. {
  124.  return rtA.GetRect()!=rtB.GetRect();
  125. }