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 INCLUDED_VCL_REGION_HXX
21 : #define INCLUDED_VCL_REGION_HXX
22 :
23 : #include <tools/gen.hxx>
24 : #include <vcl/dllapi.h>
25 :
26 : #include <basegfx/polygon/b2dpolypolygon.hxx>
27 : #include <boost/shared_ptr.hpp>
28 :
29 : class ImplRegionBand;
30 : class RegionBand;
31 : class Polygon;
32 : class PolyPolygon;
33 :
34 : typedef boost::shared_ptr< RegionBand > RegionBandPtr;
35 : typedef boost::shared_ptr< PolyPolygon > PolyPolygonPtr;
36 : typedef boost::shared_ptr< basegfx::B2DPolyPolygon > B2DPolyPolygonPtr;
37 : typedef std::vector< Rectangle > RectangleVector;
38 :
39 : class VCL_DLLPUBLIC Region
40 : {
41 : private:
42 : friend class OutputDevice;
43 : friend class Window;
44 : friend class Bitmap;
45 :
46 : // possible contents
47 : B2DPolyPolygonPtr mpB2DPolyPolygon;
48 : PolyPolygonPtr mpPolyPolygon;
49 : RegionBandPtr mpRegionBand;
50 :
51 : /// bitfield
52 : bool mbIsNull : 1;
53 :
54 : // helpers
55 : SAL_DLLPRIVATE void ImplCreatePolyPolyRegion( const PolyPolygon& rPolyPoly );
56 : SAL_DLLPRIVATE void ImplCreatePolyPolyRegion( const basegfx::B2DPolyPolygon& rPolyPoly );
57 :
58 : SAL_DLLPRIVATE PolyPolygon ImplCreatePolyPolygonFromRegionBand() const;
59 : SAL_DLLPRIVATE basegfx::B2DPolyPolygon ImplCreateB2DPolyPolygonFromRegionBand() const;
60 :
61 : public:
62 :
63 : explicit Region(bool bIsNull = false); // default creates empty region, with true a null region is created
64 : explicit Region(const Rectangle& rRect);
65 : explicit Region(const Polygon& rPolygon);
66 : explicit Region(const PolyPolygon& rPolyPoly);
67 : explicit Region(const basegfx::B2DPolyPolygon&);
68 : Region(const Region& rRegion);
69 : ~Region();
70 :
71 : // direct access to contents
72 0 : const basegfx::B2DPolyPolygon* getB2DPolyPolygon() const { return mpB2DPolyPolygon.get(); }
73 0 : const PolyPolygon* getPolyPolygon() const { return mpPolyPolygon.get(); }
74 0 : const RegionBand* getRegionBand() const { return mpRegionBand.get(); }
75 :
76 : // access with converters, the asked data will be created from the most
77 : // valuable data, buffered and returned
78 : const PolyPolygon GetAsPolyPolygon() const;
79 : const basegfx::B2DPolyPolygon GetAsB2DPolyPolygon() const;
80 : const RegionBand* GetAsRegionBand() const;
81 :
82 : // manipulators
83 : void Move( long nHorzMove, long nVertMove );
84 : void Scale( double fScaleX, double fScaleY );
85 : bool Union( const Rectangle& rRegion );
86 : bool Intersect( const Rectangle& rRegion );
87 : bool Exclude( const Rectangle& rRegion );
88 : bool XOr( const Rectangle& rRegion );
89 : bool Union( const Region& rRegion );
90 : bool Intersect( const Region& rRegion );
91 : bool Exclude( const Region& rRegion );
92 : bool XOr( const Region& rRegion );
93 :
94 : bool IsEmpty() const;
95 : bool IsNull() const;
96 :
97 : void SetEmpty();
98 : void SetNull();
99 :
100 : Rectangle GetBoundRect() const;
101 0 : bool HasPolyPolygonOrB2DPolyPolygon() const { return (getB2DPolyPolygon() || getPolyPolygon()); }
102 : void GetRegionRectangles(RectangleVector& rTarget) const;
103 :
104 : bool IsInside( const Point& rPoint ) const;
105 : bool IsInside( const Rectangle& rRect ) const;
106 : bool IsOver( const Rectangle& rRect ) const;
107 :
108 : Region& operator=( const Region& rRegion );
109 : Region& operator=( const Rectangle& rRect );
110 :
111 : bool operator==( const Region& rRegion ) const;
112 0 : bool operator!=( const Region& rRegion ) const { return !(Region::operator==( rRegion )); }
113 :
114 : friend VCL_DLLPUBLIC SvStream& ReadRegion( SvStream& rIStm, Region& rRegion );
115 : friend VCL_DLLPUBLIC SvStream& WriteRegion( SvStream& rOStm, const Region& rRegion );
116 :
117 : /* workaround: faster conversion for PolyPolygons
118 : * if half of the Polygons contained in rPolyPoly are actually
119 : * rectangles, then the returned Region will be constructed by
120 : * XOr'ing the contained Polygons together; in the case of
121 : * only Rectangles this can be up to eight times faster than
122 : * Region( const PolyPolygon& ).
123 : * Caution: this is only useful if the Region is known to be
124 : * changed to rectangles; e.g. if being set as clip region
125 : */
126 : static Region GetRegionFromPolyPolygon( const PolyPolygon& rPolyPoly );
127 : };
128 :
129 :
130 : template< typename charT, typename traits >
131 : inline std::basic_ostream<charT, traits> & operator <<(
132 : std::basic_ostream<charT, traits> & stream, const Region& rRegion)
133 : {
134 : if (rRegion.IsEmpty())
135 : return stream << "EMPTY";
136 : if (rRegion.getB2DPolyPolygon())
137 : return stream << "B2DPolyPolygon("
138 : << *rRegion.getB2DPolyPolygon()
139 : << ")";
140 : if (rRegion.getPolyPolygon())
141 : return stream << "PolyPolygon("
142 : << *rRegion.getPolyPolygon()
143 : << ")";
144 : if (rRegion.getRegionBand())
145 : { // inlined because RegionBand is private to vcl
146 : stream << "RegionBand(";
147 : RectangleVector rects;
148 : rRegion.GetRegionRectangles(rects);
149 : if (rects.empty())
150 : stream << "EMPTY";
151 : for (size_t i = 0; i < rects.size(); ++i)
152 : stream << "[" << i << "] " << rects[i];
153 : stream << ")";
154 : }
155 : return stream;
156 : }
157 :
158 : #endif // INCLUDED_VCL_REGION_HXX
159 :
160 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|