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 27 #include <svx/sdr/overlay/overlayrectangle.hxx> 28 #include <vcl/outdev.hxx> 29 #include <basegfx/matrix/b2dhommatrix.hxx> 30 #include <basegfx/polygon/b2dpolygontools.hxx> 31 #include <basegfx/polygon/b2dpolygon.hxx> 32 #include <basegfx/numeric/ftools.hxx> 33 #include <svx/sdr/overlay/overlaytools.hxx> 34 #include <svx/sdr/overlay/overlaymanager.hxx> 35 #include <vcl/svapp.hxx> 36 37 ////////////////////////////////////////////////////////////////////////////// 38 39 namespace sdr 40 { 41 namespace overlay 42 { createOverlayObjectPrimitive2DSequence()43 drawinglayer::primitive2d::Primitive2DSequence OverlayRectangle::createOverlayObjectPrimitive2DSequence() 44 { 45 const basegfx::B2DRange aHatchRange(getBasePosition(), getSecondPosition()); 46 basegfx::BColor aColor(getBaseColor().getBColor()); 47 static double fChange(0.1); // just small optical change, do not make it annoying 48 49 if(mbOverlayState) 50 { 51 aColor += basegfx::B3DTuple(fChange, fChange, fChange); 52 aColor.clamp(); 53 } 54 else 55 { 56 aColor -= basegfx::B3DTuple(fChange, fChange, fChange); 57 aColor.clamp(); 58 } 59 60 const drawinglayer::primitive2d::Primitive2DReference aReference( 61 new drawinglayer::primitive2d::OverlayRectanglePrimitive( 62 aHatchRange, 63 aColor, 64 getTransparence(), 65 getDiscreteGrow(), 66 getDiscreteShrink(), 67 getRotation())); 68 69 return drawinglayer::primitive2d::Primitive2DSequence(&aReference, 1); 70 } 71 OverlayRectangle(const basegfx::B2DPoint & rBasePosition,const basegfx::B2DPoint & rSecondPosition,const Color & rHatchColor,double fTransparence,double fDiscreteGrow,double fDiscreteShrink,double fRotation,sal_uInt32 nBlinkTime,bool bAnimate)72 OverlayRectangle::OverlayRectangle( 73 const basegfx::B2DPoint& rBasePosition, 74 const basegfx::B2DPoint& rSecondPosition, 75 const Color& rHatchColor, 76 double fTransparence, 77 double fDiscreteGrow, 78 double fDiscreteShrink, 79 double fRotation, 80 sal_uInt32 nBlinkTime, 81 bool bAnimate) 82 : OverlayObjectWithBasePosition(rBasePosition, rHatchColor), 83 maSecondPosition(rSecondPosition), 84 mfTransparence(fTransparence), 85 mfDiscreteGrow(fDiscreteGrow), 86 mfDiscreteShrink(fDiscreteShrink), 87 mfRotation(fRotation), 88 mnBlinkTime(nBlinkTime), 89 mbOverlayState(false) 90 { 91 if(Application::GetSettings().GetStyleSettings().GetHighContrastMode()) 92 { 93 // no animation in high contrast mode 94 bAnimate = false; 95 } 96 97 // set AllowsAnimation flag to mark this object as animation capable 98 mbAllowsAnimation = bAnimate; 99 100 // #i53216# check blink time value range 101 mnBlinkTime = impCheckBlinkTimeValueRange(mnBlinkTime); 102 } 103 setSecondPosition(const basegfx::B2DPoint & rNew)104 void OverlayRectangle::setSecondPosition(const basegfx::B2DPoint& rNew) 105 { 106 if(rNew != maSecondPosition) 107 { 108 // remember new value 109 maSecondPosition = rNew; 110 111 // register change (after change) 112 objectChange(); 113 } 114 } 115 setBlinkTime(sal_uInt32 nNew)116 void OverlayRectangle::setBlinkTime(sal_uInt32 nNew) 117 { 118 if(mnBlinkTime != nNew) 119 { 120 // remember new value 121 mnBlinkTime = nNew; 122 123 // #i53216# check blink time value range 124 mnBlinkTime = impCheckBlinkTimeValueRange(mnBlinkTime); 125 126 // register change (after change) 127 objectChange(); 128 } 129 } 130 Trigger(sal_uInt32 nTime)131 void OverlayRectangle::Trigger(sal_uInt32 nTime) 132 { 133 if(getOverlayManager()) 134 { 135 // #i53216# produce event after nTime + x 136 SetTime(nTime + mnBlinkTime); 137 138 // switch state 139 if(mbOverlayState) 140 { 141 mbOverlayState = false; 142 } 143 else 144 { 145 mbOverlayState = true; 146 } 147 148 // re-insert me as event 149 getOverlayManager()->InsertEvent(this); 150 151 // register change (after change) 152 objectChange(); 153 } 154 } 155 } // end of namespace overlay 156 } // end of namespace sdr 157 158 ////////////////////////////////////////////////////////////////////////////// 159 // eof 160