Use o3tl::convert in Math
[LibreOffice.git] / slideshow / source / engine / animationnodes / animationcolornode.cxx
blob14a32aae4af96465b74dfd330936e735da9e42c7
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 <com/sun/star/animations/AnimationColorSpace.hpp>
23 #include <coloranimation.hxx>
24 #include <hslcoloranimation.hxx>
25 #include "animationcolornode.hxx"
26 #include <animationfactory.hxx>
27 #include <activitiesfactory.hxx>
29 using namespace com::sun::star;
31 namespace slideshow::internal {
33 namespace {
34 /** Little wrapper for HSL to RGB mapping.
36 This class implements the HSLColorAnimation interface,
37 internally converting to RGB and forwarding to
38 ColorAnimation.
40 class HSLWrapper : public HSLColorAnimation
42 public:
43 explicit HSLWrapper( const ColorAnimationSharedPtr& rAnimation )
44 : mpAnimation( rAnimation )
46 ENSURE_OR_THROW(
47 mpAnimation,
48 "HSLWrapper::HSLWrapper(): Invalid color animation delegate" );
51 virtual void prefetch() override
54 virtual void start( const AnimatableShapeSharedPtr& rShape,
55 const ShapeAttributeLayerSharedPtr& rAttrLayer ) override
57 mpAnimation->start( rShape, rAttrLayer );
60 virtual void end() override
62 mpAnimation->end();
65 virtual bool operator()( const HSLColor& rColor ) override
67 return (*mpAnimation)( RGBColor( rColor ) );
70 virtual HSLColor getUnderlyingValue() const override
72 return HSLColor( mpAnimation->getUnderlyingValue() );
75 private:
76 ColorAnimationSharedPtr mpAnimation;
79 } // anon namespace
81 AnimationActivitySharedPtr AnimationColorNode::createActivity() const
83 ActivitiesFactory::CommonParameters aParms( fillCommonParameters() );
85 switch( mxColorNode->getColorInterpolation() )
87 case animations::AnimationColorSpace::RGB:
88 return ActivitiesFactory::createAnimateActivity(
89 aParms,
90 AnimationFactory::createColorPropertyAnimation(
91 mxColorNode->getAttributeName(),
92 getShape(),
93 getContext().mpSubsettableShapeManager,
94 getSlideSize(),
95 getContext().mpBox2DWorld ),
96 getXAnimateNode() );
98 case animations::AnimationColorSpace::HSL:
99 // Wrap a plain ColorAnimation with the HSL
100 // wrapper, which implements the HSLColorAnimation
101 // interface, and internally converts HSL to RGB color
102 return ActivitiesFactory::createAnimateActivity(
103 aParms,
104 std::make_shared<HSLWrapper>(
105 AnimationFactory::createColorPropertyAnimation(
106 mxColorNode->getAttributeName(),
107 getShape(),
108 getContext().mpSubsettableShapeManager,
109 getSlideSize(),
110 getContext().mpBox2DWorld )),
111 mxColorNode );
113 default:
114 ENSURE_OR_THROW( false, "AnimationColorNode::createColorActivity(): "
115 "Unexpected color space" );
118 return AnimationActivitySharedPtr();
121 } // namespace slideshow::internal
123 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */