Coverage Report

Created: 2025-12-31 10:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/include/drawinglayer/primitive2d/animatedprimitive2d.hxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/*
3
 * This file is part of the LibreOffice project.
4
 *
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/.
8
 *
9
 * This file incorporates work covered by the following license notice:
10
 *
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 .
18
 */
19
20
#pragma once
21
22
#include <drawinglayer/drawinglayerdllapi.h>
23
24
#include <drawinglayer/primitive2d/groupprimitive2d.hxx>
25
#include <basegfx/matrix/b2dhommatrixtools.hxx>
26
#include <memory>
27
28
// predefines
29
namespace drawinglayer::animation
30
{
31
class AnimationEntry;
32
}
33
34
namespace basegfx
35
{
36
class B2DHomMatrix;
37
}
38
39
namespace drawinglayer::primitive2d
40
{
41
/** AnimatedSwitchPrimitive2D class
42
43
    This is the basic class for simple, animated primitives. The basic idea
44
    is to have an animation definition (AnimationEntry) who's basic
45
    functionality is to return a state value for any given animation time in
46
    the range of [0.0 .. 1.0]. Depending on the state, the decomposition
47
    calculates an index, which of the members of the child vector is to
48
    be visualized.
49
50
    An example: For blinking, the Child vector should exist of two entries;
51
    for values of [0.0 .. 0.5] the first, else the last entry will be used.
52
    This mechanism is not limited to two entries, though.
53
 */
54
class DRAWINGLAYER_DLLPUBLIC AnimatedSwitchPrimitive2D : public GroupPrimitive2D
55
{
56
private:
57
    /**
58
        The animation definition which allows translation of a point in time
59
        to an animation state [0.0 .. 1.0]. This member contains a cloned
60
        definition and is owned by this implementation.
61
     */
62
    std::unique_ptr<animation::AnimationEntry> mpAnimationEntry;
63
64
    /** flag if this is a text or graphic animation. Necessary since SdrViews need to differentiate
65
        between both types if they are on/off
66
     */
67
    bool mbIsTextAnimation : 1;
68
69
protected:
70
    /** write access right for classes deriving from this who want to do special
71
        things (e.g. optimization, buffering).
72
        Caution: This is an exception from the read-only, non-modifiable paradigm
73
        for primitives, so special preparations may be needed. Usually should
74
        only be used for initialization (e.g. in a derived constructor)
75
    */
76
    void setAnimationEntry(const animation::AnimationEntry& rNew);
77
78
public:
79
    /// constructor
80
    AnimatedSwitchPrimitive2D(const animation::AnimationEntry& rAnimationEntry,
81
                              Primitive2DContainer&& aChildren, bool bIsTextAnimation);
82
83
    /// destructor - needed due to mpAnimationEntry
84
    virtual ~AnimatedSwitchPrimitive2D() override;
85
86
    /// data read access
87
0
    const animation::AnimationEntry& getAnimationEntry() const { return *mpAnimationEntry; }
88
0
    bool isTextAnimation() const { return mbIsTextAnimation; }
89
0
    bool isGraphicAnimation() const { return !isTextAnimation(); }
90
91
    /// compare operator
92
    virtual bool operator==(const BasePrimitive2D& rPrimitive) const override;
93
94
    /// provide unique ID
95
    virtual sal_uInt32 getPrimitive2DID() const override;
96
97
    /** Override getDecomposition() here since the decompose
98
        depends on the point in time, so the default implementation is
99
        not useful here, it needs to be handled locally
100
     */
101
    virtual void
102
    get2DDecomposition(Primitive2DDecompositionVisitor& rVisitor,
103
                       const geometry::ViewInformation2D& rViewInformation) const override;
104
};
105
106
/** AnimatedBlinkPrimitive2D class
107
108
    Basically the same mechanism as in AnimatedSwitchPrimitive2D, but the
109
    decomposition is specialized in delivering the children in the
110
    range [0.0.. 0.5] and an empty sequence else
111
 */
112
class DRAWINGLAYER_DLLPUBLIC AnimatedBlinkPrimitive2D final : public AnimatedSwitchPrimitive2D
113
{
114
public:
115
    /// constructor
116
    AnimatedBlinkPrimitive2D(const animation::AnimationEntry& rAnimationEntry,
117
                             Primitive2DContainer&& aChildren);
118
119
    /// create local decomposition
120
    virtual void
121
    get2DDecomposition(Primitive2DDecompositionVisitor& rVisitor,
122
                       const geometry::ViewInformation2D& rViewInformation) const override;
123
124
    /// provide unique ID
125
    virtual sal_uInt32 getPrimitive2DID() const override;
126
};
127
128
/** AnimatedInterpolatePrimitive2D class
129
130
    Specialized on multi-step animations based on matrix transformations. The
131
    Child sequence will be embedded in a matrix transformation. That transformation
132
    will be linearly combined from the decomposed values and the animation value
133
    to allow a smooth animation.
134
 */
135
class DRAWINGLAYER_DLLPUBLIC AnimatedInterpolatePrimitive2D final : public AnimatedSwitchPrimitive2D
136
{
137
private:
138
    /// the transformations
139
    std::vector<basegfx::utils::B2DHomMatrixBufferedDecompose> maMatrixStack;
140
141
public:
142
    /// constructor
143
    AnimatedInterpolatePrimitive2D(const std::vector<basegfx::B2DHomMatrix>& rmMatrixStack,
144
                                   const animation::AnimationEntry& rAnimationEntry,
145
                                   Primitive2DContainer&& aChildren);
146
147
    /// create local decomposition
148
    virtual void
149
    get2DDecomposition(Primitive2DDecompositionVisitor& rVisitor,
150
                       const geometry::ViewInformation2D& rViewInformation) const override;
151
152
    /// provide unique ID
153
    virtual sal_uInt32 getPrimitive2DID() const override;
154
};
155
156
} // end of namespace drawinglayer::primitive2d
157
158
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */