Line data Source code
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 "PresenterUIPainter.hxx"
21 :
22 : #include "PresenterCanvasHelper.hxx"
23 : #include "PresenterGeometryHelper.hxx"
24 : #include <com/sun/star/rendering/CompositeOperation.hpp>
25 : #include <com/sun/star/rendering/XPolyPolygon2D.hpp>
26 :
27 : using namespace ::com::sun::star;
28 : using namespace ::com::sun::star::uno;
29 :
30 : namespace sdext { namespace presenter {
31 :
32 0 : 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)
39 : {
40 0 : if (PresenterGeometryHelper::AreRectanglesDisjoint(rRepaintBox, rBoundingBox))
41 : {
42 : // The bounding box lies completely outside the repaint area.
43 : // Nothing has to be repainted.
44 0 : return;
45 : }
46 :
47 : // Get bitmap sizes.
48 0 : geometry::IntegerSize2D aLeftBitmapSize;
49 0 : if (rxLeftBitmap.is())
50 0 : aLeftBitmapSize = rxLeftBitmap->getSize();
51 0 : geometry::IntegerSize2D aCenterBitmapSize;
52 0 : if (rxRepeatableCenterBitmap.is())
53 0 : aCenterBitmapSize = rxRepeatableCenterBitmap->getSize();
54 0 : geometry::IntegerSize2D aRightBitmapSize;
55 0 : if (rxRightBitmap.is())
56 0 : aRightBitmapSize = rxRightBitmap->getSize();
57 :
58 : // Prepare painting.
59 : rendering::ViewState aViewState (
60 : geometry::AffineMatrix2D(1,0,0, 0,1,0),
61 0 : NULL);
62 :
63 : rendering::RenderState aRenderState (
64 : geometry::AffineMatrix2D(1,0,0, 0,1,0),
65 : NULL,
66 : Sequence<double>(4),
67 0 : rendering::CompositeOperation::SOURCE);
68 :
69 : // Paint the left bitmap once.
70 0 : if (rxLeftBitmap.is())
71 : {
72 : const awt::Rectangle aLeftBoundingBox (
73 : rBoundingBox.X,
74 : rBoundingBox.Y,
75 0 : ::std::min(aLeftBitmapSize.Width, rBoundingBox.Width),
76 0 : rBoundingBox.Height);
77 0 : aViewState.Clip = Reference<rendering::XPolyPolygon2D>(
78 : PresenterGeometryHelper::CreatePolygon(
79 : PresenterGeometryHelper::Intersection(rRepaintBox, aLeftBoundingBox),
80 0 : rxCanvas->getDevice()));
81 0 : aRenderState.AffineTransform.m02 = aLeftBoundingBox.X;
82 : aRenderState.AffineTransform.m12
83 0 : = aLeftBoundingBox.Y + (aLeftBoundingBox.Height - aLeftBitmapSize.Height) / 2;
84 0 : rxCanvas->drawBitmap(rxLeftBitmap, aViewState, aRenderState);
85 : }
86 :
87 : // Paint the right bitmap once.
88 0 : if (rxRightBitmap.is())
89 : {
90 : const awt::Rectangle aRightBoundingBox (
91 0 : rBoundingBox.X + rBoundingBox.Width - aRightBitmapSize.Width,
92 : rBoundingBox.Y,
93 0 : ::std::min(aRightBitmapSize.Width, rBoundingBox.Width),
94 0 : rBoundingBox.Height);
95 0 : aViewState.Clip = Reference<rendering::XPolyPolygon2D>(
96 : PresenterGeometryHelper::CreatePolygon(
97 : PresenterGeometryHelper::Intersection(rRepaintBox, aRightBoundingBox),
98 0 : rxCanvas->getDevice()));
99 : aRenderState.AffineTransform.m02
100 0 : = aRightBoundingBox.X + aRightBoundingBox.Width - aRightBitmapSize.Width;
101 : aRenderState.AffineTransform.m12
102 0 : = aRightBoundingBox.Y + (aRightBoundingBox.Height - aRightBitmapSize.Height) / 2;
103 0 : rxCanvas->drawBitmap(rxRightBitmap, aViewState, aRenderState);
104 : }
105 :
106 : // Paint the center bitmap to fill the remaining space.
107 0 : if (rxRepeatableCenterBitmap.is())
108 : {
109 : const awt::Rectangle aCenterBoundingBox (
110 0 : rBoundingBox.X + aLeftBitmapSize.Width,
111 : rBoundingBox.Y,
112 0 : rBoundingBox.Width - aLeftBitmapSize.Width - aRightBitmapSize.Width,
113 0 : rBoundingBox.Height);
114 0 : if (aCenterBoundingBox.Width > 0)
115 : {
116 0 : aViewState.Clip = Reference<rendering::XPolyPolygon2D>(
117 : PresenterGeometryHelper::CreatePolygon(
118 : PresenterGeometryHelper::Intersection(rRepaintBox, aCenterBoundingBox),
119 0 : rxCanvas->getDevice()));
120 0 : sal_Int32 nX (aCenterBoundingBox.X);
121 0 : const sal_Int32 nRight (aCenterBoundingBox.X + aCenterBoundingBox.Width - 1);
122 : aRenderState.AffineTransform.m12
123 0 : = aCenterBoundingBox.Y + (aCenterBoundingBox.Height-aCenterBitmapSize.Height) / 2;
124 0 : while(nX <= nRight)
125 : {
126 0 : aRenderState.AffineTransform.m02 = nX;
127 0 : rxCanvas->drawBitmap(rxRepeatableCenterBitmap, aViewState, aRenderState);
128 0 : nX += aCenterBitmapSize.Width;
129 : }
130 : }
131 0 : }
132 : }
133 :
134 0 : 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)
141 : {
142 0 : if (PresenterGeometryHelper::AreRectanglesDisjoint(rRepaintBox, rBoundingBox))
143 : {
144 : // The bounding box lies completely outside the repaint area.
145 : // Nothing has to be repainted.
146 0 : return;
147 : }
148 :
149 : // Get bitmap sizes.
150 0 : geometry::IntegerSize2D aTopBitmapSize;
151 0 : if (rxTopBitmap.is())
152 0 : aTopBitmapSize = rxTopBitmap->getSize();
153 0 : geometry::IntegerSize2D aCenterBitmapSize;
154 0 : if (rxRepeatableCenterBitmap.is())
155 0 : aCenterBitmapSize = rxRepeatableCenterBitmap->getSize();
156 0 : geometry::IntegerSize2D aBottomBitmapSize;
157 0 : if (rxBottomBitmap.is())
158 0 : aBottomBitmapSize = rxBottomBitmap->getSize();
159 :
160 : // Prepare painting.
161 : rendering::ViewState aViewState (
162 : geometry::AffineMatrix2D(1,0,0, 0,1,0),
163 0 : NULL);
164 :
165 : rendering::RenderState aRenderState (
166 : geometry::AffineMatrix2D(1,0,0, 0,1,0),
167 : NULL,
168 : Sequence<double>(4),
169 0 : rendering::CompositeOperation::SOURCE);
170 :
171 : // Paint the top bitmap once.
172 0 : if (rxTopBitmap.is())
173 : {
174 : const awt::Rectangle aTopBoundingBox (
175 : rBoundingBox.X,
176 : rBoundingBox.Y,
177 : rBoundingBox.Width,
178 0 : ::std::min(aTopBitmapSize.Height, rBoundingBox.Height));
179 0 : aViewState.Clip = Reference<rendering::XPolyPolygon2D>(
180 : PresenterGeometryHelper::CreatePolygon(
181 : PresenterGeometryHelper::Intersection(rRepaintBox, aTopBoundingBox),
182 0 : rxCanvas->getDevice()));
183 : aRenderState.AffineTransform.m02
184 0 : = aTopBoundingBox.X + (aTopBoundingBox.Width - aTopBitmapSize.Width) / 2;
185 0 : aRenderState.AffineTransform.m12 = aTopBoundingBox.Y;
186 0 : rxCanvas->drawBitmap(rxTopBitmap, aViewState, aRenderState);
187 : }
188 :
189 : // Paint the bottom bitmap once.
190 0 : if (rxBottomBitmap.is())
191 : {
192 0 : const sal_Int32 nBBoxHeight (::std::min(aBottomBitmapSize.Height, rBoundingBox.Height));
193 : const awt::Rectangle aBottomBoundingBox (
194 : rBoundingBox.X,
195 0 : rBoundingBox.Y + rBoundingBox.Height - nBBoxHeight,
196 : rBoundingBox.Width,
197 0 : nBBoxHeight);
198 0 : aViewState.Clip = Reference<rendering::XPolyPolygon2D>(
199 : PresenterGeometryHelper::CreatePolygon(
200 : PresenterGeometryHelper::Intersection(rRepaintBox, aBottomBoundingBox),
201 0 : rxCanvas->getDevice()));
202 : aRenderState.AffineTransform.m02
203 0 : = aBottomBoundingBox.X + (aBottomBoundingBox.Width - aBottomBitmapSize.Width) / 2;
204 : aRenderState.AffineTransform.m12
205 0 : = aBottomBoundingBox.Y + aBottomBoundingBox.Height - aBottomBitmapSize.Height;
206 0 : rxCanvas->drawBitmap(rxBottomBitmap, aViewState, aRenderState);
207 : }
208 :
209 : // Paint the center bitmap to fill the remaining space.
210 0 : if (rxRepeatableCenterBitmap.is())
211 : {
212 : const awt::Rectangle aCenterBoundingBox (
213 : rBoundingBox.X,
214 0 : rBoundingBox.Y + aTopBitmapSize.Height,
215 : rBoundingBox.Width,
216 0 : rBoundingBox.Height - aTopBitmapSize.Height - aBottomBitmapSize.Height);
217 0 : if (aCenterBoundingBox.Height > 0)
218 : {
219 0 : aViewState.Clip = Reference<rendering::XPolyPolygon2D>(
220 : PresenterGeometryHelper::CreatePolygon(
221 : PresenterGeometryHelper::Intersection(rRepaintBox, aCenterBoundingBox),
222 0 : rxCanvas->getDevice()));
223 0 : sal_Int32 nY (aCenterBoundingBox.Y);
224 0 : const sal_Int32 nBottom (aCenterBoundingBox.Y + aCenterBoundingBox.Height - 1);
225 : aRenderState.AffineTransform.m02
226 0 : = aCenterBoundingBox.X + (aCenterBoundingBox.Width-aCenterBitmapSize.Width) / 2;
227 0 : while(nY <= nBottom)
228 : {
229 0 : aRenderState.AffineTransform.m12 = nY;
230 0 : rxCanvas->drawBitmap(rxRepeatableCenterBitmap, aViewState, aRenderState);
231 0 : nY += aCenterBitmapSize.Height;
232 : }
233 : }
234 0 : }
235 : }
236 :
237 : } } // end of namespace sdext::presenter
238 :
239 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|