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( OutputDevice* pOut, long nExtraData ) const
100 {
101  bool bRet = false;
102 
103  if( nExtraData )
104  {
105  if( ( mnExtraData == nExtraData ) && ( !pOut || ( pOut == mpRenderContext ) ) )
106  bRet = true;
107  }
108  else if( !pOut || ( pOut == mpRenderContext ) )
109  bRet = true;
110 
111  return bRet;
112 }
113 
114 void ImplAnimView::getPosSize( const AnimationBitmap& rAnimationBitmap, Point& rPosPix, Size& rSizePix )
115 {
116  const Size& rAnmSize = mpParent->GetDisplaySizePixel();
117  Point aPt2( rAnimationBitmap.maPositionPixel.X() + rAnimationBitmap.maSizePixel.Width() - 1,
118  rAnimationBitmap.maPositionPixel.Y() + rAnimationBitmap.maSizePixel.Height() - 1 );
119  double fFactX, fFactY;
120 
121  // calculate x scaling
122  if( rAnmSize.Width() > 1 )
123  fFactX = static_cast<double>( maSzPix.Width() - 1 ) / ( rAnmSize.Width() - 1 );
124  else
125  fFactX = 1.0;
126 
127  // calculate y scaling
128  if( rAnmSize.Height() > 1 )
129  fFactY = static_cast<double>( maSzPix.Height() - 1 ) / ( rAnmSize.Height() - 1 );
130  else
131  fFactY = 1.0;
132 
133  rPosPix.setX( FRound( rAnimationBitmap.maPositionPixel.X() * fFactX ) );
134  rPosPix.setY( FRound( rAnimationBitmap.maPositionPixel.Y() * fFactY ) );
135 
136  aPt2.setX( FRound( aPt2.X() * fFactX ) );
137  aPt2.setY( FRound( aPt2.Y() * fFactY ) );
138 
139  rSizePix.setWidth( aPt2.X() - rPosPix.X() + 1 );
140  rSizePix.setHeight( aPt2.Y() - rPosPix.Y() + 1 );
141 
142  // Mirrored horizontally?
144  rPosPix.setX( maSzPix.Width() - 1 - aPt2.X() );
145 
146  // Mirrored vertically?
148  rPosPix.setY( maSzPix.Height() - 1 - aPt2.Y() );
149 }
150 
152 {
154 
155  std::unique_ptr<PaintBufferGuard> pGuard;
157  {
158  vcl::Window* pWindow = static_cast<vcl::Window*>(mpRenderContext.get());
159  pGuard.reset(new PaintBufferGuard(pWindow->ImplGetWindowImpl()->mpFrameData, pWindow));
160  pRenderContext = pGuard->GetRenderContext();
161  }
162 
164  std::unique_ptr<vcl::Region> xOldClip(!maClip.IsNull() ? new vcl::Region( pRenderContext->GetClipRegion() ) : nullptr);
165 
166  aVDev->SetOutputSizePixel( maSzPix, false );
167  nPos = std::min( nPos, static_cast<sal_uLong>(mpParent->Count()) - 1 );
168 
169  for( sal_uLong i = 0; i <= nPos; i++ )
170  draw( i, aVDev.get() );
171 
172  if (xOldClip)
173  pRenderContext->SetClipRegion( maClip );
174 
175  pRenderContext->DrawOutDev( maDispPt, maDispSz, Point(), maSzPix, *aVDev );
176  if (pGuard)
177  pGuard->SetPaintRect(tools::Rectangle(maDispPt, maDispSz));
178 
179  if (xOldClip)
180  pRenderContext->SetClipRegion(*xOldClip);
181 }
182 
184 {
186 
187  std::unique_ptr<PaintBufferGuard> pGuard;
188  if (!pVDev && mpRenderContext->GetOutDevType() == OUTDEV_WINDOW)
189  {
190  vcl::Window* pWindow = static_cast<vcl::Window*>(mpRenderContext.get());
191  pGuard.reset(new PaintBufferGuard(pWindow->ImplGetWindowImpl()->mpFrameData, pWindow));
192  pRenderContext = pGuard->GetRenderContext();
193  }
194 
195  tools::Rectangle aOutRect( pRenderContext->PixelToLogic( Point() ), pRenderContext->GetOutputSize() );
196 
197  // check, if output lies out of display
198  if( aOutRect.Intersection( tools::Rectangle( maDispPt, maDispSz ) ).IsEmpty() )
199  setMarked( true );
200  else if( !mbIsPaused )
201  {
203  Point aPosPix;
204  Point aBmpPosPix;
205  Size aSizePix;
206  Size aBmpSizePix;
207  const sal_uLong nLastPos = mpParent->Count() - 1;
208  mnActPos = std::min( nPos, nLastPos );
209  const AnimationBitmap& rAnimationBitmap = mpParent->Get( static_cast<sal_uInt16>( mnActPos ) );
210 
211  getPosSize( rAnimationBitmap, aPosPix, aSizePix );
212 
213  // Mirrored horizontally?
215  {
216  aBmpPosPix.setX( aPosPix.X() + aSizePix.Width() - 1 );
217  aBmpSizePix.setWidth( -aSizePix.Width() );
218  }
219  else
220  {
221  aBmpPosPix.setX( aPosPix.X() );
222  aBmpSizePix.setWidth( aSizePix.Width() );
223  }
224 
225  // Mirrored vertically?
227  {
228  aBmpPosPix.setY( aPosPix.Y() + aSizePix.Height() - 1 );
229  aBmpSizePix.setHeight( -aSizePix.Height() );
230  }
231  else
232  {
233  aBmpPosPix.setY( aPosPix.Y() );
234  aBmpSizePix.setHeight( aSizePix.Height() );
235  }
236 
237  // get output device
238  if( !pVDev )
239  {
241  pDev->SetOutputSizePixel( maSzPix, false );
242  pDev->DrawOutDev( Point(), maSzPix, maDispPt, maDispSz, *pRenderContext );
243  }
244  else
245  pDev = pVDev;
246 
247  // restore background after each run
248  if( !nPos )
249  {
251  maRestPt = Point();
252  maRestSz = maSzPix;
253  }
254 
255  // restore
257  {
260  else
262  }
263 
264  meLastDisposal = rAnimationBitmap.meDisposal;
265  maRestPt = aPosPix;
266  maRestSz = aSizePix;
267 
268  // What do we need to restore the next time?
269  // Put it into a bitmap if needed, else delete
270  // SaveBitmap to conserve memory
272  mpRestore->SetOutputSizePixel( Size( 1, 1 ), false );
273  else
274  {
276  mpRestore->DrawOutDev( Point(), maRestSz, aPosPix, aSizePix, *pDev );
277  }
278 
279  pDev->DrawBitmapEx( aBmpPosPix, aBmpSizePix, rAnimationBitmap.maBitmapEx );
280 
281  if( !pVDev )
282  {
283  std::unique_ptr<vcl::Region> xOldClip(!maClip.IsNull() ? new vcl::Region( pRenderContext->GetClipRegion() ) : nullptr);
284 
285  if (xOldClip)
286  pRenderContext->SetClipRegion( maClip );
287 
288  pRenderContext->DrawOutDev( maDispPt, maDispSz, Point(), maSzPix, *pDev );
289  if (pGuard)
290  pGuard->SetPaintRect(tools::Rectangle(maDispPt, maDispSz));
291 
292  if( xOldClip)
293  {
294  pRenderContext->SetClipRegion(*xOldClip);
295  xOldClip.reset();
296  }
297 
298  pDev.disposeAndClear();
299 
300  if( pRenderContext->GetOutDevType() == OUTDEV_WINDOW )
301  static_cast<vcl::Window*>( pRenderContext.get() )->Flush();
302  }
303  }
304 }
305 
307 {
308  const bool bOldPause = mbIsPaused;
309 
311 
312  mbIsPaused = false;
313  drawToPos( mnActPos );
314  mbIsPaused = bOldPause;
315 }
316 
318 {
319  AInfo* pAInfo = new AInfo;
320 
321  pAInfo->aStartOrg = maPt;
322  pAInfo->aStartSize = maSz;
323  pAInfo->pOutDev = mpRenderContext;
324  pAInfo->pViewData = const_cast<ImplAnimView *>(this);
325  pAInfo->nExtraData = mnExtraData;
326  pAInfo->bPause = mbIsPaused;
327 
328  return pAInfo;
329 }
330 
331 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
long const mnExtraData
Definition: impanmvw.hxx:52
long Width() const
static SAL_DLLPRIVATE void ImplDecAnimCount()
Definition: Animation.hxx:92
vcl::Region GetClipRegion() const
OutDevType GetOutDevType() const
Definition: outdev.hxx:522
void setMarked(bool bIsMarked)
Definition: impanmvw.hxx:92
long nExtraData
Definition: impanmvw.hxx:37
bool IsNull() const
Definition: region.hxx:102
Point aStartOrg
Definition: impanmvw.hxx:33
long FRound(double fVal)
SharedBitmapDescriptor mpBackground
A thin wrapper around rtl::Reference to implement the acquire and dispose semantics we want for refer...
Definition: button.hxx:32
long Height() const
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 getPosSize(const AnimationBitmap &rAnm, Point &rPosPix, Size &rSizePix)
Definition: impanmvw.cxx:114
sal_uIntPtr sal_uLong
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:554
void * pViewData
Definition: impanmvw.hxx:36
bool matches(OutputDevice *pOut, long nExtraData) const
Definition: impanmvw.cxx:99
void draw(sal_uLong nPos, VirtualDevice *pVDev=nullptr)
Definition: impanmvw.cxx:183
bool const mbIsMirroredHorizontally
Definition: impanmvw.hxx:67
void repaint()
Definition: impanmvw.cxx:306
void setX(long nX)
VclPtr< OutputDevice > pOutDev
Definition: impanmvw.hxx:35
VclPtr< VirtualDevice > mpRestore
Definition: impanmvw.hxx:62
AInfo * createAInfo() const
Definition: impanmvw.cxx:317
Sets up the buffer to have settings matching the window, and restores the original state in the dtor...
Definition: window.h:400
void setY(long nY)
static SAL_DLLPRIVATE void ImplIncAnimCount()
Definition: Animation.hxx:91
VclPtr< VirtualDevice > mpBackground
Definition: impanmvw.hxx:61
void drawToPos(sal_uLong nPos)
Definition: impanmvw.cxx:151
Size maSzPix
Definition: impanmvw.hxx:57
basegfx::B2DPolyPolygon maClip
bool const mbIsMirroredVertically
Definition: impanmvw.hxx:68
bool SetOutputSizePixel(const Size &rNewSize, bool bErase=true)
Definition: virdev.cxx:399
int i
Size GetOutputSize() const
Definition: outdev.hxx:450
Animation *const mpParent
Definition: impanmvw.hxx:50
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:304
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
const Size & GetDisplaySizePixel() const
Definition: Animation.hxx:55
virtual void SaveBackground(VirtualDevice &rSaveDevice, const Point &rPos, const Size &rSize, const Size &rBackgroundSize) const
long X() const
const AnimationBitmap & Get(sal_uInt16 nAnimation) const
Definition: Animation.cxx:415
Point const maPt
Definition: impanmvw.hxx:53
Point PixelToLogic(const Point &rDevicePt) const
Definition: map.cxx:1185
Size const maSz
Definition: impanmvw.hxx:56
bool bPause
Definition: impanmvw.hxx:38
Point maDispPt
Definition: impanmvw.hxx:54
void Create(SwFormatVertOrient &rItem, SvStream &rStrm, sal_uInt16 nVersionAbusedAsSize)
vcl::Region maClip
Definition: impanmvw.hxx:60
static VclPtr< reference_type > Create(Arg &&...arg)
A construction helper for VclPtr.
Definition: vclptr.hxx:127
virtual void DrawOutDev(const Point &rDestPt, const Size &rDestSize, const Point &rSrcPt, const Size &rSrcSize)
Definition: outdev.cxx:348
Point maRestPt
Definition: impanmvw.hxx:55
bool mbIsPaused
Definition: impanmvw.hxx:65
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:224
void setWidth(long nWidth)
Size aStartSize
Definition: impanmvw.hxx:34
Disposal
long Y() const
void setHeight(long nHeight)