File: myx_gc_animation.h

package info (click to toggle)
mysql-gui-tools 5.0r12-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 105,540 kB
  • ctags: 50,897
  • sloc: sql: 348,439; pascal: 285,780; cpp: 94,578; ansic: 90,768; objc: 33,761; sh: 25,629; xml: 10,924; yacc: 10,755; java: 9,986; php: 2,806; python: 2,068; makefile: 1,945; perl: 3
file content (186 lines) | stat: -rw-r--r-- 7,074 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/* Copyright (C) 2004 MySQL AB

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */

/**
 * @file myx_gc_animation.h 
 * @brief Implementation of the animation manager.
 * 
 */

#ifndef __GC_ANIMATION_H__
#define __GC_ANIMATION_H__

#include "myx_gc_base.h"
#include "myx_gc_canvas.h"
#include "myx_gc_figure.h"

//----------------------------------------------------------------------------------------------------------------------

typedef enum tagInterpolation
{
  GC_INTERPOLATION_LINEAR,
  GC_INTERPOLATION_ACCELLERATED
} TInterpolation;

class CFigureInstance;
class CAnimationManager;
/**
 * This is the base animation class, which handles time computations and communication with the
 * animated elements.
 */
class GENERIC_CANVAS_API CAnimation
{
  friend class CAnimationManager;
protected:
  CAnimationManager* FManager;
  float FDuration;           // The time the entire animation can use (in milliseconds).
  float FUsedTime;           // The time the animation already consumed (in milliseconds, not counted in suspended mode).
  bool FSuspended;           // If true then the animation is stopped and has no effect.

  virtual bool __cdecl animate(int step);
public:
  CAnimation(CAnimationManager* manager, int duration, bool suspended);
  virtual ~CAnimation(void);

  virtual void __cdecl addDependency(CAnimation* animation);
  virtual void __cdecl animationStarted(void) {};
  virtual void __cdecl animationStopped(void) {};
  virtual bool __cdecl finished(void);
  virtual bool __cdecl suspendedGet(void) { return FSuspended; };
  virtual void __cdecl suspendedSet(bool suspended);
};

/**
 * Describes properties of one point in a series of movements commonly known as path.
 */
typedef struct tagAnimationPoint
{
  TVertex offset;            // The relative distance to move.
  float usableSlice;         // Duration for the move to this point (in milliseconds).
  float usedSlice;           // Already consumed time.
} TAnimationPoint;

typedef vector<TAnimationPoint> TPoints;

/**
 * A specialized class for an animation of a figure instance which involves travelling over one or more target 
 * points (offsets).
 */
class CFigureInstancePathAnimation: public CAnimation
{
  friend class CAnimationManager;
private:
  TPoints FPoints;
  TVertex FLastOffset;            // Keeps the last computed position to determine relative movements.
  CFigureInstance* FInstance;     
protected:
  void addPoint(const TVertex offset, float slice);
  virtual bool __cdecl animate(int step);
public:
  CFigureInstancePathAnimation(CAnimationManager* manager, int duration, bool suspended, CGraphicElement* element);

  virtual void __cdecl animationStarted(void);
  virtual void __cdecl animationStopped(void);
};

/**
 * A specialized class for an animation of the zoom of a view.
 */
class CViewZoomAnimation: public CAnimation
{
  friend class CAnimationManager;
private:
  float FTargetZoom;
  float FZoomDelta;
  float FLastStep;
  
  CGCView* FView;     
protected:
  virtual bool __cdecl animate(int step);
public:
  CViewZoomAnimation(CAnimationManager* manager, float newZoom, int duration, bool suspended, CGCView* element);
  CViewZoomAnimation(CAnimationManager* manager, float from, float to, int duration, bool suspended, CGCView* element);

  virtual void __cdecl animationStarted(void);
  virtual void __cdecl animationStopped(void);
  virtual bool __cdecl finished(void);
};

/**
 * A specialized class for an animation of the offset of a view.
 */
class CViewOffsetAnimation: public CAnimation
{
  friend class CAnimationManager;
private:
  float FTargetOffsetX;
  float FTargetOffsetY;
  float FOffsetXDelta;
  float FOffsetYDelta;
  float FLastStepX;
  float FLastStepY;

  CGCView* FView;     
protected:
  virtual bool __cdecl animate(int step);
public:
  CViewOffsetAnimation(CAnimationManager* manager, float x, float y, int duration, bool suspended, CGCView* element);
  CViewOffsetAnimation(CAnimationManager* manager, float fromX, float fromY, float toX, float toY, int duration, 
    bool suspended, CGCView* element);

  virtual void __cdecl animationStarted(void);
  virtual void __cdecl animationStopped(void);
  virtual bool __cdecl finished(void);
};

//----------------------------------------------------------------------------------------------------------------------

typedef vector<CAnimation*> CAnimations;
typedef multimap<CAnimation*, CAnimation*> CAnimationDependancies;
typedef pair<CAnimation*, CAnimation*> CAnimationDependanciesPair;

class CAnimationManager: public CGCBase
{
  friend class CAnimation;
private:
  int FTimerBase;
  CAnimations FAnimations;
  CAnimationDependancies FDependencies;
protected:
  void addDependency(CAnimation* animation, CAnimation* dependentAnimation);
  void removeAllDependencies(CAnimation* animation);
  void removeDependency(CAnimation* animation, CAnimation* dependentAnimation);
  void triggerDependentAnimations(CAnimation* animation);
public:
  CAnimationManager(CGenericCanvas* canvas);
  virtual ~CAnimationManager(void);

  virtual CAnimation* __cdecl createPathAnimation(const TVertex& offset, int duration, bool suspended, CGraphicElement* element);
  virtual CAnimation* __cdecl createViewOffsetAnimation(float x, float y, int duration, bool suspended, CGCView* element);
  // Need an own name for the overloaded method here because of limitations imposed through access by non-C++ languages (like Delphi).
  virtual CAnimation* __cdecl createViewOffsetAnimation2(float fromX, float fromY, float toX, float toY, int duration, 
    bool suspended, CGCView* element);
  virtual CAnimation* __cdecl createViewZoomAnimation(float newZoom, int duration, bool suspended, CGCView* element);
  virtual CAnimation* __cdecl createViewZoomAnimation2(float from, float to, int duration, bool suspended, CGCView* element);
  virtual TGCVariant __cdecl propertyGet(const char* name, unsigned int index);
  virtual void __cdecl propertySet(const char* name, unsigned int index, TGCVariant value);
  virtual void __cdecl pulse(void);
  virtual void __cdecl timerBase(int base);
};

//----------------------------------------------------------------------------------------------------------------------

#endif // __GC_ANIMATION_H__