1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "DrawHelper.hxx"
23 #include <vcl/lineinfo.hxx>
25 namespace sfx2
{ namespace sidebar
{
27 void DrawHelper::DrawBorder(vcl::RenderContext
& rRenderContext
, const Rectangle
& rBox
, const SvBorder
& rBorderSize
,
28 const Paint
& rHorizontalPaint
, const Paint
& rVerticalPaint
)
31 DrawHorizontalLine(rRenderContext
, rBox
.Left(), rBox
.Right(),
32 rBox
.Top(), rBorderSize
.Top(), rHorizontalPaint
);
35 DrawHorizontalLine(rRenderContext
, rBox
.Left() + rBorderSize
.Left(), rBox
.Right(),
36 rBox
.Bottom() - rBorderSize
.Bottom() + 1, rBorderSize
.Bottom(),
39 DrawVerticalLine(rRenderContext
, rBox
.Top() + rBorderSize
.Top(), rBox
.Bottom(),
40 rBox
.Left(), rBorderSize
.Left(), rVerticalPaint
);
42 DrawVerticalLine(rRenderContext
, rBox
.Top() + rBorderSize
.Top(), rBox
.Bottom() - rBorderSize
.Bottom(),
43 rBox
.Right() - rBorderSize
.Right() + 1, rBorderSize
.Right(), rVerticalPaint
);
46 void DrawHelper::DrawHorizontalLine(vcl::RenderContext
& rRenderContext
, const sal_Int32 nLeft
, const sal_Int32 nRight
,
47 const sal_Int32 nY
, const sal_Int32 nHeight
, const Paint
& rPaint
)
49 switch (rPaint
.GetType())
51 case Paint::ColorPaint
:
53 const Color
aColor(rPaint
.GetColor());
54 rRenderContext
.SetLineColor(aColor
);
55 for (sal_Int32 nYOffset
= 0; nYOffset
< nHeight
; ++nYOffset
)
57 rRenderContext
.DrawLine(Point(nLeft
, nY
+ nYOffset
),
58 Point(nRight
, nY
+ nYOffset
));
62 case Paint::GradientPaint
:
63 rRenderContext
.DrawGradient(Rectangle(nLeft
, nY
, nRight
, nY
+ nHeight
- 1),
64 rPaint
.GetGradient());
73 void DrawHelper::DrawVerticalLine(vcl::RenderContext
& rRenderContext
, const sal_Int32 nTop
, const sal_Int32 nBottom
,
74 const sal_Int32 nX
, const sal_Int32 nWidth
, const Paint
& rPaint
)
76 switch (rPaint
.GetType())
78 case Paint::ColorPaint
:
80 const Color
aColor(rPaint
.GetColor());
81 rRenderContext
.SetLineColor(aColor
);
82 for (sal_Int32 nXOffset
= 0; nXOffset
< nWidth
; ++nXOffset
)
84 rRenderContext
.DrawLine(Point(nX
+ nXOffset
, nTop
),
85 Point(nX
+ nXOffset
, nBottom
));
89 case Paint::GradientPaint
:
90 rRenderContext
.DrawGradient(Rectangle(nX
, nTop
, nX
+ nWidth
- 1, nBottom
),
91 rPaint
.GetGradient());
100 void DrawHelper::DrawRoundedRectangle(vcl::RenderContext
& rRenderContext
, const Rectangle
& rBox
, const sal_Int32 nCornerRadius
,
101 const Color
& rBorderColor
, const Paint
& rFillPaint
)
103 rRenderContext
.SetLineColor(rBorderColor
);
104 switch (rFillPaint
.GetType())
106 case Paint::ColorPaint
:
107 rRenderContext
.SetFillColor(rFillPaint
.GetColor());
108 rRenderContext
.DrawRect(rBox
, nCornerRadius
, nCornerRadius
);
111 case Paint::GradientPaint
:
112 rRenderContext
.DrawGradient(rBox
, rFillPaint
.GetGradient());
113 rRenderContext
.SetFillColor();
114 rRenderContext
.DrawRect(rBox
, nCornerRadius
, nCornerRadius
);
119 rRenderContext
.SetFillColor();
120 rRenderContext
.DrawRect(rBox
, nCornerRadius
, nCornerRadius
);
125 } } // end of namespace sfx2::sidebar
127 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */