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