1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include <com/sun/star/rendering/XSprite.hpp>
31 #include <com/sun/star/rendering/XAnimatedSprite.hpp>
33 #include <basegfx/tools/canvastools.hxx>
34 #include <basegfx/polygon/b2dpolypolygon.hxx>
35 #include <canvas/canvastools.hxx>
37 #include "implsprite.hxx"
40 using namespace ::com::sun::star
;
47 ImplSprite::ImplSprite( const uno::Reference
< rendering::XSpriteCanvas
>& rParentCanvas
,
48 const uno::Reference
< rendering::XSprite
>& rSprite
,
49 const ImplSpriteCanvas::TransformationArbiterSharedPtr
& rTransformArbiter
) :
53 mpTransformArbiter( rTransformArbiter
)
55 // Avoiding ternary operator in initializer list (Solaris
56 // compiler bug, when function call and temporary is
58 if( rParentCanvas
.is() )
59 mxGraphicDevice
= rParentCanvas
->getDevice();
61 OSL_ENSURE( rParentCanvas
.is() , "ImplSprite::ImplSprite(): Invalid canvas");
62 OSL_ENSURE( mxGraphicDevice
.is(), "ImplSprite::ImplSprite(): Invalid graphic device");
63 OSL_ENSURE( mxSprite
.is(), "ImplSprite::ImplSprite(): Invalid sprite");
64 OSL_ENSURE( mpTransformArbiter
.get(), "ImplSprite::ImplSprite(): Invalid transformation arbiter");
67 ImplSprite::ImplSprite( const uno::Reference
< rendering::XSpriteCanvas
>& rParentCanvas
,
68 const uno::Reference
< rendering::XAnimatedSprite
>& rSprite
,
69 const ImplSpriteCanvas::TransformationArbiterSharedPtr
& rTransformArbiter
) :
71 mxSprite( uno::Reference
< rendering::XSprite
>(rSprite
,
73 mxAnimatedSprite( rSprite
),
74 mpTransformArbiter( rTransformArbiter
)
76 // Avoiding ternary operator in initializer list (Solaris
77 // compiler bug, when function call and temporary is
79 if( rParentCanvas
.is() )
80 mxGraphicDevice
= rParentCanvas
->getDevice();
82 OSL_ENSURE( rParentCanvas
.is() , "ImplSprite::ImplSprite(): Invalid canvas");
83 OSL_ENSURE( mxGraphicDevice
.is(), "ImplSprite::ImplSprite(): Invalid graphic device");
84 OSL_ENSURE( mxSprite
.is(), "ImplSprite::ImplSprite(): Invalid sprite");
85 OSL_ENSURE( mpTransformArbiter
.get(), "ImplSprite::ImplSprite(): Invalid transformation arbiter");
88 ImplSprite::~ImplSprite()
90 // hide the sprite on the canvas. If we don't hide the
91 // sprite, it will stay on the canvas forever, since the
92 // canvas naturally keeps a list of visible sprites
93 // (otherwise, it wouldn't be able to paint them
99 void ImplSprite::setAlpha( const double& rAlpha
)
101 OSL_ENSURE( mxSprite
.is(), "ImplSprite::setAlpha(): Invalid sprite");
104 mxSprite
->setAlpha( rAlpha
);
107 void ImplSprite::movePixel( const ::basegfx::B2DPoint
& rNewPos
)
109 OSL_ENSURE( mxSprite
.is(), "ImplSprite::movePixel(): Invalid sprite");
113 rendering::ViewState aViewState
;
114 rendering::RenderState aRenderState
;
116 ::canvas::tools::initViewState( aViewState
);
117 ::canvas::tools::initRenderState( aRenderState
);
119 mxSprite
->move( ::basegfx::unotools::point2DFromB2DPoint( rNewPos
),
125 void ImplSprite::move( const ::basegfx::B2DPoint
& rNewPos
)
127 OSL_ENSURE( mxSprite
.is(), "ImplSprite::move(): Invalid sprite");
131 rendering::ViewState aViewState
;
132 rendering::RenderState aRenderState
;
134 ::canvas::tools::initViewState( aViewState
);
135 ::canvas::tools::initRenderState( aRenderState
);
137 ::canvas::tools::setViewStateTransform( aViewState
,
138 mpTransformArbiter
->getTransformation() );
140 mxSprite
->move( ::basegfx::unotools::point2DFromB2DPoint( rNewPos
),
146 void ImplSprite::transform( const ::basegfx::B2DHomMatrix
& rMatrix
)
148 OSL_ENSURE( mxSprite
.is(), "ImplSprite::transform(): Invalid sprite");
152 geometry::AffineMatrix2D aMatrix
;
154 mxSprite
->transform( ::basegfx::unotools::affineMatrixFromHomMatrix( aMatrix
,
159 void ImplSprite::setClipPixel( const ::basegfx::B2DPolyPolygon
& rClipPoly
)
161 OSL_ENSURE( mxGraphicDevice
.is(), "ImplSprite::setClip(): Invalid canvas");
162 OSL_ENSURE( mxSprite
.is(), "ImplSprite::transform(): Invalid sprite");
164 if( mxSprite
.is() && mxGraphicDevice
.is() )
165 mxSprite
->clip( ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon( mxGraphicDevice
,
169 void ImplSprite::setClip( const ::basegfx::B2DPolyPolygon
& rClipPoly
)
171 OSL_ENSURE( mxGraphicDevice
.is(), "ImplSprite::setClip(): Invalid canvas");
172 OSL_ENSURE( mxSprite
.is(), "ImplSprite::transform(): Invalid sprite");
174 if( mxSprite
.is() && mxGraphicDevice
.is() )
176 ::basegfx::B2DPolyPolygon
aTransformedClipPoly( rClipPoly
);
178 // extract linear part of canvas view transformation (linear means:
179 // without translational components)
180 ::basegfx::B2DHomMatrix
aViewTransform( mpTransformArbiter
->getTransformation() );
181 aViewTransform
.set( 0, 2, 0.0 );
182 aViewTransform
.set( 1, 2, 0.0 );
184 // transform polygon from view to device coordinate space
185 aTransformedClipPoly
.transform( aViewTransform
);
187 mxSprite
->clip( ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon( mxGraphicDevice
,
188 aTransformedClipPoly
) );
192 void ImplSprite::setClip()
194 OSL_ENSURE( mxGraphicDevice
.is(), "ImplSprite::setClip(): Invalid canvas");
195 OSL_ENSURE( mxSprite
.is(), "ImplSprite::setClip(): Invalid sprite");
197 if( mxSprite
.is() && mxGraphicDevice
.is() )
198 mxSprite
->clip( uno::Reference
< rendering::XPolyPolygon2D
>() );
201 void ImplSprite::show()
203 OSL_ENSURE( mxSprite
.is(), "ImplSprite::show(): Invalid sprite");
209 void ImplSprite::hide()
211 OSL_ENSURE( mxSprite
.is(), "ImplSprite::hide(): Invalid sprite");
217 void ImplSprite::setPriority( double fPriority
)
219 OSL_ENSURE( mxSprite
.is(), "ImplSprite::setPriority(): Invalid sprite");
222 mxSprite
->setPriority(fPriority
);
225 uno::Reference
< rendering::XSprite
> ImplSprite::getUNOSprite() const
232 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */