1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_svx.hxx" 26 #include <svx/sdr/overlay/overlayobject.hxx> 27 #include <svx/sdr/overlay/overlaymanager.hxx> 28 #include <tools/debug.hxx> 29 #include <basegfx/matrix/b2dhommatrix.hxx> 30 #include <basegfx/vector/b2dvector.hxx> 31 #include <vcl/outdev.hxx> 32 #include <vcl/salbtype.hxx> 33 #include <basegfx/polygon/b2dpolygon.hxx> 34 #include <basegfx/polygon/b2dpolypolygon.hxx> 35 #include <basegfx/polygon/b2dpolygontools.hxx> 36 #include <basegfx/polygon/b2dpolypolygontools.hxx> 37 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx> 38 39 ////////////////////////////////////////////////////////////////////////////// 40 41 namespace sdr 42 { 43 namespace overlay 44 { objectChange()45 void OverlayObject::objectChange() 46 { 47 const basegfx::B2DRange aPreviousRange(maBaseRange); 48 maBaseRange.reset(); 49 setPrimitive2DSequence(drawinglayer::primitive2d::Primitive2DSequence()); 50 51 if(getOverlayManager() && !aPreviousRange.isEmpty()) 52 { 53 getOverlayManager()->invalidateRange(aPreviousRange); 54 } 55 56 const basegfx::B2DRange& rCurrentRange = getBaseRange(); 57 58 if(getOverlayManager() && rCurrentRange != aPreviousRange && !rCurrentRange.isEmpty()) 59 { 60 getOverlayManager()->invalidateRange(rCurrentRange); 61 } 62 } 63 64 // OverlayObject implementations. createOverlayObjectPrimitive2DSequence()65 drawinglayer::primitive2d::Primitive2DSequence OverlayObject::createOverlayObjectPrimitive2DSequence() 66 { 67 // Default implementation has to assert a missing implementation. It cannot 68 // be useful to have overlay object derivations which have no visualisation 69 // at all 70 OSL_ENSURE(false, "OverlayObject derivation without visualisation definition (missing createOverlayObjectPrimitive2DSequence implementation) (!)"); 71 return drawinglayer::primitive2d::Primitive2DSequence(); 72 } 73 impCheckBlinkTimeValueRange(sal_uInt32 nBlinkTime) const74 sal_uInt32 OverlayObject::impCheckBlinkTimeValueRange(sal_uInt32 nBlinkTime) const 75 { 76 if(nBlinkTime < 25) 77 { 78 nBlinkTime = 25; 79 } 80 else if(nBlinkTime > 10000) 81 { 82 nBlinkTime = 10000; 83 } 84 85 return nBlinkTime; 86 } 87 allowAntiAliase(bool bNew)88 void OverlayObject::allowAntiAliase(bool bNew) 89 { 90 if(bNew != (bool)mbAllowsAntiAliase) 91 { 92 // remember new value 93 mbAllowsAntiAliase = bNew; 94 95 // register change (after change) 96 objectChange(); 97 } 98 } 99 OverlayObject(Color aBaseColor)100 OverlayObject::OverlayObject(Color aBaseColor) 101 : Event(0), 102 mpOverlayManager(0), 103 maBaseColor(aBaseColor), 104 mbIsVisible(true), 105 mbIsHittable(true), 106 mbAllowsAnimation(false), 107 mbAllowsAntiAliase(true) 108 { 109 } 110 ~OverlayObject()111 OverlayObject::~OverlayObject() 112 { 113 OSL_ENSURE(0 == getOverlayManager(), "OverlayObject is destructed which is still registered at OverlayManager (!)"); 114 } 115 getOverlayObjectPrimitive2DSequence() const116 drawinglayer::primitive2d::Primitive2DSequence OverlayObject::getOverlayObjectPrimitive2DSequence() const 117 { 118 if(!getPrimitive2DSequence().hasElements()) 119 { 120 // no existing sequence; create one 121 const_cast< OverlayObject* >(this)->setPrimitive2DSequence( 122 const_cast< OverlayObject* >(this)->createOverlayObjectPrimitive2DSequence()); 123 } 124 125 return getPrimitive2DSequence(); 126 } 127 getBaseRange() const128 const basegfx::B2DRange& OverlayObject::getBaseRange() const 129 { 130 if(getOverlayManager() && maBaseRange.isEmpty()) 131 { 132 const drawinglayer::primitive2d::Primitive2DSequence& rSequence = getOverlayObjectPrimitive2DSequence(); 133 134 if(rSequence.hasElements()) 135 { 136 const drawinglayer::geometry::ViewInformation2D aViewInformation2D(getOverlayManager()->getCurrentViewInformation2D()); 137 138 const_cast< sdr::overlay::OverlayObject* >(this)->maBaseRange = 139 drawinglayer::primitive2d::getB2DRangeFromPrimitive2DSequence(rSequence, aViewInformation2D); 140 } 141 } 142 143 return maBaseRange; 144 } 145 setVisible(bool bNew)146 void OverlayObject::setVisible(bool bNew) 147 { 148 if(bNew != (bool)mbIsVisible) 149 { 150 // remember new value 151 mbIsVisible = bNew; 152 153 // register change (after change) 154 objectChange(); 155 } 156 } 157 setHittable(bool bNew)158 void OverlayObject::setHittable(bool bNew) 159 { 160 if(bNew != (bool)mbIsHittable) 161 { 162 // remember new value 163 mbIsHittable = bNew; 164 165 // register change (after change) 166 objectChange(); 167 } 168 } 169 setBaseColor(Color aNew)170 void OverlayObject::setBaseColor(Color aNew) 171 { 172 if(aNew != maBaseColor) 173 { 174 // remember new value 175 maBaseColor = aNew; 176 177 // register change (after change) 178 objectChange(); 179 } 180 } 181 Trigger(sal_uInt32)182 void OverlayObject::Trigger(sal_uInt32 /*nTime*/) 183 { 184 // default does not register again 185 } 186 stripeDefinitionHasChanged()187 void OverlayObject::stripeDefinitionHasChanged() 188 { 189 // default does not need to do anything 190 } 191 } // end of namespace overlay 192 } // end of namespace sdr 193 194 ////////////////////////////////////////////////////////////////////////////// 195 196 namespace sdr 197 { 198 namespace overlay 199 { OverlayObjectWithBasePosition(const basegfx::B2DPoint & rBasePos,Color aBaseColor)200 OverlayObjectWithBasePosition::OverlayObjectWithBasePosition(const basegfx::B2DPoint& rBasePos, Color aBaseColor) 201 : OverlayObject(aBaseColor), 202 maBasePosition(rBasePos) 203 { 204 } 205 ~OverlayObjectWithBasePosition()206 OverlayObjectWithBasePosition::~OverlayObjectWithBasePosition() 207 { 208 } 209 setBasePosition(const basegfx::B2DPoint & rNew)210 void OverlayObjectWithBasePosition::setBasePosition(const basegfx::B2DPoint& rNew) 211 { 212 if(rNew != maBasePosition) 213 { 214 // remember new value 215 maBasePosition = rNew; 216 217 // register change (after change) 218 objectChange(); 219 } 220 } 221 } // end of namespace overlay 222 } // end of namespace sdr 223 224 ////////////////////////////////////////////////////////////////////////////// 225 // eof 226