~linaro-graphics-wg/compiz-plugins-main/oneiric-gles2

« back to all changes in this revision

Viewing changes to animation/include/animation/animeffect.h

  • Committer: Sam Spilsbury
  • Date: 2011-09-20 07:43:55 UTC
  • Revision ID: sam.spilsbury@canonical.com-20110920074355-puzdutejjwsu3ta2
Sync - Remove Plugins

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#ifndef ANIMATION_ANIMEFFECT_H
2
 
#define ANIMATION_ANIMEFFECT_H
3
 
#include "animation.h"
4
 
 
5
 
typedef Animation *(*CreateAnimFunc) (CompWindow *w,
6
 
                                       WindowEvent curWindowEvent,
7
 
                                       float duration,
8
 
                                       const AnimEffect info,
9
 
                                       const CompRect &icon);
10
 
 
11
 
 /// Animation info class that holds the name, the list of supported events, and
12
 
 /// the creator function for a subclass of Animation.
13
 
 /// A pointer to this class is used as an identifier for each implemented
14
 
 /// animation.
15
 
class AnimEffectInfo
16
 
{
17
 
public:
18
 
     AnimEffectInfo (const char *name,
19
 
                     bool usedO, bool usedC, bool usedM, bool usedS, bool usedF,
20
 
                     CreateAnimFunc create, bool isRestackAnim = false);
21
 
     ~AnimEffectInfo () {}
22
 
     
23
 
     bool matchesEffectName (const CompString &animName);
24
 
     
25
 
     bool matchesPluginName (const CompString &pluginName);
26
 
     
27
 
     const char *name; ///< Name of the animation effect, e.g. "animationpack:Implode".
28
 
                                                               
29
 
    /// To be set to true for the window event animation list(s) that
30
 
    /// the new animation (value) should be added to
31
 
    /// (0: open, 1: close, 2: minimize, 3: shade, 4: focus)
32
 
    bool usedForEvents[AnimEventNum];
33
 
 
34
 
    /// Creates an instance of the Animation subclass and returns it as an
35
 
    /// Animation instance.
36
 
    CreateAnimFunc create;
37
 
 
38
 
    /// Is it a complex focus animation? (i.e. restacking-related,
39
 
    /// like FocusFade/Dodge)
40
 
    bool isRestackAnim;
41
 
};
42
 
 
43
 
template<class T>
44
 
Animation *createAnimation (CompWindow *w,
45
 
                            WindowEvent curWindowEvent,
46
 
                            float duration,
47
 
                            const AnimEffect info,
48
 
                            const CompRect &icon)
49
 
{
50
 
    return new T (w, curWindowEvent, duration, info, icon);
51
 
}
52
 
 
53
 
 
54
 
/** The base class for all animations.
55
 
 A n*imations should derive from the closest animation class
56
 
 to override as few methods as possible. Also, an animation
57
 
 method should call ancestors' methods instead of duplicating
58
 
 their code.
59
 
 */
60
 
class Animation
61
 
{
62
 
protected:
63
 
    CompWindow *mWindow;
64
 
    AnimWindow *mAWindow;
65
 
    
66
 
    float mTotalTime;
67
 
    float mRemainingTime;
68
 
    float mTimestep;            ///< to store anim. timestep at anim. start
69
 
    float mTimeElapsedWithinTimeStep;
70
 
    
71
 
    int mTimeSinceLastPaint;    ///< in milliseconds
72
 
    
73
 
    int mOverrideProgressDir;   ///< 0: default dir, 1: forward, 2: backward
74
 
    
75
 
    GLFragment::Attrib mCurPaintAttrib;
76
 
    GLushort mStoredOpacity;
77
 
    WindowEvent mCurWindowEvent;
78
 
    bool mInitialized; ///< whether the animation is initialized (in preparePaint)
79
 
    
80
 
    AnimEffect mInfo; ///< information about the animation class
81
 
    
82
 
    CompRect mIcon;
83
 
    
84
 
    int mDecorTopHeight;
85
 
    int mDecorBottomHeight;
86
 
    
87
 
    GLTexture::List *texturesCache;
88
 
    
89
 
    CompOption::Value &optVal (unsigned int optionId);
90
 
    
91
 
    inline bool       optValB (unsigned int optionId) { return optVal (optionId).b (); }
92
 
    inline int        optValI (unsigned int optionId) { return optVal (optionId).i (); }
93
 
    inline float      optValF (unsigned int optionId) { return optVal (optionId).f (); }
94
 
    inline CompString optValS (unsigned int optionId) { return optVal (optionId).s (); }
95
 
    inline unsigned short *optValC (unsigned int optionId) { return optVal (optionId).c (); }
96
 
    
97
 
public:
98
 
    
99
 
    Animation (CompWindow *w,
100
 
               WindowEvent curWindowEvent,
101
 
               float duration,
102
 
               const AnimEffect info,
103
 
               const CompRect &icon);
104
 
    virtual ~Animation ();
105
 
    
106
 
    inline AnimEffect info () { return mInfo; }
107
 
    
108
 
    // Overridable animation methods.
109
 
    
110
 
    /// Needed since virtual method calls can't be done in the constructor.
111
 
    virtual void init () {}
112
 
    
113
 
    /// To be called during post-animation clean up.
114
 
    virtual void cleanUp (bool closing,
115
 
                          bool destructing) {}
116
 
                          
117
 
    /// Returns true if frame should be skipped (e.g. due to
118
 
    /// higher timestep values). In that case no drawing is
119
 
    /// needed for that window in current frame.
120
 
    virtual bool shouldSkipFrame (int msSinceLastPaintActual);
121
 
 
122
 
    /// Advances the animation time by the given time amount.
123
 
    /// Returns true if more animation time is left.
124
 
    virtual bool advanceTime (int msSinceLastPaint);
125
 
 
126
 
    /// Computes new animation state based on remaining time.
127
 
    virtual void step () {}
128
 
    virtual void updateAttrib (GLWindowPaintAttrib &) {}
129
 
    virtual void updateTransform (GLMatrix &) {}
130
 
    virtual void prePaintWindow () {}
131
 
    virtual void postPaintWindow () {}
132
 
    virtual bool postPaintWindowUsed () { return false; }
133
 
 
134
 
    /// Returns true if the animation is still in progress.
135
 
    virtual bool prePreparePaint (int msSinceLastPaint) { return false; }
136
 
    virtual void postPreparePaint () {}
137
 
 
138
 
    /// Updates the bounding box of damaged region. Should be implemented for
139
 
    /// any animation that doesn't update the whole screen.
140
 
    virtual void updateBB (CompOutput &) {}
141
 
    virtual bool updateBBUsed () { return false; }
142
 
 
143
 
    /// Should return true for effects that make use of a region
144
 
    /// instead of just a bounding box for damaged area.
145
 
    virtual bool stepRegionUsed () { return false; }
146
 
 
147
 
    virtual bool shouldDamageWindowOnStart ();
148
 
    virtual bool shouldDamageWindowOnEnd ();
149
 
 
150
 
    /// Should return false if the animation should be stopped on move
151
 
    virtual bool moveUpdate (int dx, int dy) { return true; }
152
 
 
153
 
    /// Should return false if the animation should be stopped on resize
154
 
    virtual bool resizeUpdate (int dx, int dy,
155
 
                                int dwidth, int dheight) { return true; }
156
 
 
157
 
    virtual void adjustPointerIconSize () {}
158
 
    virtual void addGeometry (const GLTexture::MatrixList &matrix,
159
 
                            const CompRegion            &region,
160
 
                            const CompRegion            &clip,
161
 
                            unsigned int                maxGridWidth,
162
 
                            unsigned int                maxGridHeight);
163
 
    virtual void drawGeometry ();
164
 
 
165
 
    virtual bool paintWindowUsed () { return false; }
166
 
    virtual bool paintWindow (GLWindow                  *gWindow,
167
 
                            const GLWindowPaintAttrib &attrib,
168
 
                            const GLMatrix              &transform,
169
 
                            const CompRegion            &region,
170
 
                            unsigned int                mask)
171
 
    {
172
 
        return gWindow->glPaint (attrib, transform, region, mask);
173
 
    }
174
 
 
175
 
    /// Gets info about the (extension) plugin that implements this animation.
176
 
    /// Should be overriden by a base animation class in every extension plugin.
177
 
    virtual ExtensionPluginInfo *getExtensionPluginInfo ();
178
 
 
179
 
    void drawTexture (GLTexture          *texture,
180
 
                      GLFragment::Attrib &attrib,
181
 
                      unsigned int       mask);
182
 
 
183
 
    // Utility methods
184
 
 
185
 
    void reverse ();
186
 
    inline bool inProgress () { return (mRemainingTime > 0); }
187
 
 
188
 
    inline WindowEvent curWindowEvent () { return mCurWindowEvent; }
189
 
    inline float totalTime () { return mTotalTime; }
190
 
    inline float remainingTime () { return mRemainingTime; }
191
 
 
192
 
    float progressLinear ();
193
 
    float progressEaseInEaseOut ();
194
 
    float progressDecelerateCustom (float progress,
195
 
                                    float minx, float maxx);
196
 
    float progressDecelerate (float progress);
197
 
    AnimDirection getActualAnimDirection (AnimDirection dir,
198
 
                                          bool openDir);
199
 
    void perspectiveDistortAndResetZ (GLMatrix &transform);
200
 
 
201
 
    static void prepareTransform (CompOutput &output,
202
 
                                  GLMatrix &resultTransform,
203
 
                                  GLMatrix &transform);
204
 
    void setInitialized () { mInitialized = true; }
205
 
    inline bool initialized () { return mInitialized; }
206
 
    inline void setCurPaintAttrib (GLFragment::Attrib &newAttrib)
207
 
    { mCurPaintAttrib = newAttrib; }
208
 
};
209
 
#endif