Line data Source code
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 :
21 : #include <com/sun/star/rendering/XSprite.hpp>
22 : #include <com/sun/star/rendering/XAnimatedSprite.hpp>
23 :
24 : #include <basegfx/tools/canvastools.hxx>
25 : #include <basegfx/polygon/b2dpolypolygon.hxx>
26 : #include <canvas/canvastools.hxx>
27 :
28 : #include "implsprite.hxx"
29 :
30 :
31 : using namespace ::com::sun::star;
32 :
33 : namespace cppcanvas
34 : {
35 : namespace internal
36 : {
37 :
38 0 : ImplSprite::ImplSprite( const uno::Reference< rendering::XSpriteCanvas >& rParentCanvas,
39 : const uno::Reference< rendering::XSprite >& rSprite,
40 : const ImplSpriteCanvas::TransformationArbiterSharedPtr& rTransformArbiter ) :
41 : mxGraphicDevice(),
42 : mxSprite( rSprite ),
43 : mxAnimatedSprite(),
44 0 : mpTransformArbiter( rTransformArbiter )
45 : {
46 : // Avoiding ternary operator in initializer list (Solaris
47 : // compiler bug, when function call and temporary is
48 : // involved)
49 0 : if( rParentCanvas.is() )
50 0 : mxGraphicDevice = rParentCanvas->getDevice();
51 :
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");
56 0 : }
57 :
58 0 : ImplSprite::~ImplSprite()
59 : {
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
64 : // autonomously)
65 0 : if( mxSprite.is() )
66 0 : mxSprite->hide();
67 0 : }
68 :
69 0 : void ImplSprite::setAlpha( const double& rAlpha )
70 : {
71 : OSL_ENSURE( mxSprite.is(), "ImplSprite::setAlpha(): Invalid sprite");
72 :
73 0 : if( mxSprite.is() )
74 0 : mxSprite->setAlpha( rAlpha );
75 0 : }
76 :
77 0 : void ImplSprite::movePixel( const ::basegfx::B2DPoint& rNewPos )
78 : {
79 : OSL_ENSURE( mxSprite.is(), "ImplSprite::movePixel(): Invalid sprite");
80 :
81 0 : if( mxSprite.is() )
82 : {
83 0 : rendering::ViewState aViewState;
84 0 : rendering::RenderState aRenderState;
85 :
86 0 : ::canvas::tools::initViewState( aViewState );
87 0 : ::canvas::tools::initRenderState( aRenderState );
88 :
89 0 : mxSprite->move( ::basegfx::unotools::point2DFromB2DPoint( rNewPos ),
90 : aViewState,
91 0 : aRenderState );
92 : }
93 0 : }
94 :
95 0 : void ImplSprite::move( const ::basegfx::B2DPoint& rNewPos )
96 : {
97 : OSL_ENSURE( mxSprite.is(), "ImplSprite::move(): Invalid sprite");
98 :
99 0 : if( mxSprite.is() )
100 : {
101 0 : rendering::ViewState aViewState;
102 0 : rendering::RenderState aRenderState;
103 :
104 0 : ::canvas::tools::initViewState( aViewState );
105 0 : ::canvas::tools::initRenderState( aRenderState );
106 :
107 : ::canvas::tools::setViewStateTransform( aViewState,
108 0 : mpTransformArbiter->getTransformation() );
109 :
110 0 : mxSprite->move( ::basegfx::unotools::point2DFromB2DPoint( rNewPos ),
111 : aViewState,
112 0 : aRenderState );
113 : }
114 0 : }
115 :
116 0 : void ImplSprite::transform( const ::basegfx::B2DHomMatrix& rMatrix )
117 : {
118 : OSL_ENSURE( mxSprite.is(), "ImplSprite::transform(): Invalid sprite");
119 :
120 0 : if( mxSprite.is() )
121 : {
122 0 : geometry::AffineMatrix2D aMatrix;
123 :
124 0 : mxSprite->transform( ::basegfx::unotools::affineMatrixFromHomMatrix( aMatrix,
125 0 : rMatrix ) );
126 : }
127 0 : }
128 :
129 0 : void ImplSprite::setClipPixel( const ::basegfx::B2DPolyPolygon& rClipPoly )
130 : {
131 : OSL_ENSURE( mxGraphicDevice.is(), "ImplSprite::setClip(): Invalid canvas");
132 : OSL_ENSURE( mxSprite.is(), "ImplSprite::transform(): Invalid sprite");
133 :
134 0 : if( mxSprite.is() && mxGraphicDevice.is() )
135 0 : mxSprite->clip( ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon( mxGraphicDevice,
136 0 : rClipPoly ) );
137 0 : }
138 :
139 0 : void ImplSprite::setClip( const ::basegfx::B2DPolyPolygon& rClipPoly )
140 : {
141 : OSL_ENSURE( mxGraphicDevice.is(), "ImplSprite::setClip(): Invalid canvas");
142 : OSL_ENSURE( mxSprite.is(), "ImplSprite::transform(): Invalid sprite");
143 :
144 0 : if( mxSprite.is() && mxGraphicDevice.is() )
145 : {
146 0 : ::basegfx::B2DPolyPolygon aTransformedClipPoly( rClipPoly );
147 :
148 : // extract linear part of canvas view transformation (linear means:
149 : // without translational components)
150 0 : ::basegfx::B2DHomMatrix aViewTransform( mpTransformArbiter->getTransformation() );
151 0 : aViewTransform.set( 0, 2, 0.0 );
152 0 : aViewTransform.set( 1, 2, 0.0 );
153 :
154 : // transform polygon from view to device coordinate space
155 0 : aTransformedClipPoly.transform( aViewTransform );
156 :
157 0 : mxSprite->clip( ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon( mxGraphicDevice,
158 0 : aTransformedClipPoly ) );
159 : }
160 0 : }
161 :
162 0 : void ImplSprite::setClip()
163 : {
164 : OSL_ENSURE( mxGraphicDevice.is(), "ImplSprite::setClip(): Invalid canvas");
165 : OSL_ENSURE( mxSprite.is(), "ImplSprite::setClip(): Invalid sprite");
166 :
167 0 : if( mxSprite.is() && mxGraphicDevice.is() )
168 0 : mxSprite->clip( uno::Reference< rendering::XPolyPolygon2D >() );
169 0 : }
170 :
171 0 : void ImplSprite::show()
172 : {
173 : OSL_ENSURE( mxSprite.is(), "ImplSprite::show(): Invalid sprite");
174 :
175 0 : if( mxSprite.is() )
176 0 : mxSprite->show();
177 0 : }
178 :
179 0 : void ImplSprite::hide()
180 : {
181 : OSL_ENSURE( mxSprite.is(), "ImplSprite::hide(): Invalid sprite");
182 :
183 0 : if( mxSprite.is() )
184 0 : mxSprite->hide();
185 0 : }
186 :
187 0 : void ImplSprite::setPriority( double fPriority )
188 : {
189 : OSL_ENSURE( mxSprite.is(), "ImplSprite::setPriority(): Invalid sprite");
190 :
191 0 : if( mxSprite.is() )
192 0 : mxSprite->setPriority(fPriority);
193 0 : }
194 :
195 0 : uno::Reference< rendering::XSprite > ImplSprite::getUNOSprite() const
196 : {
197 0 : return mxSprite;
198 : }
199 : }
200 : }
201 :
202 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|