LibreOffice Module sdext (master)  1
PresenterSprite.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 #include "PresenterSprite.hxx"
21 
22 #include <com/sun/star/lang/XComponent.hpp>
23 #include <com/sun/star/rendering/CompositeOperation.hpp>
24 #include <com/sun/star/rendering/RenderState.hpp>
25 #include <com/sun/star/rendering/ViewState.hpp>
26 
27 using namespace ::com::sun::star;
28 using ::com::sun::star::uno::Reference;
29 using ::com::sun::star::uno::UNO_QUERY;
30 
31 namespace sdext::presenter {
32 
34  : mxSpriteFactory(),
35  mxSprite(),
36  maSize(0,0),
37  maLocation(0,0),
38  mbIsVisible(false)
39 {
40 }
41 
43 {
44  if (mxSprite.is())
45  {
46  mxSprite->hide();
48  if (xComponent.is())
49  xComponent->dispose();
50  mxSprite = nullptr;
51  }
52 }
53 
55  const css::uno::Reference<css::rendering::XSpriteCanvas>& rxSpriteFactory)
56 {
57  if (mxSpriteFactory != rxSpriteFactory)
58  {
59  DisposeSprite();
60  mxSpriteFactory = rxSpriteFactory;
61  if (mbIsVisible)
62  ProvideSprite();
63  }
64 }
65 
66 css::uno::Reference<css::rendering::XCanvas> PresenterSprite::GetCanvas()
67 {
68  ProvideSprite();
69  if (mxSprite.is())
70  return mxSprite->getContentCanvas();
71  else
72  return nullptr;
73 }
74 
76 {
77  mbIsVisible = true;
78  if (mxSprite.is())
79  mxSprite->show();
80  else
81  ProvideSprite();
82 }
83 
85 {
86  mbIsVisible = false;
87  if (mxSprite.is())
88  mxSprite->hide();
89 }
90 
91 void PresenterSprite::Resize (const css::geometry::RealSize2D& rSize)
92 {
93  maSize = rSize;
94  if (mxSprite.is())
95  DisposeSprite();
96  if (mbIsVisible)
97  ProvideSprite();
98 }
99 
100 void PresenterSprite::MoveTo (const css::geometry::RealPoint2D& rLocation)
101 {
102  maLocation = rLocation;
103  if (mxSprite.is())
104  mxSprite->move(
105  maLocation,
106  rendering::ViewState(
107  geometry::AffineMatrix2D(1,0,0, 0,1,0),
108  nullptr),
109  rendering::RenderState(
110  geometry::AffineMatrix2D(1,0,0, 0,1,0),
111  nullptr,
112  uno::Sequence<double>(4),
113  rendering::CompositeOperation::SOURCE)
114  );
115 }
116 
118 {
119  if (mxSpriteFactory.is())
120  mxSpriteFactory->updateScreen(false);
121 }
122 
124 {
125  if ( !(! mxSprite.is()
126  && mxSpriteFactory.is()
127  && maSize.Width>0
128  && maSize.Height>0))
129  return;
130 
131  mxSprite = mxSpriteFactory->createCustomSprite(maSize);
132  if (!mxSprite.is())
133  return;
134 
135  mxSprite->move(maLocation,
136  rendering::ViewState(
137  geometry::AffineMatrix2D(1,0,0, 0,1,0),
138  nullptr),
139  rendering::RenderState(
140  geometry::AffineMatrix2D(1,0,0, 0,1,0),
141  nullptr,
142  uno::Sequence<double>(4),
143  rendering::CompositeOperation::SOURCE)
144  );
145  mxSprite->setAlpha(1.0);
146  mxSprite->setPriority(0);
147  if (mbIsVisible)
148  mxSprite->show();
149 }
150 
152 {
153  if (mxSprite.is())
154  {
155  mxSprite->hide();
157  if (xComponent.is())
158  xComponent->dispose();
159  mxSprite = nullptr;
160  }
161 }
162 
163 } //end of namespace sdext::presenter
164 
165 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::geometry::RealSize2D maSize
css::uno::Reference< css::rendering::XCustomSprite > mxSprite
awt::Point maLocation
Reference< rendering::XCustomSprite > mxSprite
void SetFactory(const css::uno::Reference< css::rendering::XSpriteCanvas > &rxSpriteFactory)
The given sprite canvas is used as factory to create the sprite that is wrapped by objects of this cl...
css::uno::Reference< css::lang::XComponent > xComponent
css::uno::Reference< css::rendering::XCanvas > GetCanvas()
css::uno::Reference< css::rendering::XSpriteCanvas > mxSpriteFactory
void MoveTo(const css::geometry::RealPoint2D &rLocation)
css::geometry::RealPoint2D maLocation
void Resize(const css::geometry::RealSize2D &rSize)
geometry::RealSize2D maSize