1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <svx/sdr/overlay/overlaymanager.hxx>
#include <basegfx/point/b2dpoint.hxx>
#include <basegfx/range/b2drange.hxx>
#include <tools/gen.hxx>
#include <vcl/outdev.hxx>
#include <vcl/window.hxx>
#include <svx/sdr/overlay/overlayobject.hxx>
#include <basegfx/matrix/b2dhommatrix.hxx>
#include <drawinglayer/processor2d/processor2dtools.hxx>
#include <memory>
using namespace com::sun::star;
namespace sdr
{
namespace overlay
{
void OverlayManager::ImpDrawMembers(const basegfx::B2DRange& rRange, OutputDevice& rDestinationDevice) const
{
const sal_uInt32 nSize(maOverlayObjects.size());
if(nSize)
{
const AntialiasingFlags nOriginalAA(rDestinationDevice.GetAntialiasing());
const bool bIsAntiAliasing(getDrawinglayerOpt().IsAntiAliasing());
// create processor
std::unique_ptr<drawinglayer::processor2d::BaseProcessor2D> pProcessor(drawinglayer::processor2d::createProcessor2DFromOutputDevice(
rDestinationDevice,
getCurrentViewInformation2D()));
if(pProcessor)
{
for(OverlayObjectVector::const_iterator aIter(maOverlayObjects.begin()); aIter != maOverlayObjects.end(); ++aIter)
{
OSL_ENSURE(*aIter, "Corrupted OverlayObject List (!)");
const OverlayObject& rCandidate = **aIter;
if(rCandidate.isVisible())
{
const drawinglayer::primitive2d::Primitive2DContainer& rSequence = rCandidate.getOverlayObjectPrimitive2DSequence();
if(!rSequence.empty())
{
if(rRange.overlaps(rCandidate.getBaseRange()))
{
if(bIsAntiAliasing && rCandidate.allowsAntiAliase())
{
rDestinationDevice.SetAntialiasing(nOriginalAA | AntialiasingFlags::EnableB2dDraw);
}
else
{
rDestinationDevice.SetAntialiasing(nOriginalAA & ~AntialiasingFlags::EnableB2dDraw);
}
pProcessor->process(rSequence);
}
}
}
}
pProcessor.reset();
}
// restore AA settings
rDestinationDevice.SetAntialiasing(nOriginalAA);
}
}
void OverlayManager::ImpStripeDefinitionChanged()
{
const sal_uInt32 nSize(maOverlayObjects.size());
if(nSize)
{
OverlayObjectVector::const_iterator aEnd(maOverlayObjects.end());
for(OverlayObjectVector::iterator aIter(maOverlayObjects.begin()); aIter != aEnd; ++aIter)
{
OSL_ENSURE(*aIter, "Corrupted OverlayObject List (!)");
OverlayObject& rCandidate = **aIter;
rCandidate.stripeDefinitionHasChanged();
}
}
}
double OverlayManager::getDiscreteOne() const
{
if(basegfx::fTools::equalZero(mfDiscreteOne))
{
const basegfx::B2DVector aDiscreteInLogic(getOutputDevice().GetInverseViewTransformation() * basegfx::B2DVector(1.0, 0.0));
const_cast< OverlayManager* >(this)->mfDiscreteOne = aDiscreteInLogic.getLength();
}
return mfDiscreteOne;
}
OverlayManager::OverlayManager(OutputDevice& rOutputDevice)
: Scheduler(),
mrOutputDevice(rOutputDevice),
maOverlayObjects(),
maStripeColorA(Color(COL_BLACK)),
maStripeColorB(Color(COL_WHITE)),
mnStripeLengthPixel(5),
maDrawinglayerOpt(),
maViewTransformation(),
maViewInformation2D(),
mfDiscreteOne(0.0)
{
// set Property 'ReducedDisplayQuality' to true to allow simpler interaction
// visualisations
static bool bUseReducedDisplayQualityForDrag(true);
if(bUseReducedDisplayQualityForDrag)
{
uno::Sequence< beans::PropertyValue > xProperties(1);
xProperties[0].Name = "ReducedDisplayQuality";
xProperties[0].Value <<= true;
maViewInformation2D = drawinglayer::geometry::ViewInformation2D(xProperties);
}
}
rtl::Reference<OverlayManager> OverlayManager::create(OutputDevice& rOutputDevice)
{
return rtl::Reference<OverlayManager>(new OverlayManager(rOutputDevice));
}
const drawinglayer::geometry::ViewInformation2D OverlayManager::getCurrentViewInformation2D() const
{
if(getOutputDevice().GetViewTransformation() != maViewTransformation)
{
basegfx::B2DRange aViewRange(maViewInformation2D.getViewport());
if(OUTDEV_WINDOW == getOutputDevice().GetOutDevType())
{
const Size aOutputSizePixel(getOutputDevice().GetOutputSizePixel());
// only set when we *have* a output size, else let aViewRange
// stay on empty
if(aOutputSizePixel.Width() && aOutputSizePixel.Height())
{
aViewRange = basegfx::B2DRange(0.0, 0.0, aOutputSizePixel.getWidth(), aOutputSizePixel.getHeight());
aViewRange.transform(getOutputDevice().GetInverseViewTransformation());
}
}
OverlayManager* pThis = const_cast< OverlayManager* >(this);
pThis->maViewTransformation = getOutputDevice().GetViewTransformation();
pThis->maViewInformation2D = drawinglayer::geometry::ViewInformation2D(
maViewInformation2D.getObjectTransformation(),
maViewTransformation,
aViewRange,
maViewInformation2D.getVisualizedPage(),
maViewInformation2D.getViewTime(),
maViewInformation2D.getExtendedInformationSequence());
pThis->mfDiscreteOne = 0.0;
}
return maViewInformation2D;
}
void OverlayManager::impApplyRemoveActions(OverlayObject& rTarget)
{
// handle evtl. animation
if(rTarget.allowsAnimation())
{
// remove from event chain
RemoveEvent(&rTarget);
}
// make invisible
invalidateRange(rTarget.getBaseRange());
// clear manager
rTarget.mpOverlayManager = nullptr;
}
void OverlayManager::impApplyAddActions(OverlayObject& rTarget)
{
// set manager
rTarget.mpOverlayManager = this;
// make visible
invalidateRange(rTarget.getBaseRange());
// handle evtl. animation
if(rTarget.allowsAnimation())
{
// Trigger at current time to get alive. This will do the
// object-specific next time calculation and hand over adding
// again to the scheduler to the animated object, too. This works for
// a paused or non-paused animator.
rTarget.Trigger(GetTime());
}
}
OverlayManager::~OverlayManager()
{
// The OverlayManager is not the owner of the OverlayObjects
// and thus will not delete them, but remove them. Profit here
// from knowing that all will be removed
const sal_uInt32 nSize(maOverlayObjects.size());
if(nSize)
{
OverlayObjectVector::const_iterator aEnd = maOverlayObjects.end();
for(OverlayObjectVector::iterator aIter(maOverlayObjects.begin()); aIter != aEnd; ++aIter)
{
OSL_ENSURE(*aIter, "Corrupted OverlayObject List (!)");
OverlayObject& rCandidate = **aIter;
impApplyRemoveActions(rCandidate);
}
// erase vector
maOverlayObjects.clear();
}
}
void OverlayManager::completeRedraw(const vcl::Region& rRegion, OutputDevice* pPreRenderDevice) const
{
if(!rRegion.IsEmpty() && maOverlayObjects.size())
{
// check for changed MapModes. That may influence the
// logical size of pixel based OverlayObjects (like BitmapHandles)
//ImpCheckMapModeChange();
// paint members
const Rectangle aRegionBoundRect(rRegion.GetBoundRect());
const basegfx::B2DRange aRegionRange(
aRegionBoundRect.Left(), aRegionBoundRect.Top(),
aRegionBoundRect.Right(), aRegionBoundRect.Bottom());
OutputDevice& rTarget = (pPreRenderDevice) ? *pPreRenderDevice : getOutputDevice();
ImpDrawMembers(aRegionRange, rTarget);
}
}
void OverlayManager::flush()
{
// default has nothing to do
}
void OverlayManager::restoreBackground(const vcl::Region& /*rRegion*/) const
{
// unbuffered versions do nothing here
}
void OverlayManager::add(OverlayObject& rOverlayObject)
{
OSL_ENSURE(nullptr == rOverlayObject.mpOverlayManager, "OverlayObject is added twice to an OverlayManager (!)");
// add to the end of chain to preserve display order in paint
maOverlayObjects.push_back(&rOverlayObject);
// execute add actions
impApplyAddActions(rOverlayObject);
}
void OverlayManager::remove(OverlayObject& rOverlayObject)
{
OSL_ENSURE(rOverlayObject.mpOverlayManager == this, "OverlayObject is removed from wrong OverlayManager (!)");
// execute remove actions
impApplyRemoveActions(rOverlayObject);
// remove from vector
const OverlayObjectVector::iterator aFindResult = ::std::find(maOverlayObjects.begin(), maOverlayObjects.end(), &rOverlayObject);
const bool bFound(aFindResult != maOverlayObjects.end());
OSL_ENSURE(bFound, "OverlayObject NOT found at OverlayManager (!)");
if(bFound)
{
maOverlayObjects.erase(aFindResult);
}
}
void OverlayManager::invalidateRange(const basegfx::B2DRange& rRange)
{
if(OUTDEV_WINDOW == getOutputDevice().GetOutDevType())
{
if(getDrawinglayerOpt().IsAntiAliasing())
{
// assume AA needs one pixel more and invalidate one pixel more
const double fDiscreteOne(getDiscreteOne());
const Rectangle aInvalidateRectangle(
(sal_Int32)floor(rRange.getMinX() - fDiscreteOne),
(sal_Int32)floor(rRange.getMinY() - fDiscreteOne),
(sal_Int32)ceil(rRange.getMaxX() + fDiscreteOne),
(sal_Int32)ceil(rRange.getMaxY() + fDiscreteOne));
// simply invalidate
static_cast<vcl::Window&>(getOutputDevice()).Invalidate(aInvalidateRectangle, InvalidateFlags::NoErase);
}
else
{
// #i77674# transform to rectangle. Use floor/ceil to get all covered
// discrete pixels, see #i75163# and OverlayManagerBuffered::invalidateRange
const Rectangle aInvalidateRectangle(
(sal_Int32)floor(rRange.getMinX()), (sal_Int32)floor(rRange.getMinY()),
(sal_Int32)ceil(rRange.getMaxX()), (sal_Int32)ceil(rRange.getMaxY()));
// simply invalidate
static_cast<vcl::Window&>(getOutputDevice()).Invalidate(aInvalidateRectangle, InvalidateFlags::NoErase);
}
}
}
// stripe support ColA
void OverlayManager::setStripeColorA(Color aNew)
{
if(aNew != maStripeColorA)
{
maStripeColorA = aNew;
ImpStripeDefinitionChanged();
}
}
// stripe support ColB
void OverlayManager::setStripeColorB(Color aNew)
{
if(aNew != maStripeColorB)
{
maStripeColorB = aNew;
ImpStripeDefinitionChanged();
}
}
// stripe support StripeLengthPixel
void OverlayManager::setStripeLengthPixel(sal_uInt32 nNew)
{
if(nNew != mnStripeLengthPixel)
{
mnStripeLengthPixel = nNew;
ImpStripeDefinitionChanged();
}
}
} // end of namespace overlay
} // end of namespace sdr
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|