Bump for 3.6-28
[LibreOffice.git] / cppcanvas / source / wrapper / implsprite.cxx
blob9e6ce32a6e34f75800ff1d487991f07d845917bb
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;
42 namespace cppcanvas
44 namespace internal
47 ImplSprite::ImplSprite( const uno::Reference< rendering::XSpriteCanvas >& rParentCanvas,
48 const uno::Reference< rendering::XSprite >& rSprite,
49 const ImplSpriteCanvas::TransformationArbiterSharedPtr& rTransformArbiter ) :
50 mxGraphicDevice(),
51 mxSprite( rSprite ),
52 mxAnimatedSprite(),
53 mpTransformArbiter( rTransformArbiter )
55 // Avoiding ternary operator in initializer list (Solaris
56 // compiler bug, when function call and temporary is
57 // involved)
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 ) :
70 mxGraphicDevice(),
71 mxSprite( uno::Reference< rendering::XSprite >(rSprite,
72 uno::UNO_QUERY) ),
73 mxAnimatedSprite( rSprite ),
74 mpTransformArbiter( rTransformArbiter )
76 // Avoiding ternary operator in initializer list (Solaris
77 // compiler bug, when function call and temporary is
78 // involved)
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
94 // autonomously)
95 if( mxSprite.is() )
96 mxSprite->hide();
99 void ImplSprite::setAlpha( const double& rAlpha )
101 OSL_ENSURE( mxSprite.is(), "ImplSprite::setAlpha(): Invalid sprite");
103 if( mxSprite.is() )
104 mxSprite->setAlpha( rAlpha );
107 void ImplSprite::movePixel( const ::basegfx::B2DPoint& rNewPos )
109 OSL_ENSURE( mxSprite.is(), "ImplSprite::movePixel(): Invalid sprite");
111 if( mxSprite.is() )
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 ),
120 aViewState,
121 aRenderState );
125 void ImplSprite::move( const ::basegfx::B2DPoint& rNewPos )
127 OSL_ENSURE( mxSprite.is(), "ImplSprite::move(): Invalid sprite");
129 if( mxSprite.is() )
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 ),
141 aViewState,
142 aRenderState );
146 void ImplSprite::transform( const ::basegfx::B2DHomMatrix& rMatrix )
148 OSL_ENSURE( mxSprite.is(), "ImplSprite::transform(): Invalid sprite");
150 if( mxSprite.is() )
152 geometry::AffineMatrix2D aMatrix;
154 mxSprite->transform( ::basegfx::unotools::affineMatrixFromHomMatrix( aMatrix,
155 rMatrix ) );
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,
166 rClipPoly ) );
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");
205 if( mxSprite.is() )
206 mxSprite->show();
209 void ImplSprite::hide()
211 OSL_ENSURE( mxSprite.is(), "ImplSprite::hide(): Invalid sprite");
213 if( mxSprite.is() )
214 mxSprite->hide();
217 void ImplSprite::setPriority( double fPriority )
219 OSL_ENSURE( mxSprite.is(), "ImplSprite::setPriority(): Invalid sprite");
221 if( mxSprite.is() )
222 mxSprite->setPriority(fPriority);
225 uno::Reference< rendering::XSprite > ImplSprite::getUNOSprite() const
227 return mxSprite;
232 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */