LibreOffice Module vcl (master)  1
impanmvw.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>
21 #include <impanmvw.hxx>
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 nExtraData,
32  OutputDevice* pFirstFrameOutDev ) :
33  mpParent ( pParent ),
34  mpRenderContext ( pFirstFrameOutDev ? pFirstFrameOutDev : pOut ),
35  mnExtraData ( nExtraData ),
36  maPt ( rPt ),
37  maSz ( rSz ),
38  maSzPix ( mpRenderContext->LogicToPixel( maSz ) ),
39  maClip ( mpRenderContext->GetClipRegion() ),
41  mpRestore ( VclPtr<VirtualDevice>::Create() ),
42  meLastDisposal ( Disposal::Back ),
43  mbIsPaused ( false ),
44  mbIsMarked ( false ),
45  mbIsMirroredHorizontally ( maSz.Width() < 0 ),
46  mbIsMirroredVertically ( maSz.Height() < 0 )
47 {
49 
50  // Mirrored horizontally?
52  {
53  maDispPt.setX( maPt.X() + maSz.Width() + 1 );
56  }
57  else
58  {
59  maDispPt.setX( maPt.X() );
61  }
62 
63  // Mirrored vertically?
65  {
66  maDispPt.setY( maPt.Y() + maSz.Height() + 1 );
69  }
70  else
71  {
72  maDispPt.setY( maPt.Y() );
74  }
75 
76  // save background
79 
80  // Initialize drawing to actual position
82 
83  // If first frame OutputDevice is set, update variables now for real OutputDevice
84  if( pFirstFrameOutDev )
85  {
86  mpRenderContext = pOut;
88  }
89 }
90 
92 {
95 
97 }
98 
99 bool ImplAnimView::matches(const OutputDevice* pOut, tools::Long nExtraData) const
100 {
101  return (!pOut || pOut == mpRenderContext) && (nExtraData == 0 || nExtraData == mnExtraData);
102 }
103 
104 void ImplAnimView::getPosSize( const AnimationBitmap& rAnimationBitmap, Point& rPosPix, Size& rSizePix )
105 {
106  const Size& rAnmSize = mpParent->GetDisplaySizePixel();
107  Point aPt2( rAnimationBitmap.maPositionPixel.X() + rAnimationBitmap.maSizePixel.Width() - 1,
108  rAnimationBitmap.maPositionPixel.Y() + rAnimationBitmap.maSizePixel.Height() - 1 );
109  double fFactX, fFactY;
110 
111  // calculate x scaling
112  if( rAnmSize.Width() > 1 )
113  fFactX = static_cast<double>( maSzPix.Width() - 1 ) / ( rAnmSize.Width() - 1 );
114  else
115  fFactX = 1.0;
116 
117  // calculate y scaling
118  if( rAnmSize.Height() > 1 )
119  fFactY = static_cast<double>( maSzPix.Height() - 1 ) / ( rAnmSize.Height() - 1 );
120  else
121  fFactY = 1.0;
122 
123  rPosPix.setX( FRound( rAnimationBitmap.maPositionPixel.X() * fFactX ) );
124  rPosPix.setY( FRound( rAnimationBitmap.maPositionPixel.Y() * fFactY ) );
125 
126  aPt2.setX( FRound( aPt2.X() * fFactX ) );
127  aPt2.setY( FRound( aPt2.Y() * fFactY ) );
128 
129  rSizePix.setWidth( aPt2.X() - rPosPix.X() + 1 );
130  rSizePix.setHeight( aPt2.Y() - rPosPix.Y() + 1 );
131 
132  // Mirrored horizontally?
134  rPosPix.setX( maSzPix.Width() - 1 - aPt2.X() );
135 
136  // Mirrored vertically?
138  rPosPix.setY( maSzPix.Height() - 1 - aPt2.Y() );
139 }
140 
142 {
144 
145  std::unique_ptr<vcl::PaintBufferGuard> pGuard;
147  {
148  vcl::Window* pWindow = static_cast<vcl::Window*>(mpRenderContext.get());
149  pGuard.reset(new vcl::PaintBufferGuard(pWindow->ImplGetWindowImpl()->mpFrameData, pWindow));
150  pRenderContext = pGuard->GetRenderContext();
151  }
152 
154  std::unique_ptr<vcl::Region> xOldClip(!maClip.IsNull() ? new vcl::Region( pRenderContext->GetClipRegion() ) : nullptr);
155 
156  aVDev->SetOutputSizePixel( maSzPix, false );
157  nPos = std::min( nPos, static_cast<sal_uLong>(mpParent->Count()) - 1 );
158 
159  for( sal_uLong i = 0; i <= nPos; i++ )
160  draw( i, aVDev.get() );
161 
162  if (xOldClip)
163  pRenderContext->SetClipRegion( maClip );
164 
165  pRenderContext->DrawOutDev( maDispPt, maDispSz, Point(), maSzPix, *aVDev );
166  if (pGuard)
167  pGuard->SetPaintRect(tools::Rectangle(maDispPt, maDispSz));
168 
169  if (xOldClip)
170  pRenderContext->SetClipRegion(*xOldClip);
171 }
172 
174 {
176 
177  std::unique_ptr<vcl::PaintBufferGuard> pGuard;
178  if (!pVDev && mpRenderContext->GetOutDevType() == OUTDEV_WINDOW)
179  {
180  vcl::Window* pWindow = static_cast<vcl::Window*>(mpRenderContext.get());
181  pGuard.reset(new vcl::PaintBufferGuard(pWindow->ImplGetWindowImpl()->mpFrameData, pWindow));
182  pRenderContext = pGuard->GetRenderContext();
183  }
184 
185  tools::Rectangle aOutRect( pRenderContext->PixelToLogic( Point() ), pRenderContext->GetOutputSize() );
186 
187  // check, if output lies out of display
188  if( aOutRect.Intersection( tools::Rectangle( maDispPt, maDispSz ) ).IsEmpty() )
189  setMarked( true );
190  else if( !mbIsPaused )
191  {
193  Point aPosPix;
194  Point aBmpPosPix;
195  Size aSizePix;
196  Size aBmpSizePix;
197  const sal_uLong nLastPos = mpParent->Count() - 1;
198  mnActPos = std::min( nPos, nLastPos );
199  const AnimationBitmap& rAnimationBitmap = mpParent->Get( static_cast<sal_uInt16>( mnActPos ) );
200 
201  getPosSize( rAnimationBitmap, aPosPix, aSizePix );
202 
203  // Mirrored horizontally?
205  {
206  aBmpPosPix.setX( aPosPix.X() + aSizePix.Width() - 1 );
207  aBmpSizePix.setWidth( -aSizePix.Width() );
208  }
209  else
210  {
211  aBmpPosPix.setX( aPosPix.X() );
212  aBmpSizePix.setWidth( aSizePix.Width() );
213  }
214 
215  // Mirrored vertically?
217  {
218  aBmpPosPix.setY( aPosPix.Y() + aSizePix.Height() - 1 );
219  aBmpSizePix.setHeight( -aSizePix.Height() );
220  }
221  else
222  {
223  aBmpPosPix.setY( aPosPix.Y() );
224  aBmpSizePix.setHeight( aSizePix.Height() );
225  }
226 
227  // get output device
228  if( !pVDev )
229  {
231  pDev->SetOutputSizePixel( maSzPix, false );
232  pDev->DrawOutDev( Point(), maSzPix, maDispPt, maDispSz, *pRenderContext );
233  }
234  else
235  pDev = pVDev;
236 
237  // restore background after each run
238  if( !nPos )
239  {
241  maRestPt = Point();
242  maRestSz = maSzPix;
243  }
244 
245  // restore
247  {
250  else
252  }
253 
254  meLastDisposal = rAnimationBitmap.meDisposal;
255  maRestPt = aPosPix;
256  maRestSz = aSizePix;
257 
258  // What do we need to restore the next time?
259  // Put it into a bitmap if needed, else delete
260  // SaveBitmap to conserve memory
262  mpRestore->SetOutputSizePixel( Size( 1, 1 ), false );
263  else
264  {
266  mpRestore->DrawOutDev( Point(), maRestSz, aPosPix, aSizePix, *pDev );
267  }
268 
269  pDev->DrawBitmapEx( aBmpPosPix, aBmpSizePix, rAnimationBitmap.maBitmapEx );
270 
271  if( !pVDev )
272  {
273  std::unique_ptr<vcl::Region> xOldClip(!maClip.IsNull() ? new vcl::Region( pRenderContext->GetClipRegion() ) : nullptr);
274 
275  if (xOldClip)
276  pRenderContext->SetClipRegion( maClip );
277 
278  pRenderContext->DrawOutDev( maDispPt, maDispSz, Point(), maSzPix, *pDev );
279  if (pGuard)
280  pGuard->SetPaintRect(tools::Rectangle(maDispPt, maDispSz));
281 
282  if( xOldClip)
283  {
284  pRenderContext->SetClipRegion(*xOldClip);
285  xOldClip.reset();
286  }
287 
288  pDev.disposeAndClear();
289  pRenderContext->Flush();
290  }
291  }
292 }
293 
295 {
296  const bool bOldPause = mbIsPaused;
297 
299 
300  mbIsPaused = false;
301  drawToPos( mnActPos );
302  mbIsPaused = bOldPause;
303 }
304 
306 {
307  AInfo* pAInfo = new AInfo;
308 
309  pAInfo->aStartOrg = maPt;
310  pAInfo->aStartSize = maSz;
311  pAInfo->pOutDev = mpRenderContext;
312  pAInfo->pViewData = const_cast<ImplAnimView *>(this);
313  pAInfo->nExtraData = mnExtraData;
314  pAInfo->bPause = mbIsPaused;
315 
316  return pAInfo;
317 }
318 
319 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static SAL_DLLPRIVATE void ImplDecAnimCount()
Definition: Animation.hxx:92
vcl::Region GetClipRegion() const
OutDevType GetOutDevType() const
Definition: outdev.hxx:523
Animation * mpParent
Definition: impanmvw.hxx:50
virtual void Flush()
Definition: outdev.hxx:546
void setMarked(bool bIsMarked)
Definition: impanmvw.hxx:92
bool IsNull() const
Definition: region.hxx:102
Point aStartOrg
Definition: impanmvw.hxx:33
SharedBitmapDescriptor mpBackground
void setWidth(tools::Long nWidth)
A thin wrapper around rtl::Reference to implement the acquire and dispose semantics we want for refer...
Definition: button.hxx:32
void DrawBitmapEx(const Point &rDestPt, const BitmapEx &rBitmapEx)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void Create(SwFormatVertOrient &rItem, SvStream &rStrm, sal_uInt16 nVersionAbusedAsSize)
void getPosSize(const AnimationBitmap &rAnm, Point &rPosPix, Size &rSizePix)
Definition: impanmvw.cxx:104
sal_uIntPtr sal_uLong
long Long
void disposeAndClear()
Definition: vclptr.hxx:200
Size maDispSz
Definition: impanmvw.hxx:58
SAL_DLLPRIVATE sal_uLong ImplGetCurPos() const
Definition: Animation.hxx:93
SAL_DLLPRIVATE WindowImpl * ImplGetWindowImpl() const
Definition: window.hxx:563
void * pViewData
Definition: impanmvw.hxx:36
void draw(sal_uLong nPos, VirtualDevice *pVDev=nullptr)
Definition: impanmvw.cxx:173
void repaint()
Definition: impanmvw.cxx:294
VclPtr< OutputDevice > pOutDev
Definition: impanmvw.hxx:35
VclPtr< VirtualDevice > mpRestore
Definition: impanmvw.hxx:62
AInfo * createAInfo() const
Definition: impanmvw.cxx:305
Point maPt
Definition: impanmvw.hxx:53
tools::Long mnExtraData
Definition: impanmvw.hxx:52
static SAL_DLLPRIVATE void ImplIncAnimCount()
Definition: Animation.hxx:91
int i
VclPtr< VirtualDevice > mpBackground
Definition: impanmvw.hxx:61
void drawToPos(sal_uLong nPos)
Definition: impanmvw.cxx:141
tools::Long FRound(double fVal)
Size maSzPix
Definition: impanmvw.hxx:57
basegfx::B2DPolyPolygon maClip
bool SetOutputSizePixel(const Size &rNewSize, bool bErase=true)
Definition: virdev.cxx:395
Size GetOutputSize() const
Definition: outdev.hxx:449
tools::Long Width() const
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:302
Disposal meLastDisposal
Definition: impanmvw.hxx:64
ImplAnimView(Animation *pParent, OutputDevice *pOut, const Point &rPt, const Size &rSz, sal_uLong nExtraData, OutputDevice *pFirstFrameOutDev=nullptr)
Definition: impanmvw.cxx:29
Sets up the buffer to have settings matching the window, and restores the original state in the dtor...
Definition: window.h:402
const Size & GetDisplaySizePixel() const
Definition: Animation.hxx:55
virtual void SaveBackground(VirtualDevice &rSaveDevice, const Point &rPos, const Size &rSize, const Size &rBackgroundSize) const
bool mbIsMirroredHorizontally
Definition: impanmvw.hxx:67
const AnimationBitmap & Get(sal_uInt16 nAnimation) const
Definition: Animation.cxx:399
bool mbIsMirroredVertically
Definition: impanmvw.hxx:68
Point PixelToLogic(const Point &rDevicePt) const
Definition: map.cxx:1049
RegionData_Impl * mpParent
bool bPause
Definition: impanmvw.hxx:38
Point maDispPt
Definition: impanmvw.hxx:54
vcl::Region maClip
Definition: impanmvw.hxx:60
static VclPtr< reference_type > Create(Arg &&...arg)
A construction helper for VclPtr.
Definition: vclptr.hxx:127
tools::Long Height() const
bool matches(const OutputDevice *pOut, tools::Long nExtraData) const
Definition: impanmvw.cxx:99
tools::Long nExtraData
Definition: impanmvw.hxx:37
virtual void DrawOutDev(const Point &rDestPt, const Size &rDestSize, const Point &rSrcPt, const Size &rSrcSize)
Definition: outdev.cxx:343
Point maRestPt
Definition: impanmvw.hxx:55
bool mbIsPaused
Definition: impanmvw.hxx:65
void setHeight(tools::Long nHeight)
size_t Count() const
Definition: Animation.hxx:69
reference_type * get() const
Get the body.
Definition: vclptr.hxx:143
Size maRestSz
Definition: impanmvw.hxx:59
sal_uLong mnActPos
Definition: impanmvw.hxx:63
VclPtr< OutputDevice > mpRenderContext
Definition: impanmvw.hxx:51
ImplFrameData * mpFrameData
Definition: window.h:225
Size aStartSize
Definition: impanmvw.hxx:34
Disposal