Line data Source code
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 :
12 : #include <basegfx/color/bcolortools.hxx>
13 : #include <basegfx/polygon/b2dpolygon.hxx>
14 : #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
15 : #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
16 : #include <drawinglayer/processor2d/baseprocessor2d.hxx>
17 : #include <drawinglayer/processor2d/processorfromoutputdevice.hxx>
18 : #include <vcl/svapp.hxx>
19 : #include <vcl/settings.hxx>
20 : #include <boost/scoped_ptr.hpp>
21 :
22 428 : SwDashedLine::SwDashedLine( vcl::Window* pParent, Color& ( *pColorFn )() ) :
23 : FixedLine( pParent, WB_DIALOGCONTROL | WB_HORZ ),
24 428 : m_pColorFn( pColorFn )
25 : {
26 428 : }
27 :
28 428 : SwDashedLine::~SwDashedLine( )
29 : {
30 428 : }
31 :
32 116 : void SwDashedLine::Paint( const Rectangle& )
33 : {
34 116 : const drawinglayer::geometry::ViewInformation2D aNewViewInfos;
35 : boost::scoped_ptr<drawinglayer::processor2d::BaseProcessor2D> pProcessor(
36 : drawinglayer::processor2d::createBaseProcessor2DFromOutputDevice(
37 232 : *this, aNewViewInfos ));
38 :
39 : // Compute the start and end points
40 116 : const Rectangle aRect( Rectangle( Point( 0, 0 ), PixelToLogic( GetSizePixel() ) ) );
41 116 : double nHalfWidth = double( aRect.Top() + aRect.Bottom() ) / 2.0;
42 :
43 232 : basegfx::B2DPoint aStart( double( aRect.Left() ), nHalfWidth );
44 232 : basegfx::B2DPoint aEnd( double( aRect.Right() ), nHalfWidth );
45 :
46 232 : basegfx::B2DPolygon aPolygon;
47 116 : aPolygon.append( aStart );
48 116 : aPolygon.append( aEnd );
49 :
50 232 : drawinglayer::primitive2d::Primitive2DSequence aSeq( 1 );
51 :
52 116 : const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
53 :
54 232 : std::vector< double > aStrokePattern;
55 232 : basegfx::BColor aColor = m_pColorFn().getBColor();
56 116 : if ( rSettings.GetHighContrastMode( ) )
57 : {
58 : // Only a solid line in high contrast mode
59 0 : aColor = rSettings.GetDialogTextColor().getBColor();
60 : }
61 : else
62 : {
63 : // Get a color for the contrast
64 116 : basegfx::BColor aHslLine = basegfx::tools::rgb2hsl( aColor );
65 116 : double nLuminance = aHslLine.getZ();
66 116 : nLuminance += ( 1.0 - nLuminance ) * 0.75;
67 116 : if ( aHslLine.getZ() > 0.7 )
68 0 : nLuminance = aHslLine.getZ() * 0.7;
69 116 : aHslLine.setZ( nLuminance );
70 232 : const basegfx::BColor aOtherColor = basegfx::tools::hsl2rgb( aHslLine );
71 :
72 : // Compute the plain line
73 : drawinglayer::primitive2d::PolygonHairlinePrimitive2D * pPlainLine =
74 : new drawinglayer::primitive2d::PolygonHairlinePrimitive2D(
75 116 : aPolygon, aOtherColor );
76 :
77 116 : aSeq[0] = drawinglayer::primitive2d::Primitive2DReference( pPlainLine );
78 : // Dashed line in twips
79 116 : aStrokePattern.push_back( 3 );
80 116 : aStrokePattern.push_back( 3 );
81 :
82 232 : aSeq.realloc( 2 );
83 : }
84 :
85 : // Compute the dashed line primitive
86 : drawinglayer::primitive2d::PolyPolygonStrokePrimitive2D * pLine =
87 : new drawinglayer::primitive2d::PolyPolygonStrokePrimitive2D (
88 : basegfx::B2DPolyPolygon( aPolygon ),
89 116 : drawinglayer::attribute::LineAttribute( m_pColorFn().getBColor() ),
90 232 : drawinglayer::attribute::StrokeAttribute( aStrokePattern ) );
91 :
92 116 : aSeq[ aSeq.getLength() - 1 ] = drawinglayer::primitive2d::Primitive2DReference( pLine );
93 :
94 232 : pProcessor->process( aSeq );
95 386 : }
96 :
97 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|