1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
20 #include "ShadowOverlayObject.hxx"
23 #include <svx/sdrpaintwindow.hxx>
24 #include <svx/svdview.hxx>
25 #include <svx/sdr/overlay/overlaymanager.hxx>
27 #include <sw_primitivetypes2d.hxx>
28 #include <drawinglayer/primitive2d/primitivetools2d.hxx>
29 #include <drawinglayer/primitive2d/fillgradientprimitive2d.hxx>
30 #include <basegfx/utils/gradienttools.hxx>
32 namespace sw::sidebarwindows
{
34 // helper SwPostItShadowPrimitive
38 // Used to allow view-dependent primitive definition. For that purpose, the
39 // initially created primitive (this one) always has to be view-independent,
40 // but the decomposition is made view-dependent. Very simple primitive which
41 // just remembers the discrete data and applies it at decomposition time.
42 class ShadowPrimitive
: public drawinglayer::primitive2d::DiscreteMetricDependentPrimitive2D
45 basegfx::B2DPoint maBasePosition
;
46 basegfx::B2DPoint maSecondPosition
;
47 ShadowState maShadowState
;
50 virtual void create2DDecomposition(
51 drawinglayer::primitive2d::Primitive2DContainer
& rContainer
,
52 const drawinglayer::geometry::ViewInformation2D
& rViewInformation
) const override
;
56 const basegfx::B2DPoint
& rBasePosition
,
57 const basegfx::B2DPoint
& rSecondPosition
,
58 ShadowState aShadowState
)
59 : maBasePosition(rBasePosition
),
60 maSecondPosition(rSecondPosition
),
61 maShadowState(aShadowState
)
65 const basegfx::B2DPoint
& getSecondPosition() const { return maSecondPosition
; }
67 virtual bool operator==( const drawinglayer::primitive2d::BasePrimitive2D
& rPrimitive
) const override
;
69 virtual sal_uInt32
getPrimitive2DID() const override
;
74 void ShadowPrimitive::create2DDecomposition(
75 drawinglayer::primitive2d::Primitive2DContainer
& rContainer
,
76 const drawinglayer::geometry::ViewInformation2D
& /*rViewInformation*/) const
78 // get logic sizes in object coordinate system
79 basegfx::B2DRange
aRange(maBasePosition
);
85 aRange
.expand(basegfx::B2DTuple(getSecondPosition().getX(), getSecondPosition().getY() + (2.0 * getDiscreteUnit())));
87 ::drawinglayer::attribute::FillGradientAttribute
aFillGradientAttribute(
88 css::awt::GradientStyle_LINEAR
,
94 basegfx::BColor(230.0/255.0,230.0/255.0,230.0/255.0),
95 basegfx::BColor(180.0/255.0,180.0/255.0,180.0/255.0)));
98 new drawinglayer::primitive2d::FillGradientPrimitive2D(
100 std::move(aFillGradientAttribute
)));
105 aRange
.expand(basegfx::B2DTuple(getSecondPosition().getX(), getSecondPosition().getY() + (4.0 * getDiscreteUnit())));
106 drawinglayer::attribute::FillGradientAttribute
aFillGradientAttribute(
107 css::awt::GradientStyle_LINEAR
,
112 basegfx::BColorStops(
113 basegfx::BColor(230.0/255.0,230.0/255.0,230.0/255.0),
114 basegfx::BColor(180.0/255.0,180.0/255.0,180.0/255.0)));
116 rContainer
.push_back(
117 new drawinglayer::primitive2d::FillGradientPrimitive2D(
119 std::move(aFillGradientAttribute
)));
124 aRange
.expand(basegfx::B2DTuple(getSecondPosition().getX(), getSecondPosition().getY() + (4.0 * getDiscreteUnit())));
125 drawinglayer::attribute::FillGradientAttribute
aFillGradientAttribute(
126 css::awt::GradientStyle_LINEAR
,
131 basegfx::BColorStops(
132 basegfx::BColor(230.0/255.0,230.0/255.0,230.0/255.0),
133 basegfx::BColor(83.0/255.0,83.0/255.0,83.0/255.0)));
135 rContainer
.push_back(
136 new drawinglayer::primitive2d::FillGradientPrimitive2D(
138 std::move(aFillGradientAttribute
)));
148 bool ShadowPrimitive::operator==( const drawinglayer::primitive2d::BasePrimitive2D
& rPrimitive
) const
150 if(drawinglayer::primitive2d::DiscreteMetricDependentPrimitive2D::operator==(rPrimitive
))
152 const ShadowPrimitive
& rCompare
= static_cast< const ShadowPrimitive
& >(rPrimitive
);
154 return (maBasePosition
== rCompare
.maBasePosition
155 && getSecondPosition() == rCompare
.getSecondPosition()
156 && maShadowState
== rCompare
.maShadowState
);
162 sal_uInt32
ShadowPrimitive::getPrimitive2DID() const
164 return PRIMITIVE2D_ID_SWSIDEBARSHADOWPRIMITIVE
;
167 /* static */ std::unique_ptr
<ShadowOverlayObject
> ShadowOverlayObject::CreateShadowOverlayObject( SwView
const & rDocView
)
169 std::unique_ptr
<ShadowOverlayObject
> pShadowOverlayObject
;
171 if ( rDocView
.GetDrawView() )
173 SdrPaintWindow
* pPaintWindow
= rDocView
.GetDrawView()->GetPaintWindow(0);
176 const rtl::Reference
< sdr::overlay::OverlayManager
>& xOverlayManager
= pPaintWindow
->GetOverlayManager();
178 if ( xOverlayManager
.is() )
180 pShadowOverlayObject
.reset( new ShadowOverlayObject( basegfx::B2DPoint(0,0),
181 basegfx::B2DPoint(0,0),
183 xOverlayManager
->add(*pShadowOverlayObject
);
188 return pShadowOverlayObject
;
191 ShadowOverlayObject::ShadowOverlayObject( const basegfx::B2DPoint
& rBasePos
,
192 const basegfx::B2DPoint
& rSecondPosition
,
194 : OverlayObjectWithBasePosition(rBasePos
, aBaseColor
)
195 , maSecondPosition(rSecondPosition
)
196 , mShadowState(SS_NORMAL
)
200 ShadowOverlayObject::~ShadowOverlayObject()
202 if ( getOverlayManager() )
204 getOverlayManager()->remove(*this);
208 drawinglayer::primitive2d::Primitive2DContainer
ShadowOverlayObject::createOverlayObjectPrimitive2DSequence()
210 const drawinglayer::primitive2d::Primitive2DReference
aReference(
211 new ShadowPrimitive( getBasePosition(),
213 GetShadowState() ) );
214 return drawinglayer::primitive2d::Primitive2DContainer
{ aReference
};
217 void ShadowOverlayObject::SetShadowState(ShadowState aState
)
219 if (mShadowState
!= aState
)
221 mShadowState
= aState
;
227 void ShadowOverlayObject::SetPosition( const basegfx::B2DPoint
& rPoint1
,
228 const basegfx::B2DPoint
& rPoint2
)
230 if(!rPoint1
.equal(getBasePosition()) || !rPoint2
.equal(maSecondPosition
))
232 maBasePosition
= rPoint1
;
233 maSecondPosition
= rPoint2
;
239 } // end of namespace sw::sidebarwindows
241 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */