LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / canvas / inc / base / canvascustomspritehelper.hxx
blob32fcf6452a9969ca7b459998fe6b1470b8f1d20b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #pragma once
22 #include <basegfx/matrix/b2dhommatrix.hxx>
23 #include <basegfx/point/b2dpoint.hxx>
24 #include <basegfx/polygon/b2dpolypolygon.hxx>
25 #include <basegfx/range/b2drange.hxx>
26 #include <basegfx/vector/b2dvector.hxx>
27 #include <base/spritesurface.hxx>
28 #include <canvas/canvastoolsdllapi.h>
30 namespace com::sun::star::geometry { struct AffineMatrix2D; }
31 namespace com::sun::star::geometry { struct RealPoint2D; }
32 namespace com::sun::star::geometry { struct RealSize2D; }
33 namespace com::sun::star::rendering { class XBitmap; }
34 namespace com::sun::star::rendering { class XPolyPolygon2D; }
35 namespace com::sun::star::rendering { struct RenderState; }
36 namespace com::sun::star::rendering { struct ViewState; }
39 namespace canvas
41 /* Definition of CanvasCustomSpriteHelper class */
43 /** Base class for an XSprite helper implementation - to be used
44 in concert with CanvasCustomSpriteBase
46 class CANVASTOOLS_DLLPUBLIC CanvasCustomSpriteHelper
48 public:
49 CanvasCustomSpriteHelper();
50 virtual ~CanvasCustomSpriteHelper() {}
52 /** Init helper
54 @param rSpriteSize
55 Requested size of the sprite, as passed to the
56 XSpriteCanvas::createCustomSprite() method
58 @param rOwningSpriteCanvas
59 The XSpriteCanvas this sprite is displayed on
61 void init( const css::geometry::RealSize2D& rSpriteSize,
62 const SpriteSurface::Reference& rOwningSpriteCanvas );
64 /** Object is being disposed, release all internal references
66 @derive when overriding this method in derived classes,
67 <em>always</em> call the base class' method!
69 void disposing();
71 // XCanvas
72 /// need to call this method for XCanvas::clear(), for opacity tracking
73 void clearingContent( const Sprite::Reference& rSprite );
75 /// need to call this method for XCanvas::drawBitmap(), for opacity tracking
76 void checkDrawBitmap( const Sprite::Reference& rSprite,
77 const css::uno::Reference< css::rendering::XBitmap >& xBitmap,
78 const css::rendering::ViewState& viewState,
79 const css::rendering::RenderState& renderState );
81 // XSprite
82 void setAlpha( const Sprite::Reference& rSprite,
83 double alpha );
84 void move( const Sprite::Reference& rSprite,
85 const css::geometry::RealPoint2D& aNewPos,
86 const css::rendering::ViewState& viewState,
87 const css::rendering::RenderState& renderState );
88 void transform( const Sprite::Reference& rSprite,
89 const css::geometry::AffineMatrix2D& aTransformation );
90 void clip( const Sprite::Reference& rSprite,
91 const css::uno::Reference< css::rendering::XPolyPolygon2D >& aClip );
92 void setPriority( const Sprite::Reference& rSprite,
93 double nPriority );
94 void show( const Sprite::Reference& rSprite );
95 void hide( const Sprite::Reference& rSprite );
97 // Sprite
98 bool isAreaUpdateOpaque( const ::basegfx::B2DRange& rUpdateArea ) const;
99 const ::basegfx::B2DPoint& getPosPixel() const { return maPosition; }
100 const ::basegfx::B2DVector& getSizePixel() const { return maSize; }
101 ::basegfx::B2DRange getUpdateArea() const;
102 double getPriority() const { return mfPriority; }
104 // redraw must be implemented by derived - non sensible default implementation
105 // void redraw( const Sprite::Reference& rSprite,
106 // const ::basegfx::B2DPoint& rPos ) const;
109 // Helper methods for derived classes
112 /// Calc sprite update area from given raw sprite bounds
113 ::basegfx::B2DRange getUpdateArea( const ::basegfx::B2DRange& rUntransformedSpriteBounds ) const;
115 /** Returns true, if sprite content bitmap is fully opaque.
117 This does not take clipping or transformation into
118 account, but only denotes that the sprite bitmap's alpha
119 channel is all 1.0
121 bool isContentFullyOpaque() const { return mbIsContentFullyOpaque; }
123 /// Returns true, if transformation has changed since last transformUpdated() call
124 bool hasTransformChanged() const { return mbTransformDirty; }
126 /// Retrieve current alpha value
127 double getAlpha() const { return mfAlpha; }
129 /// Retrieve current clip
130 const css::uno::Reference<
131 css::rendering::XPolyPolygon2D >& getClip() const { return mxClipPoly; }
133 const ::basegfx::B2DHomMatrix& getTransformation() const { return maTransform; }
135 /// Retrieve current activation state
136 bool isActive() const { return mbActive; }
138 protected:
139 /** Notifies that caller is again in sync with current transformation
141 const, but modifies state visible to derived
142 classes. beware of passing this information to the
143 outside!
145 void transformUpdated() const { mbTransformDirty=false; }
147 private:
148 CanvasCustomSpriteHelper( const CanvasCustomSpriteHelper& ) = delete;
149 CanvasCustomSpriteHelper& operator=( const CanvasCustomSpriteHelper& ) = delete;
151 /** Called to convert an API polygon to a basegfx polygon
153 @derive Needs to be provided by backend-specific code
155 virtual ::basegfx::B2DPolyPolygon polyPolygonFromXPolyPolygon2D(
156 css::uno::Reference< css::rendering::XPolyPolygon2D >& xPoly ) const = 0;
158 /** Update clip information from current state
160 This method recomputes the maCurrClipBounds and
161 mbIsCurrClipRectangle members from the current clip and
162 transformation. IFF the clip changed from rectangular to
163 rectangular again, this method issues a sequence of
164 optimized SpriteSurface::updateSprite() calls.
166 @return true, if SpriteSurface::updateSprite() was already
167 called within this method.
169 bool updateClipState( const Sprite::Reference& rSprite );
172 /// Owning sprite canvas
173 SpriteSurface::Reference mpSpriteCanvas;
175 /** Currently active clip area.
177 This member is either empty, denoting that the current
178 clip shows the full sprite content, or contains a
179 rectangular subarea of the sprite, outside of which
180 the sprite content is fully clipped.
182 @see mbIsCurrClipRectangle
184 ::basegfx::B2DRange maCurrClipBounds;
186 // sprite state
187 ::basegfx::B2DPoint maPosition;
188 ::basegfx::B2DVector maSize;
189 ::basegfx::B2DHomMatrix maTransform;
190 css::uno::Reference< css::rendering::XPolyPolygon2D > mxClipPoly;
191 double mfPriority;
192 double mfAlpha;
193 bool mbActive; // true, if not hidden
195 /** If true, denotes that the current sprite clip is a true
196 rectangle, i.e. maCurrClipBounds <em>exactly</em>
197 describes the visible area of the sprite.
199 @see maCurrClipBounds
201 bool mbIsCurrClipRectangle;
203 /** Redraw speedup.
205 When true, this flag denotes that the current sprite
206 content is fully opaque, thus, that blits to the screen do
207 neither have to take alpha into account, nor prepare any
208 background for the sprite area.
210 mutable bool mbIsContentFullyOpaque;
212 /// True, iff maTransform has changed
213 mutable bool mbTransformDirty;
217 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */