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