LibreOffice Module svx (master)  1
overlayobject.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 
26 #include <osl/diagnose.h>
27 
28 namespace sdr::overlay
29 {
31  {
32  const basegfx::B2DRange aPreviousRange(maBaseRange);
35 // setPrimitive2DSequence(drawinglayer::primitive2d::Primitive2DContainer());
36 
37  if(getOverlayManager() && !aPreviousRange.isEmpty())
38  {
39  getOverlayManager()->invalidateRange(aPreviousRange);
40  }
41 
42  const basegfx::B2DRange& rCurrentRange = getBaseRange();
43 
44  if(getOverlayManager() && rCurrentRange != aPreviousRange && !rCurrentRange.isEmpty())
45  {
46  getOverlayManager()->invalidateRange(rCurrentRange);
47  }
48  }
49 
50  // OverlayObject implementations.
52  {
53  // Default implementation has to assert a missing implementation. It cannot
54  // be useful to have overlay object derivations which have no visualisation
55  // at all
56  OSL_FAIL("OverlayObject derivation without visualisation definition (missing createOverlayObjectPrimitive2DSequence implementation) (!)");
58  }
59 
60  sal_uInt32 OverlayObject::impCheckBlinkTimeValueRange(sal_uInt64 nBlinkTime)
61  {
62  if(nBlinkTime < 25)
63  {
64  nBlinkTime = 25;
65  }
66  else if(nBlinkTime > 10000)
67  {
68  nBlinkTime = 10000;
69  }
70 
71  return nBlinkTime;
72  }
73 
75  {
76  if(bNew != mbAllowsAntiAliase)
77  {
78  // remember new value
79  mbAllowsAntiAliase = bNew;
80 
81  // register change (after change)
82  objectChange();
83  }
84  }
85 
87  : mpOverlayManager(nullptr),
88  maOffset(0.0, 0.0),
89  maBaseColor(aBaseColor),
90  mbIsVisible(true),
91  mbIsHittable(true),
92  mbAllowsAnimation(false),
93  mbAllowsAntiAliase(true)
94  {
95  }
96 
98  {
99  OSL_ENSURE(nullptr == getOverlayManager(), "OverlayObject is destructed which is still registered at OverlayManager (!)");
100  }
101 
103  {
104  if(getPrimitive2DSequence().empty())
105  {
106  // no existing sequence; create one
107  const_cast< OverlayObject* >(this)->maPrimitive2DSequence = const_cast< OverlayObject* >(this)->createOverlayObjectPrimitive2DSequence();
108 
109  if(!getOffset().equalZero())
110  {
111  // embed to offset transformation
112  const basegfx::B2DHomMatrix aTranslateGridOffset(
114  getOffset()));
117  aTranslateGridOffset,
118  std::move(const_cast<drawinglayer::primitive2d::Primitive2DContainer&>(maPrimitive2DSequence))));
119 
121  }
122  }
123 
124  return getPrimitive2DSequence();
125  }
126 
128  {
130  {
132 
133  if(!rSequence.empty())
134  {
135  const drawinglayer::geometry::ViewInformation2D & aViewInformation2D(getOverlayManager()->getCurrentViewInformation2D());
136 
137  const_cast< sdr::overlay::OverlayObject* >(this)->maBaseRange =
138  rSequence.getB2DRange(aViewInformation2D);
139  }
140  }
141 
142  return maBaseRange;
143  }
144 
146  {
147  if(bNew != mbIsVisible)
148  {
149  // remember new value
150  mbIsVisible = bNew;
151 
152  // register change (after change)
153  objectChange();
154  }
155  }
156 
158  {
159  if(bNew != mbIsHittable)
160  {
161  // remember new value
162  mbIsHittable = bNew;
163 
164  // register change (after change)
165  objectChange();
166  }
167  }
168 
170  {
171  if(aNew != maBaseColor)
172  {
173  // remember new value
174  maBaseColor = aNew;
175 
176  // register change (after change)
177  objectChange();
178  }
179  }
180 
182  {
183  if(rOffset != maOffset)
184  {
185  // remember new value
186  maOffset = rOffset;
187 
188  // register change (after change)
189  objectChange();
190  }
191  }
192 
193  void OverlayObject::Trigger(sal_uInt32 /*nTime*/)
194  {
195  // default does not register again
196  }
197 
199  {
200  // default does not need to do anything
201  }
202 
203 
205  : OverlayObject(aBaseColor),
206  maBasePosition(rBasePos)
207  {
208  }
209 
211  {
212  }
213 
215  {
216  if(rNew != maBasePosition)
217  {
218  // remember new value
219  maBasePosition = rNew;
220 
221  // register change (after change)
222  objectChange();
223  }
224  }
225 
226 } // end of namespace
227 
228 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void setOffset(const basegfx::B2DVector &rOffset)
const drawinglayer::primitive2d::Primitive2DContainer & getPrimitive2DSequence() const
bool equalZero(const T &rfVal)
virtual void stripeDefinitionHasChanged()
OverlayManager * getOverlayManager() const
const basegfx::B2DRange & getBaseRange() const
virtual ~OverlayObject() override
OverlayObject(const OverlayObject &)=delete
static sal_uInt32 impCheckBlinkTimeValueRange(sal_uInt64 nBlinkTime)
OverlayObjectWithBasePosition(const basegfx::B2DPoint &rBasePos, Color aBaseColor)
basegfx::B2DRange maBaseRange
virtual drawinglayer::primitive2d::Primitive2DContainer getOverlayObjectPrimitive2DSequence() const
void allowAntiAliase(bool bNew)
virtual drawinglayer::primitive2d::Primitive2DContainer createOverlayObjectPrimitive2DSequence()
virtual void Trigger(sal_uInt32 nTime) override
drawinglayer::primitive2d::Primitive2DContainer maPrimitive2DSequence
void setBasePosition(const basegfx::B2DPoint &rNew)
const basegfx::B2DVector & getOffset() const
basegfx::B2DVector maOffset
basegfx::B2DRange getB2DRange(const geometry::ViewInformation2D &aViewInformation) const
B2DHomMatrix createTranslateB2DHomMatrix(double fTranslateX, double fTranslateY)
basegfx::B2DPoint maBasePosition
virtual void invalidateRange(const basegfx::B2DRange &rRange)
bool m_bDetectedRangeSegmentation false