xref: /trunk/main/vcl/inc/vcl/region.hxx (revision 78abece84b3742aad03bddc3860ad7b6dfda5618)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _SV_REGION_HXX
25 #define _SV_REGION_HXX
26 
27 #include <tools/gen.hxx>
28 #include <vcl/sv.h>
29 #include <vcl/dllapi.h>
30 
31 #include <basegfx/polygon/b2dpolypolygon.hxx>
32 
33 class ImplRegion;
34 class ImplRegionBand;
35 class Polygon;
36 class PolyPolygon;
37 struct ImplRegionInfo;
38 
39 // --------------
40 // - RegionType -
41 // --------------
42 
43 enum RegionType { REGION_NULL, REGION_EMPTY, REGION_RECTANGLE, REGION_COMPLEX };
44 enum RegionOverlapType { REGION_INSIDE, REGION_OVER, REGION_OUTSIDE };
45 
46 typedef long RegionHandle;
47 
48 // ----------
49 // - Region -
50 // ----------
51 
52 class VCL_DLLPUBLIC Region
53 {
54     friend class OutputDevice;
55     friend class Window;
56     friend class Bitmap;
57 
58 private:
59     ImplRegion*         mpImplRegion;
60 
61     SAL_DLLPRIVATE void             ImplCopyData();
62     SAL_DLLPRIVATE void             ImplCreateRectRegion( const Rectangle& rRect );
63     SAL_DLLPRIVATE void             ImplCreatePolyPolyRegion( const PolyPolygon& rPolyPoly );
64     SAL_DLLPRIVATE void             ImplCreatePolyPolyRegion( const basegfx::B2DPolyPolygon& rPolyPoly );
65     SAL_DLLPRIVATE void             ImplPolyPolyRegionToBandRegionFunc();
66     SAL_DLLPRIVATE inline void      ImplPolyPolyRegionToBandRegion();
67     SAL_DLLPRIVATE const ImplRegion*    ImplGetImplRegion() const { return mpImplRegion; }
68     SAL_DLLPRIVATE ImplRegion*      ImplGetImplRegion() { return mpImplRegion; }
69     SAL_DLLPRIVATE void             ImplBeginAddRect( );
70     SAL_DLLPRIVATE sal_Bool             ImplAddRect( const Rectangle& rRect );
71     SAL_DLLPRIVATE void             ImplEndAddRect( );
72     SAL_DLLPRIVATE void             ImplIntersectWithPolyPolygon( const Region& );
73     SAL_DLLPRIVATE void             ImplExcludePolyPolygon( const Region& );
74     SAL_DLLPRIVATE void             ImplUnionPolyPolygon( const Region& );
75     SAL_DLLPRIVATE void             ImplXOrPolyPolygon( const Region& );
76 
77 public: // public within vcl
78     VCL_PLUGIN_PUBLIC bool              ImplGetFirstRect( ImplRegionInfo& rImplRegionInfo,
79                                           long& nX, long& nY, long& nWidth, long& nHeight ) const;
80     VCL_PLUGIN_PUBLIC bool              ImplGetNextRect( ImplRegionInfo& rImplRegionInfo,
81                                          long& nX, long& nY, long& nWidth, long& nHeight ) const;
82 #ifdef DBG_UTIL
83     friend const char*  ImplDbgTestRegion( const void* pObj );
84 #endif
85 
86 public:
87                     Region();
88                     Region( RegionType eType );
89                     Region( const Rectangle& rRect );
90                     Region( const Polygon& rPolygon );
91                     Region( const PolyPolygon& rPolyPoly );
92                     Region( const basegfx::B2DPolyPolygon& );
93                     Region( const Region& rRegion );
94                     ~Region();
95 
96     void            Move( long nHorzMove, long nVertMove );
97     void            Scale( double fScaleX, double fScaleY );
98     sal_Bool            Union( const Rectangle& rRegion );
99     sal_Bool            Intersect( const Rectangle& rRegion );
100     sal_Bool            Exclude( const Rectangle& rRegion );
101     sal_Bool            XOr( const Rectangle& rRegion );
102     sal_Bool            Union( const Region& rRegion );
103     sal_Bool            Intersect( const Region& rRegion );
104     sal_Bool            Exclude( const Region& rRegion );
105     sal_Bool            XOr( const Region& rRegion );
106 
107     RegionType      GetType() const;
108     sal_Bool            IsEmpty() const { return GetType() == REGION_EMPTY; };
109     sal_Bool            IsNull() const { return GetType() == REGION_NULL; };
110 
111     void            SetEmpty();
112     void            SetNull();
113 
114     Rectangle       GetBoundRect() const;
115 
116     sal_Bool            HasPolyPolygon() const;
117     PolyPolygon     GetPolyPolygon() const;
118     // returns an empty polypolygon in case HasPolyPolygon is sal_False
119     const basegfx::B2DPolyPolygon GetB2DPolyPolygon() const;
120     // returns a PolyPolygon either copied from the set PolyPolygon region
121     // or created from the constituent rectangles
122     basegfx::B2DPolyPolygon ConvertToB2DPolyPolygon();
123 
124     sal_uLong           GetRectCount() const;
125     RegionHandle    BeginEnumRects();
126     sal_Bool            GetEnumRects( RegionHandle hRegionHandle, Rectangle& rRect );
127     sal_Bool            GetNextEnumRect( RegionHandle hRegionHandle, Rectangle& rRect )
128                         { return GetEnumRects( hRegionHandle, rRect ); }
129     void            EndEnumRects( RegionHandle hRegionHandle );
130 
131     sal_Bool            IsInside( const Point& rPoint ) const;
132     sal_Bool            IsInside( const Rectangle& rRect ) const;
133     sal_Bool            IsOver( const Rectangle& rRect ) const;
134 
135     Region&         operator=( const Region& rRegion );
136     Region&         operator=( const Rectangle& rRect );
137 
138     sal_Bool            operator==( const Region& rRegion ) const;
139     sal_Bool            operator!=( const Region& rRegion ) const
140                         { return !(Region::operator==( rRegion )); }
141 
142     friend VCL_DLLPUBLIC SvStream& operator>>( SvStream& rIStm, Region& rRegion );
143     friend VCL_DLLPUBLIC SvStream& operator<<( SvStream& rOStm, const Region& rRegion );
144 
145     /* workaround: faster conversion for PolyPolygons
146      * if half of the Polygons contained in rPolyPoly are actually
147      * rectangles, then the returned Region will be constructed by
148      * XOr'ing the contained Polygons together; in the case of
149      * only Rectangles this can be up to eight times faster than
150      * Region( const PolyPolygon& ).
151      * Caution: this is only useful if the Region is known to be
152      * changed to rectangles; e.g. if being set as clip region
153      */
154     static Region GetRegionFromPolyPolygon( const PolyPolygon& rPolyPoly );
155 };
156 
157 #endif  // _SV_REGION_HXX
158