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(), 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()-aBorderSize.Bottom()+1, 60 rBox.Left(), 61 aBorderSize.Left(), 62 rVerticalPaint); 63 // Draw right line. 64 DrawVerticalLine( 65 rDevice, 66 rBox.Top(), 67 rBox.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 int nLeft, 79 const int nRight, 80 const int nY, 81 const int 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 rDevice.SetLineColor(rPaint.GetColor()); 92 if (nHeight == 1) 93 rDevice.DrawLine( 94 Point(nLeft,nY), 95 Point(nRight,nY)); 96 else 97 rDevice.DrawLine( 98 Point(nLeft,nY), 99 Point(nRight,nY), 100 LineInfo(LINE_SOLID,nHeight)); 101 break; 102 103 case Paint::GradientPaint: 104 rDevice.DrawGradient( 105 Rectangle( 106 nLeft, 107 nY, 108 nRight, 109 nY+nHeight-1), 110 rPaint.GetGradient()); 111 break; 112 } 113 } 114 115 116 117 118 void DrawHelper::DrawVerticalLine( 119 OutputDevice& rDevice, 120 const int nTop, 121 const int nBottom, 122 const int nX, 123 const int nWidth, 124 const Paint& rPaint) 125 { 126 switch (rPaint.GetType()) 127 { 128 case Paint::NoPaint: 129 default: 130 break; 131 132 case Paint::ColorPaint: 133 rDevice.SetLineColor(rPaint.GetColor()); 134 if (nWidth == 1) 135 rDevice.DrawLine( 136 Point(nX, nTop), 137 Point(nX, nBottom)); 138 else 139 rDevice.DrawLine( 140 Point(nX, nTop), 141 Point(nX, nBottom), 142 LineInfo(LINE_SOLID, nWidth)); 143 break; 144 145 case Paint::GradientPaint: 146 rDevice.DrawGradient( 147 Rectangle( 148 nX, 149 nTop, 150 nX+nWidth-1, 151 nBottom), 152 rPaint.GetGradient()); 153 break; 154 } 155 } 156 157 158 159 160 void DrawHelper::DrawRoundedRectangle ( 161 OutputDevice& rDevice, 162 const Rectangle& rBox, 163 const int nCornerRadius, 164 const Color& rBorderColor, 165 const Paint& rFillPaint) 166 { 167 rDevice.SetLineColor(rBorderColor); 168 switch(rFillPaint.GetType()) 169 { 170 case Paint::NoPaint: 171 default: 172 rDevice.SetFillColor(); 173 rDevice.DrawRect(rBox, nCornerRadius, nCornerRadius); 174 break; 175 176 case Paint::ColorPaint: 177 rDevice.SetFillColor(rFillPaint.GetColor()); 178 rDevice.DrawRect(rBox, nCornerRadius, nCornerRadius); 179 break; 180 181 case Paint::GradientPaint: 182 rDevice.DrawGradient( 183 rBox, 184 rFillPaint.GetGradient()); 185 rDevice.SetFillColor(); 186 rDevice.DrawRect(rBox, nCornerRadius, nCornerRadius); 187 break; 188 } 189 } 190 191 192 193 } } // end of namespace sfx2::sidebar 194