1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <com/sun/star/rendering/XSprite.hpp>
22 #include <com/sun/star/rendering/XAnimatedSprite.hpp>
24 #include <basegfx/tools/canvastools.hxx>
25 #include <basegfx/polygon/b2dpolypolygon.hxx>
26 #include <canvas/canvastools.hxx>
28 #include "implsprite.hxx"
31 using namespace ::com::sun::star
;
38 ImplSprite::ImplSprite( const uno::Reference
< rendering::XSpriteCanvas
>& rParentCanvas
,
39 const uno::Reference
< rendering::XSprite
>& rSprite
,
40 const ImplSpriteCanvas::TransformationArbiterSharedPtr
& rTransformArbiter
) :
44 mpTransformArbiter( rTransformArbiter
)
46 // Avoiding ternary operator in initializer list (Solaris
47 // compiler bug, when function call and temporary is
49 if( rParentCanvas
.is() )
50 mxGraphicDevice
= rParentCanvas
->getDevice();
52 OSL_ENSURE( rParentCanvas
.is() , "ImplSprite::ImplSprite(): Invalid canvas");
53 OSL_ENSURE( mxGraphicDevice
.is(), "ImplSprite::ImplSprite(): Invalid graphic device");
54 OSL_ENSURE( mxSprite
.is(), "ImplSprite::ImplSprite(): Invalid sprite");
55 OSL_ENSURE( mpTransformArbiter
.get(), "ImplSprite::ImplSprite(): Invalid transformation arbiter");
58 ImplSprite::~ImplSprite()
60 // hide the sprite on the canvas. If we don't hide the
61 // sprite, it will stay on the canvas forever, since the
62 // canvas naturally keeps a list of visible sprites
63 // (otherwise, it wouldn't be able to paint them
69 void ImplSprite::setAlpha( const double& rAlpha
)
71 OSL_ENSURE( mxSprite
.is(), "ImplSprite::setAlpha(): Invalid sprite");
74 mxSprite
->setAlpha( rAlpha
);
77 void ImplSprite::movePixel( const ::basegfx::B2DPoint
& rNewPos
)
79 OSL_ENSURE( mxSprite
.is(), "ImplSprite::movePixel(): Invalid sprite");
83 rendering::ViewState aViewState
;
84 rendering::RenderState aRenderState
;
86 ::canvas::tools::initViewState( aViewState
);
87 ::canvas::tools::initRenderState( aRenderState
);
89 mxSprite
->move( ::basegfx::unotools::point2DFromB2DPoint( rNewPos
),
95 void ImplSprite::move( const ::basegfx::B2DPoint
& rNewPos
)
97 OSL_ENSURE( mxSprite
.is(), "ImplSprite::move(): Invalid sprite");
101 rendering::ViewState aViewState
;
102 rendering::RenderState aRenderState
;
104 ::canvas::tools::initViewState( aViewState
);
105 ::canvas::tools::initRenderState( aRenderState
);
107 ::canvas::tools::setViewStateTransform( aViewState
,
108 mpTransformArbiter
->getTransformation() );
110 mxSprite
->move( ::basegfx::unotools::point2DFromB2DPoint( rNewPos
),
116 void ImplSprite::transform( const ::basegfx::B2DHomMatrix
& rMatrix
)
118 OSL_ENSURE( mxSprite
.is(), "ImplSprite::transform(): Invalid sprite");
122 geometry::AffineMatrix2D aMatrix
;
124 mxSprite
->transform( ::basegfx::unotools::affineMatrixFromHomMatrix( aMatrix
,
129 void ImplSprite::setClipPixel( const ::basegfx::B2DPolyPolygon
& rClipPoly
)
131 OSL_ENSURE( mxGraphicDevice
.is(), "ImplSprite::setClip(): Invalid canvas");
132 OSL_ENSURE( mxSprite
.is(), "ImplSprite::transform(): Invalid sprite");
134 if( mxSprite
.is() && mxGraphicDevice
.is() )
135 mxSprite
->clip( ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon( mxGraphicDevice
,
139 void ImplSprite::setClip( const ::basegfx::B2DPolyPolygon
& rClipPoly
)
141 OSL_ENSURE( mxGraphicDevice
.is(), "ImplSprite::setClip(): Invalid canvas");
142 OSL_ENSURE( mxSprite
.is(), "ImplSprite::transform(): Invalid sprite");
144 if( mxSprite
.is() && mxGraphicDevice
.is() )
146 ::basegfx::B2DPolyPolygon
aTransformedClipPoly( rClipPoly
);
148 // extract linear part of canvas view transformation (linear means:
149 // without translational components)
150 ::basegfx::B2DHomMatrix
aViewTransform( mpTransformArbiter
->getTransformation() );
151 aViewTransform
.set( 0, 2, 0.0 );
152 aViewTransform
.set( 1, 2, 0.0 );
154 // transform polygon from view to device coordinate space
155 aTransformedClipPoly
.transform( aViewTransform
);
157 mxSprite
->clip( ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon( mxGraphicDevice
,
158 aTransformedClipPoly
) );
162 void ImplSprite::setClip()
164 OSL_ENSURE( mxGraphicDevice
.is(), "ImplSprite::setClip(): Invalid canvas");
165 OSL_ENSURE( mxSprite
.is(), "ImplSprite::setClip(): Invalid sprite");
167 if( mxSprite
.is() && mxGraphicDevice
.is() )
168 mxSprite
->clip( uno::Reference
< rendering::XPolyPolygon2D
>() );
171 void ImplSprite::show()
173 OSL_ENSURE( mxSprite
.is(), "ImplSprite::show(): Invalid sprite");
179 void ImplSprite::hide()
181 OSL_ENSURE( mxSprite
.is(), "ImplSprite::hide(): Invalid sprite");
187 void ImplSprite::setPriority( double fPriority
)
189 OSL_ENSURE( mxSprite
.is(), "ImplSprite::setPriority(): Invalid sprite");
192 mxSprite
->setPriority(fPriority
);
195 uno::Reference
< rendering::XSprite
> ImplSprite::getUNOSprite() const
202 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */