Get the style color and number just once
[LibreOffice.git] / include / vcl / animate / Animation.hxx
bloba6ec7db4192fc6dfac293e2bb88972b4e7d70dea
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 .
20 #ifndef INCLUDED_VCL_ANIMATE_ANIMATION_HXX
21 #define INCLUDED_VCL_ANIMATE_ANIMATION_HXX
23 #include <tools/solar.h>
24 #include <vcl/dllapi.h>
25 #include <vcl/timer.hxx>
26 #include <vcl/animate/AnimationFrame.hxx>
28 #define ANIMATION_TIMEOUT_ON_CLICK 2147483647L
30 class AnimationRenderer;
31 struct AnimationData;
33 class VCL_DLLPUBLIC Animation
35 public:
36 Animation();
37 Animation(const Animation& rAnimation);
38 ~Animation();
40 SAL_DLLPRIVATE Animation& operator=(const Animation& rAnimation);
41 SAL_DLLPRIVATE bool operator==(const Animation& rAnimation) const;
42 bool operator!=(const Animation& rAnimation) const { return !(*this == rAnimation); }
44 void Clear();
46 SAL_DLLPRIVATE bool Start(OutputDevice& rOutDev, const Point& rDestPt, const Size& rDestSz,
47 tools::Long nRendererId, OutputDevice* pFirstFrameOutDev);
49 SAL_DLLPRIVATE void Stop(const OutputDevice* pOutDev = nullptr, tools::Long nRendererId = 0);
51 SAL_DLLPRIVATE void Draw(OutputDevice& rOutDev, const Point& rDestPt) const;
52 SAL_DLLPRIVATE void Draw(OutputDevice& rOutDev, const Point& rDestPt,
53 const Size& rDestSz) const;
55 bool IsInAnimation() const { return mbIsInAnimation; }
56 SAL_DLLPRIVATE bool IsTransparent() const;
58 const Size& GetDisplaySizePixel() const { return maGlobalSize; }
59 void SetDisplaySizePixel(const Size& rSize) { maGlobalSize = rSize; }
61 const BitmapEx& GetBitmapEx() const { return maBitmapEx; }
62 void SetBitmapEx(const BitmapEx& rBmpEx) { maBitmapEx = rBmpEx; }
64 sal_uInt32 GetLoopCount() const { return mnLoopCount; }
65 void SetLoopCount(const sal_uInt32 nLoopCount);
66 SAL_DLLPRIVATE void ResetLoopCount();
68 void SetNotifyHdl(const Link<Animation*, void>& rLink) { maNotifyLink = rLink; }
69 const Link<Animation*, void>& GetNotifyHdl() const { return maNotifyLink; }
71 std::vector<std::unique_ptr<AnimationFrame>>& GetAnimationFrames() { return maFrames; }
72 size_t Count() const { return maFrames.size(); }
73 bool Insert(const AnimationFrame& rAnimationFrame);
74 const AnimationFrame& Get(sal_uInt16 nAnimation) const;
75 void Replace(const AnimationFrame& rNewAnimationBmp, sal_uInt16 nAnimation);
77 SAL_DLLPRIVATE sal_uLong GetSizeBytes() const;
78 SAL_DLLPRIVATE BitmapChecksum GetChecksum() const;
80 public:
81 SAL_DLLPRIVATE void Convert(BmpConversion eConversion);
82 bool ReduceColors(sal_uInt16 nNewColorCount);
84 bool Invert();
85 SAL_DLLPRIVATE void Mirror(BmpMirrorFlags nMirrorFlags);
86 SAL_DLLPRIVATE void Adjust(short nLuminancePercent, short nContrastPercent,
87 short nChannelRPercent, short nChannelGPercent,
88 short nChannelBPercent, double fGamma = 1.0, bool bInvert = false);
90 friend SvStream& ReadAnimation(SvStream& rIStream, Animation& rAnimation);
91 friend SvStream& WriteAnimation(SvStream& rOStream, const Animation& rAnimation);
93 public:
94 SAL_DLLPRIVATE static void ImplIncAnimCount() { gAnimationRendererCount++; }
95 SAL_DLLPRIVATE static void ImplDecAnimCount() { gAnimationRendererCount--; }
96 SAL_DLLPRIVATE sal_uLong ImplGetCurPos() const { return mnFrameIndex; }
98 private:
99 SAL_DLLPRIVATE static sal_uLong gAnimationRendererCount;
101 std::vector<std::unique_ptr<AnimationFrame>> maFrames;
102 std::vector<std::unique_ptr<AnimationRenderer>> maRenderers;
104 Link<Animation*, void> maNotifyLink;
105 BitmapEx maBitmapEx;
106 Timer maTimer;
107 Size maGlobalSize;
108 sal_uInt32 mnLoopCount;
109 sal_uInt32 mnLoops;
110 size_t mnFrameIndex;
111 bool mbIsInAnimation;
112 bool mbLoopTerminated;
114 SAL_DLLPRIVATE std::vector<std::unique_ptr<AnimationData>> CreateAnimationDataItems();
115 SAL_DLLPRIVATE void PopulateRenderers();
116 SAL_DLLPRIVATE void RenderNextFrameInAllRenderers();
117 SAL_DLLPRIVATE void PruneMarkedRenderers();
118 SAL_DLLPRIVATE bool IsAnyRendererActive();
120 SAL_DLLPRIVATE void ImplRestartTimer(sal_uLong nTimeout);
121 DECL_DLLPRIVATE_LINK(ImplTimeoutHdl, Timer*, void);
124 #endif // INCLUDED_VCL_ANIMATE_ANIMATION_HXX
126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */