summaryrefslogtreecommitdiff
path: root/canvas/inc/canvas/base/canvascustomspritehelper.hxx
blob: 222be8503ac6b00543f0e0c63be31e5fadf97a82 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2000, 2010 Oracle and/or its affiliates.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

#ifndef INCLUDED_CANVAS_CANVASCUSTOMSPRITEHELPER_HXX
#define INCLUDED_CANVAS_CANVASCUSTOMSPRITEHELPER_HXX

#include <com/sun/star/rendering/XCustomSprite.hpp>
#include <com/sun/star/rendering/XPolyPolygon2D.hpp>
#include <basegfx/point/b2dpoint.hxx>
#include <basegfx/vector/b2dvector.hxx>
#include <basegfx/range/b2drange.hxx>
#include <basegfx/matrix/b2dhommatrix.hxx>
#include <canvas/base/spritesurface.hxx>


namespace canvas
{
    /* Definition of CanvasCustomSpriteHelper class */

    /** Base class for an XSprite helper implementation - to be used
        in concert with CanvasCustomSpriteBase
     */
    class CanvasCustomSpriteHelper
    {
    public:
        CanvasCustomSpriteHelper();
        virtual ~CanvasCustomSpriteHelper() {}

        /** Init helper

            @param rSpriteSize
            Requested size of the sprite, as passed to the
            XSpriteCanvas::createCustomSprite() method

            @param rOwningSpriteCanvas
            The XSpriteCanvas this sprite is displayed on
         */
        void init( const ::com::sun::star::geometry::RealSize2D&    rSpriteSize,
                   const SpriteSurface::Reference&                  rOwningSpriteCanvas );

        /** Object is being disposed, release all internal references

            @derive when overriding this method in derived classes,
            <em>always</em> call the base class' method!
         */
        void disposing();

        // XCanvas
        /// need  to call this method for XCanvas::clear(), for opacity tracking
        void clearingContent( const Sprite::Reference& rSprite );

        /// need to call this method for XCanvas::drawBitmap(), for opacity tracking
        void checkDrawBitmap( const Sprite::Reference&                                                          rSprite,
                              const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XBitmap >&   xBitmap,
                              const ::com::sun::star::rendering::ViewState&                                     viewState,
                              const ::com::sun::star::rendering::RenderState&                                   renderState );

        // XSprite
        void setAlpha( const Sprite::Reference& rSprite,
                       double                   alpha );
        void move( const Sprite::Reference&                         rSprite,
                   const ::com::sun::star::geometry::RealPoint2D&   aNewPos,
                   const ::com::sun::star::rendering::ViewState&    viewState,
                   const ::com::sun::star::rendering::RenderState&  renderState );
        void transform( const Sprite::Reference&                            rSprite,
                       const ::com::sun::star::geometry::AffineMatrix2D&    aTransformation );
        void clip( const Sprite::Reference&                                                                 rSprite,
                   const ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D >&   aClip );
        void setPriority( const Sprite::Reference&  rSprite,
                          double                    nPriority );
        void show( const Sprite::Reference& rSprite );
        void hide( const Sprite::Reference& rSprite );

        // Sprite
        bool isAreaUpdateOpaque( const ::basegfx::B2DRange& rUpdateArea ) const;
        ::basegfx::B2DPoint  getPosPixel() const;
        ::basegfx::B2DVector getSizePixel() const;
        ::basegfx::B2DRange  getUpdateArea() const;
        double               getPriority() const;

        // redraw must be implemented by derived - non sensible default implementation
        // void redraw( const Sprite::Reference& rSprite,
        //              const ::basegfx::B2DPoint& rPos ) const;


        // Helper methods for derived classes
        // ----------------------------------

        /// Calc sprite update area from given raw sprite bounds
        ::basegfx::B2DRange getUpdateArea( const ::basegfx::B2DRange& rUntransformedSpriteBounds ) const;

        /// Calc update area for unclipped sprite content
        ::basegfx::B2DRange getFullSpriteRect() const;

        /** Returns true, if sprite content bitmap is fully opaque.

            This does not take clipping or transformation into
            account, but only denotes that the sprite bitmap's alpha
            channel is all 1.0
         */
        bool isContentFullyOpaque() const { return mbIsContentFullyOpaque; }

        /// Returns true, if transformation has changed since last transformUpdated() call
        bool hasAlphaChanged() const { return mbAlphaDirty; }

        /// Returns true, if transformation has changed since last transformUpdated() call
        bool hasPositionChanged() const { return mbPositionDirty; }

        /// Returns true, if transformation has changed since last transformUpdated() call
        bool hasTransformChanged() const { return mbTransformDirty; }

        /// Returns true, if transformation has changed since last transformUpdated() call
        bool hasClipChanged() const { return mbClipDirty; }

        /// Returns true, if transformation has changed since last transformUpdated() call
        bool hasPrioChanged() const { return mbPrioDirty; }

