1*c142477cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*c142477cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*c142477cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*c142477cSAndrew Rist  * distributed with this work for additional information
6*c142477cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*c142477cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*c142477cSAndrew Rist  * "License"); you may not use this file except in compliance
9*c142477cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*c142477cSAndrew Rist  *
11*c142477cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*c142477cSAndrew Rist  *
13*c142477cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*c142477cSAndrew Rist  * software distributed under the License is distributed on an
15*c142477cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*c142477cSAndrew Rist  * KIND, either express or implied.  See the License for the
17*c142477cSAndrew Rist  * specific language governing permissions and limitations
18*c142477cSAndrew Rist  * under the License.
19*c142477cSAndrew Rist  *
20*c142477cSAndrew Rist  *************************************************************/
21*c142477cSAndrew Rist 
22*c142477cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sdext.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "PresenterSprite.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp>
30cdf0e10cSrcweir #include <com/sun/star/rendering/CompositeOperation.hpp>
31cdf0e10cSrcweir #include <com/sun/star/rendering/RenderState.hpp>
32cdf0e10cSrcweir #include <com/sun/star/rendering/ViewState.hpp>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir using namespace ::com::sun::star;
35cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
36cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY;
37cdf0e10cSrcweir 
38cdf0e10cSrcweir namespace sdext { namespace presenter {
39cdf0e10cSrcweir 
PresenterSprite(void)40cdf0e10cSrcweir PresenterSprite::PresenterSprite (void)
41cdf0e10cSrcweir     : mxSpriteFactory(),
42cdf0e10cSrcweir       mxSprite(),
43cdf0e10cSrcweir       maSize(0,0),
44cdf0e10cSrcweir       maLocation(0,0),
45cdf0e10cSrcweir       maTransform(1,0,0, 0,1,0),
46cdf0e10cSrcweir       mbIsVisible(false),
47cdf0e10cSrcweir       mnPriority(0),
48cdf0e10cSrcweir       mnAlpha(1.0)
49cdf0e10cSrcweir {
50cdf0e10cSrcweir }
51cdf0e10cSrcweir 
52cdf0e10cSrcweir 
53cdf0e10cSrcweir 
54cdf0e10cSrcweir 
~PresenterSprite(void)55cdf0e10cSrcweir PresenterSprite::~PresenterSprite (void)
56cdf0e10cSrcweir {
57cdf0e10cSrcweir     if (mxSprite.is())
58cdf0e10cSrcweir     {
59cdf0e10cSrcweir         mxSprite->hide();
60cdf0e10cSrcweir         Reference<lang::XComponent> xComponent (mxSprite, UNO_QUERY);
61cdf0e10cSrcweir         if (xComponent.is())
62cdf0e10cSrcweir             xComponent->dispose();
63cdf0e10cSrcweir         mxSprite = NULL;
64cdf0e10cSrcweir     }
65cdf0e10cSrcweir }
66cdf0e10cSrcweir 
67cdf0e10cSrcweir 
68cdf0e10cSrcweir 
69cdf0e10cSrcweir 
SetFactory(const::css::uno::Reference<css::rendering::XSpriteCanvas> & rxSpriteFactory)70cdf0e10cSrcweir void PresenterSprite::SetFactory (
71cdf0e10cSrcweir     const ::css::uno::Reference<css::rendering::XSpriteCanvas>& rxSpriteFactory)
72cdf0e10cSrcweir {
73cdf0e10cSrcweir     if (mxSpriteFactory != rxSpriteFactory)
74cdf0e10cSrcweir     {
75cdf0e10cSrcweir         DisposeSprite();
76cdf0e10cSrcweir         mxSpriteFactory = rxSpriteFactory;
77cdf0e10cSrcweir         if (mbIsVisible)
78cdf0e10cSrcweir             PresenterSprite();
79cdf0e10cSrcweir     }
80cdf0e10cSrcweir }
81cdf0e10cSrcweir 
82cdf0e10cSrcweir 
83cdf0e10cSrcweir 
84cdf0e10cSrcweir 
GetCanvas(void)85cdf0e10cSrcweir ::css::uno::Reference<css::rendering::XCanvas> PresenterSprite::GetCanvas (void)
86cdf0e10cSrcweir {
87cdf0e10cSrcweir     ProvideSprite();
88cdf0e10cSrcweir     if (mxSprite.is())
89cdf0e10cSrcweir         return mxSprite->getContentCanvas();
90cdf0e10cSrcweir     else
91cdf0e10cSrcweir         return NULL;
92cdf0e10cSrcweir }
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 
95cdf0e10cSrcweir 
96cdf0e10cSrcweir 
Show(void)97cdf0e10cSrcweir void PresenterSprite::Show (void)
98cdf0e10cSrcweir {
99cdf0e10cSrcweir     mbIsVisible = true;
100cdf0e10cSrcweir     if (mxSprite.is())
101cdf0e10cSrcweir         mxSprite->show();
102cdf0e10cSrcweir     else
103cdf0e10cSrcweir         ProvideSprite();
104cdf0e10cSrcweir }
105cdf0e10cSrcweir 
106cdf0e10cSrcweir 
107cdf0e10cSrcweir 
108cdf0e10cSrcweir 
Hide(void)109cdf0e10cSrcweir void PresenterSprite::Hide (void)
110cdf0e10cSrcweir {
111cdf0e10cSrcweir     mbIsVisible = false;
112cdf0e10cSrcweir     if (mxSprite.is())
113cdf0e10cSrcweir         mxSprite->hide();
114cdf0e10cSrcweir }
115cdf0e10cSrcweir 
116cdf0e10cSrcweir 
117cdf0e10cSrcweir 
118cdf0e10cSrcweir 
IsVisible(void) const119cdf0e10cSrcweir bool PresenterSprite::IsVisible (void) const
120cdf0e10cSrcweir {
121cdf0e10cSrcweir     return mbIsVisible;
122cdf0e10cSrcweir }
123cdf0e10cSrcweir 
124cdf0e10cSrcweir 
125cdf0e10cSrcweir 
126cdf0e10cSrcweir 
SetPriority(const double nPriority)127cdf0e10cSrcweir void PresenterSprite::SetPriority (const double nPriority)
128cdf0e10cSrcweir {
129cdf0e10cSrcweir     mnPriority = nPriority;
130cdf0e10cSrcweir     if (mxSprite.is())
131cdf0e10cSrcweir         mxSprite->setPriority(mnPriority);
132cdf0e10cSrcweir }
133cdf0e10cSrcweir 
134cdf0e10cSrcweir 
135cdf0e10cSrcweir 
136cdf0e10cSrcweir 
GetPriority(void) const137cdf0e10cSrcweir double PresenterSprite::GetPriority (void) const
138cdf0e10cSrcweir {
139cdf0e10cSrcweir     return mnPriority;
140cdf0e10cSrcweir }
141cdf0e10cSrcweir 
142cdf0e10cSrcweir 
143cdf0e10cSrcweir 
144cdf0e10cSrcweir 
Resize(const css::geometry::RealSize2D & rSize)145cdf0e10cSrcweir void PresenterSprite::Resize (const css::geometry::RealSize2D& rSize)
146cdf0e10cSrcweir {
147cdf0e10cSrcweir     maSize = rSize;
148cdf0e10cSrcweir     if (mxSprite.is())
149cdf0e10cSrcweir         DisposeSprite();
150cdf0e10cSrcweir     if (mbIsVisible)
151cdf0e10cSrcweir         ProvideSprite();
152cdf0e10cSrcweir }
153cdf0e10cSrcweir 
154cdf0e10cSrcweir 
155cdf0e10cSrcweir 
156cdf0e10cSrcweir 
GetSize(void) const157cdf0e10cSrcweir css::geometry::RealSize2D PresenterSprite::GetSize (void) const
158cdf0e10cSrcweir {
159cdf0e10cSrcweir     return maSize;
160cdf0e10cSrcweir }
161cdf0e10cSrcweir 
162cdf0e10cSrcweir 
163cdf0e10cSrcweir 
164cdf0e10cSrcweir 
MoveTo(const css::geometry::RealPoint2D & rLocation)165cdf0e10cSrcweir void PresenterSprite::MoveTo (const css::geometry::RealPoint2D& rLocation)
166cdf0e10cSrcweir {
167cdf0e10cSrcweir     maLocation = rLocation;
168cdf0e10cSrcweir     if (mxSprite.is())
169cdf0e10cSrcweir         mxSprite->move(
170cdf0e10cSrcweir             maLocation,
171cdf0e10cSrcweir             rendering::ViewState(
172cdf0e10cSrcweir                 geometry::AffineMatrix2D(1,0,0, 0,1,0),
173cdf0e10cSrcweir                 NULL),
174cdf0e10cSrcweir             rendering::RenderState(
175cdf0e10cSrcweir                 geometry::AffineMatrix2D(1,0,0, 0,1,0),
176cdf0e10cSrcweir                 NULL,
177cdf0e10cSrcweir                 uno::Sequence<double>(4),
178cdf0e10cSrcweir                 rendering::CompositeOperation::SOURCE)
179cdf0e10cSrcweir             );
180cdf0e10cSrcweir }
181cdf0e10cSrcweir 
182cdf0e10cSrcweir 
183cdf0e10cSrcweir 
184cdf0e10cSrcweir 
GetLocation(void) const185cdf0e10cSrcweir css::geometry::RealPoint2D PresenterSprite::GetLocation (void) const
186cdf0e10cSrcweir {
187cdf0e10cSrcweir     return maLocation;
188cdf0e10cSrcweir }
189cdf0e10cSrcweir 
190cdf0e10cSrcweir 
191cdf0e10cSrcweir 
192cdf0e10cSrcweir 
Transform(const css::geometry::AffineMatrix2D & rTransform)193cdf0e10cSrcweir void PresenterSprite::Transform (const css::geometry::AffineMatrix2D& rTransform)
194cdf0e10cSrcweir {
195cdf0e10cSrcweir     maTransform = rTransform;
196cdf0e10cSrcweir     if (mxSprite.is())
197cdf0e10cSrcweir         mxSprite->transform(maTransform);
198cdf0e10cSrcweir }
199cdf0e10cSrcweir 
200cdf0e10cSrcweir 
201cdf0e10cSrcweir 
202cdf0e10cSrcweir 
GetTransform(void) const203cdf0e10cSrcweir css::geometry::AffineMatrix2D PresenterSprite::GetTransform (void) const
204cdf0e10cSrcweir {
205cdf0e10cSrcweir     return maTransform;
206cdf0e10cSrcweir }
207cdf0e10cSrcweir 
208cdf0e10cSrcweir 
209cdf0e10cSrcweir 
210cdf0e10cSrcweir 
SetAlpha(const double nAlpha)211cdf0e10cSrcweir void PresenterSprite::SetAlpha (const double nAlpha)
212cdf0e10cSrcweir {
213cdf0e10cSrcweir     mnAlpha = nAlpha;
214cdf0e10cSrcweir     if (mxSprite.is())
215cdf0e10cSrcweir         mxSprite->setAlpha(mnAlpha);
216cdf0e10cSrcweir }
217cdf0e10cSrcweir 
218cdf0e10cSrcweir 
219cdf0e10cSrcweir 
220cdf0e10cSrcweir 
GetAlpha(void) const221cdf0e10cSrcweir double PresenterSprite::GetAlpha (void) const
222cdf0e10cSrcweir {
223cdf0e10cSrcweir     return mnAlpha;
224cdf0e10cSrcweir }
225cdf0e10cSrcweir 
226cdf0e10cSrcweir 
227cdf0e10cSrcweir 
228cdf0e10cSrcweir 
Update(void)229cdf0e10cSrcweir void PresenterSprite::Update (void)
230cdf0e10cSrcweir {
231cdf0e10cSrcweir     if (mxSpriteFactory.is())
232cdf0e10cSrcweir         mxSpriteFactory->updateScreen(sal_False);
233cdf0e10cSrcweir }
234cdf0e10cSrcweir 
235cdf0e10cSrcweir 
236cdf0e10cSrcweir 
237cdf0e10cSrcweir 
ProvideSprite(void)238cdf0e10cSrcweir void PresenterSprite::ProvideSprite (void)
239cdf0e10cSrcweir {
240cdf0e10cSrcweir     if ( ! mxSprite.is()
241cdf0e10cSrcweir         && mxSpriteFactory.is()
242cdf0e10cSrcweir         && maSize.Width>0
243cdf0e10cSrcweir         && maSize.Height>0)
244cdf0e10cSrcweir     {
245cdf0e10cSrcweir         mxSprite = mxSpriteFactory->createCustomSprite(maSize);
246cdf0e10cSrcweir         if (mxSprite.is())
247cdf0e10cSrcweir         {
248cdf0e10cSrcweir             mxSprite->transform(maTransform);
249cdf0e10cSrcweir             mxSprite->move(maLocation,
250cdf0e10cSrcweir                 rendering::ViewState(
251cdf0e10cSrcweir                 geometry::AffineMatrix2D(1,0,0, 0,1,0),
252cdf0e10cSrcweir                 NULL),
253cdf0e10cSrcweir             rendering::RenderState(
254cdf0e10cSrcweir                 geometry::AffineMatrix2D(1,0,0, 0,1,0),
255cdf0e10cSrcweir                 NULL,
256cdf0e10cSrcweir                 uno::Sequence<double>(4),
257cdf0e10cSrcweir                 rendering::CompositeOperation::SOURCE)
258cdf0e10cSrcweir                 );
259cdf0e10cSrcweir             mxSprite->setAlpha(mnAlpha);
260cdf0e10cSrcweir             mxSprite->setPriority(mnPriority);
261cdf0e10cSrcweir             if (mbIsVisible)
262cdf0e10cSrcweir                 mxSprite->show();
263cdf0e10cSrcweir         }
264cdf0e10cSrcweir     }
265cdf0e10cSrcweir }
266cdf0e10cSrcweir 
267cdf0e10cSrcweir 
268cdf0e10cSrcweir 
269cdf0e10cSrcweir 
DisposeSprite(void)270cdf0e10cSrcweir void PresenterSprite::DisposeSprite (void)
271cdf0e10cSrcweir {
272cdf0e10cSrcweir     if (mxSprite.is())
273cdf0e10cSrcweir     {
274cdf0e10cSrcweir         mxSprite->hide();
275cdf0e10cSrcweir         Reference<lang::XComponent> xComponent (mxSprite, UNO_QUERY);
276cdf0e10cSrcweir         if (xComponent.is())
277cdf0e10cSrcweir             xComponent->dispose();
278cdf0e10cSrcweir         mxSprite = NULL;
279cdf0e10cSrcweir     }
280cdf0e10cSrcweir }
281cdf0e10cSrcweir 
282cdf0e10cSrcweir 
283cdf0e10cSrcweir 
284cdf0e10cSrcweir 
285cdf0e10cSrcweir } } //end of namespace sdext::presenter
286