1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_slideshow.hxx"
26
27 // must be first
28 #include <canvas/debug.hxx>
29 #include <canvas/verbosetrace.hxx>
30 #include <com/sun/star/animations/AnimationColorSpace.hpp>
31
32 #include "coloranimation.hxx"
33 #include "hslcoloranimation.hxx"
34 #include "animationcolornode.hxx"
35 #include "animationfactory.hxx"
36 #include "activitiesfactory.hxx"
37
38 using namespace com::sun::star;
39
40 namespace slideshow {
41 namespace internal {
42
43 namespace {
44 /** Little wrapper for HSL to RGB mapping.
45
46 This class implements the HSLColorAnimation interface,
47 internally converting to RGB and forwarding to
48 ColorAnimation.
49 */
50 class HSLWrapper : public HSLColorAnimation
51 {
52 public:
HSLWrapper(const ColorAnimationSharedPtr & rAnimation)53 HSLWrapper( const ColorAnimationSharedPtr& rAnimation )
54 : mpAnimation( rAnimation )
55 {
56 ENSURE_OR_THROW(
57 mpAnimation,
58 "HSLWrapper::HSLWrapper(): Invalid color animation delegate" );
59 }
60
prefetch(const AnimatableShapeSharedPtr &,const ShapeAttributeLayerSharedPtr &)61 virtual void prefetch( const AnimatableShapeSharedPtr&,
62 const ShapeAttributeLayerSharedPtr& )
63 {}
64
start(const AnimatableShapeSharedPtr & rShape,const ShapeAttributeLayerSharedPtr & rAttrLayer)65 virtual void start( const AnimatableShapeSharedPtr& rShape,
66 const ShapeAttributeLayerSharedPtr& rAttrLayer )
67 {
68 mpAnimation->start( rShape, rAttrLayer );
69 }
70
end()71 virtual void end()
72 {
73 mpAnimation->end();
74 }
75
operator ()(const HSLColor & rColor)76 virtual bool operator()( const HSLColor& rColor )
77 {
78 return (*mpAnimation)( RGBColor( rColor ) );
79 }
80
getUnderlyingValue() const81 virtual HSLColor getUnderlyingValue() const
82 {
83 return HSLColor( mpAnimation->getUnderlyingValue() );
84 }
85
86 private:
87 ColorAnimationSharedPtr mpAnimation;
88 };
89
90 } // anon namespace
91
createActivity() const92 AnimationActivitySharedPtr AnimationColorNode::createActivity() const
93 {
94 ActivitiesFactory::CommonParameters aParms( fillCommonParameters() );
95
96 switch( mxColorNode->getColorInterpolation() )
97 {
98 case animations::AnimationColorSpace::RGB:
99 return ActivitiesFactory::createAnimateActivity(
100 aParms,
101 AnimationFactory::createColorPropertyAnimation(
102 mxColorNode->getAttributeName(),
103 getShape(),
104 getContext().mpSubsettableShapeManager,
105 getSlideSize() ),
106 getXAnimateNode() );
107
108 case animations::AnimationColorSpace::HSL:
109 // Wrap a plain ColorAnimation with the HSL
110 // wrapper, which implements the HSLColorAnimation
111 // interface, and internally converts HSL to RGB color
112 return ActivitiesFactory::createAnimateActivity(
113 aParms,
114 HSLColorAnimationSharedPtr(
115 new HSLWrapper(
116 AnimationFactory::createColorPropertyAnimation(
117 mxColorNode->getAttributeName(),
118 getShape(),
119 getContext().mpSubsettableShapeManager,
120 getSlideSize() ))),
121 mxColorNode );
122
123 default:
124 ENSURE_OR_THROW( false, "AnimationColorNode::createColorActivity(): "
125 "Unexpected color space" );
126 }
127
128 return AnimationActivitySharedPtr();
129 }
130
131 } // namespace internal
132 } // namespace slideshow
133
134