LibreOffice Module vcl (master) 1
AnimationRenderer.cxx
Go to the documentation of this file.
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#include <memory>
22
23#include <vcl/virdev.hxx>
24#include <vcl/window.hxx>
25#include <tools/helpers.hxx>
26
27#include <window.h>
28
30 const Point& rPt, const Size& rSz,
31 sal_uLong nRendererId,
32 OutputDevice* pFirstFrameOutDev ) :
33 mpParent ( pParent ),
34 mpRenderContext ( pFirstFrameOutDev ? pFirstFrameOutDev : pOut ),
35 mnRendererId ( nRendererId ),
36 maOriginPt ( rPt ),
37 maLogicalSize ( rSz ),
38 maSizePx ( mpRenderContext->LogicToPixel( maLogicalSize ) ),
39 maClip ( mpRenderContext->GetClipRegion() ),
41 mpRestore ( VclPtr<VirtualDevice>::Create() ),
42 mnActIndex ( 0 ),
43 meLastDisposal ( Disposal::Back ),
44 mbIsPaused ( false ),
45 mbIsMarked ( false ),
46 mbIsMirroredHorizontally( maLogicalSize.Width() < 0 ),
47 mbIsMirroredVertically( maLogicalSize.Height() < 0 )
48{
50
51 // Mirrored horizontally?
53 {
54 maDispPt.setX( maOriginPt.X() + maLogicalSize.Width() + 1 );
57 }
58 else
59 {
60 maDispPt.setX( maOriginPt.X() );
62 }
63
64 // Mirrored vertically?
66 {
67 maDispPt.setY( maOriginPt.Y() + maLogicalSize.Height() + 1 );
70 }
71 else
72 {
73 maDispPt.setY( maOriginPt.Y() );
75 }
76
77 // save background
80
81 // Initialize drawing to actual position
83
84 // If first frame OutputDevice is set, update variables now for real OutputDevice
85 if( pFirstFrameOutDev )
86 {
89 }
90}
91
93{
96
98}
99
100bool AnimationRenderer::matches(const OutputDevice* pOut, tools::Long nRendererId) const
101{
102 return (!pOut || pOut == mpRenderContext) && (nRendererId == 0 || nRendererId == mnRendererId);
103}
104
105void AnimationRenderer::getPosSize( const AnimationBitmap& rAnimationBitmap, Point& rPosPix, Size& rSizePix )
106{
107 const Size& rAnmSize = mpParent->GetDisplaySizePixel();
108 Point aPt2( rAnimationBitmap.maPositionPixel.X() + rAnimationBitmap.maSizePixel.Width() - 1,
109 rAnimationBitmap.maPositionPixel.Y() + rAnimationBitmap.maSizePixel.Height() - 1 );
110 double fFactX, fFactY;
111
112 // calculate x scaling
113 if( rAnmSize.Width() > 1 )
114 fFactX = static_cast<double>( maSizePx.Width() - 1 ) / ( rAnmSize.Width() - 1 );
115 else
116 fFactX = 1.0;
117
118 // calculate y scaling
119 if( rAnmSize.Height() > 1 )
120 fFactY = static_cast<double>( maSizePx.Height() - 1 ) / ( rAnmSize.Height() - 1 );
121 else
122 fFactY = 1.0;
123
124 rPosPix.setX( FRound( rAnimationBitmap.maPositionPixel.X() * fFactX ) );
125 rPosPix.setY( FRound( rAnimationBitmap.maPositionPixel.Y() * fFactY ) );
126
127 aPt2.setX( FRound( aPt2.X() * fFactX ) );
128 aPt2.setY( FRound( aPt2.Y() * fFactY ) );
129
130 rSizePix.setWidth( aPt2.X() - rPosPix.X() + 1 );
131 rSizePix.setHeight( aPt2.Y() - rPosPix.Y() + 1 );
132
133 // Mirrored horizontally?
135 rPosPix.setX( maSizePx.Width() - 1 - aPt2.X() );
136
137 // Mirrored vertically?
139 rPosPix.setY( maSizePx.Height() - 1 - aPt2.Y() );
140}
141
143{
145
148 {
149 vcl::Window* pWindow = static_cast<vcl::WindowOutputDevice*>(mpRenderContext.get())->GetOwnerWindow();
150 pGuard.reset(new vcl::PaintBufferGuard(pWindow->ImplGetWindowImpl()->mpFrameData, pWindow));
151 pRenderContext = pGuard->GetRenderContext();
152 }
153
155 std::optional<vcl::Region> xOldClip;
156 if (!maClip.IsNull())
157 xOldClip = pRenderContext->GetClipRegion();
158
159 aVDev->SetOutputSizePixel( maSizePx, false );
160 nIndex = std::min( nIndex, static_cast<sal_uLong>(mpParent->Count()) - 1 );
161
162 for( sal_uLong i = 0; i <= nIndex; i++ )
163 draw( i, aVDev.get() );
164
165 if (xOldClip)
166 pRenderContext->SetClipRegion( maClip );
167
168 pRenderContext->DrawOutDev( maDispPt, maDispSz, Point(), maSizePx, *aVDev );
169 if (pGuard)
170 pGuard->SetPaintRect(tools::Rectangle(maDispPt, maDispSz));
171
172 if (xOldClip)
173 pRenderContext->SetClipRegion(*xOldClip);
174}
175
177{
179
181 if (!pVDev && mpRenderContext->GetOutDevType() == OUTDEV_WINDOW)
182 {
183 vcl::Window* pWindow = static_cast<vcl::WindowOutputDevice*>(mpRenderContext.get())->GetOwnerWindow();
184 pGuard.reset(new vcl::PaintBufferGuard(pWindow->ImplGetWindowImpl()->mpFrameData, pWindow));
185 pRenderContext = pGuard->GetRenderContext();
186 }
187
188 tools::Rectangle aOutRect( pRenderContext->PixelToLogic( Point() ), pRenderContext->GetOutputSize() );
189
190 // check, if output lies out of display
192 setMarked( true );
193 else if( !mbIsPaused )
194 {
196 Point aPosPix;
197 Point aBmpPosPix;
198 Size aSizePix;
199 Size aBmpSizePix;
200 const sal_uLong nLastPos = mpParent->Count() - 1;
201 mnActIndex = std::min( nIndex, nLastPos );
202 const AnimationBitmap& rAnimationBitmap = mpParent->Get( static_cast<sal_uInt16>( mnActIndex ) );
203
204 getPosSize( rAnimationBitmap, aPosPix, aSizePix );
205
206 // Mirrored horizontally?
208 {
209 aBmpPosPix.setX( aPosPix.X() + aSizePix.Width() - 1 );
210 aBmpSizePix.setWidth( -aSizePix.Width() );
211 }
212 else
213 {
214 aBmpPosPix.setX( aPosPix.X() );
215 aBmpSizePix.setWidth( aSizePix.Width() );
216 }
217
218 // Mirrored vertically?
220 {
221 aBmpPosPix.setY( aPosPix.Y() + aSizePix.Height() - 1 );
222 aBmpSizePix.setHeight( -aSizePix.Height() );
223 }
224 else
225 {
226 aBmpPosPix.setY( aPosPix.Y() );
227 aBmpSizePix.setHeight( aSizePix.Height() );
228 }
229
230 // get output device
231 if( !pVDev )
232 {
234 pDev->SetOutputSizePixel( maSizePx, false );
235 pDev->DrawOutDev( Point(), maSizePx, maDispPt, maDispSz, *pRenderContext );
236 }
237 else
238 pDev = pVDev;
239
240 // restore background after each run
241 if( !nIndex )
242 {
244 maRestPt = Point();
246 }
247
248 // restore
250 {
253 else
255 }
256
257 meLastDisposal = rAnimationBitmap.meDisposal;
258 maRestPt = aPosPix;
259 maRestSz = aSizePix;
260
261 // What do we need to restore the next time?
262 // Put it into a bitmap if needed, else delete
263 // SaveBitmap to conserve memory
265 mpRestore->SetOutputSizePixel( Size( 1, 1 ), false );
266 else
267 {
269 mpRestore->DrawOutDev( Point(), maRestSz, aPosPix, aSizePix, *pDev );
270 }
271
272 pDev->DrawBitmapEx( aBmpPosPix, aBmpSizePix, rAnimationBitmap.maBitmapEx );
273
274 if( !pVDev )
275 {
276 std::optional<vcl::Region> xOldClip;
277 if (!maClip.IsNull())
278 xOldClip = pRenderContext->GetClipRegion();
279
280 if (xOldClip)
281 pRenderContext->SetClipRegion( maClip );
282
283 pRenderContext->DrawOutDev( maDispPt, maDispSz, Point(), maSizePx, *pDev );
284 if (pGuard)
285 pGuard->SetPaintRect(tools::Rectangle(maDispPt, maDispSz));
286
287 if( xOldClip)
288 {
289 pRenderContext->SetClipRegion(*xOldClip);
290 xOldClip.reset();
291 }
292
293 pDev.disposeAndClear();
294 pRenderContext->Flush();
295 }
296 }
297}
298
300{
301 const bool bOldPause = mbIsPaused;
302
304
305 mbIsPaused = false;
307 mbIsPaused = bOldPause;
308}
309
311{
312 AnimationData* pDataItem = new AnimationData;
313
314 pDataItem->aStartOrg = maOriginPt;
315 pDataItem->aStartSize = maLogicalSize;
316 pDataItem->pOutDev = mpRenderContext;
317 pDataItem->pRendererData = const_cast<AnimationRenderer *>(this);
318 pDataItem->nRendererId = mnRendererId;
319 pDataItem->mbIsPaused = mbIsPaused;
320
321 return pDataItem;
322}
323
324/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Disposal
SharedBitmapDescriptor mpBackground
AnimationRenderer(Animation *pParent, OutputDevice *pOut, const Point &rPt, const Size &rSz, sal_uLong nRendererId, OutputDevice *pFirstFrameOutDev=nullptr)
void setMarked(bool bIsMarked)
VclPtr< OutputDevice > mpRenderContext
AnimationData * createAnimationData() const
bool matches(const OutputDevice *pOut, tools::Long nRendererId) const
VclPtr< VirtualDevice > mpBackground
void drawToIndex(sal_uLong nIndex)
void getPosSize(const AnimationBitmap &rAnm, Point &rPosPix, Size &rSizePix)
void draw(sal_uLong nIndex, VirtualDevice *pVDev=nullptr)
VclPtr< VirtualDevice > mpRestore
SAL_DLLPRIVATE sal_uLong ImplGetCurPos() const
Definition: Animation.hxx:94
size_t Count() const
Definition: Animation.hxx:70
static SAL_DLLPRIVATE void ImplIncAnimCount()
Definition: Animation.hxx:92
const Size & GetDisplaySizePixel() const
Definition: Animation.hxx:56
const AnimationBitmap & Get(sal_uInt16 nAnimation) const
Definition: Animation.cxx:416
static SAL_DLLPRIVATE void ImplDecAnimCount()
Definition: Animation.hxx:93
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:170
virtual void SaveBackground(VirtualDevice &rSaveDevice, const Point &rPos, const Size &rSize, const Size &rBackgroundSize) const
vcl::Region GetClipRegion() const
void DrawBitmapEx(const Point &rDestPt, const BitmapEx &rBitmapEx)
Definition: bitmapex.cxx:33
virtual void DrawOutDev(const Point &rDestPt, const Size &rDestSize, const Point &rSrcPt, const Size &rSrcSize)
Definition: outdev.cxx:433
OutDevType GetOutDevType() const
Definition: outdev.hxx:407
constexpr tools::Long Height() const
void setWidth(tools::Long nWidth)
void setHeight(tools::Long nHeight)
constexpr tools::Long Width() const
A thin wrapper around rtl::Reference to implement the acquire and dispose semantics we want for refer...
Definition: vclptr.hxx:58
void disposeAndClear()
Definition: vclptr.hxx:200
void reset(reference_type *pBody)
Definition: vclptr.hxx:153
reference_type * get() const
Get the body.
Definition: vclptr.hxx:143
static VclPtr< reference_type > Create(Arg &&... arg)
A construction helper for VclPtr.
Definition: vclptr.hxx:127
bool SetOutputSizePixel(const Size &rNewSize, bool bErase=true)
Definition: virdev.cxx:408
ImplFrameData * mpFrameData
Definition: window.h:228
tools::Rectangle & Intersection(const tools::Rectangle &rRect)
constexpr bool IsEmpty() const
Sets up the buffer to have settings matching the window, and restores the original state in the dtor.
Definition: window.h:404
bool IsNull() const
Definition: region.hxx:99
SAL_DLLPRIVATE WindowImpl * ImplGetWindowImpl() const
Definition: window.hxx:528
RegionData_Impl * mpParent
tools::Long FRound(double fVal)
sal_Int32 nIndex
int i
void Create(SwFormatVertOrient &rItem, SvStream &rStrm, sal_uInt16 nVersionAbusedAsSize)
long Long
std::unique_ptr< PaintBufferGuard, o3tl::default_delete< PaintBufferGuard > > PaintBufferGuardPtr
Definition: window.h:421
@ OUTDEV_WINDOW
Definition: outdev.hxx:143
basegfx::B2DPolyPolygon maClip
sal_uIntPtr sal_uLong
VclPtr< OutputDevice > pOutDev
tools::Long nRendererId
oslFileHandle & pOut