xref: /trunk/main/canvas/inc/canvas/base/sprite.hxx (revision 91c99ff4)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef INCLUDED_CANVAS_SPRITE_HXX
25 #define INCLUDED_CANVAS_SPRITE_HXX
26 
27 #include <rtl/ref.hxx>
28 #include <com/sun/star/lang/XComponent.hpp>
29 #include <com/sun/star/rendering/XCanvas.hpp>
30 #include <basegfx/point/b2dpoint.hxx>
31 #include <basegfx/vector/b2dsize.hxx>
32 
33 namespace basegfx
34 {
35     class B2DPoint;
36     class B2DVector;
37     class B2DRange;
38 }
39 
40 namespace canvas
41 {
42 	/* Definition of Sprite interface (as we mix with UNO here, has to
43        be XInterface - reference holders to a Sprite must be able to
44        control lifetime of reference target)
45      */
46 
47     /** Helper interface to connect SpriteCanvas with various
48         sprite implementations.
49 
50         This interface should be implemented from every sprite class,
51         as it provides essential repaint and update area facilitates.
52 
53         @derive typically, each canvas implementation will derive
54         another interface from this one, that adds rendering
55         functionality (which, of course, is impossible here in a
56         generic way)
57     */
58     class Sprite : public ::com::sun::star::lang::XComponent
59     {
60     public:
61         typedef ::rtl::Reference< Sprite > Reference;
62 
63         /** Query whether sprite update will fully cover the given area.
64 
65         	Use this method to determine whether any background
66         	content (regardless of static or sprite) needs an update
67         	before rendering this sprite.
68 
69             @return true, if sprite redraw will fully overwrite given
70             area (and thus, the background need not be redrawn
71             beforehand).
72          */
73         virtual bool isAreaUpdateOpaque( const ::basegfx::B2DRange& rUpdateArea ) const = 0;
74 
75         /** Query whether content has changed
76          */
77         virtual bool isContentChanged() const = 0;
78 
79         /** Query position of the left, top pixel of the sprite
80          */
81         virtual ::basegfx::B2DPoint getPosPixel() const = 0;
82 
83         /** Query size of the sprite in pixel.
84          */
85         virtual ::basegfx::B2DVector getSizePixel() const = 0;
86 
87         /** Get area that is currently covered by the sprite
88 
89         	This area is already adapted to clipping, alpha and
90         	transformation state of this sprite.
91          */
92         virtual ::basegfx::B2DRange getUpdateArea() const = 0;
93 
94         /** Query sprite priority
95          */
96         virtual double              getPriority() const = 0;
97     };
98 
99     /** Functor providing a StrictWeakOrdering for sprite references
100      */
101     struct SpriteComparator
102     {
operator ()canvas::SpriteComparator103         bool operator()( const Sprite::Reference& rLHS,
104                          const Sprite::Reference& rRHS )
105         {
106             const double nPrioL( rLHS->getPriority() );
107             const double nPrioR( rRHS->getPriority() );
108 
109             // if prios are equal, tie-break on ptr value
110             return nPrioL == nPrioR ? rLHS.get() < rRHS.get() : nPrioL < nPrioR;
111         }
112     };
113 }
114 
115 #endif /* INCLUDED_CANVAS_SPRITE_HXX */
116