Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <com/sun/star/rendering/XSprite.hpp>
31 : : #include <com/sun/star/rendering/XAnimatedSprite.hpp>
32 : :
33 : : #include <basegfx/tools/canvastools.hxx>
34 : : #include <basegfx/polygon/b2dpolypolygon.hxx>
35 : : #include <canvas/canvastools.hxx>
36 : :
37 : : #include "implsprite.hxx"
38 : :
39 : :
40 : : using namespace ::com::sun::star;
41 : :
42 : : namespace cppcanvas
43 : : {
44 : : namespace internal
45 : : {
46 : :
47 : 0 : ImplSprite::ImplSprite( const uno::Reference< rendering::XSpriteCanvas >& rParentCanvas,
48 : : const uno::Reference< rendering::XSprite >& rSprite,
49 : : const ImplSpriteCanvas::TransformationArbiterSharedPtr& rTransformArbiter ) :
50 : : mxGraphicDevice(),
51 : : mxSprite( rSprite ),
52 : : mxAnimatedSprite(),
53 [ # # ][ # # ]: 0 : mpTransformArbiter( rTransformArbiter )
54 : : {
55 : : // Avoiding ternary operator in initializer list (Solaris
56 : : // compiler bug, when function call and temporary is
57 : : // involved)
58 [ # # ][ # # ]: 0 : if( rParentCanvas.is() )
59 [ # # ][ # # ]: 0 : mxGraphicDevice = rParentCanvas->getDevice();
[ # # ][ # # ]
[ # # ][ # # ]
60 : :
61 : : OSL_ENSURE( rParentCanvas.is() , "ImplSprite::ImplSprite(): Invalid canvas");
62 : : OSL_ENSURE( mxGraphicDevice.is(), "ImplSprite::ImplSprite(): Invalid graphic device");
63 : : OSL_ENSURE( mxSprite.is(), "ImplSprite::ImplSprite(): Invalid sprite");
64 : : OSL_ENSURE( mpTransformArbiter.get(), "ImplSprite::ImplSprite(): Invalid transformation arbiter");
65 : 0 : }
66 : :
67 [ # # ][ # # ]: 0 : ImplSprite::~ImplSprite()
68 : : {
69 : : // hide the sprite on the canvas. If we don't hide the
70 : : // sprite, it will stay on the canvas forever, since the
71 : : // canvas naturally keeps a list of visible sprites
72 : : // (otherwise, it wouldn't be able to paint them
73 : : // autonomously)
74 [ # # ][ # # ]: 0 : if( mxSprite.is() )
75 [ # # ][ # # ]: 0 : mxSprite->hide();
[ # # ][ # # ]
76 [ # # ][ # # ]: 0 : }
[ # # # # ]
[ # # ][ # # ]
77 : :
78 : 0 : void ImplSprite::setAlpha( const double& rAlpha )
79 : : {
80 : : OSL_ENSURE( mxSprite.is(), "ImplSprite::setAlpha(): Invalid sprite");
81 : :
82 [ # # ]: 0 : if( mxSprite.is() )
83 : 0 : mxSprite->setAlpha( rAlpha );
84 : 0 : }
85 : :
86 : 0 : void ImplSprite::movePixel( const ::basegfx::B2DPoint& rNewPos )
87 : : {
88 : : OSL_ENSURE( mxSprite.is(), "ImplSprite::movePixel(): Invalid sprite");
89 : :
90 [ # # ]: 0 : if( mxSprite.is() )
91 : : {
92 [ # # ]: 0 : rendering::ViewState aViewState;
93 [ # # ]: 0 : rendering::RenderState aRenderState;
94 : :
95 [ # # ]: 0 : ::canvas::tools::initViewState( aViewState );
96 [ # # ]: 0 : ::canvas::tools::initRenderState( aRenderState );
97 : :
98 [ # # ]: 0 : mxSprite->move( ::basegfx::unotools::point2DFromB2DPoint( rNewPos ),
99 : : aViewState,
100 [ # # ][ # # ]: 0 : aRenderState );
[ # # ][ # # ]
101 : : }
102 : 0 : }
103 : :
104 : 0 : void ImplSprite::move( const ::basegfx::B2DPoint& rNewPos )
105 : : {
106 : : OSL_ENSURE( mxSprite.is(), "ImplSprite::move(): Invalid sprite");
107 : :
108 [ # # ]: 0 : if( mxSprite.is() )
109 : : {
110 [ # # ]: 0 : rendering::ViewState aViewState;
111 [ # # ]: 0 : rendering::RenderState aRenderState;
112 : :
113 [ # # ]: 0 : ::canvas::tools::initViewState( aViewState );
114 [ # # ]: 0 : ::canvas::tools::initRenderState( aRenderState );
115 : :
116 : : ::canvas::tools::setViewStateTransform( aViewState,
117 [ # # ][ # # ]: 0 : mpTransformArbiter->getTransformation() );
[ # # ]
118 : :
119 [ # # ]: 0 : mxSprite->move( ::basegfx::unotools::point2DFromB2DPoint( rNewPos ),
120 : : aViewState,
121 [ # # ][ # # ]: 0 : aRenderState );
[ # # ][ # # ]
122 : : }
123 : 0 : }
124 : :
125 : 0 : void ImplSprite::transform( const ::basegfx::B2DHomMatrix& rMatrix )
126 : : {
127 : : OSL_ENSURE( mxSprite.is(), "ImplSprite::transform(): Invalid sprite");
128 : :
129 [ # # ]: 0 : if( mxSprite.is() )
130 : : {
131 : 0 : geometry::AffineMatrix2D aMatrix;
132 : :
133 [ # # ]: 0 : mxSprite->transform( ::basegfx::unotools::affineMatrixFromHomMatrix( aMatrix,
134 [ # # ][ # # ]: 0 : rMatrix ) );
135 : : }
136 : 0 : }
137 : :
138 : 0 : void ImplSprite::setClipPixel( const ::basegfx::B2DPolyPolygon& rClipPoly )
139 : : {
140 : : OSL_ENSURE( mxGraphicDevice.is(), "ImplSprite::setClip(): Invalid canvas");
141 : : OSL_ENSURE( mxSprite.is(), "ImplSprite::transform(): Invalid sprite");
142 : :
143 [ # # ][ # # ]: 0 : if( mxSprite.is() && mxGraphicDevice.is() )
[ # # ]
144 : 0 : mxSprite->clip( ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon( mxGraphicDevice,
145 [ # # ]: 0 : rClipPoly ) );
146 : 0 : }
147 : :
148 : 0 : void ImplSprite::setClip( const ::basegfx::B2DPolyPolygon& rClipPoly )
149 : : {
150 : : OSL_ENSURE( mxGraphicDevice.is(), "ImplSprite::setClip(): Invalid canvas");
151 : : OSL_ENSURE( mxSprite.is(), "ImplSprite::transform(): Invalid sprite");
152 : :
153 [ # # ][ # # ]: 0 : if( mxSprite.is() && mxGraphicDevice.is() )
[ # # ]
154 : : {
155 [ # # ]: 0 : ::basegfx::B2DPolyPolygon aTransformedClipPoly( rClipPoly );
156 : :
157 : : // extract linear part of canvas view transformation (linear means:
158 : : // without translational components)
159 [ # # ]: 0 : ::basegfx::B2DHomMatrix aViewTransform( mpTransformArbiter->getTransformation() );
160 [ # # ]: 0 : aViewTransform.set( 0, 2, 0.0 );
161 [ # # ]: 0 : aViewTransform.set( 1, 2, 0.0 );
162 : :
163 : : // transform polygon from view to device coordinate space
164 [ # # ]: 0 : aTransformedClipPoly.transform( aViewTransform );
165 : :
166 [ # # ]: 0 : mxSprite->clip( ::basegfx::unotools::xPolyPolygonFromB2DPolyPolygon( mxGraphicDevice,
167 [ # # ][ # # ]: 0 : aTransformedClipPoly ) );
[ # # ][ # # ]
168 : : }
169 : 0 : }
170 : :
171 : 0 : void ImplSprite::setClip()
172 : : {
173 : : OSL_ENSURE( mxGraphicDevice.is(), "ImplSprite::setClip(): Invalid canvas");
174 : : OSL_ENSURE( mxSprite.is(), "ImplSprite::setClip(): Invalid sprite");
175 : :
176 [ # # ][ # # ]: 0 : if( mxSprite.is() && mxGraphicDevice.is() )
[ # # ]
177 [ # # ]: 0 : mxSprite->clip( uno::Reference< rendering::XPolyPolygon2D >() );
178 : 0 : }
179 : :
180 : 0 : void ImplSprite::show()
181 : : {
182 : : OSL_ENSURE( mxSprite.is(), "ImplSprite::show(): Invalid sprite");
183 : :
184 [ # # ]: 0 : if( mxSprite.is() )
185 : 0 : mxSprite->show();
186 : 0 : }
187 : :
188 : 0 : void ImplSprite::hide()
189 : : {
190 : : OSL_ENSURE( mxSprite.is(), "ImplSprite::hide(): Invalid sprite");
191 : :
192 [ # # ]: 0 : if( mxSprite.is() )
193 : 0 : mxSprite->hide();
194 : 0 : }
195 : :
196 : 0 : void ImplSprite::setPriority( double fPriority )
197 : : {
198 : : OSL_ENSURE( mxSprite.is(), "ImplSprite::setPriority(): Invalid sprite");
199 : :
200 [ # # ]: 0 : if( mxSprite.is() )
201 : 0 : mxSprite->setPriority(fPriority);
202 : 0 : }
203 : :
204 : 0 : uno::Reference< rendering::XSprite > ImplSprite::getUNOSprite() const
205 : : {
206 : 0 : return mxSprite;
207 : : }
208 : : }
209 : : }
210 : :
211 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|