Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * Version: MPL 1.1 / GPLv3+ / LGPLv3+
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License or as specified alternatively below. You may obtain a copy of
8 : * the License at http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * Major Contributor(s):
16 : * [ Copyright (C) 2011 SUSE <cbosdonnat@suse.com> (initial developer) ]
17 : *
18 : * All Rights Reserved.
19 : *
20 : * For minor contributions see the git repository.
21 : *
22 : * Alternatively, the contents of this file may be used under the terms of
23 : * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
24 : * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
25 : * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
26 : * instead of those above.
27 : */
28 :
29 : #include <DashedLine.hxx>
30 :
31 : #include <basegfx/color/bcolortools.hxx>
32 : #include <basegfx/polygon/b2dpolygon.hxx>
33 : #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
34 : #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
35 : #include <drawinglayer/processor2d/baseprocessor2d.hxx>
36 : #include <drawinglayer/processor2d/processorfromoutputdevice.hxx>
37 : #include <vcl/svapp.hxx>
38 :
39 13 : SwDashedLine::SwDashedLine( Window* pParent, Color& ( *pColorFn )() ) :
40 : FixedLine( pParent, WB_DIALOGCONTROL | WB_HORZ ),
41 13 : m_pColorFn( pColorFn )
42 : {
43 13 : }
44 :
45 1 : SwDashedLine::~SwDashedLine( )
46 : {
47 1 : }
48 :
49 6 : void SwDashedLine::Paint( const Rectangle& )
50 : {
51 6 : const drawinglayer::geometry::ViewInformation2D aNewViewInfos;
52 : drawinglayer::processor2d::BaseProcessor2D * pProcessor =
53 : drawinglayer::processor2d::createBaseProcessor2DFromOutputDevice(
54 6 : *this, aNewViewInfos );
55 :
56 : // Compute the start and end points
57 6 : const Rectangle aRect( Rectangle( Point( 0, 0 ), PixelToLogic( GetSizePixel() ) ) );
58 6 : double nHalfWidth = double( aRect.Top() + aRect.Bottom() ) / 2.0;
59 :
60 6 : basegfx::B2DPoint aStart( double( aRect.Left() ), nHalfWidth );
61 6 : basegfx::B2DPoint aEnd( double( aRect.Right() ), nHalfWidth );
62 :
63 6 : basegfx::B2DPolygon aPolygon;
64 6 : aPolygon.append( aStart );
65 6 : aPolygon.append( aEnd );
66 :
67 6 : drawinglayer::primitive2d::Primitive2DSequence aSeq( 1 );
68 :
69 6 : const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
70 :
71 6 : std::vector< double > aStrokePattern;
72 6 : basegfx::BColor aColor = m_pColorFn().getBColor();
73 6 : if ( rSettings.GetHighContrastMode( ) )
74 : {
75 : // Only a solid line in high contrast mode
76 0 : aColor = rSettings.GetDialogTextColor().getBColor();
77 : }
78 : else
79 : {
80 : // Get a color for the contrast
81 6 : basegfx::BColor aHslLine = basegfx::tools::rgb2hsl( aColor );
82 6 : double nLuminance = aHslLine.getZ();
83 6 : nLuminance += ( 1.0 - nLuminance ) * 0.75;
84 6 : if ( aHslLine.getZ() > 0.7 )
85 0 : nLuminance = aHslLine.getZ() * 0.7;
86 6 : aHslLine.setZ( nLuminance );
87 6 : const basegfx::BColor aOtherColor = basegfx::tools::hsl2rgb( aHslLine );
88 :
89 : // Compute the plain line
90 : drawinglayer::primitive2d::PolygonHairlinePrimitive2D * pPlainLine =
91 : new drawinglayer::primitive2d::PolygonHairlinePrimitive2D(
92 6 : aPolygon, aOtherColor );
93 :
94 6 : aSeq[0] = drawinglayer::primitive2d::Primitive2DReference( pPlainLine );
95 : // Dashed line in twips
96 6 : aStrokePattern.push_back( 3 );
97 6 : aStrokePattern.push_back( 3 );
98 :
99 6 : aSeq.realloc( 2 );
100 : }
101 :
102 : // Compute the dashed line primitive
103 : drawinglayer::primitive2d::PolyPolygonStrokePrimitive2D * pLine =
104 : new drawinglayer::primitive2d::PolyPolygonStrokePrimitive2D (
105 : basegfx::B2DPolyPolygon( aPolygon ),
106 6 : drawinglayer::attribute::LineAttribute( m_pColorFn().getBColor() ),
107 12 : drawinglayer::attribute::StrokeAttribute( aStrokePattern ) );
108 :
109 6 : aSeq[ aSeq.getLength() - 1 ] = drawinglayer::primitive2d::Primitive2DReference( pLine );
110 :
111 6 : pProcessor->process( aSeq );
112 6 : delete pProcessor;
113 6 : }
114 :
115 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|