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