        /// Returns true, if transformation has changed since last transformUpdated() call
        bool hasVisibilityChanged() const { return mbVisibilityDirty; }

        /// Retrieve current alpha value
        double getAlpha() const { return mfAlpha; }

        /// Retrieve current clip
        const ::com::sun::star::uno::Reference<
            ::com::sun::star::rendering::XPolyPolygon2D >& getClip() const { return mxClipPoly; }

        const ::basegfx::B2DHomMatrix& getTransformation() const { return maTransform; }

        /// Retrieve current activation state
        bool isActive() const { return mbActive; }

    protected:
        /** Notifies that caller is again in sync with current alph

            const, but modifies state visible to derived
            classes. beware of passing this information to the
            outside!
         */
        void alphaUpdated() const { mbAlphaDirty=false; }

        /** Notifies that caller is again in sync with current position

            const, but modifies state visible to derived
            classes. beware of passing this information to the
            outside!
         */
        void positionUpdated() const { mbPositionDirty=false; }

        /** Notifies that caller is again in sync with current transformation

            const, but modifies state visible to derived
            classes. beware of passing this information to the
            outside!
         */
        void transformUpdated() const { mbTransformDirty=false; }

        /** Notifies that caller is again in sync with current clip

            const, but modifies state visible to derived
            classes. beware of passing this information to the
            outside!
         */
        void clipUpdated() const { mbClipDirty=false; }

        /** Notifies that caller is again in sync with current priority

            const, but modifies state visible to derived
            classes. beware of passing this information to the
            outside!
         */
        void prioUpdated() const { mbPrioDirty=false; }

        /** Notifies that caller is again in sync with current visibility

            const, but modifies state visible to derived
            classes. beware of passing this information to the
            outside!
         */
        void visibilityUpdated() const { mbVisibilityDirty=false; }

    private:
        CanvasCustomSpriteHelper( const CanvasCustomSpriteHelper& );
        CanvasCustomSpriteHelper& operator=( const CanvasCustomSpriteHelper& );

        /** Called to convert an API polygon to a basegfx polygon

            @derive Needs to be provided by backend-specific code
         */
        virtual ::basegfx::B2DPolyPolygon polyPolygonFromXPolyPolygon2D(
            ::com::sun::star::uno::Reference< ::com::sun::star::rendering::XPolyPolygon2D >& xPoly ) const = 0;

        /** Update clip information from current state

            This method recomputes the maCurrClipBounds and
            mbIsCurrClipRectangle members from the current clip and
            transformation. IFF the clip changed from rectangular to
            rectangular again, this method issues a sequence of
            optimized SpriteSurface::updateSprite() calls.

            @return true, if SpriteSurface::updateSprite() was already
            called within this method.
         */
        bool updateClipState( const Sprite::Reference& rSprite );

        // --------------------------------------------------------------------

        /// Owning sprite canvas
        SpriteSurface::Reference                            mpSpriteCanvas;

        /** Currently active clip area.

            This member is either empty, denoting that the current
            clip shows the full sprite content, or contains a
            rectangular subarea of the sprite, outside of which
            the sprite content is fully clipped.

            @see mbIsCurrClipRectangle
         */
        ::basegfx::B2DRange                                 maCurrClipBounds;

        // sprite state
        ::basegfx::B2DPoint                                 maPosition;
        ::basegfx::B2DVector                                maSize;
        ::basegfx::B2DHomMatrix                             maTransform;
        ::com::sun::star::uno::Reference<
              ::com::sun::star::rendering::XPolyPolygon2D > mxClipPoly;
        double                                              mfPriority;
        double                                              mfAlpha;
        bool                                                mbActive; // true, if not hidden

        /** If true, denotes that the current sprite clip is a true
            rectangle, i.e. maCurrClipBounds <em>exactly</em>
            describes the visible area of the sprite.

            @see maCurrClipBounds
         */
        bool                                                mbIsCurrClipRectangle;

        /** Redraw speedup.

            When true, this flag denotes that the current sprite
            content is fully opaque, thus, that blits to the screen do
            neither have to take alpha into account, nor prepare any
            background for the sprite area.
         */
        mutable bool                                        mbIsContentFullyOpaque;

        /// True, iff mfAlpha has changed
        mutable bool                                        mbAlphaDirty;

        /// True, iff maPosition has changed
        mutable bool                                        mbPositionDirty;

        /// True, iff maTransform has changed
        mutable bool                                        mbTransformDirty;

        /// True, iff mxClipPoly has changed
        mutable bool                                        mbClipDirty;

        /// True, iff mnPriority has changed
        mutable bool                                        mbPrioDirty;

        /// True, iff mbActive has changed
        mutable bool                                        mbVisibilityDirty;
    };
}

#endif /* INCLUDED_CANVAS_CANVASCUSTOMSPRITEHELPER_HXX */

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */