fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sdext / source / presenter / PresenterUIPainter.cxx
blob4731f745877e4f7fd3104caad0f71f54b592128d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "PresenterUIPainter.hxx"
22 #include "PresenterCanvasHelper.hxx"
23 #include "PresenterGeometryHelper.hxx"
24 #include <com/sun/star/rendering/CompositeOperation.hpp>
25 #include <com/sun/star/rendering/XPolyPolygon2D.hpp>
27 using namespace ::com::sun::star;
28 using namespace ::com::sun::star::uno;
30 namespace sdext { namespace presenter {
32 void PresenterUIPainter::PaintHorizontalBitmapComposite (
33 const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
34 const css::awt::Rectangle& rRepaintBox,
35 const css::awt::Rectangle& rBoundingBox,
36 const css::uno::Reference<css::rendering::XBitmap>& rxLeftBitmap,
37 const css::uno::Reference<css::rendering::XBitmap>& rxRepeatableCenterBitmap,
38 const css::uno::Reference<css::rendering::XBitmap>& rxRightBitmap)
40 if (PresenterGeometryHelper::AreRectanglesDisjoint(rRepaintBox, rBoundingBox))
42 // The bounding box lies completely outside the repaint area.
43 // Nothing has to be repainted.
44 return;
47 // Get bitmap sizes.
48 geometry::IntegerSize2D aLeftBitmapSize;
49 if (rxLeftBitmap.is())
50 aLeftBitmapSize = rxLeftBitmap->getSize();
51 geometry::IntegerSize2D aCenterBitmapSize;
52 if (rxRepeatableCenterBitmap.is())
53 aCenterBitmapSize = rxRepeatableCenterBitmap->getSize();
54 geometry::IntegerSize2D aRightBitmapSize;
55 if (rxRightBitmap.is())
56 aRightBitmapSize = rxRightBitmap->getSize();
58 // Prepare painting.
59 rendering::ViewState aViewState (
60 geometry::AffineMatrix2D(1,0,0, 0,1,0),
61 NULL);
63 rendering::RenderState aRenderState (
64 geometry::AffineMatrix2D(1,0,0, 0,1,0),
65 NULL,
66 Sequence<double>(4),
67 rendering::CompositeOperation::SOURCE);
69 // Paint the left bitmap once.
70 if (rxLeftBitmap.is())
72 const awt::Rectangle aLeftBoundingBox (
73 rBoundingBox.X,
74 rBoundingBox.Y,
75 ::std::min(aLeftBitmapSize.Width, rBoundingBox.Width),
76 rBoundingBox.Height);
77 aViewState.Clip = Reference<rendering::XPolyPolygon2D>(
78 PresenterGeometryHelper::CreatePolygon(
79 PresenterGeometryHelper::Intersection(rRepaintBox, aLeftBoundingBox),
80 rxCanvas->getDevice()));
81 aRenderState.AffineTransform.m02 = aLeftBoundingBox.X;
82 aRenderState.AffineTransform.m12
83 = aLeftBoundingBox.Y + (aLeftBoundingBox.Height - aLeftBitmapSize.Height) / 2;
84 rxCanvas->drawBitmap(rxLeftBitmap, aViewState, aRenderState);
87 // Paint the right bitmap once.
88 if (rxRightBitmap.is())
90 const awt::Rectangle aRightBoundingBox (
91 rBoundingBox.X + rBoundingBox.Width - aRightBitmapSize.Width,
92 rBoundingBox.Y,
93 ::std::min(aRightBitmapSize.Width, rBoundingBox.Width),
94 rBoundingBox.Height);
95 aViewState.Clip = Reference<rendering::XPolyPolygon2D>(
96 PresenterGeometryHelper::CreatePolygon(
97 PresenterGeometryHelper::Intersection(rRepaintBox, aRightBoundingBox),
98 rxCanvas->getDevice()));
99 aRenderState.AffineTransform.m02
100 = aRightBoundingBox.X + aRightBoundingBox.Width - aRightBitmapSize.Width;
101 aRenderState.AffineTransform.m12
102 = aRightBoundingBox.Y + (aRightBoundingBox.Height - aRightBitmapSize.Height) / 2;
103 rxCanvas->drawBitmap(rxRightBitmap, aViewState, aRenderState);
106 // Paint the center bitmap to fill the remaining space.
107 if (rxRepeatableCenterBitmap.is())
109 const awt::Rectangle aCenterBoundingBox (
110 rBoundingBox.X + aLeftBitmapSize.Width,
111 rBoundingBox.Y,
112 rBoundingBox.Width - aLeftBitmapSize.Width - aRightBitmapSize.Width,
113 rBoundingBox.Height);
114 if (aCenterBoundingBox.Width > 0)
116 aViewState.Clip = Reference<rendering::XPolyPolygon2D>(
117 PresenterGeometryHelper::CreatePolygon(
118 PresenterGeometryHelper::Intersection(rRepaintBox, aCenterBoundingBox),
119 rxCanvas->getDevice()));
120 sal_Int32 nX (aCenterBoundingBox.X);
121 const sal_Int32 nRight (aCenterBoundingBox.X + aCenterBoundingBox.Width - 1);
122 aRenderState.AffineTransform.m12
123 = aCenterBoundingBox.Y + (aCenterBoundingBox.Height-aCenterBitmapSize.Height) / 2;
124 while(nX <= nRight)
126 aRenderState.AffineTransform.m02 = nX;
127 rxCanvas->drawBitmap(rxRepeatableCenterBitmap, aViewState, aRenderState);
128 nX += aCenterBitmapSize.Width;
134 void PresenterUIPainter::PaintVerticalBitmapComposite (
135 const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
136 const css::awt::Rectangle& rRepaintBox,
137 const css::awt::Rectangle& rBoundingBox,
138 const css::uno::Reference<css::rendering::XBitmap>& rxTopBitmap,
139 const css::uno::Reference<css::rendering::XBitmap>& rxRepeatableCenterBitmap,
140 const css::uno::Reference<css::rendering::XBitmap>& rxBottomBitmap)
142 if (PresenterGeometryHelper::AreRectanglesDisjoint(rRepaintBox, rBoundingBox))
144 // The bounding box lies completely outside the repaint area.
145 // Nothing has to be repainted.
146 return;
149 // Get bitmap sizes.
150 geometry::IntegerSize2D aTopBitmapSize;
151 if (rxTopBitmap.is())
152 aTopBitmapSize = rxTopBitmap->getSize();
153 geometry::IntegerSize2D aCenterBitmapSize;
154 if (rxRepeatableCenterBitmap.is())
155 aCenterBitmapSize = rxRepeatableCenterBitmap->getSize();
156 geometry::IntegerSize2D aBottomBitmapSize;
157 if (rxBottomBitmap.is())
158 aBottomBitmapSize = rxBottomBitmap->getSize();
160 // Prepare painting.
161 rendering::ViewState aViewState (
162 geometry::AffineMatrix2D(1,0,0, 0,1,0),
163 NULL);
165 rendering::RenderState aRenderState (
166 geometry::AffineMatrix2D(1,0,0, 0,1,0),
167 NULL,
168 Sequence<double>(4),
169 rendering::CompositeOperation::SOURCE);
171 // Paint the top bitmap once.
172 if (rxTopBitmap.is())
174 const awt::Rectangle aTopBoundingBox (
175 rBoundingBox.X,
176 rBoundingBox.Y,
177 rBoundingBox.Width,
178 ::std::min(aTopBitmapSize.Height, rBoundingBox.Height));
179 aViewState.Clip = Reference<rendering::XPolyPolygon2D>(
180 PresenterGeometryHelper::CreatePolygon(
181 PresenterGeometryHelper::Intersection(rRepaintBox, aTopBoundingBox),
182 rxCanvas->getDevice()));
183 aRenderState.AffineTransform.m02
184 = aTopBoundingBox.X + (aTopBoundingBox.Width - aTopBitmapSize.Width) / 2;
185 aRenderState.AffineTransform.m12 = aTopBoundingBox.Y;
186 rxCanvas->drawBitmap(rxTopBitmap, aViewState, aRenderState);
189 // Paint the bottom bitmap once.
190 if (rxBottomBitmap.is())
192 const sal_Int32 nBBoxHeight (::std::min(aBottomBitmapSize.Height, rBoundingBox.Height));
193 const awt::Rectangle aBottomBoundingBox (
194 rBoundingBox.X,
195 rBoundingBox.Y + rBoundingBox.Height - nBBoxHeight,
196 rBoundingBox.Width,
197 nBBoxHeight);
198 aViewState.Clip = Reference<rendering::XPolyPolygon2D>(
199 PresenterGeometryHelper::CreatePolygon(
200 PresenterGeometryHelper::Intersection(rRepaintBox, aBottomBoundingBox),
201 rxCanvas->getDevice()));
202 aRenderState.AffineTransform.m02
203 = aBottomBoundingBox.X + (aBottomBoundingBox.Width - aBottomBitmapSize.Width) / 2;
204 aRenderState.AffineTransform.m12
205 = aBottomBoundingBox.Y + aBottomBoundingBox.Height - aBottomBitmapSize.Height;
206 rxCanvas->drawBitmap(rxBottomBitmap, aViewState, aRenderState);
209 // Paint the center bitmap to fill the remaining space.
210 if (rxRepeatableCenterBitmap.is())
212 const awt::Rectangle aCenterBoundingBox (
213 rBoundingBox.X,
214 rBoundingBox.Y + aTopBitmapSize.Height,
215 rBoundingBox.Width,
216 rBoundingBox.Height - aTopBitmapSize.Height - aBottomBitmapSize.Height);
217 if (aCenterBoundingBox.Height > 0)
219 aViewState.Clip = Reference<rendering::XPolyPolygon2D>(
220 PresenterGeometryHelper::CreatePolygon(
221 PresenterGeometryHelper::Intersection(rRepaintBox, aCenterBoundingBox),
222 rxCanvas->getDevice()));
223 sal_Int32 nY (aCenterBoundingBox.Y);
224 const sal_Int32 nBottom (aCenterBoundingBox.Y + aCenterBoundingBox.Height - 1);
225 aRenderState.AffineTransform.m02
226 = aCenterBoundingBox.X + (aCenterBoundingBox.Width-aCenterBitmapSize.Width) / 2;
227 while(nY <= nBottom)
229 aRenderState.AffineTransform.m12 = nY;
230 rxCanvas->drawBitmap(rxRepeatableCenterBitmap, aViewState, aRenderState);
231 nY += aCenterBitmapSize.Height;
237 } } // end of namespace sdext::presenter
239 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */