1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: PresenterUIPainter.cxx,v $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_sdext.hxx"
35 #include "PresenterUIPainter.hxx"
37 #include "PresenterCanvasHelper.hxx"
38 #include "PresenterGeometryHelper.hxx"
39 #include <com/sun/star/rendering/CompositeOperation.hpp>
40 #include <com/sun/star/rendering/XPolyPolygon2D.hpp>
42 using namespace ::com::sun::star
;
43 using namespace ::com::sun::star::uno
;
45 namespace sdext
{ namespace presenter
{
48 void PresenterUIPainter::PaintHorizontalBitmapComposite (
49 const css::uno::Reference
<css::rendering::XCanvas
>& rxCanvas
,
50 const css::awt::Rectangle
& rRepaintBox
,
51 const css::awt::Rectangle
& rBoundingBox
,
52 const css::uno::Reference
<css::rendering::XBitmap
>& rxLeftBitmap
,
53 const css::uno::Reference
<css::rendering::XBitmap
>& rxRepeatableCenterBitmap
,
54 const css::uno::Reference
<css::rendering::XBitmap
>& rxRightBitmap
)
56 if (PresenterGeometryHelper::AreRectanglesDisjoint(rRepaintBox
, rBoundingBox
))
58 // The bounding box lies completly outside the repaint area.
59 // Nothing has to be repainted.
64 geometry::IntegerSize2D aLeftBitmapSize
;
65 if (rxLeftBitmap
.is())
66 aLeftBitmapSize
= rxLeftBitmap
->getSize();
67 geometry::IntegerSize2D aCenterBitmapSize
;
68 if (rxRepeatableCenterBitmap
.is())
69 aCenterBitmapSize
= rxRepeatableCenterBitmap
->getSize();
70 geometry::IntegerSize2D aRightBitmapSize
;
71 if (rxRightBitmap
.is())
72 aRightBitmapSize
= rxRightBitmap
->getSize();
75 rendering::ViewState
aViewState (
76 geometry::AffineMatrix2D(1,0,0, 0,1,0),
79 rendering::RenderState
aRenderState (
80 geometry::AffineMatrix2D(1,0,0, 0,1,0),
83 rendering::CompositeOperation::SOURCE
);
85 // Paint the left bitmap once.
86 if (rxLeftBitmap
.is())
88 const awt::Rectangle
aLeftBoundingBox (
91 ::std::min(aLeftBitmapSize
.Width
, rBoundingBox
.Width
),
93 aViewState
.Clip
= Reference
<rendering::XPolyPolygon2D
>(
94 PresenterGeometryHelper::CreatePolygon(
95 PresenterGeometryHelper::Intersection(rRepaintBox
, aLeftBoundingBox
),
96 rxCanvas
->getDevice()));
97 aRenderState
.AffineTransform
.m02
= aLeftBoundingBox
.X
;
98 aRenderState
.AffineTransform
.m12
99 = aLeftBoundingBox
.Y
+ (aLeftBoundingBox
.Height
- aLeftBitmapSize
.Height
) / 2;
100 rxCanvas
->drawBitmap(rxLeftBitmap
, aViewState
, aRenderState
);
103 // Paint the right bitmap once.
104 if (rxRightBitmap
.is())
106 const awt::Rectangle
aRightBoundingBox (
107 rBoundingBox
.X
+ rBoundingBox
.Width
- aRightBitmapSize
.Width
,
109 ::std::min(aRightBitmapSize
.Width
, rBoundingBox
.Width
),
110 rBoundingBox
.Height
);
111 aViewState
.Clip
= Reference
<rendering::XPolyPolygon2D
>(
112 PresenterGeometryHelper::CreatePolygon(
113 PresenterGeometryHelper::Intersection(rRepaintBox
, aRightBoundingBox
),
114 rxCanvas
->getDevice()));
115 aRenderState
.AffineTransform
.m02
116 = aRightBoundingBox
.X
+ aRightBoundingBox
.Width
- aRightBitmapSize
.Width
;
117 aRenderState
.AffineTransform
.m12
118 = aRightBoundingBox
.Y
+ (aRightBoundingBox
.Height
- aRightBitmapSize
.Height
) / 2;
119 rxCanvas
->drawBitmap(rxRightBitmap
, aViewState
, aRenderState
);
122 // Paint the center bitmap to fill the remaining space.
123 if (rxRepeatableCenterBitmap
.is())
125 const awt::Rectangle
aCenterBoundingBox (
126 rBoundingBox
.X
+ aLeftBitmapSize
.Width
,
128 rBoundingBox
.Width
- aLeftBitmapSize
.Width
- aRightBitmapSize
.Width
,
129 rBoundingBox
.Height
);
130 if (aCenterBoundingBox
.Width
> 0)
132 aViewState
.Clip
= Reference
<rendering::XPolyPolygon2D
>(
133 PresenterGeometryHelper::CreatePolygon(
134 PresenterGeometryHelper::Intersection(rRepaintBox
, aCenterBoundingBox
),
135 rxCanvas
->getDevice()));
136 sal_Int32
nX (aCenterBoundingBox
.X
);
137 const sal_Int32
nRight (aCenterBoundingBox
.X
+ aCenterBoundingBox
.Width
- 1);
138 aRenderState
.AffineTransform
.m12
139 = aCenterBoundingBox
.Y
+ (aCenterBoundingBox
.Height
-aCenterBitmapSize
.Height
) / 2;
142 aRenderState
.AffineTransform
.m02
= nX
;
143 rxCanvas
->drawBitmap(rxRepeatableCenterBitmap
, aViewState
, aRenderState
);
144 nX
+= aCenterBitmapSize
.Width
;
153 void PresenterUIPainter::PaintVerticalBitmapComposite (
154 const css::uno::Reference
<css::rendering::XCanvas
>& rxCanvas
,
155 const css::awt::Rectangle
& rRepaintBox
,
156 const css::awt::Rectangle
& rBoundingBox
,
157 const css::uno::Reference
<css::rendering::XBitmap
>& rxTopBitmap
,
158 const css::uno::Reference
<css::rendering::XBitmap
>& rxRepeatableCenterBitmap
,
159 const css::uno::Reference
<css::rendering::XBitmap
>& rxBottomBitmap
)
161 if (PresenterGeometryHelper::AreRectanglesDisjoint(rRepaintBox
, rBoundingBox
))
163 // The bounding box lies completly outside the repaint area.
164 // Nothing has to be repainted.
169 geometry::IntegerSize2D aTopBitmapSize
;
170 if (rxTopBitmap
.is())
171 aTopBitmapSize
= rxTopBitmap
->getSize();
172 geometry::IntegerSize2D aCenterBitmapSize
;
173 if (rxRepeatableCenterBitmap
.is())
174 aCenterBitmapSize
= rxRepeatableCenterBitmap
->getSize();
175 geometry::IntegerSize2D aBottomBitmapSize
;
176 if (rxBottomBitmap
.is())
177 aBottomBitmapSize
= rxBottomBitmap
->getSize();
180 rendering::ViewState
aViewState (
181 geometry::AffineMatrix2D(1,0,0, 0,1,0),
184 rendering::RenderState
aRenderState (
185 geometry::AffineMatrix2D(1,0,0, 0,1,0),
188 rendering::CompositeOperation::SOURCE
);
190 // Paint the top bitmap once.
191 if (rxTopBitmap
.is())
193 const awt::Rectangle
aTopBoundingBox (
197 ::std::min(aTopBitmapSize
.Height
, rBoundingBox
.Height
));
198 aViewState
.Clip
= Reference
<rendering::XPolyPolygon2D
>(
199 PresenterGeometryHelper::CreatePolygon(
200 PresenterGeometryHelper::Intersection(rRepaintBox
, aTopBoundingBox
),
201 rxCanvas
->getDevice()));
202 aRenderState
.AffineTransform
.m02
203 = aTopBoundingBox
.X
+ (aTopBoundingBox
.Width
- aTopBitmapSize
.Width
) / 2;
204 aRenderState
.AffineTransform
.m12
= aTopBoundingBox
.Y
;
205 rxCanvas
->drawBitmap(rxTopBitmap
, aViewState
, aRenderState
);
208 // Paint the bottom bitmap once.
209 if (rxBottomBitmap
.is())
211 const sal_Int32
nBBoxHeight (::std::min(aBottomBitmapSize
.Height
, rBoundingBox
.Height
));
212 const awt::Rectangle
aBottomBoundingBox (
214 rBoundingBox
.Y
+ rBoundingBox
.Height
- nBBoxHeight
,
217 aViewState
.Clip
= Reference
<rendering::XPolyPolygon2D
>(
218 PresenterGeometryHelper::CreatePolygon(
219 PresenterGeometryHelper::Intersection(rRepaintBox
, aBottomBoundingBox
),
220 rxCanvas
->getDevice()));
221 aRenderState
.AffineTransform
.m02
222 = aBottomBoundingBox
.X
+ (aBottomBoundingBox
.Width
- aBottomBitmapSize
.Width
) / 2;
223 aRenderState
.AffineTransform
.m12
224 = aBottomBoundingBox
.Y
+ aBottomBoundingBox
.Height
- aBottomBitmapSize
.Height
;
225 rxCanvas
->drawBitmap(rxBottomBitmap
, aViewState
, aRenderState
);
228 // Paint the center bitmap to fill the remaining space.
229 if (rxRepeatableCenterBitmap
.is())
231 const awt::Rectangle
aCenterBoundingBox (
233 rBoundingBox
.Y
+ aTopBitmapSize
.Height
,
235 rBoundingBox
.Height
- aTopBitmapSize
.Height
- aBottomBitmapSize
.Height
);
236 if (aCenterBoundingBox
.Height
> 0)
238 aViewState
.Clip
= Reference
<rendering::XPolyPolygon2D
>(
239 PresenterGeometryHelper::CreatePolygon(
240 PresenterGeometryHelper::Intersection(rRepaintBox
, aCenterBoundingBox
),
241 rxCanvas
->getDevice()));
242 sal_Int32
nY (aCenterBoundingBox
.Y
);
243 const sal_Int32
nBottom (aCenterBoundingBox
.Y
+ aCenterBoundingBox
.Height
- 1);
244 aRenderState
.AffineTransform
.m02
245 = aCenterBoundingBox
.X
+ (aCenterBoundingBox
.Width
-aCenterBitmapSize
.Width
) / 2;
248 aRenderState
.AffineTransform
.m12
= nY
;
249 rxCanvas
->drawBitmap(rxRepeatableCenterBitmap
, aViewState
, aRenderState
);
250 nY
+= aCenterBitmapSize
.Height
;
260 } } // end of namespace sdext::presenter