1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 #ifndef _SV_REGION_HXX 23 #define _SV_REGION_HXX 24 25 #include <tools/gen.hxx> 26 #include <vcl/sv.h> 27 #include <vcl/dllapi.h> 28 #include <basegfx/polygon/b2dpolypolygon.hxx> 29 #include <boost/shared_ptr.hpp> 30 31 class ImplRegionBand; 32 class RegionBand; 33 class Polygon; 34 class PolyPolygon; 35 36 ////////////////////////////////////////////////////////////////////////////// 37 38 typedef boost::shared_ptr< RegionBand > RegionBandPtr; 39 typedef boost::shared_ptr< PolyPolygon > PolyPolygonPtr; 40 typedef boost::shared_ptr< basegfx::B2DPolyPolygon > B2DPolyPolygonPtr; 41 typedef std::vector< Rectangle > RectangleVector; 42 43 ////////////////////////////////////////////////////////////////////////////// 44 45 class VCL_DLLPUBLIC Region 46 { 47 private: 48 friend class OutputDevice; 49 friend class Window; 50 friend class Bitmap; 51 52 // possible contents 53 B2DPolyPolygonPtr mpB2DPolyPolygon; 54 PolyPolygonPtr mpPolyPolygon; 55 RegionBandPtr mpRegionBand; 56 57 /// bitfield 58 bool mbIsNull : 1; 59 60 // helpers 61 SAL_DLLPRIVATE void ImplCreatePolyPolyRegion( const PolyPolygon& rPolyPoly ); 62 SAL_DLLPRIVATE void ImplCreatePolyPolyRegion( const basegfx::B2DPolyPolygon& rPolyPoly ); 63 64 SAL_DLLPRIVATE PolyPolygon ImplCreatePolyPolygonFromRegionBand() const; 65 SAL_DLLPRIVATE basegfx::B2DPolyPolygon ImplCreateB2DPolyPolygonFromRegionBand() const; 66 67 public: 68 Region(bool bIsNull = false); // default creates empty region, with true a null region is created 69 Region(const Rectangle& rRect); 70 Region(const Polygon& rPolygon); 71 Region(const PolyPolygon& rPolyPoly); 72 Region(const basegfx::B2DPolyPolygon&); 73 Region(const Region& rRegion); 74 ~Region(); 75 76 // direct access to contents getB2DPolyPolygon() const77 const basegfx::B2DPolyPolygon* getB2DPolyPolygon() const { return mpB2DPolyPolygon.get(); } getPolyPolygon() const78 const PolyPolygon* getPolyPolygon() const { return mpPolyPolygon.get(); } getRegionBand() const79 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; HasPolyPolygonOrB2DPolyPolygon() const106 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; operator !=(const Region & rRegion) const117 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 ////////////////////////////////////////////////////////////////////////////// 137 // eof 138