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 
23 
24 #ifndef _BGFX_TOOLS_CLIPSTATE_HXX
25 #define _BGFX_TOOLS_CLIPSTATE_HXX
26 
27 #include <sal/types.h>
28 #include <o3tl/cow_wrapper.hxx>
29 
30 //////////////////////////////////////////////////////////////////////////////
31 
32 namespace basegfx
33 {
34     class B2DRange;
35     class B2DPolyRange;
36     class B2DPolygon;
37     class B2DPolyPolygon;
38 
39     namespace tools
40     {
41         struct ImplB2DClipState;
42 
43         /** This class provides an optimized, symbolic clip state for graphical output
44 
45             Having a current 'clip' state is a common attribute of
46             almost all graphic output APIs, most of which internally
47             represent it via a list of rectangular bands. In contrast,
48             this implementation purely uses symbolic clips, but in a
49             quite efficient manner, deferring actual evaluation until
50             a clip representation is requested, and using faster code
51             paths for common special cases (like all-rectangle clips)
52          */
53         class B2DClipState
54         {
55         public:
56             typedef o3tl::cow_wrapper< ImplB2DClipState > ImplType;
57 
58         private:
59             ImplType mpImpl;
60 
61         public:
62             /// Init clip, in 'cleared' state - everything is visible
63             B2DClipState();
64             ~B2DClipState();
65             B2DClipState( const B2DClipState& );
66             explicit B2DClipState( const B2DRange& );
67             explicit B2DClipState( const B2DPolygon& );
68             explicit B2DClipState( const B2DPolyPolygon& );
69             B2DClipState& operator=( const B2DClipState& );
70 
71             /// unshare this poly-range with all internally shared instances
72             void makeUnique();
73 
74             /// Set clip to 'null' - nothing is visible
75             void makeNull();
76             /// returns true when clip is 'null' - nothing is visible
77             bool isNull() const;
78 
79             /// Set clip 'cleared' - everything is visible
80             void makeClear();
81             /// returns true when clip is 'cleared' - everything is visible
82             bool isCleared() const;
83 
84             bool operator==(const B2DClipState&) const;
85             bool operator!=(const B2DClipState&) const;
86 
87             void unionRange(const B2DRange& );
88             void unionPolygon(const B2DPolygon& );
89             void unionPolyPolygon(const B2DPolyPolygon& );
90             void unionClipState(const B2DClipState& );
91 
92             void intersectRange(const B2DRange& );
93             void intersectPolygon(const B2DPolygon& );
94             void intersectPolyPolygon(const B2DPolyPolygon& );
95             void intersectClipState(const B2DClipState& );
96 
97             void subtractRange(const B2DRange& );
98             void subtractPolygon(const B2DPolygon& );
99             void subtractPolyPolygon(const B2DPolyPolygon& );
100             void subtractClipState(const B2DClipState& );
101 
102             void xorRange(const B2DRange& );
103             void xorPolygon(const B2DPolygon& );
104             void xorPolyPolygon(const B2DPolyPolygon& );
105             void xorClipState(const B2DClipState& );
106 
107             B2DPolyPolygon getClipPoly() const;
108         };
109     }
110 }
111 
112 #endif // _BGFX_TOOLS_CLIPSTATE_HXX
113