1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_svx.hxx"
30 #include <svx/sdr/overlay/overlayanimatedbitmapex.hxx>
31 #include <vcl/salbtype.hxx>
32 #include <vcl/outdev.hxx>
33 #include <svx/sdr/overlay/overlaymanager.hxx>
34 #include <basegfx/matrix/b2dhommatrix.hxx>
35 #include <svx/sdr/overlay/overlaytools.hxx>
36 
37 //////////////////////////////////////////////////////////////////////////////
38 
39 namespace sdr
40 {
41 	namespace overlay
42 	{
43 		// #i53216# check blink time value range
44 		void OverlayAnimatedBitmapEx::impCheckBlinkTimeValueRange()
45 		{
46 			if(mnBlinkTime < 25)
47 			{
48 				mnBlinkTime = 25;
49 			}
50 			else if(mnBlinkTime > 10000)
51 			{
52 				mnBlinkTime = 10000;
53 			}
54 		}
55 
56 		drawinglayer::primitive2d::Primitive2DSequence OverlayAnimatedBitmapEx::createOverlayObjectPrimitive2DSequence()
57 		{
58             if(mbOverlayState)
59             {
60                 const drawinglayer::primitive2d::Primitive2DReference aPrimitive(
61                     new drawinglayer::primitive2d::OverlayBitmapExPrimitive(
62                         getBitmapEx1(),
63                         getBasePosition(),
64                         getCenterX1(),
65                         getCenterY1()));
66 
67                 return drawinglayer::primitive2d::Primitive2DSequence(&aPrimitive, 1);
68             }
69             else
70             {
71                 const drawinglayer::primitive2d::Primitive2DReference aPrimitive(
72                     new drawinglayer::primitive2d::OverlayBitmapExPrimitive(
73                         getBitmapEx2(),
74                         getBasePosition(),
75                         getCenterX2(),
76                         getCenterY2()));
77 
78                 return drawinglayer::primitive2d::Primitive2DSequence(&aPrimitive, 1);
79             }
80 		}
81 
82 		OverlayAnimatedBitmapEx::OverlayAnimatedBitmapEx(
83 			const basegfx::B2DPoint& rBasePos,
84 			const BitmapEx& rBitmapEx1,
85 			const BitmapEx& rBitmapEx2,
86 			sal_uInt32 nBlinkTime,
87 			sal_uInt16 nCenX1,
88 			sal_uInt16 nCenY1,
89 			sal_uInt16 nCenX2,
90 			sal_uInt16 nCenY2)
91 		:	OverlayObjectWithBasePosition(rBasePos, Color(COL_WHITE)),
92 			maBitmapEx1(rBitmapEx1),
93 			maBitmapEx2(rBitmapEx2),
94 			mnCenterX1(nCenX1), mnCenterY1(nCenY1),
95 			mnCenterX2(nCenX2), mnCenterY2(nCenY2),
96 			mnBlinkTime(nBlinkTime),
97 			mbOverlayState(false)
98         {
99 			// set AllowsAnimation flag to mark this object as animation capable
100 			mbAllowsAnimation = true;
101 
102 			// #i53216# check blink time value range
103 			impCheckBlinkTimeValueRange();
104 		}
105 
106 		OverlayAnimatedBitmapEx::~OverlayAnimatedBitmapEx()
107 		{
108 		}
109 
110 		void OverlayAnimatedBitmapEx::setBitmapEx1(const BitmapEx& rNew)
111 		{
112 			if(rNew != maBitmapEx1)
113 			{
114 				// remember new Bitmap
115 				maBitmapEx1 = rNew;
116 
117 				// register change (after change)
118 				objectChange();
119 			}
120 		}
121 
122 		void OverlayAnimatedBitmapEx::setBitmapEx2(const BitmapEx& rNew)
123 		{
124 			if(rNew != maBitmapEx2)
125 			{
126 				// remember new Bitmap
127 				maBitmapEx2 = rNew;
128 
129 				// register change (after change)
130 				objectChange();
131 			}
132 		}
133 
134 		void OverlayAnimatedBitmapEx::setCenterXY1(sal_uInt16 nNewX, sal_uInt16 nNewY)
135 		{
136 			if(nNewX != mnCenterX1 || nNewY != mnCenterY1)
137 			{
138 				// remember new values
139 				if(nNewX != mnCenterX1)
140 				{
141 					mnCenterX1 = nNewX;
142 				}
143 
144 				if(nNewY != mnCenterY1)
145 				{
146 					mnCenterY1 = nNewY;
147 				}
148 
149 				// register change (after change)
150 				objectChange();
151 			}
152 		}
153 
154 		void OverlayAnimatedBitmapEx::setCenterXY2(sal_uInt16 nNewX, sal_uInt16 nNewY)
155 		{
156 			if(nNewX != mnCenterX2 || nNewY != mnCenterY2)
157 			{
158 				// remember new values
159 				if(nNewX != mnCenterX2)
160 				{
161 					mnCenterX2 = nNewX;
162 				}
163 
164 				if(nNewY != mnCenterY2)
165 				{
166 					mnCenterY2 = nNewY;
167 				}
168 
169 				// register change (after change)
170 				objectChange();
171 			}
172 		}
173 
174 		void OverlayAnimatedBitmapEx::setBlinkTime(sal_uInt32 nNew)
175 		{
176 			if(mnBlinkTime != nNew)
177 			{
178 				// remember new value
179 				mnBlinkTime = nNew;
180 
181 				// #i53216# check blink time value range
182 				impCheckBlinkTimeValueRange();
183 
184 				// register change (after change)
185 				objectChange();
186 			}
187 		}
188 
189 		void OverlayAnimatedBitmapEx::Trigger(sal_uInt32 nTime)
190 		{
191 			if(getOverlayManager())
192 			{
193 				// #i53216# produce event after nTime + x
194 				SetTime(nTime + mnBlinkTime);
195 
196 				// switch state
197 				if(mbOverlayState)
198 				{
199 					mbOverlayState = false;
200 				}
201 				else
202 				{
203 					mbOverlayState = true;
204 				}
205 
206 				// re-insert me as event
207 				getOverlayManager()->InsertEvent(this);
208 
209                 // register change (after change)
210 				objectChange();
211 			}
212 		}
213 	} // end of namespace overlay
214 } // end of namespace sdr
215 
216 //////////////////////////////////////////////////////////////////////////////
217 // eof
218