Version 7.1.7.1, tag libreoffice-7.1.7.1
[LibreOffice.git] / svx / source / svdraw / sdrhittesthelper.cxx
blob2a93dc372555a636938740753b7fce3f85d365cb
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 .
21 #include <svx/sdrhittesthelper.hxx>
22 #include <svx/obj3d.hxx>
23 #include <svx/helperhittest3d.hxx>
24 #include <svx/svdpage.hxx>
25 #include <svx/sdrpagewindow.hxx>
26 #include <svx/sdr/contact/viewobjectcontact.hxx>
27 #include <svx/sdr/contact/displayinfo.hxx>
28 #include <svx/sdr/contact/objectcontact.hxx>
29 #include <drawinglayer/processor2d/hittestprocessor2d.hxx>
30 #include <svx/svdpagv.hxx>
31 #include <svx/sdr/contact/viewcontact.hxx>
34 // #i101872# new Object HitTest as View-tooling
36 SdrObject* SdrObjectPrimitiveHit(
37 const SdrObject& rObject,
38 const Point& rPnt,
39 sal_uInt16 nTol,
40 const SdrPageView& rSdrPageView,
41 const SdrLayerIDSet* pVisiLayer,
42 bool bTextOnly,
43 drawinglayer::primitive2d::Primitive2DContainer* pHitContainer)
45 SdrObject* pResult = nullptr;
47 if(rObject.GetSubList() && rObject.GetSubList()->GetObjCount())
49 // group or scene with content. Single 3D objects also have a
50 // true == rObject.GetSubList(), but no content
51 pResult = SdrObjListPrimitiveHit(*rObject.GetSubList(), rPnt, nTol, rSdrPageView, pVisiLayer, bTextOnly);
53 else
55 if( rObject.IsVisible() && (!pVisiLayer || pVisiLayer->IsSet(rObject.GetLayer())))
57 // single object, 3d object, empty scene or empty group. Check if
58 // it's a single 3D object
59 const E3dCompoundObject* pE3dCompoundObject = dynamic_cast< const E3dCompoundObject* >(&rObject);
61 if(pE3dCompoundObject)
63 const basegfx::B2DPoint aHitPosition(rPnt.X(), rPnt.Y());
65 if(checkHitSingle3DObject(aHitPosition, *pE3dCompoundObject))
67 pResult = const_cast< E3dCompoundObject* >(pE3dCompoundObject);
70 else
72 // not a single 3D object; Check in first PageWindow using primitives (only SC
73 // with split views uses multiple PageWindows nowadays)
74 if(rSdrPageView.PageWindowCount())
76 const double fLogicTolerance(nTol);
77 const basegfx::B2DPoint aHitPosition(rPnt.X(), rPnt.Y());
78 const sdr::contact::ViewObjectContact& rVOC = rObject.GetViewContact().GetViewObjectContact(
79 rSdrPageView.GetPageWindow(0)->GetObjectContact());
81 if(ViewObjectContactPrimitiveHit(rVOC, aHitPosition, fLogicTolerance, bTextOnly, pHitContainer))
83 pResult = const_cast< SdrObject* >(&rObject);
90 return pResult;
94 SdrObject* SdrObjListPrimitiveHit(
95 const SdrObjList& rList,
96 const Point& rPnt,
97 sal_uInt16 nTol,
98 const SdrPageView& rSdrPageView,
99 const SdrLayerIDSet* pVisiLayer,
100 bool bTextOnly)
102 size_t nObjNum(rList.GetObjCount());
103 SdrObject* pRetval = nullptr;
105 while(!pRetval && nObjNum > 0)
107 nObjNum--;
108 SdrObject* pObj = rList.GetObj(nObjNum);
110 pRetval = SdrObjectPrimitiveHit(*pObj, rPnt, nTol, rSdrPageView, pVisiLayer, bTextOnly);
113 return pRetval;
117 bool ViewObjectContactPrimitiveHit(
118 const sdr::contact::ViewObjectContact& rVOC,
119 const basegfx::B2DPoint& rHitPosition,
120 double fLogicHitTolerance,
121 bool bTextOnly,
122 drawinglayer::primitive2d::Primitive2DContainer* pHitContainer)
124 basegfx::B2DRange aObjectRange(rVOC.getObjectRange());
126 if(!aObjectRange.isEmpty())
128 // first do a rough B2DRange based HitTest; do not forget to
129 // include the HitTolerance if given
130 if(basegfx::fTools::more(fLogicHitTolerance, 0.0))
132 aObjectRange.grow(fLogicHitTolerance);
135 if(aObjectRange.isInside(rHitPosition))
137 // get primitive sequence
138 sdr::contact::DisplayInfo aDisplayInfo;
139 const drawinglayer::primitive2d::Primitive2DContainer& rSequence(rVOC.getPrimitive2DSequence(aDisplayInfo));
141 if(!rSequence.empty())
143 // create a HitTest processor
144 const drawinglayer::geometry::ViewInformation2D& rViewInformation2D = rVOC.GetObjectContact().getViewInformation2D();
145 drawinglayer::processor2d::HitTestProcessor2D aHitTestProcessor2D(
146 rViewInformation2D,
147 rHitPosition,
148 fLogicHitTolerance,
149 bTextOnly);
151 // ask for HitStack
152 aHitTestProcessor2D.collectHitStack(true);
154 // feed it with the primitives
155 aHitTestProcessor2D.process(rSequence);
157 // deliver result
158 if (aHitTestProcessor2D.getHit())
160 if (pHitContainer)
162 // fetch HitStack primitives if requested
163 *pHitContainer = aHitTestProcessor2D.getHitStack();
166 return true;
172 return false;
175 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */