xref: /AOO41X/main/svx/source/sdr/overlay/overlayanimatedbitmapex.cxx (revision 414a0e15e815c63b516e4c585a9b911a100c756a)
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/overlayanimatedbitmapex.hxx>
27 #include <vcl/salbtype.hxx>
28 #include <vcl/outdev.hxx>
29 #include <svx/sdr/overlay/overlaymanager.hxx>
30 #include <basegfx/matrix/b2dhommatrix.hxx>
31 #include <svx/sdr/overlay/overlaytools.hxx>
32 
33 //////////////////////////////////////////////////////////////////////////////
34 
35 namespace sdr
36 {
37     namespace overlay
38     {
createOverlayObjectPrimitive2DSequence()39         drawinglayer::primitive2d::Primitive2DSequence OverlayAnimatedBitmapEx::createOverlayObjectPrimitive2DSequence()
40         {
41             if(mbOverlayState)
42             {
43                 const drawinglayer::primitive2d::Primitive2DReference aPrimitive(
44                     new drawinglayer::primitive2d::OverlayBitmapExPrimitive(
45                         getBitmapEx1(),
46                         getBasePosition(),
47                         getCenterX1(),
48                         getCenterY1(),
49                         getShearX(),
50                         getRotation()));
51 
52                 return drawinglayer::primitive2d::Primitive2DSequence(&aPrimitive, 1);
53             }
54             else
55             {
56                 const drawinglayer::primitive2d::Primitive2DReference aPrimitive(
57                     new drawinglayer::primitive2d::OverlayBitmapExPrimitive(
58                         getBitmapEx2(),
59                         getBasePosition(),
60                         getCenterX2(),
61                         getCenterY2(),
62                         getShearX(),
63                         getRotation()));
64 
65                 return drawinglayer::primitive2d::Primitive2DSequence(&aPrimitive, 1);
66             }
67         }
68 
OverlayAnimatedBitmapEx(const basegfx::B2DPoint & rBasePos,const BitmapEx & rBitmapEx1,const BitmapEx & rBitmapEx2,sal_uInt32 nBlinkTime,sal_uInt16 nCenX1,sal_uInt16 nCenY1,sal_uInt16 nCenX2,sal_uInt16 nCenY2,double fShearX,double fRotation)69         OverlayAnimatedBitmapEx::OverlayAnimatedBitmapEx(
70             const basegfx::B2DPoint& rBasePos,
71             const BitmapEx& rBitmapEx1,
72             const BitmapEx& rBitmapEx2,
73             sal_uInt32 nBlinkTime,
74             sal_uInt16 nCenX1,
75             sal_uInt16 nCenY1,
76             sal_uInt16 nCenX2,
77             sal_uInt16 nCenY2,
78             double fShearX,
79             double fRotation)
80         :   OverlayObjectWithBasePosition(rBasePos, Color(COL_WHITE)),
81             maBitmapEx1(rBitmapEx1),
82             maBitmapEx2(rBitmapEx2),
83             mnCenterX1(nCenX1), mnCenterY1(nCenY1),
84             mnCenterX2(nCenX2), mnCenterY2(nCenY2),
85             mnBlinkTime(nBlinkTime),
86             mfShearX(fShearX),
87             mfRotation(fRotation),
88             mbOverlayState(false)
89         {
90             // set AllowsAnimation flag to mark this object as animation capable
91             mbAllowsAnimation = true;
92 
93             // #i53216# check blink time value range
94             mnBlinkTime = impCheckBlinkTimeValueRange(mnBlinkTime);
95         }
96 
~OverlayAnimatedBitmapEx()97         OverlayAnimatedBitmapEx::~OverlayAnimatedBitmapEx()
98         {
99         }
100 
setBitmapEx1(const BitmapEx & rNew)101         void OverlayAnimatedBitmapEx::setBitmapEx1(const BitmapEx& rNew)
102         {
103             if(rNew != maBitmapEx1)
104             {
105                 // remember new Bitmap
106                 maBitmapEx1 = rNew;
107 
108                 // register change (after change)
109                 objectChange();
110             }
111         }
112 
setBitmapEx2(const BitmapEx & rNew)113         void OverlayAnimatedBitmapEx::setBitmapEx2(const BitmapEx& rNew)
114         {
115             if(rNew != maBitmapEx2)
116             {
117                 // remember new Bitmap
118                 maBitmapEx2 = rNew;
119 
120                 // register change (after change)
121                 objectChange();
122             }
123         }
124 
setCenterXY1(sal_uInt16 nNewX,sal_uInt16 nNewY)125         void OverlayAnimatedBitmapEx::setCenterXY1(sal_uInt16 nNewX, sal_uInt16 nNewY)
126         {
127             if(nNewX != mnCenterX1 || nNewY != mnCenterY1)
128             {
129                 // remember new values
130                 if(nNewX != mnCenterX1)
131                 {
132                     mnCenterX1 = nNewX;
133                 }
134 
135                 if(nNewY != mnCenterY1)
136                 {
137                     mnCenterY1 = nNewY;
138                 }
139 
140                 // register change (after change)
141                 objectChange();
142             }
143         }
144 
setCenterXY2(sal_uInt16 nNewX,sal_uInt16 nNewY)145         void OverlayAnimatedBitmapEx::setCenterXY2(sal_uInt16 nNewX, sal_uInt16 nNewY)
146         {
147             if(nNewX != mnCenterX2 || nNewY != mnCenterY2)
148             {
149                 // remember new values
150                 if(nNewX != mnCenterX2)
151                 {
152                     mnCenterX2 = nNewX;
153                 }
154 
155                 if(nNewY != mnCenterY2)
156                 {
157                     mnCenterY2 = nNewY;
158                 }
159 
160                 // register change (after change)
161                 objectChange();
162             }
163         }
164 
setBlinkTime(sal_uInt32 nNew)165         void OverlayAnimatedBitmapEx::setBlinkTime(sal_uInt32 nNew)
166         {
167             if(mnBlinkTime != nNew)
168             {
169                 // remember new value
170                 mnBlinkTime = nNew;
171 
172                 // #i53216# check blink time value range
173                 mnBlinkTime = impCheckBlinkTimeValueRange(mnBlinkTime);
174 
175                 // register change (after change)
176                 objectChange();
177             }
178         }
179 
Trigger(sal_uInt32 nTime)180         void OverlayAnimatedBitmapEx::Trigger(sal_uInt32 nTime)
181         {
182             if(getOverlayManager())
183             {
184                 // #i53216# produce event after nTime + x
185                 SetTime(nTime + mnBlinkTime);
186 
187                 // switch state
188                 if(mbOverlayState)
189                 {
190                     mbOverlayState = false;
191                 }
192                 else
193                 {
194                     mbOverlayState = true;
195                 }
196 
197                 // re-insert me as event
198                 getOverlayManager()->InsertEvent(this);
199 
200                 // register change (after change)
201                 objectChange();
202             }
203         }
204     } // end of namespace overlay
205 } // end of namespace sdr
206 
207 //////////////////////////////////////////////////////////////////////////////
208 // eof
209