LibreOffice Module cppcanvas (master) 1
implsprite.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20
24#include <utility>
25
26#include "implsprite.hxx"
27
28
29using namespace ::com::sun::star;
30
31namespace cppcanvas::internal
32{
33
34 ImplSprite::ImplSprite( const uno::Reference< rendering::XSpriteCanvas >& rParentCanvas,
35 uno::Reference< rendering::XSprite > rSprite,
37 mxSprite(std::move( rSprite )),
38 mpTransformArbiter(std::move( xTransformArbiter ))
39 {
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();
45
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");
50 }
51
52 ImplSprite::~ImplSprite()
53 {
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();
61 }
62
63 void ImplSprite::setAlpha( const double& rAlpha )
64 {
65 OSL_ENSURE( mxSprite.is(), "ImplSprite::setAlpha(): Invalid sprite");
66
67 if( mxSprite.is() )
68 mxSprite->setAlpha( rAlpha );
69 }
70
71 void ImplSprite::movePixel( const ::basegfx::B2DPoint& rNewPos )
72 {
73 OSL_ENSURE( mxSprite.is(), "ImplSprite::movePixel(): Invalid sprite");
74
75 if( mxSprite.is() )
76 {
77 rendering::ViewState aViewState;
78 rendering::RenderState aRenderState;
79
80 ::canvas::tools::initViewState( aViewState );
82
83 mxSprite->move( ::basegfx::unotools::point2DFromB2DPoint( rNewPos ),
84 aViewState,
85 aRenderState );
86 }
87 }
88
89 void ImplSprite::move( const ::basegfx::B2DPoint& rNewPos )
90 {
91 OSL_ENSURE( mxSprite.is(), "ImplSprite::move(): Invalid sprite");
92
93 if( !mxSprite.is() )
94 return;
95
96 rendering::ViewState aViewState;
97 rendering::RenderState aRenderState;
98
99 ::canvas::tools::initViewState( aViewState );
100 ::canvas::tools::initRenderState( aRenderState );
101
102 ::canvas::tools::setViewStateTransform( aViewState,
103 mpTransformArbiter->getTransformation() );
104
105 mxSprite->move( ::basegfx::unotools::point2DFromB2DPoint( rNewPos ),
106 aViewState,
107 aRenderState );
108 }
109
110 void ImplSprite::transform( const ::basegfx::B2DHomMatrix& rMatrix )
111 {
112 OSL_ENSURE( mxSprite.is(), "ImplSprite::transform(): Invalid sprite");
113
114 if( mxSprite.is() )
115 {
116 geometry::AffineMatrix2D aMatrix;
117
118 mxSprite->transform( ::basegfx::unotools::affineMatrixFromHomMatrix( aMatrix,
119 rMatrix ) );
120 }
121 }
122
123 void ImplSprite::setClipPixel( const ::basegfx::B2DPolyPolygon& rClipPoly )
124 {
125 OSL_ENSURE( mxGraphicDevice.is(), "ImplSprite::setClip(): Invalid canvas");
126 OSL_ENSURE( mxSprite.is(), "ImplSprite::transform(): Invalid sprite");
127
128 if( mxSprite.is() && mxGraphicDevice.is() )
129 mxSprite->clip( ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon( mxGraphicDevice,
130 rClipPoly ) );
131 }
132
133 void ImplSprite::setClip( const ::basegfx::B2DPolyPolygon& rClipPoly )
134 {
135 OSL_ENSURE( mxGraphicDevice.is(), "ImplSprite::setClip(): Invalid canvas");
136 OSL_ENSURE( mxSprite.is(), "ImplSprite::transform(): Invalid sprite");
137
138 if( !(mxSprite.is() && mxGraphicDevice.is()) )
139 return;
140
141 ::basegfx::B2DPolyPolygon aTransformedClipPoly( rClipPoly );
142
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 );
148
149 // transform polygon from view to device coordinate space
150 aTransformedClipPoly.transform( aViewTransform );
151
152 mxSprite->clip( ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon( mxGraphicDevice,
153 aTransformedClipPoly ) );
154 }
155
156 void ImplSprite::setClip()
157 {
158 OSL_ENSURE( mxGraphicDevice.is(), "ImplSprite::setClip(): Invalid canvas");
159 OSL_ENSURE( mxSprite.is(), "ImplSprite::setClip(): Invalid sprite");
160
161 if( mxSprite.is() && mxGraphicDevice.is() )
162 mxSprite->clip( uno::Reference< rendering::XPolyPolygon2D >() );
163 }
164
165 void ImplSprite::show()
166 {
167 OSL_ENSURE( mxSprite.is(), "ImplSprite::show(): Invalid sprite");
168
169 if( mxSprite.is() )
170 mxSprite->show();
171 }
172
173 void ImplSprite::hide()
174 {
175 OSL_ENSURE( mxSprite.is(), "ImplSprite::hide(): Invalid sprite");
176
177 if( mxSprite.is() )
178 mxSprite->hide();
179 }
180
181 void ImplSprite::setPriority( double fPriority )
182 {
183 OSL_ENSURE( mxSprite.is(), "ImplSprite::setPriority(): Invalid sprite");
184
185 if( mxSprite.is() )
186 mxSprite->setPriority(fPriority);
187 }
188}
189
190/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< rendering::XCustomSprite > mxSprite
void set(sal_uInt16 nRow, sal_uInt16 nColumn, double fValue)
void transform(const basegfx::B2DHomMatrix &rMatrix)
std::shared_ptr< TransformationArbiter > TransformationArbiterSharedPtr
ImplSprite(const css::uno::Reference< css::rendering::XSpriteCanvas > &rParentCanvas, css::uno::Reference< css::rendering::XSprite > xSprite, ImplSpriteCanvas::TransformationArbiterSharedPtr xTransformArbiter)
void initRenderState(rendering::RenderState &renderState, const ::cppcanvas::internal::OutDevState &outdevState)
Definition: mtftools.cxx:42