home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / bc45 / owlsrc.pak / REGION.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-24  |  2.8 KB  |  104 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // (C) Copyright 1992, 1994 by Borland International, All Rights Reserved
  4. //
  5. //   Implementation of GDI Region object class
  6. //----------------------------------------------------------------------------
  7. #include <owl/owlpch.h>
  8. #include <owl/gdiobjec.h>
  9.  
  10. DIAG_DECLARE_GROUP(OwlGDI);        // General GDI diagnostic group
  11.  
  12. TRegion::TRegion()
  13. {
  14.   Handle = ::CreateRectRgn(0, 0, 0, 0);
  15.   WARNX(OwlGDI, !Handle, 0, "Cannot create empty rect region");
  16.   CheckValid();
  17. }
  18.  
  19. TRegion::TRegion(HRGN handle, TAutoDelete autoDelete)
  20. :
  21.   TGdiBase(handle, autoDelete)
  22. {
  23. }
  24.  
  25. TRegion::TRegion(const TRegion& source)
  26. {
  27.   Handle = ::CreateRectRgn(0, 0, 0, 0);
  28.   WARNX(OwlGDI, !Handle, 0, "Cannot create copy of region " << 
  29.         uint(HRGN(source)));
  30.   CheckValid();
  31.   ::CombineRgn((HRGN)Handle, source, 0, RGN_COPY);
  32. }
  33.  
  34. TRegion::TRegion(const TRect& rect)
  35. {
  36.   Handle = ::CreateRectRgnIndirect(&rect);
  37.   WARNX(OwlGDI, !Handle, 0, "Cannot create rect region " << rect);
  38.   CheckValid();
  39. }
  40.  
  41. TRegion::TRegion(const TRect& rect, TRegion::TEllipse)
  42. {
  43.   Handle = ::CreateEllipticRgnIndirect(&rect);
  44.   WARNX(OwlGDI, !Handle, 0, "Cannot create elliptic region " << rect);
  45.   CheckValid();
  46. }
  47.  
  48. TRegion::TRegion(const TRect& rect, const TSize& corner)
  49. {
  50.   Handle = ::CreateRoundRectRgn(rect.left, rect.top, rect.right, rect.bottom,
  51.                                 corner.cx, corner.cy);
  52.   WARNX(OwlGDI, !Handle, 0, "Cannot create roundrect region " << rect << corner);
  53.   CheckValid();
  54. }
  55.  
  56. TRegion::TRegion(const TPoint* points, int count, int fillMode)
  57. {
  58.   Handle = ::CreatePolygonRgn(points, count, fillMode);
  59.   WARNX(OwlGDI, !Handle, 0, "Cannot create poly region " << count << 
  60.         "pts @" << hex << uint32(LPVOID(points)));
  61.   CheckValid();
  62. }
  63.  
  64. TRegion::TRegion(const TPoint* points, const int* polyCounts, int count,
  65.                  int fillMode)
  66. {
  67.   Handle = ::CreatePolyPolygonRgn(points, polyCounts, count, fillMode);
  68.   WARNX(OwlGDI, !Handle, 0, "Cannot create polypoly region " << count << 
  69.         "polies @" << hex << uint32(LPVOID(points)));
  70.   CheckValid();
  71. }
  72.  
  73. //
  74. // No orphan control for regions since they are not selectable into DCs,
  75. // just delete
  76. //
  77. TRegion::~TRegion()
  78. {
  79.   if (ShouldDelete)
  80.     if (!::DeleteObject(Handle))
  81.       THROW( TGdiObject::TXGdi(IDS_GDIDELETEFAIL, Handle) );
  82. }
  83.  
  84. TRegion&
  85. TRegion::operator &=(const TRect& source)
  86. {
  87.   ::CombineRgn((HRGN)Handle, (HRGN)Handle, TRegion(source), RGN_AND);
  88.   return *this;
  89. }
  90.  
  91. TRegion&
  92. TRegion::operator |=(const TRect& source)
  93. {
  94.   ::CombineRgn((HRGN)Handle, (HRGN)Handle, TRegion(source), RGN_OR);
  95.   return *this;
  96. }
  97.  
  98. TRegion&
  99. TRegion::operator ^=(const TRect& source)
  100. {
  101.   ::CombineRgn((HRGN)Handle, (HRGN)Handle, TRegion(source), RGN_XOR);
  102.   return *this;
  103. }
  104.