LibreOffice Module sw (master) 1
DashedLine.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 */
9
10#include <DashedLine.hxx>
11
18#include <vcl/svapp.hxx>
19#include <vcl/settings.hxx>
20#include <memory>
21
22SwDashedLine::SwDashedLine( vcl::Window* pParent, Color& ( *pColorFn )() )
23 : Control( pParent, WB_DIALOGCONTROL | WB_HORZ )
24 , m_pColorFn( pColorFn )
25{
26}
27
29{
30}
31
33{
35 std::unique_ptr<drawinglayer::processor2d::BaseProcessor2D> pProcessor(
37
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;
41
42 basegfx::B2DPoint aStart(double(aRect.Left()), nHalfWidth);
43 basegfx::B2DPoint aEnd(double(aRect.Right()), nHalfWidth);
44
45 basegfx::B2DPolygon aPolygon;
46 aPolygon.append(aStart);
47 aPolygon.append(aEnd);
48
50
52
53 std::vector<double> aStrokePattern;
55 if (rSettings.GetHighContrastMode())
56 {
57 // Only a solid line in high contrast mode
58 aColor = rSettings.GetDialogTextColor().getBColor();
59 }
60 else
61 {
62 // Get a color for the contrast
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);
70
71 // Compute the plain line
72 aSeq[0] = new drawinglayer::primitive2d::PolygonHairlinePrimitive2D(aPolygon, aOtherColor);
73
74 // Dashed line in twips
75 aStrokePattern.push_back(3);
76 aStrokePattern.push_back(3);
77
78 aSeq.resize(2);
79 }
80
81 // Compute the dashed line primitive
82 aSeq[aSeq.size() - 1] =
86 drawinglayer::attribute::StrokeAttribute(std::move(aStrokePattern)));
87
88 pProcessor->process(aSeq);
89}
90
91/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
basegfx::BColor getBColor() const
SAL_WARN_UNUSED_RESULT Point PixelToLogic(const Point &rDevicePt) const
const Color & GetDialogTextColor() const
bool GetHighContrastMode() const
Color &(* m_pColorFn)()
Definition: DashedLine.hxx:18
virtual ~SwDashedLine() override
Definition: DashedLine.cxx:28
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect) override
Definition: DashedLine.cxx:32
SwDashedLine(vcl::Window *pParent, Color &(*pColorFn)())
Definition: DashedLine.cxx:22
void append(const basegfx::B2DPoint &rPoint, sal_uInt32 nCount)
TYPE getZ() const
void setZ(TYPE fZ)
constexpr tools::Long Top() const
constexpr tools::Long Right() const
constexpr tools::Long Left() const
constexpr tools::Long Bottom() const
virtual Size GetSizePixel() const
Sequence< sal_Int8 > aSeq
BColor rgb2hsl(const BColor &rRGBColor)
BColor hsl2rgb(const BColor &rHSLColor)
std::unique_ptr< drawinglayer::processor2d::BaseProcessor2D > createBaseProcessor2DFromOutputDevice(OutputDevice &rTargetOutDev, const drawinglayer::geometry::ViewInformation2D &rViewInformation2D)
WinBits const WB_DIALOGCONTROL
WinBits const WB_HORZ