1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef INCLUDED_DRAWINGLAYER_PROCESSOR2D_HITTESTPROCESSOR2D_HXX
29 #define INCLUDED_DRAWINGLAYER_PROCESSOR2D_HITTESTPROCESSOR2D_HXX
30 
31 #include <drawinglayer/processor2d/baseprocessor2d.hxx>
32 
33 //////////////////////////////////////////////////////////////////////////////
34 // predeclarations
35 
36 namespace basegfx { class B2DPolygon; }
37 namespace basegfx { class B2DPolyPolygon; }
38 namespace drawinglayer { namespace primitive2d { class ScenePrimitive2D; }}
39 
40 //////////////////////////////////////////////////////////////////////////////
41 
42 namespace drawinglayer
43 {
44 	namespace processor2d
45 	{
46         /** HitTestProcessor2D class
47 
48             This processor implements a HitTest with the feeded primitives,
49             given tolerance and extras
50          */
51 		class HitTestProcessor2D : public BaseProcessor2D
52 		{
53 		private:
54 			/// discrete HitTest position
55 			basegfx::B2DPoint			maDiscreteHitPosition;
56 
57 			/// discrete HitTolerance
58 			double						mfDiscreteHitTolerance;
59 
60 			/// bitfield
61 			unsigned					mbHit : 1;
62 			unsigned					mbHitToleranceUsed : 1;
63 
64 			/*  this flag decides if primitives which are embedded to an
65                 UnifiedTransparencePrimitive2D and are invisible will be taken into account for
66                 HitTesting or not. Those primitives are created for objects which are else
67                 completely invisible and normally their content exists of hairline
68                 primitives describing the object's contour
69              */
70 			unsigned					mbUseInvisiblePrimitiveContent : 1;
71 
72             /// flag to concentraze on text hits only
73             unsigned                    mbHitTextOnly : 1;
74 
75 			/// tooling methods
76 			void processBasePrimitive2D(const primitive2d::BasePrimitive2D& rCandidate);
77 			bool checkHairlineHitWithTolerance(
78 				const basegfx::B2DPolygon& rPolygon,
79 				double fDiscreteHitTolerance);
80 			bool checkFillHitWithTolerance(
81 				const basegfx::B2DPolyPolygon& rPolyPolygon,
82 				double fDiscreteHitTolerance);
83 			void check3DHit(const primitive2d::ScenePrimitive2D& rCandidate);
84 
85 		public:
86 			HitTestProcessor2D(
87 				const geometry::ViewInformation2D& rViewInformation,
88 				const basegfx::B2DPoint& rLogicHitPosition,
89 				double fLogicHitTolerance,
90                 bool bHitTextOnly);
91 			virtual ~HitTestProcessor2D();
92 
93 			/// data write access
94 			void setUseInvisiblePrimitiveContent(bool bNew)
95 			{
96 				if((bool)mbUseInvisiblePrimitiveContent != bNew) mbUseInvisiblePrimitiveContent = bNew;
97 			}
98 
99             /// data read access
100 			const basegfx::B2DPoint& getDiscreteHitPosition() const { return maDiscreteHitPosition; }
101 			double getDiscreteHitTolerance() const { return mfDiscreteHitTolerance; }
102 			bool getHit() const { return mbHit; }
103 			bool getHitToleranceUsed() const { return mbHitToleranceUsed; }
104 			bool getUseInvisiblePrimitiveContent() const { return mbUseInvisiblePrimitiveContent;}
105             bool getHitTextOnly() const { return mbHitTextOnly; }
106 		};
107 	} // end of namespace processor2d
108 } // end of namespace drawinglayer
109 
110 //////////////////////////////////////////////////////////////////////////////
111 
112 #endif // INCLUDED_DRAWINGLAYER_PROCESSOR2D_HITTESTPROCESSOR2D_HXX
113 
114 // eof
115