1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: implsprite.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_cppcanvas.hxx"
34 #include <com/sun/star/rendering/XSprite.hpp>
35 #include <com/sun/star/rendering/XAnimatedSprite.hpp>
37 #include <basegfx/tools/canvastools.hxx>
38 #include <basegfx/polygon/b2dpolypolygon.hxx>
39 #include <canvas/canvastools.hxx>
41 #include "implsprite.hxx"
44 using namespace ::com::sun::star
;
51 ImplSprite::ImplSprite( const uno::Reference
< rendering::XSpriteCanvas
>& rParentCanvas
,
52 const uno::Reference
< rendering::XSprite
>& rSprite
,
53 const ImplSpriteCanvas::TransformationArbiterSharedPtr
& rTransformArbiter
) :
57 mpTransformArbiter( rTransformArbiter
)
59 // Avoiding ternary operator in initializer list (Solaris
60 // compiler bug, when function call and temporary is
62 if( rParentCanvas
.is() )
63 mxGraphicDevice
= rParentCanvas
->getDevice();
65 OSL_ENSURE( rParentCanvas
.is() , "ImplSprite::ImplSprite(): Invalid canvas");
66 OSL_ENSURE( mxGraphicDevice
.is(), "ImplSprite::ImplSprite(): Invalid graphic device");
67 OSL_ENSURE( mxSprite
.is(), "ImplSprite::ImplSprite(): Invalid sprite");
68 OSL_ENSURE( mpTransformArbiter
.get(), "ImplSprite::ImplSprite(): Invalid transformation arbiter");
71 ImplSprite::ImplSprite( const uno::Reference
< rendering::XSpriteCanvas
>& rParentCanvas
,
72 const uno::Reference
< rendering::XAnimatedSprite
>& rSprite
,
73 const ImplSpriteCanvas::TransformationArbiterSharedPtr
& rTransformArbiter
) :
75 mxSprite( uno::Reference
< rendering::XSprite
>(rSprite
,
77 mxAnimatedSprite( rSprite
),
78 mpTransformArbiter( rTransformArbiter
)
80 // Avoiding ternary operator in initializer list (Solaris
81 // compiler bug, when function call and temporary is
83 if( rParentCanvas
.is() )
84 mxGraphicDevice
= rParentCanvas
->getDevice();
86 OSL_ENSURE( rParentCanvas
.is() , "ImplSprite::ImplSprite(): Invalid canvas");
87 OSL_ENSURE( mxGraphicDevice
.is(), "ImplSprite::ImplSprite(): Invalid graphic device");
88 OSL_ENSURE( mxSprite
.is(), "ImplSprite::ImplSprite(): Invalid sprite");
89 OSL_ENSURE( mpTransformArbiter
.get(), "ImplSprite::ImplSprite(): Invalid transformation arbiter");
92 ImplSprite::~ImplSprite()
94 // hide the sprite on the canvas. If we don't hide the
95 // sprite, it will stay on the canvas forever, since the
96 // canvas naturally keeps a list of visible sprites
97 // (otherwise, it wouldn't be able to paint them
103 void ImplSprite::setAlpha( const double& rAlpha
)
105 OSL_ENSURE( mxSprite
.is(), "ImplSprite::setAlpha(): Invalid sprite");
108 mxSprite
->setAlpha( rAlpha
);
111 void ImplSprite::movePixel( const ::basegfx::B2DPoint
& rNewPos
)
113 OSL_ENSURE( mxSprite
.is(), "ImplSprite::movePixel(): Invalid sprite");
117 rendering::ViewState aViewState
;
118 rendering::RenderState aRenderState
;
120 ::canvas::tools::initViewState( aViewState
);
121 ::canvas::tools::initRenderState( aRenderState
);
123 mxSprite
->move( ::basegfx::unotools::point2DFromB2DPoint( rNewPos
),
129 void ImplSprite::move( const ::basegfx::B2DPoint
& rNewPos
)
131 OSL_ENSURE( mxSprite
.is(), "ImplSprite::move(): Invalid sprite");
135 rendering::ViewState aViewState
;
136 rendering::RenderState aRenderState
;
138 ::canvas::tools::initViewState( aViewState
);
139 ::canvas::tools::initRenderState( aRenderState
);
141 ::canvas::tools::setViewStateTransform( aViewState
,
142 mpTransformArbiter
->getTransformation() );
144 mxSprite
->move( ::basegfx::unotools::point2DFromB2DPoint( rNewPos
),
150 void ImplSprite::transform( const ::basegfx::B2DHomMatrix
& rMatrix
)
152 OSL_ENSURE( mxSprite
.is(), "ImplSprite::transform(): Invalid sprite");
156 geometry::AffineMatrix2D aMatrix
;
158 mxSprite
->transform( ::basegfx::unotools::affineMatrixFromHomMatrix( aMatrix
,
163 void ImplSprite::setClipPixel( const ::basegfx::B2DPolyPolygon
& rClipPoly
)
165 OSL_ENSURE( mxGraphicDevice
.is(), "ImplSprite::setClip(): Invalid canvas");
166 OSL_ENSURE( mxSprite
.is(), "ImplSprite::transform(): Invalid sprite");
168 if( mxSprite
.is() && mxGraphicDevice
.is() )
169 mxSprite
->clip( ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon( mxGraphicDevice
,
173 void ImplSprite::setClip( const ::basegfx::B2DPolyPolygon
& rClipPoly
)
175 OSL_ENSURE( mxGraphicDevice
.is(), "ImplSprite::setClip(): Invalid canvas");
176 OSL_ENSURE( mxSprite
.is(), "ImplSprite::transform(): Invalid sprite");
178 if( mxSprite
.is() && mxGraphicDevice
.is() )
180 ::basegfx::B2DPolyPolygon
aTransformedClipPoly( rClipPoly
);
182 // extract linear part of canvas view transformation (linear means:
183 // without translational components)
184 ::basegfx::B2DHomMatrix
aViewTransform( mpTransformArbiter
->getTransformation() );
185 aViewTransform
.set( 0, 2, 0.0 );
186 aViewTransform
.set( 1, 2, 0.0 );
188 // transform polygon from view to device coordinate space
189 aTransformedClipPoly
.transform( aViewTransform
);
191 mxSprite
->clip( ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon( mxGraphicDevice
,
192 aTransformedClipPoly
) );
196 void ImplSprite::setClip()
198 OSL_ENSURE( mxGraphicDevice
.is(), "ImplSprite::setClip(): Invalid canvas");
199 OSL_ENSURE( mxSprite
.is(), "ImplSprite::setClip(): Invalid sprite");
201 if( mxSprite
.is() && mxGraphicDevice
.is() )
202 mxSprite
->clip( uno::Reference
< rendering::XPolyPolygon2D
>() );
205 void ImplSprite::show()
207 OSL_ENSURE( mxSprite
.is(), "ImplSprite::show(): Invalid sprite");
213 void ImplSprite::hide()
215 OSL_ENSURE( mxSprite
.is(), "ImplSprite::hide(): Invalid sprite");
221 void ImplSprite::setPriority( double fPriority
)
223 OSL_ENSURE( mxSprite
.is(), "ImplSprite::setPriority(): Invalid sprite");
226 mxSprite
->setPriority(fPriority
);
229 uno::Reference
< rendering::XSprite
> ImplSprite::getUNOSprite() const
234 uno::Reference
< rendering::XGraphicDevice
> ImplSprite::getGraphicDevice() const
236 return mxGraphicDevice
;