android: Update app-specific/MIME type icons
[LibreOffice.git] / cppcanvas / source / wrapper / implsprite.cxx
blob66434f9412713e553bff8219e7ba466af2862819
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <basegfx/utils/canvastools.hxx>
22 #include <basegfx/polygon/b2dpolypolygon.hxx>
23 #include <canvas/canvastools.hxx>
24 #include <utility>
26 #include "implsprite.hxx"
29 using namespace ::com::sun::star;
31 namespace cppcanvas::internal
34 ImplSprite::ImplSprite( const uno::Reference< rendering::XSpriteCanvas >& rParentCanvas,
35 uno::Reference< rendering::XSprite > rSprite,
36 ImplSpriteCanvas::TransformationArbiterSharedPtr xTransformArbiter ) :
37 mxSprite(std::move( rSprite )),
38 mpTransformArbiter(std::move( xTransformArbiter ))
40 // Avoiding ternary operator in initializer list (Solaris
41 // compiler bug, when function call and temporary is
42 // involved)
43 if( rParentCanvas.is() )
44 mxGraphicDevice = rParentCanvas->getDevice();
46 OSL_ENSURE( rParentCanvas.is() , "ImplSprite::ImplSprite(): Invalid canvas");
47 OSL_ENSURE( mxGraphicDevice.is(), "ImplSprite::ImplSprite(): Invalid graphic device");
48 OSL_ENSURE( mxSprite.is(), "ImplSprite::ImplSprite(): Invalid sprite");
49 OSL_ENSURE( mpTransformArbiter, "ImplSprite::ImplSprite(): Invalid transformation arbiter");
52 ImplSprite::~ImplSprite()
54 // hide the sprite on the canvas. If we don't hide the
55 // sprite, it will stay on the canvas forever, since the
56 // canvas naturally keeps a list of visible sprites
57 // (otherwise, it wouldn't be able to paint them
58 // autonomously)
59 if( mxSprite.is() )
60 mxSprite->hide();
63 void ImplSprite::setAlpha( const double& rAlpha )
65 OSL_ENSURE( mxSprite.is(), "ImplSprite::setAlpha(): Invalid sprite");
67 if( mxSprite.is() )
68 mxSprite->setAlpha( rAlpha );
71 void ImplSprite::movePixel( const ::basegfx::B2DPoint& rNewPos )
73 OSL_ENSURE( mxSprite.is(), "ImplSprite::movePixel(): Invalid sprite");
75 if( mxSprite.is() )
77 rendering::ViewState aViewState;
78 rendering::RenderState aRenderState;
80 ::canvas::tools::initViewState( aViewState );
81 ::canvas::tools::initRenderState( aRenderState );
83 mxSprite->move( ::basegfx::unotools::point2DFromB2DPoint( rNewPos ),
84 aViewState,
85 aRenderState );
89 void ImplSprite::move( const ::basegfx::B2DPoint& rNewPos )
91 OSL_ENSURE( mxSprite.is(), "ImplSprite::move(): Invalid sprite");
93 if( !mxSprite.is() )
94 return;
96 rendering::ViewState aViewState;
97 rendering::RenderState aRenderState;
99 ::canvas::tools::initViewState( aViewState );
100 ::canvas::tools::initRenderState( aRenderState );
102 ::canvas::tools::setViewStateTransform( aViewState,
103 mpTransformArbiter->getTransformation() );
105 mxSprite->move( ::basegfx::unotools::point2DFromB2DPoint( rNewPos ),
106 aViewState,
107 aRenderState );
110 void ImplSprite::transform( const ::basegfx::B2DHomMatrix& rMatrix )
112 OSL_ENSURE( mxSprite.is(), "ImplSprite::transform(): Invalid sprite");
114 if( mxSprite.is() )
116 geometry::AffineMatrix2D aMatrix;
118 mxSprite->transform( ::basegfx::unotools::affineMatrixFromHomMatrix( aMatrix,
119 rMatrix ) );
123 void ImplSprite::setClipPixel( const ::basegfx::B2DPolyPolygon& rClipPoly )
125 OSL_ENSURE( mxGraphicDevice.is(), "ImplSprite::setClip(): Invalid canvas");
126 OSL_ENSURE( mxSprite.is(), "ImplSprite::transform(): Invalid sprite");
128 if( mxSprite.is() && mxGraphicDevice.is() )
129 mxSprite->clip( ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon( mxGraphicDevice,
130 rClipPoly ) );
133 void ImplSprite::setClip( const ::basegfx::B2DPolyPolygon& rClipPoly )
135 OSL_ENSURE( mxGraphicDevice.is(), "ImplSprite::setClip(): Invalid canvas");
136 OSL_ENSURE( mxSprite.is(), "ImplSprite::transform(): Invalid sprite");
138 if( !(mxSprite.is() && mxGraphicDevice.is()) )
139 return;
141 ::basegfx::B2DPolyPolygon aTransformedClipPoly( rClipPoly );
143 // extract linear part of canvas view transformation (linear means:
144 // without translational components)
145 ::basegfx::B2DHomMatrix aViewTransform( mpTransformArbiter->getTransformation() );
146 aViewTransform.set( 0, 2, 0.0 );
147 aViewTransform.set( 1, 2, 0.0 );
149 // transform polygon from view to device coordinate space
150 aTransformedClipPoly.transform( aViewTransform );
152 mxSprite->clip( ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon( mxGraphicDevice,
153 aTransformedClipPoly ) );
156 void ImplSprite::setClip()
158 OSL_ENSURE( mxGraphicDevice.is(), "ImplSprite::setClip(): Invalid canvas");
159 OSL_ENSURE( mxSprite.is(), "ImplSprite::setClip(): Invalid sprite");
161 if( mxSprite.is() && mxGraphicDevice.is() )
162 mxSprite->clip( uno::Reference< rendering::XPolyPolygon2D >() );
165 void ImplSprite::show()
167 OSL_ENSURE( mxSprite.is(), "ImplSprite::show(): Invalid sprite");
169 if( mxSprite.is() )
170 mxSprite->show();
173 void ImplSprite::hide()
175 OSL_ENSURE( mxSprite.is(), "ImplSprite::hide(): Invalid sprite");
177 if( mxSprite.is() )
178 mxSprite->hide();
181 void ImplSprite::setPriority( double fPriority )
183 OSL_ENSURE( mxSprite.is(), "ImplSprite::setPriority(): Invalid sprite");
185 if( mxSprite.is() )
186 mxSprite->setPriority(fPriority);
190 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */