Region.h revision 669ac9d6
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
12namespace 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 */
19typedef struct {
20	int32	left;
21	int32	top;
22	int32	right;
23	int32	bottom;
24} clipping_rect;
25
26
27class BRegion {
28public:
29								BRegion();
30								BRegion(const BRegion& other);
31								BRegion(const BRect rect);
32	virtual						~BRegion();
33
34			BRegion&			operator=(const BRegion& other);
35			bool				operator==(const BRegion& other) const;
36
37			void				Set(BRect rect);
38			void				Set(clipping_rect clipping);
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 clipping) 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(const BPoint& point);
61			void				OffsetBy(int32 x, int32 y);
62			void				ScaleBy(float x, float y);
63
64			void				MakeEmpty();
65
66			void				Include(BRect rect);
67			void				Include(clipping_rect clipping);
68			void				Include(const BRegion* region);
69
70			void				Exclude(BRect rect);
71			void				Exclude(clipping_rect clipping);
72			void				Exclude(const BRegion* region);
73
74			void				IntersectWith(const BRegion* region);
75
76			void				ExclusiveInclude(const BRegion* region);
77
78private:
79	friend class BDirectWindow;
80	friend class BPrivate::ServerLink;
81	friend class BPrivate::LinkReceiver;
82
83	class Support;
84	friend class Support;
85
86private:
87								BRegion(const clipping_rect& clipping);
88
89			void				_AdoptRegionData(BRegion& region);
90			bool				_SetSize(int32 newSize);
91
92			clipping_rect		_Convert(const BRect& rect) const;
93			clipping_rect		_ConvertToInternal(const BRect& rect) const;
94			clipping_rect		_ConvertToInternal(
95									const clipping_rect& rect) const;
96
97private:
98			int32				fCount;
99			int32				fDataSize;
100			clipping_rect		fBounds;
101			clipping_rect*		fData;
102};
103
104
105#endif // _REGION_H
106