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/.
10 #include <DashedLine.hxx>
12 #include <basegfx/color/bcolortools.hxx>
13 #include <basegfx/polygon/b2dpolygon.hxx>
14 #include <drawinglayer/primitive2d/PolygonHairlinePrimitive2D.hxx>
15 #include <drawinglayer/primitive2d/PolyPolygonStrokePrimitive2D.hxx>
16 #include <drawinglayer/processor2d/baseprocessor2d.hxx>
17 #include <drawinglayer/processor2d/processor2dtools.hxx>
18 #include <vcl/svapp.hxx>
19 #include <vcl/settings.hxx>
22 SwDashedLine::SwDashedLine( vcl::Window
* pParent
, const Color
& ( SwViewOption::* pColorFn
)() const )
23 : Control( pParent
, WB_DIALOGCONTROL
| WB_HORZ
)
24 , m_pColorFn( pColorFn
)
28 SwDashedLine::~SwDashedLine( )
32 void SwDashedLine::Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
&)
34 const drawinglayer::geometry::ViewInformation2D aNewViewInfos
;
35 std::unique_ptr
<drawinglayer::processor2d::BaseProcessor2D
> pProcessor(
36 drawinglayer::processor2d::createProcessor2DFromOutputDevice(rRenderContext
, aNewViewInfos
));
38 // Compute the start and end points
39 const tools::Rectangle
aRect(tools::Rectangle(Point(0, 0), rRenderContext
.PixelToLogic(GetSizePixel())));
40 double nHalfWidth
= double(aRect
.Top() + aRect
.Bottom()) / 2.0;
42 basegfx::B2DPoint
aStart(double(aRect
.Left()), nHalfWidth
);
43 basegfx::B2DPoint
aEnd(double(aRect
.Right()), nHalfWidth
);
45 basegfx::B2DPolygon aPolygon
;
46 aPolygon
.append(aStart
);
47 aPolygon
.append(aEnd
);
49 drawinglayer::primitive2d::Primitive2DContainer
aSeq(1);
51 const StyleSettings
& rSettings
= Application::GetSettings().GetStyleSettings();
53 std::vector
<double> aStrokePattern
;
54 basegfx::BColor aColor
= (SwViewOption::GetCurrentViewOptions().*m_pColorFn
)().getBColor();
55 if (rSettings
.GetHighContrastMode())
57 // Only a solid line in high contrast mode
58 aColor
= rSettings
.GetDialogTextColor().getBColor();
62 // Get a color for the contrast
63 basegfx::BColor aHslLine
= basegfx::utils::rgb2hsl(aColor
);
64 double nLuminance
= aHslLine
.getZ();
65 nLuminance
+= (1.0 - nLuminance
) * 0.75;
66 if (aHslLine
.getZ() > 0.7)
67 nLuminance
= aHslLine
.getZ() * 0.7;
68 aHslLine
.setZ(nLuminance
);
69 const basegfx::BColor aOtherColor
= basegfx::utils::hsl2rgb(aHslLine
);
71 // Compute the plain line
72 aSeq
[0] = new drawinglayer::primitive2d::PolygonHairlinePrimitive2D(aPolygon
, aOtherColor
);
74 // Dashed line in twips
75 aStrokePattern
.push_back(3);
76 aStrokePattern
.push_back(3);
81 // Compute the dashed line primitive
82 aSeq
[aSeq
.size() - 1] =
83 new drawinglayer::primitive2d::PolyPolygonStrokePrimitive2D(
84 basegfx::B2DPolyPolygon(aPolygon
),
85 drawinglayer::attribute::LineAttribute((SwViewOption::GetCurrentViewOptions().*m_pColorFn
)().getBColor()),
86 drawinglayer::attribute::StrokeAttribute(std::move(aStrokePattern
)));
88 pProcessor
->process(aSeq
);
91 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */