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