1ff12d537SAndre Fischer /**************************************************************
2ff12d537SAndre Fischer *
3ff12d537SAndre Fischer * Licensed to the Apache Software Foundation (ASF) under one
4ff12d537SAndre Fischer * or more contributor license agreements. See the NOTICE file
5ff12d537SAndre Fischer * distributed with this work for additional information
6ff12d537SAndre Fischer * regarding copyright ownership. The ASF licenses this file
7ff12d537SAndre Fischer * to you under the Apache License, Version 2.0 (the
8ff12d537SAndre Fischer * "License"); you may not use this file except in compliance
9ff12d537SAndre Fischer * with the License. You may obtain a copy of the License at
10ff12d537SAndre Fischer *
11ff12d537SAndre Fischer * http://www.apache.org/licenses/LICENSE-2.0
12ff12d537SAndre Fischer *
13ff12d537SAndre Fischer * Unless required by applicable law or agreed to in writing,
14ff12d537SAndre Fischer * software distributed under the License is distributed on an
15ff12d537SAndre Fischer * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16ff12d537SAndre Fischer * KIND, either express or implied. See the License for the
17ff12d537SAndre Fischer * specific language governing permissions and limitations
18ff12d537SAndre Fischer * under the License.
19ff12d537SAndre Fischer *
20ff12d537SAndre Fischer *************************************************************/
21ff12d537SAndre Fischer
22ff12d537SAndre Fischer #include "precompiled_sfx2.hxx"
23ff12d537SAndre Fischer
24ff12d537SAndre Fischer #include "DrawHelper.hxx"
25ff12d537SAndre Fischer #include "Paint.hxx"
26ff12d537SAndre Fischer
27ff12d537SAndre Fischer #include <vcl/lineinfo.hxx>
28ff12d537SAndre Fischer
29ff12d537SAndre Fischer
30ff12d537SAndre Fischer namespace sfx2 { namespace sidebar {
31ff12d537SAndre Fischer
DrawBorder(OutputDevice & rDevice,const Rectangle rBox,const SvBorder aBorderSize,const Paint & rHorizontalPaint,const Paint & rVerticalPaint)32ff12d537SAndre Fischer void DrawHelper::DrawBorder (
33ff12d537SAndre Fischer OutputDevice& rDevice,
34ff12d537SAndre Fischer const Rectangle rBox,
35ff12d537SAndre Fischer const SvBorder aBorderSize,
36ff12d537SAndre Fischer const Paint& rHorizontalPaint,
37ff12d537SAndre Fischer const Paint& rVerticalPaint)
38ff12d537SAndre Fischer {
39ff12d537SAndre Fischer // Draw top line.
40ff12d537SAndre Fischer DrawHorizontalLine(
41ff12d537SAndre Fischer rDevice,
42ff12d537SAndre Fischer rBox.Left(),
43ff12d537SAndre Fischer rBox.Right(),
44ff12d537SAndre Fischer rBox.Top(),
45ff12d537SAndre Fischer aBorderSize.Top(),
46ff12d537SAndre Fischer rHorizontalPaint);
47ff12d537SAndre Fischer // Draw bottom line.
48ff12d537SAndre Fischer DrawHorizontalLine(
49ff12d537SAndre Fischer rDevice,
50b9e67834SAndre Fischer rBox.Left()+aBorderSize.Left(),
51ff12d537SAndre Fischer rBox.Right(),
52ff12d537SAndre Fischer rBox.Bottom()-aBorderSize.Bottom()+1,
53ff12d537SAndre Fischer aBorderSize.Bottom(),
54ff12d537SAndre Fischer rHorizontalPaint);
55ff12d537SAndre Fischer // Draw left line.
56ff12d537SAndre Fischer DrawVerticalLine(
57ff12d537SAndre Fischer rDevice,
58ff12d537SAndre Fischer rBox.Top()+aBorderSize.Top(),
59b9e67834SAndre Fischer rBox.Bottom(),
60ff12d537SAndre Fischer rBox.Left(),
61ff12d537SAndre Fischer aBorderSize.Left(),
62ff12d537SAndre Fischer rVerticalPaint);
63ff12d537SAndre Fischer // Draw right line.
64ff12d537SAndre Fischer DrawVerticalLine(
65ff12d537SAndre Fischer rDevice,
66b9e67834SAndre Fischer rBox.Top()+aBorderSize.Top(),
67b9e67834SAndre Fischer rBox.Bottom()-aBorderSize.Bottom(),
68ff12d537SAndre Fischer rBox.Right()-aBorderSize.Right()+1,
69ff12d537SAndre Fischer aBorderSize.Right(),
70ff12d537SAndre Fischer rVerticalPaint);
71ff12d537SAndre Fischer }
72ff12d537SAndre Fischer
73ff12d537SAndre Fischer
74ff12d537SAndre Fischer
75ff12d537SAndre Fischer
DrawBevelBorder(OutputDevice & rDevice,const Rectangle rBox,const SvBorder aBorderSize,const Paint & rTopLeftPaint,const Paint & rCenterPaint,const Paint & rBottomRightPaint)76*95a18594SAndre Fischer void DrawHelper::DrawBevelBorder (
77*95a18594SAndre Fischer OutputDevice& rDevice,
78*95a18594SAndre Fischer const Rectangle rBox,
79*95a18594SAndre Fischer const SvBorder aBorderSize,
80*95a18594SAndre Fischer const Paint& rTopLeftPaint,
81*95a18594SAndre Fischer const Paint& rCenterPaint,
82*95a18594SAndre Fischer const Paint& rBottomRightPaint)
83*95a18594SAndre Fischer {
84*95a18594SAndre Fischer // Draw top line.
85*95a18594SAndre Fischer DrawHorizontalLine(
86*95a18594SAndre Fischer rDevice,
87*95a18594SAndre Fischer rBox.Left(),
88*95a18594SAndre Fischer rBox.Right() - aBorderSize.Right(),
89*95a18594SAndre Fischer rBox.Top(),
90*95a18594SAndre Fischer aBorderSize.Top(),
91*95a18594SAndre Fischer rTopLeftPaint);
92*95a18594SAndre Fischer // Draw bottom line.
93*95a18594SAndre Fischer DrawHorizontalLine(
94*95a18594SAndre Fischer rDevice,
95*95a18594SAndre Fischer rBox.Left()+aBorderSize.Left(),
96*95a18594SAndre Fischer rBox.Right(),
97*95a18594SAndre Fischer rBox.Bottom()-aBorderSize.Bottom()+1,
98*95a18594SAndre Fischer aBorderSize.Bottom(),
99*95a18594SAndre Fischer rBottomRightPaint);
100*95a18594SAndre Fischer // Draw left line.
101*95a18594SAndre Fischer DrawVerticalLine(
102*95a18594SAndre Fischer rDevice,
103*95a18594SAndre Fischer rBox.Top()+aBorderSize.Top(),
104*95a18594SAndre Fischer rBox.Bottom() - aBorderSize.Bottom(),
105*95a18594SAndre Fischer rBox.Left(),
106*95a18594SAndre Fischer aBorderSize.Left(),
107*95a18594SAndre Fischer rTopLeftPaint);
108*95a18594SAndre Fischer // Draw right line.
109*95a18594SAndre Fischer DrawVerticalLine(
110*95a18594SAndre Fischer rDevice,
111*95a18594SAndre Fischer rBox.Top()+aBorderSize.Top(),
112*95a18594SAndre Fischer rBox.Bottom()-aBorderSize.Bottom(),
113*95a18594SAndre Fischer rBox.Right()-aBorderSize.Right()+1,
114*95a18594SAndre Fischer aBorderSize.Right(),
115*95a18594SAndre Fischer rBottomRightPaint);
116*95a18594SAndre Fischer // Draw top right corner.
117*95a18594SAndre Fischer DrawVerticalLine(
118*95a18594SAndre Fischer rDevice,
119*95a18594SAndre Fischer rBox.Top(),
120*95a18594SAndre Fischer rBox.Top()+aBorderSize.Top()-1,
121*95a18594SAndre Fischer rBox.Right()-aBorderSize.Right()+1,
122*95a18594SAndre Fischer aBorderSize.Right(),
123*95a18594SAndre Fischer rCenterPaint);
124*95a18594SAndre Fischer // Draw bottom right corner.
125*95a18594SAndre Fischer DrawVerticalLine(
126*95a18594SAndre Fischer rDevice,
127*95a18594SAndre Fischer rBox.Bottom() - aBorderSize.Bottom()+1,
128*95a18594SAndre Fischer rBox.Bottom(),
129*95a18594SAndre Fischer rBox.Left(),
130*95a18594SAndre Fischer aBorderSize.Left(),
131*95a18594SAndre Fischer rCenterPaint);
132*95a18594SAndre Fischer }
133*95a18594SAndre Fischer
134*95a18594SAndre Fischer
135*95a18594SAndre Fischer
136*95a18594SAndre Fischer
DrawHorizontalLine(OutputDevice & rDevice,const sal_Int32 nLeft,const sal_Int32 nRight,const sal_Int32 nY,const sal_Int32 nHeight,const Paint & rPaint)137ff12d537SAndre Fischer void DrawHelper::DrawHorizontalLine(
138ff12d537SAndre Fischer OutputDevice& rDevice,
139b9e67834SAndre Fischer const sal_Int32 nLeft,
140b9e67834SAndre Fischer const sal_Int32 nRight,
141b9e67834SAndre Fischer const sal_Int32 nY,
142b9e67834SAndre Fischer const sal_Int32 nHeight,
143ff12d537SAndre Fischer const Paint& rPaint)
144ff12d537SAndre Fischer {
145ff12d537SAndre Fischer switch (rPaint.GetType())
146ff12d537SAndre Fischer {
147ff12d537SAndre Fischer case Paint::NoPaint:
148ff12d537SAndre Fischer default:
149ff12d537SAndre Fischer break;
150ff12d537SAndre Fischer
151ff12d537SAndre Fischer case Paint::ColorPaint:
152b9e67834SAndre Fischer {
153b9e67834SAndre Fischer const Color aColor (rPaint.GetColor());
154b9e67834SAndre Fischer rDevice.SetLineColor(aColor);
155b9e67834SAndre Fischer for (sal_Int32 nYOffset=0; nYOffset<nHeight; ++nYOffset)
156ff12d537SAndre Fischer rDevice.DrawLine(
157b9e67834SAndre Fischer Point(nLeft,nY+nYOffset),
158b9e67834SAndre Fischer Point(nRight,nY+nYOffset));
159ff12d537SAndre Fischer break;
160b9e67834SAndre Fischer }
161ff12d537SAndre Fischer case Paint::GradientPaint:
162ff12d537SAndre Fischer rDevice.DrawGradient(
163ff12d537SAndre Fischer Rectangle(
164ff12d537SAndre Fischer nLeft,
165ff12d537SAndre Fischer nY,
166ff12d537SAndre Fischer nRight,
167ff12d537SAndre Fischer nY+nHeight-1),
168ff12d537SAndre Fischer rPaint.GetGradient());
169ff12d537SAndre Fischer break;
170ff12d537SAndre Fischer }
171ff12d537SAndre Fischer }
172ff12d537SAndre Fischer
173ff12d537SAndre Fischer
174ff12d537SAndre Fischer
175ff12d537SAndre Fischer
DrawVerticalLine(OutputDevice & rDevice,const sal_Int32 nTop,const sal_Int32 nBottom,const sal_Int32 nX,const sal_Int32 nWidth,const Paint & rPaint)176ff12d537SAndre Fischer void DrawHelper::DrawVerticalLine(
177ff12d537SAndre Fischer OutputDevice& rDevice,
178b9e67834SAndre Fischer const sal_Int32 nTop,
179b9e67834SAndre Fischer const sal_Int32 nBottom,
180b9e67834SAndre Fischer const sal_Int32 nX,
181b9e67834SAndre Fischer const sal_Int32 nWidth,
182ff12d537SAndre Fischer const Paint& rPaint)
183ff12d537SAndre Fischer {
184ff12d537SAndre Fischer switch (rPaint.GetType())
185ff12d537SAndre Fischer {
186ff12d537SAndre Fischer case Paint::NoPaint:
187ff12d537SAndre Fischer default:
188ff12d537SAndre Fischer break;
189ff12d537SAndre Fischer
190ff12d537SAndre Fischer case Paint::ColorPaint:
191b9e67834SAndre Fischer {
192b9e67834SAndre Fischer const Color aColor (rPaint.GetColor());
193b9e67834SAndre Fischer rDevice.SetLineColor(aColor);
194b9e67834SAndre Fischer for (sal_Int32 nXOffset=0; nXOffset<nWidth; ++nXOffset)
195ff12d537SAndre Fischer rDevice.DrawLine(
196b9e67834SAndre Fischer Point(nX+nXOffset, nTop),
197b9e67834SAndre Fischer Point(nX+nXOffset, nBottom));
198ff12d537SAndre Fischer break;
199b9e67834SAndre Fischer }
200ff12d537SAndre Fischer case Paint::GradientPaint:
201ff12d537SAndre Fischer rDevice.DrawGradient(
202ff12d537SAndre Fischer Rectangle(
203ff12d537SAndre Fischer nX,
204ff12d537SAndre Fischer nTop,
205ff12d537SAndre Fischer nX+nWidth-1,
206ff12d537SAndre Fischer nBottom),
207ff12d537SAndre Fischer rPaint.GetGradient());
208ff12d537SAndre Fischer break;
209ff12d537SAndre Fischer }
210ff12d537SAndre Fischer }
211ff12d537SAndre Fischer
212ff12d537SAndre Fischer
213ff12d537SAndre Fischer
214ff12d537SAndre Fischer
DrawRoundedRectangle(OutputDevice & rDevice,const Rectangle & rBox,const sal_Int32 nCornerRadius,const Color & rBorderColor,const Paint & rFillPaint)215ff12d537SAndre Fischer void DrawHelper::DrawRoundedRectangle (
216ff12d537SAndre Fischer OutputDevice& rDevice,
217ff12d537SAndre Fischer const Rectangle& rBox,
218b9e67834SAndre Fischer const sal_Int32 nCornerRadius,
219ff12d537SAndre Fischer const Color& rBorderColor,
220ff12d537SAndre Fischer const Paint& rFillPaint)
221ff12d537SAndre Fischer {
222ff12d537SAndre Fischer rDevice.SetLineColor(rBorderColor);
223ff12d537SAndre Fischer switch(rFillPaint.GetType())
224ff12d537SAndre Fischer {
225ff12d537SAndre Fischer case Paint::NoPaint:
226ff12d537SAndre Fischer default:
227ff12d537SAndre Fischer rDevice.SetFillColor();
228ff12d537SAndre Fischer rDevice.DrawRect(rBox, nCornerRadius, nCornerRadius);
229ff12d537SAndre Fischer break;
230ff12d537SAndre Fischer
231ff12d537SAndre Fischer case Paint::ColorPaint:
232ff12d537SAndre Fischer rDevice.SetFillColor(rFillPaint.GetColor());
233ff12d537SAndre Fischer rDevice.DrawRect(rBox, nCornerRadius, nCornerRadius);
234ff12d537SAndre Fischer break;
235ff12d537SAndre Fischer
236ff12d537SAndre Fischer case Paint::GradientPaint:
237ff12d537SAndre Fischer rDevice.DrawGradient(
238ff12d537SAndre Fischer rBox,
239ff12d537SAndre Fischer rFillPaint.GetGradient());
240ff12d537SAndre Fischer rDevice.SetFillColor();
241ff12d537SAndre Fischer rDevice.DrawRect(rBox, nCornerRadius, nCornerRadius);
242ff12d537SAndre Fischer break;
243ff12d537SAndre Fischer }
244ff12d537SAndre Fischer }
245ff12d537SAndre Fischer
246ff12d537SAndre Fischer
247ff12d537SAndre Fischer
248*95a18594SAndre Fischer
249ff12d537SAndre Fischer } } // end of namespace sfx2::sidebar
250