/src/libreoffice/svx/source/svdraw/sdrhittesthelper.cxx
Line | Count | Source |
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 | | |
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> |
32 | | |
33 | | |
34 | | // #i101872# new Object HitTest as View-tooling |
35 | | |
36 | | SdrObject* SdrObjectPrimitiveHit( |
37 | | const SdrObject& rObject, |
38 | | const Point& rPnt, |
39 | | const basegfx::B2DVector& rHitTolerance, |
40 | | const SdrPageView& rSdrPageView, |
41 | | const SdrLayerIDSet* pVisiLayer, |
42 | | bool bTextOnly, |
43 | | drawinglayer::primitive2d::Primitive2DContainer* pHitContainer) |
44 | 0 | { |
45 | 0 | SdrObject* pResult = nullptr; |
46 | |
|
47 | 0 | if(rObject.GetSubList() && rObject.GetSubList()->GetObjCount()) |
48 | 0 | { |
49 | | // group or scene with content. Single 3D objects also have a |
50 | | // true == rObject.GetSubList(), but no content |
51 | 0 | pResult = SdrObjListPrimitiveHit(*rObject.GetSubList(), rPnt, rHitTolerance, rSdrPageView, pVisiLayer, bTextOnly); |
52 | 0 | } |
53 | 0 | else |
54 | 0 | { |
55 | 0 | if( rObject.IsVisible() && (!pVisiLayer || pVisiLayer->IsSet(rObject.GetLayer()))) |
56 | 0 | { |
57 | | // single object, 3d object, empty scene or empty group. Check if |
58 | | // it's a single 3D object |
59 | 0 | const E3dCompoundObject* pE3dCompoundObject = dynamic_cast< const E3dCompoundObject* >(&rObject); |
60 | |
|
61 | 0 | if(pE3dCompoundObject) |
62 | 0 | { |
63 | 0 | const basegfx::B2DPoint aHitPosition(rPnt.X(), rPnt.Y()); |
64 | |
|
65 | 0 | if(checkHitSingle3DObject(aHitPosition, *pE3dCompoundObject)) |
66 | 0 | { |
67 | 0 | pResult = const_cast< E3dCompoundObject* >(pE3dCompoundObject); |
68 | 0 | } |
69 | 0 | } |
70 | 0 | else |
71 | 0 | { |
72 | | // not a single 3D object; Check in first PageWindow using primitives (only SC |
73 | | // with split views uses multiple PageWindows nowadays) |
74 | 0 | if(rSdrPageView.PageWindowCount()) |
75 | 0 | { |
76 | 0 | const basegfx::B2DPoint aHitPosition(rPnt.X(), rPnt.Y()); |
77 | 0 | const sdr::contact::ViewObjectContact& rVOC = rObject.GetViewContact().GetViewObjectContact( |
78 | 0 | rSdrPageView.GetPageWindow(0)->GetObjectContact()); |
79 | |
|
80 | 0 | if(ViewObjectContactPrimitiveHit(rVOC, aHitPosition, rHitTolerance, bTextOnly, pHitContainer)) |
81 | 0 | { |
82 | 0 | pResult = const_cast< SdrObject* >(&rObject); |
83 | 0 | } |
84 | 0 | } |
85 | 0 | } |
86 | 0 | } |
87 | 0 | } |
88 | |
|
89 | 0 | return pResult; |
90 | 0 | } |
91 | | |
92 | | |
93 | | SdrObject* SdrObjListPrimitiveHit( |
94 | | const SdrObjList& rList, |
95 | | const Point& rPnt, |
96 | | const basegfx::B2DVector& rHitTolerance, |
97 | | const SdrPageView& rSdrPageView, |
98 | | const SdrLayerIDSet* pVisiLayer, |
99 | | bool bTextOnly) |
100 | 0 | { |
101 | 0 | size_t nObjNum(rList.GetObjCount()); |
102 | 0 | SdrObject* pRetval = nullptr; |
103 | |
|
104 | 0 | while(!pRetval && nObjNum > 0) |
105 | 0 | { |
106 | 0 | nObjNum--; |
107 | 0 | SdrObject* pObj = rList.GetObj(nObjNum); |
108 | |
|
109 | 0 | pRetval = SdrObjectPrimitiveHit(*pObj, rPnt, rHitTolerance, rSdrPageView, pVisiLayer, bTextOnly); |
110 | 0 | } |
111 | |
|
112 | 0 | return pRetval; |
113 | 0 | } |
114 | | |
115 | | |
116 | | bool ViewObjectContactPrimitiveHit( |
117 | | const sdr::contact::ViewObjectContact& rVOC, |
118 | | const basegfx::B2DPoint& rHitPosition, |
119 | | const basegfx::B2DVector& rLogicHitTolerance, |
120 | | bool bTextOnly, |
121 | | drawinglayer::primitive2d::Primitive2DContainer* pHitContainer) |
122 | 0 | { |
123 | | // Only use the range if we already have it, computing the range can be more expensive |
124 | | // than running the HitTestProcessor. |
125 | 0 | if (rVOC.hasCachedObjectRange()) |
126 | 0 | { |
127 | 0 | basegfx::B2DRange aObjectRange(rVOC.getObjectRange()); |
128 | |
|
129 | 0 | if(aObjectRange.isEmpty()) |
130 | 0 | return false; |
131 | | |
132 | | // first do a rough B2DRange based HitTest; do not forget to |
133 | | // include the HitTolerance if given |
134 | 0 | if(rLogicHitTolerance.getX() > 0 || rLogicHitTolerance.getY() > 0) |
135 | 0 | { |
136 | 0 | aObjectRange.grow(rLogicHitTolerance); |
137 | 0 | } |
138 | |
|
139 | 0 | if(!aObjectRange.isInside(rHitPosition)) |
140 | 0 | return false; |
141 | 0 | } |
142 | | |
143 | | // get primitive sequence |
144 | 0 | sdr::contact::DisplayInfo aDisplayInfo; |
145 | | // have to make a copy of this container here, because it might be changed underneath us |
146 | 0 | const drawinglayer::primitive2d::Primitive2DContainer aSequence(rVOC.getPrimitive2DSequence(aDisplayInfo)); |
147 | |
|
148 | 0 | if(!aSequence.empty()) |
149 | 0 | { |
150 | | // create a HitTest processor |
151 | 0 | const drawinglayer::geometry::ViewInformation2D& rViewInformation2D = rVOC.GetObjectContact().getViewInformation2D(); |
152 | 0 | drawinglayer::processor2d::HitTestProcessor2D aHitTestProcessor2D( |
153 | 0 | rViewInformation2D, |
154 | 0 | rHitPosition, |
155 | 0 | rLogicHitTolerance, |
156 | 0 | bTextOnly); |
157 | | |
158 | | // ask for HitStack |
159 | 0 | aHitTestProcessor2D.collectHitStack(pHitContainer != nullptr); |
160 | | |
161 | | // feed it with the primitives |
162 | 0 | aHitTestProcessor2D.process(aSequence); |
163 | | |
164 | | // deliver result |
165 | 0 | if (aHitTestProcessor2D.getHit()) |
166 | 0 | { |
167 | 0 | if (pHitContainer) |
168 | 0 | { |
169 | | // fetch HitStack primitives if requested |
170 | 0 | *pHitContainer = aHitTestProcessor2D.getHitStack(); |
171 | 0 | } |
172 | |
|
173 | 0 | return true; |
174 | 0 | } |
175 | 0 | } |
176 | | |
177 | 0 | return false; |
178 | 0 | } |
179 | | |
180 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |