1 /* 2 * Copyright 2007, Haiku. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 #ifndef _REGION_H 7 #define _REGION_H 8 9 #include <BeBuild.h> 10 #include <Rect.h> 11 12 namespace BPrivate { 13 class ServerLink; 14 class LinkReceiver; 15 }; 16 17 /* Integer rect used to define a clipping rectangle. All bounds are inclusive. */ 18 /* Moved from DirectWindow.h */ 19 typedef struct { 20 int32 left; 21 int32 top; 22 int32 right; 23 int32 bottom; 24 } clipping_rect; 25 26 27 class BRegion { 28 public: 29 BRegion(); 30 BRegion(const BRegion& region); 31 BRegion(const BRect rect); 32 virtual ~BRegion(); 33 34 BRegion& operator=(const BRegion& from); 35 bool operator==(const BRegion& other) const; 36 37 void Set(BRect newBounds); 38 void Set(clipping_rect newBounds); 39 40 BRect Frame() const; 41 clipping_rect FrameInt() const; 42 43 BRect RectAt(int32 index); 44 BRect RectAt(int32 index) const; 45 clipping_rect RectAtInt(int32 index); 46 clipping_rect RectAtInt(int32 index) const; 47 48 int32 CountRects(); 49 int32 CountRects() const; 50 51 bool Intersects(BRect rect) const; 52 bool Intersects(clipping_rect rect) const; 53 54 bool Contains(BPoint point) const; 55 bool Contains(int32 x, int32 y); 56 bool Contains(int32 x, int32 y) const; 57 58 void PrintToStream() const; 59 60 void OffsetBy(int32 x, int32 y); 61 62 void MakeEmpty(); 63 64 void Include(BRect rect); 65 void Include(clipping_rect rect); 66 void Include(const BRegion*); 67 68 void Exclude(BRect r); 69 void Exclude(clipping_rect r); 70 void Exclude(const BRegion* region); 71 72 void IntersectWith(const BRegion* region); 73 74 void ExclusiveInclude(const BRegion* region); 75 76 private: 77 friend class BDirectWindow; 78 friend class BPrivate::ServerLink; 79 friend class BPrivate::LinkReceiver; 80 81 class Support; 82 friend class Support; 83 84 private: 85 BRegion(const clipping_rect& rect); 86 87 void _AdoptRegionData(BRegion& region); 88 bool _SetSize(long newSize); 89 90 clipping_rect _Convert(const BRect& rect) const; 91 clipping_rect _ConvertToInternal(const BRect& rect) const; 92 clipping_rect _ConvertToInternal( 93 const clipping_rect& rect) const; 94 95 private: 96 long fCount; 97 long fDataSize; 98 clipping_rect fBounds; 99 clipping_rect* fData; 100 }; 101 102 #endif // _REGION_H 103