xref: /haiku/headers/os/interface/Region.h (revision 344ded80d400028c8f561b4b876257b94c12db4a)
1 /*
2  * Copyright 2003-2014 Haiku, Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef	_REGION_H
6 #define	_REGION_H
7 
8 
9 #include <Rect.h>
10 
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& other);
31 								BRegion(const BRect rect);
32 #if defined(__cplusplus) && __cplusplus >= 201103L
33 								BRegion(BRegion&& other);
34 #endif
35 	virtual						~BRegion();
36 
37 			BRegion&			operator=(const BRegion& other);
38 #if defined(__cplusplus) && __cplusplus >= 201103L
39 			BRegion&			operator=(BRegion&& other);
40 #endif
41 			bool				operator==(const BRegion& other) const;
42 
43 			void				Set(BRect rect);
44 			void				Set(clipping_rect clipping);
45 			void				MoveFrom(BRegion& other);
46 
47 			BRect				Frame() const;
48 			clipping_rect		FrameInt() const;
49 
50 			BRect				RectAt(int32 index);
51 			BRect				RectAt(int32 index) const;
52 			clipping_rect		RectAtInt(int32 index);
53 			clipping_rect		RectAtInt(int32 index) const;
54 
55 			int32				CountRects();
56 			int32				CountRects() const;
57 
58 			bool				Intersects(BRect rect) const;
59 			bool				Intersects(clipping_rect clipping) const;
60 
61 			bool				Contains(BPoint point) const;
62 			bool				Contains(int32 x, int32 y);
63 			bool				Contains(int32 x, int32 y) const;
64 
65 			void				PrintToStream() const;
66 
67 			void				OffsetBy(const BPoint& point);
68 			void				OffsetBy(int32 x, int32 y);
69 			void				ScaleBy(BSize scale);
70 			void				ScaleBy(float x, float y);
71 
72 			void				MakeEmpty();
73 
74 			void				Include(BRect rect);
75 			void				Include(clipping_rect clipping);
76 			void				Include(const BRegion* region);
77 
78 			void				Exclude(BRect rect);
79 			void				Exclude(clipping_rect clipping);
80 			void				Exclude(const BRegion* region);
81 
82 			void				IntersectWith(const BRegion* region);
83 
84 			void				ExclusiveInclude(const BRegion* region);
85 
86 private:
87 	friend class BDirectWindow;
88 	friend class BPrivate::ServerLink;
89 	friend class BPrivate::LinkReceiver;
90 
91 	class Support;
92 	friend class Support;
93 
94 private:
95 								BRegion(const clipping_rect& clipping);
96 
97 			void				_AdoptRegionData(BRegion& region);
98 			bool				_SetSize(int32 newSize);
99 
100 			clipping_rect		_Convert(const BRect& rect) const;
101 			clipping_rect		_ConvertToInternal(const BRect& rect) const;
102 			clipping_rect		_ConvertToInternal(
103 									const clipping_rect& rect) const;
104 
105 private:
106 			int32				fCount;
107 			int32				fDataSize;
108 			clipping_rect		fBounds;
109 			clipping_rect*		fData;
110 };
111 
112 
113 #endif // _REGION_H
114