Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include "impanmvw.hxx"
22 : #include <vcl/virdev.hxx>
23 : #include <vcl/window.hxx>
24 : #include <tools/helpers.hxx>
25 :
26 0 : ImplAnimView::ImplAnimView( Animation* pParent, OutputDevice* pOut,
27 : const Point& rPt, const Size& rSz,
28 : sal_uLong nExtraData,
29 : OutputDevice* pFirstFrameOutDev ) :
30 : mpParent ( pParent ),
31 : mpOut ( pFirstFrameOutDev ? pFirstFrameOutDev : pOut ),
32 : mnExtraData ( nExtraData ),
33 : maPt ( rPt ),
34 : maSz ( rSz ),
35 0 : maSzPix ( mpOut->LogicToPixel( maSz ) ),
36 : maClip ( mpOut->GetClipRegion() ),
37 0 : mpBackground ( new VirtualDevice ),
38 0 : mpRestore ( new VirtualDevice ),
39 : meLastDisposal ( DISPOSE_BACK ),
40 : mbPause ( sal_False ),
41 : mbMarked ( sal_False ),
42 0 : mbHMirr ( maSz.Width() < 0L ),
43 0 : mbVMirr ( maSz.Height() < 0L )
44 : {
45 0 : mpParent->ImplIncAnimCount();
46 :
47 : // Mirrored horizontally?
48 0 : if( mbHMirr )
49 : {
50 0 : maDispPt.X() = maPt.X() + maSz.Width() + 1L;
51 0 : maDispSz.Width() = -maSz.Width();
52 0 : maSzPix.Width() = -maSzPix.Width();
53 : }
54 : else
55 : {
56 0 : maDispPt.X() = maPt.X();
57 0 : maDispSz.Width() = maSz.Width();
58 : }
59 :
60 : // Mirrored vertically?
61 0 : if( mbVMirr )
62 : {
63 0 : maDispPt.Y() = maPt.Y() + maSz.Height() + 1L;
64 0 : maDispSz.Height() = -maSz.Height();
65 0 : maSzPix.Height() = -maSzPix.Height();
66 : }
67 : else
68 : {
69 0 : maDispPt.Y() = maPt.Y();
70 0 : maDispSz.Height() = maSz.Height();
71 : }
72 :
73 : // save background
74 0 : mpBackground->SetOutputSizePixel( maSzPix );
75 :
76 0 : if( mpOut->GetOutDevType() == OUTDEV_WINDOW )
77 : {
78 0 : MapMode aTempMap( mpOut->GetMapMode() );
79 0 : aTempMap.SetOrigin( Point() );
80 0 : mpBackground->SetMapMode( aTempMap );
81 0 : ( (Window*) mpOut )->SaveBackground( maDispPt, maDispSz, Point(), *mpBackground );
82 0 : mpBackground->SetMapMode( MapMode() );
83 : }
84 : else
85 0 : mpBackground->DrawOutDev( Point(), maSzPix, maDispPt, maDispSz, *mpOut );
86 :
87 : // Initialize drawing to actual position
88 0 : ImplDrawToPos( mpParent->ImplGetCurPos() );
89 :
90 : // If first frame OutputDevice is set, update variables now for real OutputDevice
91 0 : if( pFirstFrameOutDev )
92 0 : maClip = ( mpOut = pOut )->GetClipRegion();
93 0 : }
94 :
95 0 : ImplAnimView::~ImplAnimView()
96 : {
97 0 : delete mpBackground;
98 0 : delete mpRestore;
99 :
100 0 : mpParent->ImplDecAnimCount();
101 0 : }
102 :
103 0 : sal_Bool ImplAnimView::ImplMatches( OutputDevice* pOut, long nExtraData ) const
104 : {
105 0 : sal_Bool bRet = sal_False;
106 :
107 0 : if( nExtraData )
108 : {
109 0 : if( ( mnExtraData == nExtraData ) && ( !pOut || ( pOut == mpOut ) ) )
110 0 : bRet = sal_True;
111 : }
112 0 : else if( !pOut || ( pOut == mpOut ) )
113 0 : bRet = sal_True;
114 :
115 0 : return bRet;
116 : }
117 :
118 0 : void ImplAnimView::ImplGetPosSize( const AnimationBitmap& rAnm, Point& rPosPix, Size& rSizePix )
119 : {
120 0 : const Size& rAnmSize = mpParent->GetDisplaySizePixel();
121 0 : Point aPt2( rAnm.aPosPix.X() + rAnm.aSizePix.Width() - 1L,
122 0 : rAnm.aPosPix.Y() + rAnm.aSizePix.Height() - 1L );
123 : double fFactX, fFactY;
124 :
125 : // calculate x scaling
126 0 : if( rAnmSize.Width() > 1L )
127 0 : fFactX = (double) ( maSzPix.Width() - 1L ) / ( rAnmSize.Width() - 1L );
128 : else
129 0 : fFactX = 1.0;
130 :
131 : // calculate y scaling
132 0 : if( rAnmSize.Height() > 1L )
133 0 : fFactY = (double) ( maSzPix.Height() - 1L ) / ( rAnmSize.Height() - 1L );
134 : else
135 0 : fFactY = 1.0;
136 :
137 0 : rPosPix.X() = FRound( rAnm.aPosPix.X() * fFactX );
138 0 : rPosPix.Y() = FRound( rAnm.aPosPix.Y() * fFactY );
139 :
140 0 : aPt2.X() = FRound( aPt2.X() * fFactX );
141 0 : aPt2.Y() = FRound( aPt2.Y() * fFactY );
142 :
143 0 : rSizePix.Width() = aPt2.X() - rPosPix.X() + 1L;
144 0 : rSizePix.Height() = aPt2.Y() - rPosPix.Y() + 1L;
145 :
146 : // Mirrored horizontally?
147 0 : if( mbHMirr )
148 0 : rPosPix.X() = maSzPix.Width() - 1L - aPt2.X();
149 :
150 : // Mirrored vertically?
151 0 : if( mbVMirr )
152 0 : rPosPix.Y() = maSzPix.Height() - 1L - aPt2.Y();
153 0 : }
154 :
155 0 : void ImplAnimView::ImplDrawToPos( sal_uLong nPos )
156 : {
157 0 : VirtualDevice aVDev;
158 0 : Region* pOldClip = !maClip.IsNull() ? new Region( mpOut->GetClipRegion() ) : NULL;
159 :
160 0 : aVDev.SetOutputSizePixel( maSzPix, sal_False );
161 0 : nPos = std::min( nPos, (sal_uLong) mpParent->Count() - 1UL );
162 :
163 0 : for( sal_uLong i = 0UL; i <= nPos; i++ )
164 0 : ImplDraw( i, &aVDev );
165 :
166 0 : if( pOldClip )
167 0 : mpOut->SetClipRegion( maClip );
168 :
169 0 : mpOut->DrawOutDev( maDispPt, maDispSz, Point(), maSzPix, aVDev );
170 :
171 0 : if( pOldClip )
172 : {
173 0 : mpOut->SetClipRegion( *pOldClip );
174 0 : delete pOldClip;
175 0 : }
176 0 : }
177 :
178 0 : void ImplAnimView::ImplDraw( sal_uLong nPos )
179 : {
180 0 : ImplDraw( nPos, NULL );
181 0 : }
182 :
183 0 : void ImplAnimView::ImplDraw( sal_uLong nPos, VirtualDevice* pVDev )
184 : {
185 0 : Rectangle aOutRect( mpOut->PixelToLogic( Point() ), mpOut->GetOutputSize() );
186 :
187 : // check, if output lies out of display
188 0 : if( aOutRect.Intersection( Rectangle( maDispPt, maDispSz ) ).IsEmpty() )
189 0 : ImplSetMarked( sal_True );
190 0 : else if( !mbPause )
191 : {
192 : VirtualDevice* pDev;
193 0 : Point aPosPix;
194 0 : Point aBmpPosPix;
195 0 : Size aSizePix;
196 0 : Size aBmpSizePix;
197 0 : const sal_uLong nLastPos = mpParent->Count() - 1;
198 0 : const AnimationBitmap& rAnm = mpParent->Get( (sal_uInt16) ( mnActPos = std::min( nPos, nLastPos ) ) );
199 :
200 0 : ImplGetPosSize( rAnm, aPosPix, aSizePix );
201 :
202 : // Mirrored horizontally?
203 0 : if( mbHMirr )
204 : {
205 0 : aBmpPosPix.X() = aPosPix.X() + aSizePix.Width() - 1L;
206 0 : aBmpSizePix.Width() = -aSizePix.Width();
207 : }
208 : else
209 : {
210 0 : aBmpPosPix.X() = aPosPix.X();
211 0 : aBmpSizePix.Width() = aSizePix.Width();
212 : }
213 :
214 : // Mirrored vertically?
215 0 : if( mbVMirr )
216 : {
217 0 : aBmpPosPix.Y() = aPosPix.Y() + aSizePix.Height() - 1L;
218 0 : aBmpSizePix.Height() = -aSizePix.Height();
219 : }
220 : else
221 : {
222 0 : aBmpPosPix.Y() = aPosPix.Y();
223 0 : aBmpSizePix.Height() = aSizePix.Height();
224 : }
225 :
226 : // get output device
227 0 : if( !pVDev )
228 : {
229 0 : pDev = new VirtualDevice;
230 0 : pDev->SetOutputSizePixel( maSzPix, sal_False );
231 0 : pDev->DrawOutDev( Point(), maSzPix, maDispPt, maDispSz, *mpOut );
232 : }
233 : else
234 0 : pDev = pVDev;
235 :
236 : // restore background after each run
237 0 : if( !nPos )
238 : {
239 0 : meLastDisposal = DISPOSE_BACK;
240 0 : maRestPt = Point();
241 0 : maRestSz = maSzPix;
242 : }
243 :
244 : // restore
245 0 : if( ( DISPOSE_NOT != meLastDisposal ) && maRestSz.Width() && maRestSz.Height() )
246 : {
247 0 : if( DISPOSE_BACK == meLastDisposal )
248 0 : pDev->DrawOutDev( maRestPt, maRestSz, maRestPt, maRestSz, *mpBackground );
249 : else
250 0 : pDev->DrawOutDev( maRestPt, maRestSz, Point(), maRestSz, *mpRestore );
251 : }
252 :
253 0 : meLastDisposal = rAnm.eDisposal;
254 0 : maRestPt = aPosPix;
255 0 : maRestSz = aSizePix;
256 :
257 : // What do we need to restore the next time?
258 : // Put it into a bitmap if needed, else delete
259 : // SaveBitmap to conserve memory
260 0 : if( ( meLastDisposal == DISPOSE_BACK ) || ( meLastDisposal == DISPOSE_NOT ) )
261 0 : mpRestore->SetOutputSizePixel( Size( 1, 1 ), sal_False );
262 : else
263 : {
264 0 : mpRestore->SetOutputSizePixel( maRestSz, sal_False );
265 0 : mpRestore->DrawOutDev( Point(), maRestSz, aPosPix, aSizePix, *pDev );
266 : }
267 :
268 0 : pDev->DrawBitmapEx( aBmpPosPix, aBmpSizePix, rAnm.aBmpEx );
269 :
270 0 : if( !pVDev )
271 : {
272 0 : Region* pOldClip = !maClip.IsNull() ? new Region( mpOut->GetClipRegion() ) : NULL;
273 :
274 0 : if( pOldClip )
275 0 : mpOut->SetClipRegion( maClip );
276 :
277 0 : mpOut->DrawOutDev( maDispPt, maDispSz, Point(), maSzPix, *pDev );
278 :
279 0 : if( pOldClip )
280 : {
281 0 : mpOut->SetClipRegion( *pOldClip );
282 0 : delete pOldClip;
283 : }
284 :
285 0 : delete pDev;
286 :
287 0 : if( mpOut->GetOutDevType() == OUTDEV_WINDOW )
288 0 : ( (Window*) mpOut )->Sync();
289 : }
290 : }
291 0 : }
292 :
293 0 : void ImplAnimView::ImplRepaint()
294 : {
295 0 : const sal_Bool bOldPause = mbPause;
296 :
297 0 : if( mpOut->GetOutDevType() == OUTDEV_WINDOW )
298 : {
299 0 : MapMode aTempMap( mpOut->GetMapMode() );
300 0 : aTempMap.SetOrigin( Point() );
301 0 : mpBackground->SetMapMode( aTempMap );
302 0 : ( (Window*) mpOut )->SaveBackground( maDispPt, maDispSz, Point(), *mpBackground );
303 0 : mpBackground->SetMapMode( MapMode() );
304 : }
305 : else
306 0 : mpBackground->DrawOutDev( Point(), maSzPix, maDispPt, maDispSz, *mpOut );
307 :
308 0 : mbPause = sal_False;
309 0 : ImplDrawToPos( mnActPos );
310 0 : mbPause = bOldPause;
311 0 : }
312 :
313 0 : AInfo* ImplAnimView::ImplCreateAInfo() const
314 : {
315 0 : AInfo* pAInfo = new AInfo;
316 :
317 0 : pAInfo->aStartOrg = maPt;
318 0 : pAInfo->aStartSize = maSz;
319 0 : pAInfo->pOutDev = mpOut;
320 0 : pAInfo->pViewData = (void*) this;
321 0 : pAInfo->nExtraData = mnExtraData;
322 0 : pAInfo->bPause = mbPause;
323 :
324 0 : return pAInfo;
325 465 : }
326 :
327 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|