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