LibreOffice Module svx (master)  1
overlayobjectlist.cxx
Go to the documentation of this file.
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 
22 #include <svx/svdmodel.hxx>
23 #include <vcl/outdev.hxx>
25 #include <tools/gen.hxx>
26 
28 #include <comphelper/lok.hxx>
29 
30 #define DEFAULT_VALUE_FOR_HITTEST_PIXEL (2)
31 #define DEFAULT_VALUE_FOR_HITTEST_TWIP (30)
32 
33 namespace sdr::overlay
34  {
36  {
37  clear();
38  }
39 
41  {
42  for(auto & pCandidate : maVector)
43  {
44  if(pCandidate->getOverlayManager())
45  pCandidate->getOverlayManager()->remove(*pCandidate);
46  }
47  maVector.clear();
48  }
49 
50  void OverlayObjectList::append(std::unique_ptr<OverlayObject> pOverlayObject)
51  {
52  assert(pOverlayObject && "tried to add invalid OverlayObject to OverlayObjectList");
53  maVector.push_back(std::move(pOverlayObject));
54  }
55 
56  bool OverlayObjectList::isHitLogic(const basegfx::B2DPoint& rLogicPosition, double fLogicTolerance) const
57  {
58  if(!maVector.empty())
59  {
60  OverlayObject* pFirst = maVector.front().get();
61  OverlayManager* pManager = pFirst->getOverlayManager();
62 
63  if(pManager)
64  {
65  if(0.0 == fLogicTolerance)
66  {
67  Size aSizeLogic(pManager->getOutputDevice().PixelToLogic(
69 
70  // When tiled rendering, we always work in logic units, use the non-pixel default.
72  {
74  if (pManager->getOutputDevice().GetMapMode().GetMapUnit() == MapUnit::Map100thMM)
75  aSizeLogic = OutputDevice::LogicToLogic(aSizeLogic, MapMode(MapUnit::MapTwip), MapMode(MapUnit::Map100thMM));
76  }
77 
78  fLogicTolerance = aSizeLogic.Width();
79  }
80 
81  const drawinglayer::geometry::ViewInformation2D& aViewInformation2D(pManager->getCurrentViewInformation2D());
83  aViewInformation2D,
84  rLogicPosition,
85  fLogicTolerance,
86  false);
87 
88  for(auto & pCandidate : maVector)
89  {
90  if(pCandidate->isHittable())
91  {
92  const drawinglayer::primitive2d::Primitive2DContainer& rSequence = pCandidate->getOverlayObjectPrimitive2DSequence();
93 
94  if(!rSequence.empty())
95  {
96  aHitTestProcessor2D.process(rSequence);
97 
98  if(aHitTestProcessor2D.getHit())
99  {
100  return true;
101  }
102  }
103  }
104  }
105  }
106  }
107 
108  return false;
109  }
110 
111  bool OverlayObjectList::isHitPixel(const Point& rDiscretePosition) const
112  {
113  sal_uInt32 nDiscreteTolerance = DEFAULT_VALUE_FOR_HITTEST_PIXEL;
114  if(!maVector.empty())
115  {
116  OverlayObject* pCandidate = maVector.front().get();
117  OverlayManager* pManager = pCandidate->getOverlayManager();
118 
119  if(pManager)
120  {
121  const Point aPosLogic(pManager->getOutputDevice().PixelToLogic(rDiscretePosition));
122  const basegfx::B2DPoint aPosition(aPosLogic.X(), aPosLogic.Y());
123 
124  const Size aSizeLogic(pManager->getOutputDevice().PixelToLogic(Size(nDiscreteTolerance, nDiscreteTolerance)));
125  return isHitLogic(aPosition, static_cast<double>(aSizeLogic.Width()));
126  }
127  }
128 
129  return false;
130  }
131 
133  {
134  basegfx::B2DRange aRetval;
135 
136  for(auto & pCandidate : maVector)
137  {
138  aRetval.expand(pCandidate->getBaseRange());
139  }
140 
141  return aRetval;
142  }
143  } // end of namespace sdr
144 
145 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void expand(const B2DTuple &rTuple)
Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
bool isHitPixel(const Point &rDiscretePosition) const
const MapMode & GetMapMode() const
void append(std::unique_ptr< OverlayObject > pOverlayObject)
#define DEFAULT_VALUE_FOR_HITTEST_PIXEL
#define DEFAULT_VALUE_FOR_HITTEST_TWIP
OverlayManager * getOverlayManager() const
::std::vector< std::unique_ptr< OverlayObject > > maVector
MapUnit GetMapUnit() const
drawinglayer::geometry::ViewInformation2D const & getCurrentViewInformation2D() const
Point PixelToLogic(const Point &rDevicePt) const
OutputDevice & getOutputDevice() const
basegfx::B2DRange getBaseRange() const
bool isHitLogic(const basegfx::B2DPoint &rLogicPosition, double fLogicTolerance=0.0) const