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