Line data Source code
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/sdrpagewindow.hxx>
25 : #include <svx/sdr/contact/viewobjectcontact.hxx>
26 : #include <svx/sdr/contact/displayinfo.hxx>
27 : #include <svx/sdr/contact/objectcontact.hxx>
28 : #include <drawinglayer/processor2d/hittestprocessor2d.hxx>
29 : #include <svx/svdpagv.hxx>
30 : #include <svx/sdr/contact/viewcontact.hxx>
31 : #include <svx/svdmodel.hxx>
32 :
33 :
34 : // #i101872# new Object HitTest as View-tooling
35 :
36 119 : SdrObject* SdrObjectPrimitiveHit(
37 : const SdrObject& rObject,
38 : const Point& rPnt,
39 : sal_uInt16 nTol,
40 : const SdrPageView& rSdrPageView,
41 : const SetOfByte* pVisiLayer,
42 : bool bTextOnly)
43 : {
44 119 : SdrObject* pResult = 0;
45 :
46 119 : if(rObject.GetSubList() && rObject.GetSubList()->GetObjCount())
47 : {
48 : // group or scene with content. Single 3D objects also have a
49 : // true == rObject.GetSubList(), but no content
50 0 : pResult = SdrObjListPrimitiveHit(*rObject.GetSubList(), rPnt, nTol, rSdrPageView, pVisiLayer, bTextOnly);
51 : }
52 : else
53 : {
54 119 : if( rObject.IsVisible() && (!pVisiLayer || pVisiLayer->IsSet(rObject.GetLayer())))
55 : {
56 : // single object, 3d object, empty scene or empty group. Check if
57 : // it's a single 3D object
58 119 : const E3dCompoundObject* pE3dCompoundObject = dynamic_cast< const E3dCompoundObject* >(&rObject);
59 :
60 119 : if(pE3dCompoundObject)
61 : {
62 0 : const basegfx::B2DPoint aHitPosition(rPnt.X(), rPnt.Y());
63 :
64 0 : if(checkHitSingle3DObject(aHitPosition, *pE3dCompoundObject))
65 : {
66 0 : pResult = const_cast< E3dCompoundObject* >(pE3dCompoundObject);
67 0 : }
68 : }
69 : else
70 : {
71 : // not a single 3D object; Check in first PageWindow using prmitives (only SC
72 : // with split views uses multiple PageWindows nowadays)
73 119 : if(rSdrPageView.PageWindowCount())
74 : {
75 119 : const double fLogicTolerance(nTol);
76 119 : const basegfx::B2DPoint aHitPosition(rPnt.X(), rPnt.Y());
77 119 : const sdr::contact::ViewObjectContact& rVOC = rObject.GetViewContact().GetViewObjectContact(
78 238 : rSdrPageView.GetPageWindow(0)->GetObjectContact());
79 :
80 119 : if(ViewObjectContactPrimitiveHit(rObject, rVOC, aHitPosition, fLogicTolerance, bTextOnly))
81 : {
82 38 : pResult = const_cast< SdrObject* >(&rObject);
83 119 : }
84 : }
85 : }
86 : }
87 : }
88 :
89 119 : return pResult;
90 : }
91 :
92 :
93 :
94 0 : SdrObject* SdrObjListPrimitiveHit(
95 : const SdrObjList& rList,
96 : const Point& rPnt,
97 : sal_uInt16 nTol,
98 : const SdrPageView& rSdrPageView,
99 : const SetOfByte* pVisiLayer,
100 : bool bTextOnly)
101 : {
102 0 : size_t nObjNum(rList.GetObjCount());
103 0 : SdrObject* pRetval = 0;
104 :
105 0 : while(!pRetval && nObjNum > 0)
106 : {
107 0 : nObjNum--;
108 0 : SdrObject* pObj = rList.GetObj(nObjNum);
109 :
110 0 : pRetval = SdrObjectPrimitiveHit(*pObj, rPnt, nTol, rSdrPageView, pVisiLayer, bTextOnly);
111 : }
112 :
113 0 : return pRetval;
114 : }
115 :
116 :
117 :
118 119 : bool ViewObjectContactPrimitiveHit(
119 : const SdrObject& rObject,
120 : const sdr::contact::ViewObjectContact& rVOC,
121 : const basegfx::B2DPoint& rHitPosition,
122 : double fLogicHitTolerance,
123 : bool bTextOnly)
124 : {
125 119 : basegfx::B2DRange aObjectRange(rVOC.getObjectRange());
126 :
127 119 : if(!aObjectRange.isEmpty())
128 : {
129 : // first do a rough B2DRange based HitTest; do not forget to
130 : // include the HitTolerance if given
131 73 : if(basegfx::fTools::more(fLogicHitTolerance, 0.0))
132 : {
133 37 : aObjectRange.grow(fLogicHitTolerance);
134 : }
135 :
136 73 : if(aObjectRange.isInside(rHitPosition))
137 : {
138 : // get primitive sequence
139 71 : sdr::contact::DisplayInfo aDisplayInfo;
140 71 : const drawinglayer::primitive2d::Primitive2DSequence& rSequence(rVOC.getPrimitive2DSequence(aDisplayInfo));
141 :
142 71 : if(rSequence.hasElements())
143 : {
144 : // create a HitTest processor
145 71 : const drawinglayer::geometry::ViewInformation2D& rViewInformation2D = rVOC.GetObjectContact().getViewInformation2D();
146 : drawinglayer::processor2d::HitTestProcessor2D aHitTestProcessor2D(
147 : rViewInformation2D,
148 : rHitPosition,
149 : fLogicHitTolerance,
150 : bTextOnly,
151 71 : rObject.GetModel()->isTiledRendering());
152 :
153 : // feed it with the primitives
154 71 : aHitTestProcessor2D.process(rSequence);
155 :
156 : // deliver result
157 71 : return aHitTestProcessor2D.getHit();
158 0 : }
159 : }
160 : }
161 :
162 48 : return false;
163 435 : }
164 :
165 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|