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