update credits
[LibreOffice.git] / include / vcl / region.hxx
blob02eebc7ec50ee2e3a0f9f1b067d5efa58d4ffa6e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef _SV_REGION_HXX
21 #define _SV_REGION_HXX
23 #include <tools/gen.hxx>
24 #include <tools/solar.h>
25 #include <vcl/dllapi.h>
27 #include <basegfx/polygon/b2dpolypolygon.hxx>
29 class ImplRegion;
30 class ImplRegionBand;
31 class Polygon;
32 class PolyPolygon;
33 struct ImplRegionInfo;
35 // --------------
36 // - RegionType -
37 // --------------
39 enum RegionType { REGION_NULL, REGION_EMPTY, REGION_RECTANGLE, REGION_COMPLEX };
40 enum RegionOverlapType { REGION_INSIDE, REGION_OVER, REGION_OUTSIDE };
42 typedef long RegionHandle;
44 // ----------
45 // - Region -
46 // ----------
48 class VCL_DLLPUBLIC Region
50 friend class OutputDevice;
51 friend class Window;
52 friend class Bitmap;
54 private:
55 ImplRegion* mpImplRegion;
57 SAL_DLLPRIVATE void ImplCopyData();
58 SAL_DLLPRIVATE void ImplCreateRectRegion( const Rectangle& rRect );
59 SAL_DLLPRIVATE void ImplCreatePolyPolyRegion( const PolyPolygon& rPolyPoly );
60 SAL_DLLPRIVATE void ImplCreatePolyPolyRegion( const basegfx::B2DPolyPolygon& rPolyPoly );
61 SAL_DLLPRIVATE void ImplPolyPolyRegionToBandRegionFunc();
62 SAL_DLLPRIVATE inline void ImplPolyPolyRegionToBandRegion();
63 SAL_DLLPRIVATE const ImplRegion* ImplGetImplRegion() const { return mpImplRegion; }
64 SAL_DLLPRIVATE ImplRegion* ImplGetImplRegion() { return mpImplRegion; }
65 SAL_DLLPRIVATE void ImplBeginAddRect( );
66 SAL_DLLPRIVATE sal_Bool ImplAddRect( const Rectangle& rRect );
67 SAL_DLLPRIVATE void ImplEndAddRect( );
68 SAL_DLLPRIVATE void ImplIntersectWithPolyPolygon( const Region& );
69 SAL_DLLPRIVATE void ImplExcludePolyPolygon( const Region& );
70 SAL_DLLPRIVATE void ImplUnionPolyPolygon( const Region& );
71 SAL_DLLPRIVATE void ImplXOrPolyPolygon( const Region& );
73 public: // public within vcl
74 VCL_PLUGIN_PUBLIC bool ImplGetFirstRect( ImplRegionInfo& rImplRegionInfo,
75 long& nX, long& nY, long& nWidth, long& nHeight ) const;
76 VCL_PLUGIN_PUBLIC bool ImplGetNextRect( ImplRegionInfo& rImplRegionInfo,
77 long& nX, long& nY, long& nWidth, long& nHeight ) const;
78 #ifdef DBG_UTIL
79 friend const char* ImplDbgTestRegion( const void* pObj );
80 #endif
82 public:
83 explicit Region();
84 explicit Region( RegionType eType );
85 explicit Region( const Rectangle& rRect );
86 explicit Region( const Polygon& rPolygon );
87 explicit Region( const PolyPolygon& rPolyPoly );
88 explicit Region( const basegfx::B2DPolyPolygon& );
89 Region( const Region& rRegion );
90 ~Region();
92 void Move( long nHorzMove, long nVertMove );
93 void Scale( double fScaleX, double fScaleY );
94 void Union( const Rectangle& rRegion );
95 void Intersect( const Rectangle& rRegion );
96 void Exclude( const Rectangle& rRegion );
97 void XOr( const Rectangle& rRegion );
98 void Union( const Region& rRegion );
99 void Intersect( const Region& rRegion );
100 void Exclude( const Region& rRegion );
101 void XOr( const Region& rRegion );
103 RegionType GetType() const;
104 sal_Bool IsEmpty() const { return GetType() == REGION_EMPTY; };
105 sal_Bool IsNull() const { return GetType() == REGION_NULL; };
107 void SetEmpty();
108 void SetNull();
110 Rectangle GetBoundRect() const;
112 sal_Bool HasPolyPolygon() const;
113 PolyPolygon GetPolyPolygon() const;
114 // returns an empty polypolygon in case HasPolyPolygon is sal_False
115 const basegfx::B2DPolyPolygon GetB2DPolyPolygon() const;
116 // returns a PolyPolygon either copied from the set PolyPolygon region
117 // or created from the constituent rectangles
118 basegfx::B2DPolyPolygon ConvertToB2DPolyPolygon();
120 sal_uLong GetRectCount() const;
121 RegionHandle BeginEnumRects();
122 sal_Bool GetEnumRects( RegionHandle hRegionHandle, Rectangle& rRect );
123 sal_Bool GetNextEnumRect( RegionHandle hRegionHandle, Rectangle& rRect )
124 { return GetEnumRects( hRegionHandle, rRect ); }
125 void EndEnumRects( RegionHandle hRegionHandle );
127 sal_Bool IsInside( const Point& rPoint ) const;
128 sal_Bool IsInside( const Rectangle& rRect ) const;
129 sal_Bool IsOver( const Rectangle& rRect ) const;
131 Region& operator=( const Region& rRegion );
132 Region& operator=( const Rectangle& rRect );
134 sal_Bool operator==( const Region& rRegion ) const;
135 sal_Bool operator!=( const Region& rRegion ) const
136 { return !(Region::operator==( rRegion )); }
138 friend VCL_DLLPUBLIC SvStream& operator>>( SvStream& rIStm, Region& rRegion );
139 friend VCL_DLLPUBLIC SvStream& operator<<( SvStream& rOStm, const Region& rRegion );
141 /* workaround: faster conversion for PolyPolygons
142 * if half of the Polygons contained in rPolyPoly are actually
143 * rectangles, then the returned Region will be constructed by
144 * XOr'ing the contained Polygons together; in the case of
145 * only Rectangles this can be up to eight times faster than
146 * Region( const PolyPolygon& ).
147 * Caution: this is only useful if the Region is known to be
148 * changed to rectangles; e.g. if being set as clip region
150 static Region GetRegionFromPolyPolygon( const PolyPolygon& rPolyPoly );
153 #endif // _SV_REGION_HXX
155 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */