home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / OWLSRC.PAK / REGION.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  3.4 KB  |  142 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1992, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.6  $
  6. //
  7. // Implementation of class TRegion, a GDI Region object encapsulation
  8. //----------------------------------------------------------------------------
  9. #include <owl/pch.h>
  10. #if !defined(OWL_GDIOBJEC_H)
  11. # include <owl/gdiobjec.h>
  12. #endif
  13.  
  14. OWL_DIAGINFO;
  15. DIAG_DECLARE_GROUP(OwlGDI);        // General GDI diagnostic group
  16.  
  17. //
  18. // Constructor to create an empty region.
  19. //
  20. TRegion::TRegion()
  21. {
  22.   Handle = ::CreateRectRgn(0, 0, 0, 0);
  23.   WARNX(OwlGDI, !Handle, 0, "Cannot create empty rect region");
  24.   CheckValid();
  25. }
  26.  
  27. //
  28. // Alias constructor for an existing region.
  29. //
  30. TRegion::TRegion(HRGN handle, TAutoDelete autoDelete)
  31. :
  32.   TGdiBase(handle, autoDelete)
  33. {
  34. }
  35.  
  36. //
  37. // Copy an existing region.
  38. //
  39. TRegion::TRegion(const TRegion& source)
  40. {
  41.   Handle = ::CreateRectRgn(0, 0, 0, 0);
  42.   WARNX(OwlGDI, !Handle, 0, "Cannot create copy of region " <<
  43.         uint(HRGN(source)));
  44.   CheckValid();
  45.   ::CombineRgn((HRGN)Handle, source, 0, RGN_COPY);
  46. }
  47.  
  48. //
  49. // Create a rectangular region.
  50. //
  51. TRegion::TRegion(const TRect& rect)
  52. {
  53.   Handle = ::CreateRectRgnIndirect(&rect);
  54.   WARNX(OwlGDI, !Handle, 0, "Cannot create rect region " << rect);
  55.   CheckValid();
  56. }
  57.  
  58. //
  59. // Create an elliptic region.
  60. //
  61. TRegion::TRegion(const TRect& rect, TRegion::TEllipse)
  62. {
  63.   Handle = ::CreateEllipticRgnIndirect(&rect);
  64.   WARNX(OwlGDI, !Handle, 0, "Cannot create elliptic region " << rect);
  65.   CheckValid();
  66. }
  67.  
  68. //
  69. // Create a rounded rectangular region.
  70. //
  71. TRegion::TRegion(const TRect& rect, const TSize& corner)
  72. {
  73.   Handle = ::CreateRoundRectRgn(rect.left, rect.top, rect.right, rect.bottom,
  74.                                 corner.cx, corner.cy);
  75.   WARNX(OwlGDI, !Handle, 0, "Cannot create roundrect region " << rect << corner);
  76.   CheckValid();
  77. }
  78.  
  79. //
  80. // Create a region out of a polygon.
  81. //
  82. TRegion::TRegion(const TPoint* points, int count, int fillMode)
  83. {
  84.   Handle = ::CreatePolygonRgn(points, count, fillMode);
  85.   WARNX(OwlGDI, !Handle, 0, "Cannot create poly region " << count <<
  86.         "pts @" << hex << uint32(LPVOID(points)));
  87.   CheckValid();
  88. }
  89.  
  90. //
  91. // Create a poly-polygon region.
  92. //
  93. TRegion::TRegion(const TPoint* points, const int* polyCounts, int count,
  94.                  int fillMode)
  95. {
  96.   Handle = ::CreatePolyPolygonRgn(points, polyCounts, count, fillMode);
  97.   WARNX(OwlGDI, !Handle, 0, "Cannot create polypoly region " << count <<
  98.         "polies @" << hex << uint32(LPVOID(points)));
  99.   CheckValid();
  100. }
  101.  
  102. //
  103. // No orphan control for regions since they are not selectable into DCs,
  104. // just delete
  105. //
  106. TRegion::~TRegion()
  107. {
  108.   if (ShouldDelete)
  109.     if (!::DeleteObject(Handle))
  110.       TXGdi::Raise(IDS_GDIDELETEFAIL, Handle);
  111. }
  112.  
  113. //
  114. // Modify and return the intersection of two regions.
  115. //
  116. TRegion&
  117. TRegion::operator &=(const TRect& source)
  118. {
  119.   ::CombineRgn((HRGN)Handle, (HRGN)Handle, TRegion(source), RGN_AND);
  120.   return *this;
  121. }
  122.  
  123. //
  124. // Modify and return the union of two regions.
  125. //
  126. TRegion&
  127. TRegion::operator |=(const TRect& source)
  128. {
  129.   ::CombineRgn((HRGN)Handle, (HRGN)Handle, TRegion(source), RGN_OR);
  130.   return *this;
  131. }
  132.  
  133. //
  134. // Modify and return the exclusive or of two regions.
  135. //
  136. TRegion&
  137. TRegion::operator ^=(const TRect& source)
  138. {
  139.   ::CombineRgn((HRGN)Handle, (HRGN)Handle, TRegion(source), RGN_XOR);
  140.   return *this;
  141. }
  142.