Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef _SV_REGION_HXX
21 : #define _SV_REGION_HXX
22 :
23 : #include <tools/gen.hxx>
24 : #include <tools/solar.h>
25 : #include <vcl/dllapi.h>
26 :
27 : #include <basegfx/polygon/b2dpolypolygon.hxx>
28 : #include <boost/shared_ptr.hpp>
29 :
30 : class ImplRegionBand;
31 : class RegionBand;
32 : class Polygon;
33 : class PolyPolygon;
34 :
35 : //////////////////////////////////////////////////////////////////////////////
36 :
37 : typedef boost::shared_ptr< RegionBand > RegionBandPtr;
38 : typedef boost::shared_ptr< PolyPolygon > PolyPolygonPtr;
39 : typedef boost::shared_ptr< basegfx::B2DPolyPolygon > B2DPolyPolygonPtr;
40 : typedef std::vector< Rectangle > RectangleVector;
41 :
42 : //////////////////////////////////////////////////////////////////////////////
43 :
44 : class VCL_DLLPUBLIC Region
45 : {
46 : private:
47 : friend class OutputDevice;
48 : friend class Window;
49 : friend class Bitmap;
50 :
51 : // possible contents
52 : B2DPolyPolygonPtr mpB2DPolyPolygon;
53 : PolyPolygonPtr mpPolyPolygon;
54 : RegionBandPtr mpRegionBand;
55 :
56 : /// bitfield
57 : bool mbIsNull : 1;
58 :
59 : // helpers
60 : SAL_DLLPRIVATE void ImplCreatePolyPolyRegion( const PolyPolygon& rPolyPoly );
61 : SAL_DLLPRIVATE void ImplCreatePolyPolyRegion( const basegfx::B2DPolyPolygon& rPolyPoly );
62 :
63 : SAL_DLLPRIVATE PolyPolygon ImplCreatePolyPolygonFromRegionBand() const;
64 : SAL_DLLPRIVATE basegfx::B2DPolyPolygon ImplCreateB2DPolyPolygonFromRegionBand() const;
65 :
66 : public:
67 :
68 : explicit Region(bool bIsNull = false); // default creates empty region, with true a null region is created
69 : explicit Region(const Rectangle& rRect);
70 : explicit Region(const Polygon& rPolygon);
71 : explicit Region(const PolyPolygon& rPolyPoly);
72 : explicit Region(const basegfx::B2DPolyPolygon&);
73 : Region(const Region& rRegion);
74 : ~Region();
75 :
76 : // direct access to contents
77 2132102 : const basegfx::B2DPolyPolygon* getB2DPolyPolygon() const { return mpB2DPolyPolygon.get(); }
78 2131480 : const PolyPolygon* getPolyPolygon() const { return mpPolyPolygon.get(); }
79 4282383 : const RegionBand* getRegionBand() const { return mpRegionBand.get(); }
80 :
81 : // access with converters, the asked data will be created from the most
82 : // valuable data, buffered and returned
83 : const PolyPolygon GetAsPolyPolygon() const;
84 : const basegfx::B2DPolyPolygon GetAsB2DPolyPolygon() const;
85 : const RegionBand* GetAsRegionBand() const;
86 :
87 : // manipulators
88 : void Move( long nHorzMove, long nVertMove );
89 : void Scale( double fScaleX, double fScaleY );
90 : bool Union( const Rectangle& rRegion );
91 : bool Intersect( const Rectangle& rRegion );
92 : bool Exclude( const Rectangle& rRegion );
93 : bool XOr( const Rectangle& rRegion );
94 : bool Union( const Region& rRegion );
95 : bool Intersect( const Region& rRegion );
96 : bool Exclude( const Region& rRegion );
97 : bool XOr( const Region& rRegion );
98 :
99 : bool IsEmpty() const;
100 : bool IsNull() const;
101 :
102 : void SetEmpty();
103 : void SetNull();
104 :
105 : Rectangle GetBoundRect() const;
106 999255 : bool HasPolyPolygonOrB2DPolyPolygon() const { return (getB2DPolyPolygon() || getPolyPolygon()); }
107 : void GetRegionRectangles(RectangleVector& rTarget) const;
108 :
109 : bool IsInside( const Point& rPoint ) const;
110 : bool IsInside( const Rectangle& rRect ) const;
111 : bool IsOver( const Rectangle& rRect ) const;
112 :
113 : Region& operator=( const Region& rRegion );
114 : Region& operator=( const Rectangle& rRect );
115 :
116 : bool operator==( const Region& rRegion ) const;
117 15794 : bool operator!=( const Region& rRegion ) const { return !(Region::operator==( rRegion )); }
118 :
119 : friend VCL_DLLPUBLIC SvStream& operator>>( SvStream& rIStm, Region& rRegion );
120 : friend VCL_DLLPUBLIC SvStream& operator<<( SvStream& rOStm, const Region& rRegion );
121 :
122 : /* workaround: faster conversion for PolyPolygons
123 : * if half of the Polygons contained in rPolyPoly are actually
124 : * rectangles, then the returned Region will be constructed by
125 : * XOr'ing the contained Polygons together; in the case of
126 : * only Rectangles this can be up to eight times faster than
127 : * Region( const PolyPolygon& ).
128 : * Caution: this is only useful if the Region is known to be
129 : * changed to rectangles; e.g. if being set as clip region
130 : */
131 : static Region GetRegionFromPolyPolygon( const PolyPolygon& rPolyPoly );
132 : };
133 :
134 : #endif // _SV_REGION_HXX
135 :
136 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|