update dev300-m58
[ooovba.git] / cppcanvas / source / wrapper / implsprite.cxx
blob1454ffd1896b6cbce1ac52fe568a41691b73eefd
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: implsprite.cxx,v $
10 * $Revision: 1.11 $
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;
46 namespace cppcanvas
48 namespace internal
51 ImplSprite::ImplSprite( const uno::Reference< rendering::XSpriteCanvas >& rParentCanvas,
52 const uno::Reference< rendering::XSprite >& rSprite,
53 const ImplSpriteCanvas::TransformationArbiterSharedPtr& rTransformArbiter ) :
54 mxGraphicDevice(),
55 mxSprite( rSprite ),
56 mxAnimatedSprite(),
57 mpTransformArbiter( rTransformArbiter )
59 // Avoiding ternary operator in initializer list (Solaris
60 // compiler bug, when function call and temporary is
61 // involved)
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 ) :
74 mxGraphicDevice(),
75 mxSprite( uno::Reference< rendering::XSprite >(rSprite,
76 uno::UNO_QUERY) ),
77 mxAnimatedSprite( rSprite ),
78 mpTransformArbiter( rTransformArbiter )
80 // Avoiding ternary operator in initializer list (Solaris
81 // compiler bug, when function call and temporary is
82 // involved)
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
98 // autonomously)
99 if( mxSprite.is() )
100 mxSprite->hide();
103 void ImplSprite::setAlpha( const double& rAlpha )
105 OSL_ENSURE( mxSprite.is(), "ImplSprite::setAlpha(): Invalid sprite");
107 if( mxSprite.is() )
108 mxSprite->setAlpha( rAlpha );
111 void ImplSprite::movePixel( const ::basegfx::B2DPoint& rNewPos )
113 OSL_ENSURE( mxSprite.is(), "ImplSprite::movePixel(): Invalid sprite");
115 if( mxSprite.is() )
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 ),
124 aViewState,
125 aRenderState );
129 void ImplSprite::move( const ::basegfx::B2DPoint& rNewPos )
131 OSL_ENSURE( mxSprite.is(), "ImplSprite::move(): Invalid sprite");
133 if( mxSprite.is() )
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 ),
145 aViewState,
146 aRenderState );
150 void ImplSprite::transform( const ::basegfx::B2DHomMatrix& rMatrix )
152 OSL_ENSURE( mxSprite.is(), "ImplSprite::transform(): Invalid sprite");
154 if( mxSprite.is() )
156 geometry::AffineMatrix2D aMatrix;
158 mxSprite->transform( ::basegfx::unotools::affineMatrixFromHomMatrix( aMatrix,
159 rMatrix ) );
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,
170 rClipPoly ) );
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");
209 if( mxSprite.is() )
210 mxSprite->show();
213 void ImplSprite::hide()
215 OSL_ENSURE( mxSprite.is(), "ImplSprite::hide(): Invalid sprite");
217 if( mxSprite.is() )
218 mxSprite->hide();
221 void ImplSprite::setPriority( double fPriority )
223 OSL_ENSURE( mxSprite.is(), "ImplSprite::setPriority(): Invalid sprite");
225 if( mxSprite.is() )
226 mxSprite->setPriority(fPriority);
229 uno::Reference< rendering::XSprite > ImplSprite::getUNOSprite() const
231 return mxSprite;
234 uno::Reference< rendering::XGraphicDevice > ImplSprite::getGraphicDevice() const
236 return mxGraphicDevice;