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 
22 SwDashedLine::SwDashedLine( vcl::Window* pParent, Color& ( *pColorFn )() ) :
23  FixedLine( 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
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);
70 
71  // Compute the plain line
74 
76  // Dashed line in twips
77  aStrokePattern.push_back(3);
78  aStrokePattern.push_back(3);
79 
80  aSeq.resize(2);
81  }
82 
83  // Compute the dashed line primitive
86  basegfx::B2DPolyPolygon(aPolygon),
89 
90  aSeq[aSeq.size() - 1] = drawinglayer::primitive2d::Primitive2DReference(pLine);
91 
92  pProcessor->process(aSeq);
93 }
94 
95 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void append(const basegfx::B2DPoint &rPoint, sal_uInt32 nCount)
BColor rgb2hsl(const BColor &rRGBColor)
virtual ~SwDashedLine() override
Definition: DashedLine.cxx:28
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
virtual Size GetSizePixel() const
double getZ() const
long Right() const
Color &(*const m_pColorFn)()
Definition: DashedLine.hxx:18
bool GetHighContrastMode() const
long Top() const
SwDashedLine(vcl::Window *pParent, Color &(*pColorFn)())
Definition: DashedLine.cxx:22
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect) override
Definition: DashedLine.cxx:32
BColor hsl2rgb(const BColor &rHSLColor)
WinBits const WB_DIALOGCONTROL
long Bottom() const
Point PixelToLogic(const Point &rDevicePt) const
std::unique_ptr< drawinglayer::processor2d::BaseProcessor2D > createBaseProcessor2DFromOutputDevice(OutputDevice &rTargetOutDev, const drawinglayer::geometry::ViewInformation2D &rViewInformation2D)
css::uno::Reference< css::graphic::XPrimitive2D > Primitive2DReference
long Left() const
basegfx::BColor getBColor() const
const Color & GetDialogTextColor() const
WinBits const WB_HORZ
void setZ(double fZ)