xref: /AOO41X/main/sdext/source/presenter/PresenterUIPainter.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sdext.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "PresenterUIPainter.hxx"
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include "PresenterCanvasHelper.hxx"
34*cdf0e10cSrcweir #include "PresenterGeometryHelper.hxx"
35*cdf0e10cSrcweir #include <com/sun/star/rendering/CompositeOperation.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/rendering/XPolyPolygon2D.hpp>
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir using namespace ::com::sun::star;
39*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir namespace sdext { namespace presenter {
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir void PresenterUIPainter::PaintHorizontalBitmapComposite (
45*cdf0e10cSrcweir     const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
46*cdf0e10cSrcweir     const css::awt::Rectangle& rRepaintBox,
47*cdf0e10cSrcweir     const css::awt::Rectangle& rBoundingBox,
48*cdf0e10cSrcweir     const css::uno::Reference<css::rendering::XBitmap>& rxLeftBitmap,
49*cdf0e10cSrcweir     const css::uno::Reference<css::rendering::XBitmap>& rxRepeatableCenterBitmap,
50*cdf0e10cSrcweir     const css::uno::Reference<css::rendering::XBitmap>& rxRightBitmap)
51*cdf0e10cSrcweir {
52*cdf0e10cSrcweir     if (PresenterGeometryHelper::AreRectanglesDisjoint(rRepaintBox, rBoundingBox))
53*cdf0e10cSrcweir     {
54*cdf0e10cSrcweir         // The bounding box lies completly outside the repaint area.
55*cdf0e10cSrcweir         // Nothing has to be repainted.
56*cdf0e10cSrcweir         return;
57*cdf0e10cSrcweir     }
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir     // Get bitmap sizes.
60*cdf0e10cSrcweir     geometry::IntegerSize2D aLeftBitmapSize;
61*cdf0e10cSrcweir     if (rxLeftBitmap.is())
62*cdf0e10cSrcweir         aLeftBitmapSize = rxLeftBitmap->getSize();
63*cdf0e10cSrcweir     geometry::IntegerSize2D aCenterBitmapSize;
64*cdf0e10cSrcweir     if (rxRepeatableCenterBitmap.is())
65*cdf0e10cSrcweir         aCenterBitmapSize = rxRepeatableCenterBitmap->getSize();
66*cdf0e10cSrcweir     geometry::IntegerSize2D aRightBitmapSize;
67*cdf0e10cSrcweir     if (rxRightBitmap.is())
68*cdf0e10cSrcweir         aRightBitmapSize = rxRightBitmap->getSize();
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir     // Prepare painting.
71*cdf0e10cSrcweir     rendering::ViewState aViewState (
72*cdf0e10cSrcweir         geometry::AffineMatrix2D(1,0,0, 0,1,0),
73*cdf0e10cSrcweir         NULL);
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir     rendering::RenderState aRenderState (
76*cdf0e10cSrcweir         geometry::AffineMatrix2D(1,0,0, 0,1,0),
77*cdf0e10cSrcweir         NULL,
78*cdf0e10cSrcweir         Sequence<double>(4),
79*cdf0e10cSrcweir         rendering::CompositeOperation::SOURCE);
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir     // Paint the left bitmap once.
82*cdf0e10cSrcweir     if (rxLeftBitmap.is())
83*cdf0e10cSrcweir     {
84*cdf0e10cSrcweir         const awt::Rectangle aLeftBoundingBox (
85*cdf0e10cSrcweir             rBoundingBox.X,
86*cdf0e10cSrcweir             rBoundingBox.Y,
87*cdf0e10cSrcweir             ::std::min(aLeftBitmapSize.Width, rBoundingBox.Width),
88*cdf0e10cSrcweir             rBoundingBox.Height);
89*cdf0e10cSrcweir         aViewState.Clip = Reference<rendering::XPolyPolygon2D>(
90*cdf0e10cSrcweir             PresenterGeometryHelper::CreatePolygon(
91*cdf0e10cSrcweir                 PresenterGeometryHelper::Intersection(rRepaintBox, aLeftBoundingBox),
92*cdf0e10cSrcweir                 rxCanvas->getDevice()));
93*cdf0e10cSrcweir         aRenderState.AffineTransform.m02 = aLeftBoundingBox.X;
94*cdf0e10cSrcweir         aRenderState.AffineTransform.m12
95*cdf0e10cSrcweir             = aLeftBoundingBox.Y + (aLeftBoundingBox.Height - aLeftBitmapSize.Height) / 2;
96*cdf0e10cSrcweir         rxCanvas->drawBitmap(rxLeftBitmap, aViewState, aRenderState);
97*cdf0e10cSrcweir     }
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir     // Paint the right bitmap once.
100*cdf0e10cSrcweir     if (rxRightBitmap.is())
101*cdf0e10cSrcweir     {
102*cdf0e10cSrcweir         const awt::Rectangle aRightBoundingBox (
103*cdf0e10cSrcweir             rBoundingBox.X + rBoundingBox.Width - aRightBitmapSize.Width,
104*cdf0e10cSrcweir             rBoundingBox.Y,
105*cdf0e10cSrcweir             ::std::min(aRightBitmapSize.Width, rBoundingBox.Width),
106*cdf0e10cSrcweir             rBoundingBox.Height);
107*cdf0e10cSrcweir         aViewState.Clip = Reference<rendering::XPolyPolygon2D>(
108*cdf0e10cSrcweir             PresenterGeometryHelper::CreatePolygon(
109*cdf0e10cSrcweir                 PresenterGeometryHelper::Intersection(rRepaintBox, aRightBoundingBox),
110*cdf0e10cSrcweir                 rxCanvas->getDevice()));
111*cdf0e10cSrcweir         aRenderState.AffineTransform.m02
112*cdf0e10cSrcweir             = aRightBoundingBox.X + aRightBoundingBox.Width - aRightBitmapSize.Width;
113*cdf0e10cSrcweir         aRenderState.AffineTransform.m12
114*cdf0e10cSrcweir             = aRightBoundingBox.Y + (aRightBoundingBox.Height - aRightBitmapSize.Height) / 2;
115*cdf0e10cSrcweir         rxCanvas->drawBitmap(rxRightBitmap, aViewState, aRenderState);
116*cdf0e10cSrcweir     }
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir     // Paint the center bitmap to fill the remaining space.
119*cdf0e10cSrcweir     if (rxRepeatableCenterBitmap.is())
120*cdf0e10cSrcweir     {
121*cdf0e10cSrcweir         const awt::Rectangle aCenterBoundingBox (
122*cdf0e10cSrcweir             rBoundingBox.X + aLeftBitmapSize.Width,
123*cdf0e10cSrcweir             rBoundingBox.Y,
124*cdf0e10cSrcweir             rBoundingBox.Width - aLeftBitmapSize.Width - aRightBitmapSize.Width,
125*cdf0e10cSrcweir             rBoundingBox.Height);
126*cdf0e10cSrcweir         if (aCenterBoundingBox.Width > 0)
127*cdf0e10cSrcweir         {
128*cdf0e10cSrcweir             aViewState.Clip = Reference<rendering::XPolyPolygon2D>(
129*cdf0e10cSrcweir                 PresenterGeometryHelper::CreatePolygon(
130*cdf0e10cSrcweir                     PresenterGeometryHelper::Intersection(rRepaintBox, aCenterBoundingBox),
131*cdf0e10cSrcweir                     rxCanvas->getDevice()));
132*cdf0e10cSrcweir             sal_Int32 nX (aCenterBoundingBox.X);
133*cdf0e10cSrcweir             const sal_Int32 nRight (aCenterBoundingBox.X + aCenterBoundingBox.Width - 1);
134*cdf0e10cSrcweir             aRenderState.AffineTransform.m12
135*cdf0e10cSrcweir                 = aCenterBoundingBox.Y + (aCenterBoundingBox.Height-aCenterBitmapSize.Height) / 2;
136*cdf0e10cSrcweir             while(nX <= nRight)
137*cdf0e10cSrcweir             {
138*cdf0e10cSrcweir                 aRenderState.AffineTransform.m02 = nX;
139*cdf0e10cSrcweir                 rxCanvas->drawBitmap(rxRepeatableCenterBitmap, aViewState, aRenderState);
140*cdf0e10cSrcweir                 nX += aCenterBitmapSize.Width;
141*cdf0e10cSrcweir             }
142*cdf0e10cSrcweir         }
143*cdf0e10cSrcweir     }
144*cdf0e10cSrcweir }
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir void PresenterUIPainter::PaintVerticalBitmapComposite (
150*cdf0e10cSrcweir     const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
151*cdf0e10cSrcweir     const css::awt::Rectangle& rRepaintBox,
152*cdf0e10cSrcweir     const css::awt::Rectangle& rBoundingBox,
153*cdf0e10cSrcweir     const css::uno::Reference<css::rendering::XBitmap>& rxTopBitmap,
154*cdf0e10cSrcweir     const css::uno::Reference<css::rendering::XBitmap>& rxRepeatableCenterBitmap,
155*cdf0e10cSrcweir     const css::uno::Reference<css::rendering::XBitmap>& rxBottomBitmap)
156*cdf0e10cSrcweir {
157*cdf0e10cSrcweir     if (PresenterGeometryHelper::AreRectanglesDisjoint(rRepaintBox, rBoundingBox))
158*cdf0e10cSrcweir     {
159*cdf0e10cSrcweir         // The bounding box lies completly outside the repaint area.
160*cdf0e10cSrcweir         // Nothing has to be repainted.
161*cdf0e10cSrcweir         return;
162*cdf0e10cSrcweir     }
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir     // Get bitmap sizes.
165*cdf0e10cSrcweir     geometry::IntegerSize2D aTopBitmapSize;
166*cdf0e10cSrcweir     if (rxTopBitmap.is())
167*cdf0e10cSrcweir         aTopBitmapSize = rxTopBitmap->getSize();
168*cdf0e10cSrcweir     geometry::IntegerSize2D aCenterBitmapSize;
169*cdf0e10cSrcweir     if (rxRepeatableCenterBitmap.is())
170*cdf0e10cSrcweir         aCenterBitmapSize = rxRepeatableCenterBitmap->getSize();
171*cdf0e10cSrcweir     geometry::IntegerSize2D aBottomBitmapSize;
172*cdf0e10cSrcweir     if (rxBottomBitmap.is())
173*cdf0e10cSrcweir         aBottomBitmapSize = rxBottomBitmap->getSize();
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir     // Prepare painting.
176*cdf0e10cSrcweir     rendering::ViewState aViewState (
177*cdf0e10cSrcweir         geometry::AffineMatrix2D(1,0,0, 0,1,0),
178*cdf0e10cSrcweir         NULL);
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir     rendering::RenderState aRenderState (
181*cdf0e10cSrcweir         geometry::AffineMatrix2D(1,0,0, 0,1,0),
182*cdf0e10cSrcweir         NULL,
183*cdf0e10cSrcweir         Sequence<double>(4),
184*cdf0e10cSrcweir         rendering::CompositeOperation::SOURCE);
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir     // Paint the top bitmap once.
187*cdf0e10cSrcweir     if (rxTopBitmap.is())
188*cdf0e10cSrcweir     {
189*cdf0e10cSrcweir         const awt::Rectangle aTopBoundingBox (
190*cdf0e10cSrcweir             rBoundingBox.X,
191*cdf0e10cSrcweir             rBoundingBox.Y,
192*cdf0e10cSrcweir             rBoundingBox.Width,
193*cdf0e10cSrcweir             ::std::min(aTopBitmapSize.Height, rBoundingBox.Height));
194*cdf0e10cSrcweir         aViewState.Clip = Reference<rendering::XPolyPolygon2D>(
195*cdf0e10cSrcweir             PresenterGeometryHelper::CreatePolygon(
196*cdf0e10cSrcweir                 PresenterGeometryHelper::Intersection(rRepaintBox, aTopBoundingBox),
197*cdf0e10cSrcweir                 rxCanvas->getDevice()));
198*cdf0e10cSrcweir         aRenderState.AffineTransform.m02
199*cdf0e10cSrcweir             = aTopBoundingBox.X + (aTopBoundingBox.Width - aTopBitmapSize.Width) / 2;
200*cdf0e10cSrcweir         aRenderState.AffineTransform.m12 = aTopBoundingBox.Y;
201*cdf0e10cSrcweir         rxCanvas->drawBitmap(rxTopBitmap, aViewState, aRenderState);
202*cdf0e10cSrcweir     }
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir     // Paint the bottom bitmap once.
205*cdf0e10cSrcweir     if (rxBottomBitmap.is())
206*cdf0e10cSrcweir     {
207*cdf0e10cSrcweir         const sal_Int32 nBBoxHeight (::std::min(aBottomBitmapSize.Height, rBoundingBox.Height));
208*cdf0e10cSrcweir         const awt::Rectangle aBottomBoundingBox (
209*cdf0e10cSrcweir             rBoundingBox.X,
210*cdf0e10cSrcweir             rBoundingBox.Y  + rBoundingBox.Height - nBBoxHeight,
211*cdf0e10cSrcweir             rBoundingBox.Width,
212*cdf0e10cSrcweir             nBBoxHeight);
213*cdf0e10cSrcweir         aViewState.Clip = Reference<rendering::XPolyPolygon2D>(
214*cdf0e10cSrcweir             PresenterGeometryHelper::CreatePolygon(
215*cdf0e10cSrcweir                 PresenterGeometryHelper::Intersection(rRepaintBox, aBottomBoundingBox),
216*cdf0e10cSrcweir                 rxCanvas->getDevice()));
217*cdf0e10cSrcweir         aRenderState.AffineTransform.m02
218*cdf0e10cSrcweir             = aBottomBoundingBox.X + (aBottomBoundingBox.Width - aBottomBitmapSize.Width) / 2;
219*cdf0e10cSrcweir         aRenderState.AffineTransform.m12
220*cdf0e10cSrcweir             = aBottomBoundingBox.Y + aBottomBoundingBox.Height - aBottomBitmapSize.Height;
221*cdf0e10cSrcweir         rxCanvas->drawBitmap(rxBottomBitmap, aViewState, aRenderState);
222*cdf0e10cSrcweir     }
223*cdf0e10cSrcweir 
224*cdf0e10cSrcweir     // Paint the center bitmap to fill the remaining space.
225*cdf0e10cSrcweir     if (rxRepeatableCenterBitmap.is())
226*cdf0e10cSrcweir     {
227*cdf0e10cSrcweir         const awt::Rectangle aCenterBoundingBox (
228*cdf0e10cSrcweir             rBoundingBox.X,
229*cdf0e10cSrcweir             rBoundingBox.Y + aTopBitmapSize.Height,
230*cdf0e10cSrcweir             rBoundingBox.Width,
231*cdf0e10cSrcweir             rBoundingBox.Height - aTopBitmapSize.Height - aBottomBitmapSize.Height);
232*cdf0e10cSrcweir         if (aCenterBoundingBox.Height > 0)
233*cdf0e10cSrcweir         {
234*cdf0e10cSrcweir             aViewState.Clip = Reference<rendering::XPolyPolygon2D>(
235*cdf0e10cSrcweir                 PresenterGeometryHelper::CreatePolygon(
236*cdf0e10cSrcweir                     PresenterGeometryHelper::Intersection(rRepaintBox, aCenterBoundingBox),
237*cdf0e10cSrcweir                     rxCanvas->getDevice()));
238*cdf0e10cSrcweir             sal_Int32 nY (aCenterBoundingBox.Y);
239*cdf0e10cSrcweir             const sal_Int32 nBottom (aCenterBoundingBox.Y + aCenterBoundingBox.Height - 1);
240*cdf0e10cSrcweir             aRenderState.AffineTransform.m02
241*cdf0e10cSrcweir                 = aCenterBoundingBox.X + (aCenterBoundingBox.Width-aCenterBitmapSize.Width) / 2;
242*cdf0e10cSrcweir             while(nY <= nBottom)
243*cdf0e10cSrcweir             {
244*cdf0e10cSrcweir                 aRenderState.AffineTransform.m12 = nY;
245*cdf0e10cSrcweir                 rxCanvas->drawBitmap(rxRepeatableCenterBitmap, aViewState, aRenderState);
246*cdf0e10cSrcweir                 nY += aCenterBitmapSize.Height;
247*cdf0e10cSrcweir             }
248*cdf0e10cSrcweir         }
249*cdf0e10cSrcweir     }
250*cdf0e10cSrcweir }
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir 
254*cdf0e10cSrcweir 
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir } } // end of namespace sdext::presenter
257