LibreOffice Module canvas (master) 1
canvascustomspritebase.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 <com/sun/star/rendering/XCanvas.hpp>
23
29
30namespace com::sun::star::rendering { class XPolyPolygon2D; }
31
32namespace canvas
33{
70 template< class Base,
71 class SpriteHelper,
72 class CanvasHelper,
73 class Mutex=::osl::MutexGuard,
74 class UnambiguousBase = css::uno::XInterface > class CanvasCustomSpriteBase :
75 public IntegerBitmapBase< BitmapCanvasBase2<Base, CanvasHelper, Mutex, UnambiguousBase> >
76 {
77 public:
79
82 {
83 }
84
93 virtual void disposeThis() override
94 {
95 typename BaseType::MutexType aGuard( BaseType::m_aMutex );
96
97 maSpriteHelper.disposing();
98
99 // pass on to base class
100 BaseType::disposeThis();
101 }
102
103 // XCanvas: selectively override base's methods here, for opacity tracking
104 virtual void SAL_CALL clear() override
105 {
106 typename BaseType::MutexType aGuard( BaseType::m_aMutex );
107
108 maSpriteHelper.clearingContent( this );
109
110 // and forward to base class, which handles the actual rendering
111 return BaseType::clear();
112 }
113
114 virtual css::uno::Reference< css::rendering::XCachedPrimitive > SAL_CALL
115 drawBitmap( const css::uno::Reference< css::rendering::XBitmap >& xBitmap,
116 const css::rendering::ViewState& viewState,
117 const css::rendering::RenderState& renderState ) override
118 {
119 tools::verifyArgs(xBitmap, viewState, renderState,
120 __func__,
121 static_cast< typename BaseType::UnambiguousBaseType* >(this));
122
123 typename BaseType::MutexType aGuard( BaseType::m_aMutex );
124
125 maSpriteHelper.checkDrawBitmap( this, xBitmap, viewState, renderState );
126
127 // and forward to base class, which handles the actual rendering
128 return BaseType::drawBitmap( xBitmap,
129 viewState,
130 renderState );
131 }
132
133 // TODO(F3): If somebody uses the XIntegerBitmap methods to
134 // clear pixel (setting alpha != 1.0 there), or a compositing
135 // mode results in similar alpha, maSpriteHelper might
136 // erroneously report fully opaque sprites. Effectively, all
137 // render methods must be overridden here; or better,
138 // functionality provided at the baseclass.
139
140 // XSprite
141 virtual void SAL_CALL setAlpha( double alpha ) override
142 {
143 tools::verifyRange( alpha, 0.0, 1.0 );
144
145 typename BaseType::MutexType aGuard( BaseType::m_aMutex );
146
147 maSpriteHelper.setAlpha( this, alpha );
148 }
149
150 virtual void SAL_CALL move( const css::geometry::RealPoint2D& aNewPos,
151 const css::rendering::ViewState& viewState,
152 const css::rendering::RenderState& renderState ) override
153 {
154 tools::verifyArgs(aNewPos, viewState, renderState,
155 __func__,
156 static_cast< typename BaseType::UnambiguousBaseType* >(this));
157
158 typename BaseType::MutexType aGuard( BaseType::m_aMutex );
159
160 maSpriteHelper.move( this, aNewPos, viewState, renderState );
161 }
162
163 virtual void SAL_CALL transform( const css::geometry::AffineMatrix2D& aTransformation ) override
164 {
165 tools::verifyArgs(aTransformation,
166 __func__,
167 static_cast< typename BaseType::UnambiguousBaseType* >(this));
168
169 typename BaseType::MutexType aGuard( BaseType::m_aMutex );
170
171 maSpriteHelper.transform( this, aTransformation );
172 }
173
174 virtual void SAL_CALL clip( const css::uno::Reference< css::rendering::XPolyPolygon2D >& aClip ) override
175 {
176 // NULL xClip explicitly allowed here (to clear clipping)
177
178 typename BaseType::MutexType aGuard( BaseType::m_aMutex );
179
180 maSpriteHelper.clip( this, aClip );
181 }
182
183 virtual void SAL_CALL setPriority( double nPriority ) override
184 {
185 typename BaseType::MutexType aGuard( BaseType::m_aMutex );
186
187 maSpriteHelper.setPriority( this, nPriority );
188 }
189
190 virtual void SAL_CALL show() override
191 {
192 typename BaseType::MutexType aGuard( BaseType::m_aMutex );
193
194 maSpriteHelper.show( this );
195 }
196
197 virtual void SAL_CALL hide() override
198 {
199 typename BaseType::MutexType aGuard( BaseType::m_aMutex );
200
201 maSpriteHelper.hide( this );
202 }
203
204 // XCustomSprite
205 virtual css::uno::Reference< css::rendering::XCanvas > SAL_CALL
207 {
208 typename BaseType::MutexType aGuard( BaseType::m_aMutex );
209
210 return this;
211 }
212
213 // Sprite
214 virtual bool isAreaUpdateOpaque( const ::basegfx::B2DRange& rUpdateArea ) const override
215 {
216 typename BaseType::MutexType aGuard( BaseType::m_aMutex );
217
218 return maSpriteHelper.isAreaUpdateOpaque( rUpdateArea );
219 }
220
221 virtual bool isContentChanged() const override
222 {
223 typename BaseType::MutexType aGuard( BaseType::m_aMutex );
224
225 return BaseType::mbSurfaceDirty;
226 }
227
228 virtual ::basegfx::B2DPoint getPosPixel() const override
229 {
230 typename BaseType::MutexType aGuard( BaseType::m_aMutex );
231
232 return maSpriteHelper.getPosPixel();
233 }
234
235 virtual ::basegfx::B2DVector getSizePixel() const override
236 {
237 typename BaseType::MutexType aGuard( BaseType::m_aMutex );
238
239 return maSpriteHelper.getSizePixel();
240 }
241
242 virtual ::basegfx::B2DRange getUpdateArea() const override
243 {
244 typename BaseType::MutexType aGuard( BaseType::m_aMutex );
245
246 return maSpriteHelper.getUpdateArea();
247 }
248
249 virtual double getPriority() const override
250 {
251 typename BaseType::MutexType aGuard( BaseType::m_aMutex );
252
253 return maSpriteHelper.getPriority();
254 }
255
256 protected:
257 SpriteHelper maSpriteHelper;
258 };
259}
260
261/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Helper template to handle XCustomSprite method forwarding to CanvasCustomSpriteHelper.
virtual css::uno::Reference< css::rendering::XCanvas > SAL_CALL getContentCanvas() override
virtual void SAL_CALL transform(const css::geometry::AffineMatrix2D &aTransformation) override
virtual void SAL_CALL setAlpha(double alpha) override
virtual void SAL_CALL setPriority(double nPriority) override
virtual bool isAreaUpdateOpaque(const ::basegfx::B2DRange &rUpdateArea) const override
virtual void SAL_CALL clear() override
virtual ::basegfx::B2DVector getSizePixel() const override
virtual void SAL_CALL show() override
virtual void SAL_CALL hide() override
virtual void SAL_CALL clip(const css::uno::Reference< css::rendering::XPolyPolygon2D > &aClip) override
virtual void disposeThis() override
Object is being disposed.
virtual bool isContentChanged() const override
virtual void SAL_CALL move(const css::geometry::RealPoint2D &aNewPos, const css::rendering::ViewState &viewState, const css::rendering::RenderState &renderState) override
virtual css::uno::Reference< css::rendering::XCachedPrimitive > SAL_CALL drawBitmap(const css::uno::Reference< css::rendering::XBitmap > &xBitmap, const css::rendering::ViewState &viewState, const css::rendering::RenderState &renderState) override
virtual ::basegfx::B2DPoint getPosPixel() const override
virtual double getPriority() const override
virtual ::basegfx::B2DRange getUpdateArea() const override
IntegerBitmapBase< BitmapCanvasBase2< Base, CanvasHelper, Mutex, UnambiguousBase > > BaseType
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.
void verifyArgs(const Arg0 &rArg0, const char *pStr, const css::uno::Reference< css::uno::XInterface > &xIf)
constexpr double alpha[nDetails]
Base