tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / cppcanvas / source / wrapper / implsprite.cxx
blobd0b2d617944eea117bbcad959d1ed832be87c5e2
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 <osl/diagnose.h>
25 #include <utility>
27 #include "implsprite.hxx"
30 using namespace ::com::sun::star;
32 namespace cppcanvas::internal
35 ImplSprite::ImplSprite( const uno::Reference< rendering::XSpriteCanvas >& rParentCanvas,
36 uno::Reference< rendering::XSprite > rSprite,
37 ImplSpriteCanvas::TransformationArbiterSharedPtr xTransformArbiter ) :
38 mxSprite(std::move( rSprite )),
39 mpTransformArbiter(std::move( xTransformArbiter ))
41 // Avoiding ternary operator in initializer list (Solaris
42 // compiler bug, when function call and temporary is
43 // involved)
44 if( rParentCanvas.is() )
45 mxGraphicDevice = rParentCanvas->getDevice();
47 OSL_ENSURE( rParentCanvas.is() , "ImplSprite::ImplSprite(): Invalid canvas");
48 OSL_ENSURE( mxGraphicDevice.is(), "ImplSprite::ImplSprite(): Invalid graphic device");
49 OSL_ENSURE( mxSprite.is(), "ImplSprite::ImplSprite(): Invalid sprite");
50 OSL_ENSURE( mpTransformArbiter, "ImplSprite::ImplSprite(): Invalid transformation arbiter");
53 ImplSprite::~ImplSprite()
55 // hide the sprite on the canvas. If we don't hide the
56 // sprite, it will stay on the canvas forever, since the
57 // canvas naturally keeps a list of visible sprites
58 // (otherwise, it wouldn't be able to paint them
59 // autonomously)
60 if( mxSprite.is() )
61 mxSprite->hide();
64 void ImplSprite::setAlpha( const double& rAlpha )
66 OSL_ENSURE( mxSprite.is(), "ImplSprite::setAlpha(): Invalid sprite");
68 if( mxSprite.is() )
69 mxSprite->setAlpha( rAlpha );
72 void ImplSprite::movePixel( const ::basegfx::B2DPoint& rNewPos )
74 OSL_ENSURE( mxSprite.is(), "ImplSprite::movePixel(): Invalid sprite");
76 if( mxSprite.is() )
78 rendering::ViewState aViewState;
79 rendering::RenderState aRenderState;
81 ::canvas::tools::initViewState( aViewState );
82 ::canvas::tools::initRenderState( aRenderState );
84 mxSprite->move( ::basegfx::unotools::point2DFromB2DPoint( rNewPos ),
85 aViewState,
86 aRenderState );
90 void ImplSprite::move( const ::basegfx::B2DPoint& rNewPos )
92 OSL_ENSURE( mxSprite.is(), "ImplSprite::move(): Invalid sprite");
94 if( !mxSprite.is() )
95 return;
97 rendering::ViewState aViewState;
98 rendering::RenderState aRenderState;
100 ::canvas::tools::initViewState( aViewState );
101 ::canvas::tools::initRenderState( aRenderState );
103 ::canvas::tools::setViewStateTransform( aViewState,
104 mpTransformArbiter->getTransformation() );
106 mxSprite->move( ::basegfx::unotools::point2DFromB2DPoint( rNewPos ),
107 aViewState,
108 aRenderState );
111 void ImplSprite::transform( const ::basegfx::B2DHomMatrix& rMatrix )
113 OSL_ENSURE( mxSprite.is(), "ImplSprite::transform(): Invalid sprite");
115 if( mxSprite.is() )
117 geometry::AffineMatrix2D aMatrix;
119 mxSprite->transform( ::basegfx::unotools::affineMatrixFromHomMatrix( aMatrix,
120 rMatrix ) );
124 void ImplSprite::setClipPixel( const ::basegfx::B2DPolyPolygon& rClipPoly )
126 OSL_ENSURE( mxGraphicDevice.is(), "ImplSprite::setClip(): Invalid canvas");
127 OSL_ENSURE( mxSprite.is(), "ImplSprite::transform(): Invalid sprite");
129 if( mxSprite.is() && mxGraphicDevice.is() )
130 mxSprite->clip( ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon( mxGraphicDevice,
131 rClipPoly ) );
134 void ImplSprite::setClip( const ::basegfx::B2DPolyPolygon& rClipPoly )
136 OSL_ENSURE( mxGraphicDevice.is(), "ImplSprite::setClip(): Invalid canvas");
137 OSL_ENSURE( mxSprite.is(), "ImplSprite::transform(): Invalid sprite");
139 if( !(mxSprite.is() && mxGraphicDevice.is()) )
140 return;
142 ::basegfx::B2DPolyPolygon aTransformedClipPoly( rClipPoly );
144 // extract linear part of canvas view transformation (linear means:
145 // without translational components)
146 ::basegfx::B2DHomMatrix aViewTransform( mpTransformArbiter->getTransformation() );
147 aViewTransform.set( 0, 2, 0.0 );
148 aViewTransform.set( 1, 2, 0.0 );
150 // transform polygon from view to device coordinate space
151 aTransformedClipPoly.transform( aViewTransform );
153 mxSprite->clip( ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon( mxGraphicDevice,
154 aTransformedClipPoly ) );
157 void ImplSprite::setClip()
159 OSL_ENSURE( mxGraphicDevice.is(), "ImplSprite::setClip(): Invalid canvas");
160 OSL_ENSURE( mxSprite.is(), "ImplSprite::setClip(): Invalid sprite");
162 if( mxSprite.is() && mxGraphicDevice.is() )
163 mxSprite->clip( uno::Reference< rendering::XPolyPolygon2D >() );
166 void ImplSprite::show()
168 OSL_ENSURE( mxSprite.is(), "ImplSprite::show(): Invalid sprite");
170 if( mxSprite.is() )
171 mxSprite->show();
174 void ImplSprite::hide()
176 OSL_ENSURE( mxSprite.is(), "ImplSprite::hide(): Invalid sprite");
178 if( mxSprite.is() )
179 mxSprite->hide();
182 void ImplSprite::setPriority( double fPriority )
184 OSL_ENSURE( mxSprite.is(), "ImplSprite::setPriority(): Invalid sprite");
186 if( mxSprite.is() )
187 mxSprite->setPriority(fPriority);
191 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */