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::DrawBevelBorder ( 77 OutputDevice& rDevice, 78 const Rectangle rBox, 79 const SvBorder aBorderSize, 80 const Paint& rTopLeftPaint, 81 const Paint& rCenterPaint, 82 const Paint& rBottomRightPaint) 83 { 84 // Draw top line. 85 DrawHorizontalLine( 86 rDevice, 87 rBox.Left(), 88 rBox.Right() - aBorderSize.Right(), 89 rBox.Top(), 90 aBorderSize.Top(), 91 rTopLeftPaint); 92 // Draw bottom line. 93 DrawHorizontalLine( 94 rDevice, 95 rBox.Left()+aBorderSize.Left(), 96 rBox.Right(), 97 rBox.Bottom()-aBorderSize.Bottom()+1, 98 aBorderSize.Bottom(), 99 rBottomRightPaint); 100 // Draw left line. 101 DrawVerticalLine( 102 rDevice, 103 rBox.Top()+aBorderSize.Top(), 104 rBox.Bottom() - aBorderSize.Bottom(), 105 rBox.Left(), 106 aBorderSize.Left(), 107 rTopLeftPaint); 108 // Draw right line. 109 DrawVerticalLine( 110 rDevice, 111 rBox.Top()+aBorderSize.Top(), 112 rBox.Bottom()-aBorderSize.Bottom(), 113 rBox.Right()-aBorderSize.Right()+1, 114 aBorderSize.Right(), 115 rBottomRightPaint); 116 // Draw top right corner. 117 DrawVerticalLine( 118 rDevice, 119 rBox.Top(), 120 rBox.Top()+aBorderSize.Top()-1, 121 rBox.Right()-aBorderSize.Right()+1, 122 aBorderSize.Right(), 123 rCenterPaint); 124 // Draw bottom right corner. 125 DrawVerticalLine( 126 rDevice, 127 rBox.Bottom() - aBorderSize.Bottom()+1, 128 rBox.Bottom(), 129 rBox.Left(), 130 aBorderSize.Left(), 131 rCenterPaint); 132 } 133 134 135 136 137 void DrawHelper::DrawHorizontalLine( 138 OutputDevice& rDevice, 139 const sal_Int32 nLeft, 140 const sal_Int32 nRight, 141 const sal_Int32 nY, 142 const sal_Int32 nHeight, 143 const Paint& rPaint) 144 { 145 switch (rPaint.GetType()) 146 { 147 case Paint::NoPaint: 148 default: 149 break; 150 151 case Paint::ColorPaint: 152 { 153 const Color aColor (rPaint.GetColor()); 154 rDevice.SetLineColor(aColor); 155 for (sal_Int32 nYOffset=0; nYOffset<nHeight; ++nYOffset) 156 rDevice.DrawLine( 157 Point(nLeft,nY+nYOffset), 158 Point(nRight,nY+nYOffset)); 159 break; 160 } 161 case Paint::GradientPaint: 162 rDevice.DrawGradient( 163 Rectangle( 164 nLeft, 165 nY, 166 nRight, 167 nY+nHeight-1), 168 rPaint.GetGradient()); 169 break; 170 } 171 } 172 173 174 175 176 void DrawHelper::DrawVerticalLine( 177 OutputDevice& rDevice, 178 const sal_Int32 nTop, 179 const sal_Int32 nBottom, 180 const sal_Int32 nX, 181 const sal_Int32 nWidth, 182 const Paint& rPaint) 183 { 184 switch (rPaint.GetType()) 185 { 186 case Paint::NoPaint: 187 default: 188 break; 189 190 case Paint::ColorPaint: 191 { 192 const Color aColor (rPaint.GetColor()); 193 rDevice.SetLineColor(aColor); 194 for (sal_Int32 nXOffset=0; nXOffset<nWidth; ++nXOffset) 195 rDevice.DrawLine( 196 Point(nX+nXOffset, nTop), 197 Point(nX+nXOffset, nBottom)); 198 break; 199 } 200 case Paint::GradientPaint: 201 rDevice.DrawGradient( 202 Rectangle( 203 nX, 204 nTop, 205 nX+nWidth-1, 206 nBottom), 207 rPaint.GetGradient()); 208 break; 209 } 210 } 211 212 213 214 215 void DrawHelper::DrawRoundedRectangle ( 216 OutputDevice& rDevice, 217 const Rectangle& rBox, 218 const sal_Int32 nCornerRadius, 219 const Color& rBorderColor, 220 const Paint& rFillPaint) 221 { 222 rDevice.SetLineColor(rBorderColor); 223 switch(rFillPaint.GetType()) 224 { 225 case Paint::NoPaint: 226 default: 227 rDevice.SetFillColor(); 228 rDevice.DrawRect(rBox, nCornerRadius, nCornerRadius); 229 break; 230 231 case Paint::ColorPaint: 232 rDevice.SetFillColor(rFillPaint.GetColor()); 233 rDevice.DrawRect(rBox, nCornerRadius, nCornerRadius); 234 break; 235 236 case Paint::GradientPaint: 237 rDevice.DrawGradient( 238 rBox, 239 rFillPaint.GetGradient()); 240 rDevice.SetFillColor(); 241 rDevice.DrawRect(rBox, nCornerRadius, nCornerRadius); 242 break; 243 } 244 } 245 246 247 248 249 } } // end of namespace sfx2::sidebar 250