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