LibreOffice Module canvas (master)  1
spritecanvasbase.hxx
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 #ifndef INCLUDED_CANVAS_BASE_SPRITECANVASBASE_HXX
21 #define INCLUDED_CANVAS_BASE_SPRITECANVASBASE_HXX
22 
23 #include <rtl/ref.hxx>
24 #include <com/sun/star/rendering/InterpolationMode.hpp>
28 
29 namespace com::sun::star::rendering { class XAnimation; }
30 namespace com::sun::star::rendering { class XAnimatedSprite; }
31 namespace com::sun::star::rendering { class XCustomSprite; }
32 namespace com::sun::star::rendering { class XSprite; }
33 
34 
35 namespace canvas
36 {
70  template< class Base,
71  class CanvasHelper,
72  class Mutex=::osl::MutexGuard,
73  class UnambiguousBase = css::uno::XInterface > class SpriteCanvasBase :
74  public IntegerBitmapBase< BitmapCanvasBase<Base, CanvasHelper, Mutex, UnambiguousBase> >
75  {
76  public:
78  typedef ::rtl::Reference< SpriteCanvasBase > Reference;
79 
82  {
83  }
84 
85  virtual void disposeThis() override
86  {
87  typename BaseType::MutexType aGuard( BaseType::m_aMutex );
88 
90 
91  // pass on to base class
93  }
94 
95  // XSpriteCanvas
96  virtual css::uno::Reference< css::rendering::XAnimatedSprite > SAL_CALL createSpriteFromAnimation( const css::uno::Reference< css::rendering::XAnimation >& animation ) override
97  {
98  tools::verifyArgs(animation,
99  OSL_THIS_FUNC,
100  static_cast< typename BaseType::UnambiguousBaseType* >(this));
101 
102  typename BaseType::MutexType aGuard( BaseType::m_aMutex );
103 
104  return BaseType::maCanvasHelper.createSpriteFromAnimation(animation);
105  }
106 
107  virtual css::uno::Reference< css::rendering::XAnimatedSprite > SAL_CALL createSpriteFromBitmaps( const css::uno::Sequence< css::uno::Reference< css::rendering::XBitmap > >& animationBitmaps,
108  sal_Int8 interpolationMode ) override
109  {
110  tools::verifyArgs(animationBitmaps,
111  OSL_THIS_FUNC,
112  static_cast< typename BaseType::UnambiguousBaseType* >(this));
113  tools::verifyRange( interpolationMode,
114  css::rendering::InterpolationMode::NEAREST_NEIGHBOR,
115  css::rendering::InterpolationMode::BEZIERSPLINE4 );
116 
117  typename BaseType::MutexType aGuard( BaseType::m_aMutex );
118 
119  return BaseType::maCanvasHelper.createSpriteFromBitmaps(animationBitmaps, interpolationMode);
120  }
121 
122  virtual css::uno::Reference< css::rendering::XCustomSprite > SAL_CALL createCustomSprite( const css::geometry::RealSize2D& spriteSize ) override
123  {
124  tools::verifySpriteSize(spriteSize,
125  OSL_THIS_FUNC,
126  static_cast< typename BaseType::UnambiguousBaseType* >(this));
127 
128  typename BaseType::MutexType aGuard( BaseType::m_aMutex );
129 
130  return BaseType::maCanvasHelper.createCustomSprite(spriteSize);
131  }
132 
133  virtual css::uno::Reference< css::rendering::XSprite > SAL_CALL createClonedSprite( const css::uno::Reference< css::rendering::XSprite >& original ) override
134  {
135  tools::verifyArgs(original,
136  OSL_THIS_FUNC,
137  static_cast< typename BaseType::UnambiguousBaseType* >(this));
138 
139  typename BaseType::MutexType aGuard( BaseType::m_aMutex );
140 
141  return BaseType::maCanvasHelper.createClonedSprite(original);
142  }
143 
144  // SpriteSurface
145  virtual void showSprite( const Sprite::Reference& rSprite ) override
146  {
147  OSL_ASSERT( rSprite.is() );
148 
149  typename BaseType::MutexType aGuard( BaseType::m_aMutex );
150 
151  maRedrawManager.showSprite( rSprite );
152  }
153 
154  virtual void hideSprite( const Sprite::Reference& rSprite ) override
155  {
156  OSL_ASSERT( rSprite.is() );
157 
158  typename BaseType::MutexType aGuard( BaseType::m_aMutex );
159 
160  maRedrawManager.hideSprite( rSprite );
161  }
162 
163  virtual void moveSprite( const Sprite::Reference& rSprite,
164  const ::basegfx::B2DPoint& rOldPos,
165  const ::basegfx::B2DPoint& rNewPos,
166  const ::basegfx::B2DVector& rSpriteSize ) override
167  {
168  OSL_ASSERT( rSprite.is() );
169 
170  typename BaseType::MutexType aGuard( BaseType::m_aMutex );
171 
172  maRedrawManager.moveSprite( rSprite, rOldPos, rNewPos, rSpriteSize );
173  }
174 
175  virtual void updateSprite( const Sprite::Reference& rSprite,
176  const ::basegfx::B2DPoint& rPos,
177  const ::basegfx::B2DRange& rUpdateArea ) override
178  {
179  OSL_ASSERT( rSprite.is() );
180 
181  typename BaseType::MutexType aGuard( BaseType::m_aMutex );
182 
183  maRedrawManager.updateSprite( rSprite, rPos, rUpdateArea );
184  }
185 
186  protected:
188  };
189 }
190 
191 #endif // INCLUDED_CANVAS_BASE_SPRITECANVASBASE_HXX
192 
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void updateSprite(const Sprite::Reference &rSprite, const ::basegfx::B2DPoint &rPos, const ::basegfx::B2DRange &rUpdateArea) override
signed char sal_Int8
virtual css::uno::Reference< css::rendering::XCustomSprite > SAL_CALL createCustomSprite(const css::geometry::RealSize2D &spriteSize) override
void updateSprite(const Sprite::Reference &rSprite, const ::basegfx::B2DPoint &rPos, const ::basegfx::B2DRange &rUpdateArea)
void showSprite(const Sprite::Reference &rSprite)
void moveSprite(const Sprite::Reference &rSprite, const ::basegfx::B2DPoint &rOldPos, const ::basegfx::B2DPoint &rNewPos, const ::basegfx::B2DVector &rSpriteSize)
This class manages smooth SpriteCanvas updates.
virtual void hideSprite(const Sprite::Reference &rSprite) override
SpriteRedrawManager maRedrawManager
IntegerBitmapBase< BitmapCanvasBase< Base, CanvasHelper, Mutex, UnambiguousBase > > BaseType
Helper template to handle XIntegerBitmap method forwarding to BitmapCanvasHelper. ...
void verifySpriteSize(const geometry::RealSize2D &size, const char *pStr, const uno::Reference< uno::XInterface > &xIf)
Helper template to handle XIntegerBitmap method forwarding to BitmapCanvasHelper. ...
void verifyRange(NumType arg, NumType lowerBound, NumType upperBound)
Range checker, which throws css::lang::IllegalArgument exception, when range is violated.
virtual void disposeThis() override
CanvasHelper maCanvasHelper
Definition: canvasbase.hxx:443
void disposing()
Must be called when user of this object gets disposed.
virtual void showSprite(const Sprite::Reference &rSprite) override
void hideSprite(const Sprite::Reference &rSprite)
virtual css::uno::Reference< css::rendering::XAnimatedSprite > SAL_CALL createSpriteFromBitmaps(const css::uno::Sequence< css::uno::Reference< css::rendering::XBitmap > > &animationBitmaps, sal_Int8 interpolationMode) override
virtual css::uno::Reference< css::rendering::XAnimatedSprite > SAL_CALL createSpriteFromAnimation(const css::uno::Reference< css::rendering::XAnimation > &animation) override
virtual void moveSprite(const Sprite::Reference &rSprite, const ::basegfx::B2DPoint &rOldPos, const ::basegfx::B2DPoint &rNewPos, const ::basegfx::B2DVector &rSpriteSize) override
virtual css::uno::Reference< css::rendering::XSprite > SAL_CALL createClonedSprite(const css::uno::Reference< css::rendering::XSprite > &original) override
virtual void disposeThis() override
Definition: canvasbase.hxx:125
::rtl::Reference< SpriteCanvasBase > Reference
void verifyArgs(const Arg0 &rArg0, const char *pStr, const css::uno::Reference< css::uno::XInterface > &xIf)