tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / cppcanvas / source / wrapper / implpolypolygon.cxx
blob536bfa60a53b18c858160e884a28130bdd2ba5a0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <rtl/math.hxx>
22 #include <osl/diagnose.h>
24 #include <com/sun/star/rendering/XCanvas.hpp>
25 #include <com/sun/star/rendering/PathJoinType.hpp>
26 #include <com/sun/star/rendering/PathCapType.hpp>
28 #include "implpolypolygon.hxx"
29 #include <tools.hxx>
30 #include <utility>
33 using namespace ::com::sun::star;
36 namespace cppcanvas::internal
38 ImplPolyPolygon::ImplPolyPolygon( const CanvasSharedPtr& rParentCanvas,
39 uno::Reference< rendering::XPolyPolygon2D > xPolyPoly ) :
40 CanvasGraphicHelper( rParentCanvas ),
41 mxPolyPoly(std::move( xPolyPoly )),
42 maStrokeAttributes(1.0,
43 10.0,
44 uno::Sequence< double >(),
45 uno::Sequence< double >(),
46 rendering::PathCapType::ROUND,
47 rendering::PathCapType::ROUND,
48 rendering::PathJoinType::ROUND ),
49 mbFillColorSet( false ),
50 mbStrokeColorSet( false )
52 OSL_ENSURE( mxPolyPoly.is(), "PolyPolygonImpl::PolyPolygonImpl: no valid polygon" );
55 ImplPolyPolygon::~ImplPolyPolygon()
59 void ImplPolyPolygon::setRGBAFillColor( IntSRGBA aColor )
61 maFillColor = tools::intSRGBAToDoubleSequence( aColor );
62 mbFillColorSet = true;
65 void ImplPolyPolygon::setRGBALineColor( IntSRGBA aColor )
67 maStrokeColor = tools::intSRGBAToDoubleSequence( aColor );
68 mbStrokeColorSet = true;
71 IntSRGBA ImplPolyPolygon::getRGBALineColor() const
73 return tools::doubleSequenceToIntSRGBA( maStrokeColor );
76 void ImplPolyPolygon::setStrokeWidth( const double& rStrokeWidth )
78 maStrokeAttributes.StrokeWidth = rStrokeWidth;
81 double ImplPolyPolygon::getStrokeWidth() const
83 return maStrokeAttributes.StrokeWidth;
86 bool ImplPolyPolygon::draw() const
88 CanvasSharedPtr pCanvas( getCanvas() );
90 OSL_ENSURE( pCanvas && pCanvas->getUNOCanvas().is(),
91 "ImplBitmap::draw: invalid canvas" );
93 if( !pCanvas ||
94 !pCanvas->getUNOCanvas().is() )
95 return false;
97 if( mbFillColorSet )
99 rendering::RenderState aLocalState( getRenderState() );
100 aLocalState.DeviceColor = maFillColor;
102 pCanvas->getUNOCanvas()->fillPolyPolygon( mxPolyPoly,
103 pCanvas->getViewState(),
104 aLocalState );
107 if( mbStrokeColorSet )
109 rendering::RenderState aLocalState( getRenderState() );
110 aLocalState.DeviceColor = maStrokeColor;
112 if( ::rtl::math::approxEqual(maStrokeAttributes.StrokeWidth, 1.0) )
113 pCanvas->getUNOCanvas()->drawPolyPolygon( mxPolyPoly,
114 pCanvas->getViewState(),
115 aLocalState );
116 else
117 pCanvas->getUNOCanvas()->strokePolyPolygon( mxPolyPoly,
118 pCanvas->getViewState(),
119 aLocalState,
120 maStrokeAttributes );
123 return true;
126 uno::Reference< rendering::XPolyPolygon2D > ImplPolyPolygon::getUNOPolyPolygon() const
128 return mxPolyPoly;
133 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */