1 #ifndef _COMPIZ_ANIMATION_H
2 #define _COMPIZ_ANIMATION_H
3 
4 #define ANIMATION_ABIVERSION 20081221
5 
6 typedef enum
7 {
8     WindowEventOpen = 0,
9     WindowEventClose,
10     WindowEventMinimize,
11     WindowEventUnminimize,
12     WindowEventShade,
13     WindowEventUnshade,
14     WindowEventFocus,
15     WindowEventNum,
16     WindowEventNone
17 } WindowEvent;
18 
19 typedef enum
20 {
21     AnimEventOpen = 0,
22     AnimEventClose,
23     AnimEventMinimize,
24     AnimEventShade,
25     AnimEventFocus,
26     AnimEventNum
27 } AnimEvent;
28 
29 typedef struct _AnimEffectProperties
30 {
31     void (*updateWindowAttribFunc) (CompWindow *,
32 				    WindowPaintAttrib *);
33     void (*prePaintWindowFunc) (CompWindow *);
34     void (*postPaintWindowFunc) (CompWindow *);
35     void (*animStepFunc) (CompWindow *, float time);
36     Bool (*initFunc) (CompWindow *);
37     void (*initGridFunc) (CompWindow *, int *, int *);
38     void (*addCustomGeometryFunc) (CompWindow *, int, Box *,
39 				   int, CompMatrix *);
40     void (*drawCustomGeometryFunc) (CompWindow *);
41     Bool (*letOthersDrawGeomsFunc) (CompWindow *);
42     void (*updateWinTransformFunc) (CompWindow *,
43 				    CompTransform *);
44     Bool (*prePrepPaintScreenFunc) (CompWindow *, int msSinceLastPaint);
45     void (*postPrepPaintScreenFunc) (CompWindow *);
46     void (*updateBBFunc) (CompOutput *, CompWindow *, Box *);
47     void (*cleanupFunc) (CompWindow *);
48     void (*refreshFunc) (CompWindow *, Bool animInitialized);
49     Bool (*zoomToIconFunc) (CompWindow *);
50     Bool modelAnimIs3D;		// TRUE if anim uses model and 3d coords
51     Bool useQTexCoord;		// TRUE if effect needs Q texture coordinates
52     void *extraProperties;
53 } AnimEffectProperties;
54 
55 typedef struct _AnimEffectInfo
56 {
57     char *name; // name of the animation effect, e.g. "animationpack:Implode"
58 
59     // to be set to TRUE for the window event animation list(s) that
60     // the new animation (value) should be added to
61     // (0: open, 1: close, 2: minimize, 3: shade, 4: focus)
62     Bool usedForEvents[AnimEventNum];
63 
64     AnimEffectProperties properties;
65 } AnimEffectInfo;
66 
67 typedef const AnimEffectInfo * AnimEffect;
68 
69 typedef struct _ExtensionPluginInfo
70 {
71     unsigned int nEffects;
72     AnimEffect *effects;
73 
74     // Plugin options to be used in "effect options" strings
75     unsigned int nEffectOptions;
76     CompOption *effectOptions;
77 
78     // Non-window functions
79     void (*prePaintOutputFunc) (CompScreen *s, CompOutput *output);
80 } ExtensionPluginInfo;
81 
82 typedef struct _xy_pair
83 {
84     float x, y;
85 } Point, Vector;
86 
87 typedef struct
88 {
89     float x1, x2, y1, y2;
90 } Boxf;
91 
92 typedef struct _xyz_tuple
93 {
94     float x, y, z;
95 } Point3d, Vector3d;
96 
97 typedef struct _Object
98 {
99     Point gridPosition;		// position on window in [0,1] range
100     Point3d position;		// position on screen
101 
102     // Texture x, y coordinates will be offset by given amounts
103     // for quads that fall after and before this object in x and y directions.
104     // Currently only y offset can be used.
105     Point offsetTexCoordForQuadBefore;
106     Point offsetTexCoordForQuadAfter;
107 } Object;
108 
109 typedef struct _Model
110 {
111     Object *objects;
112     int numObjects;
113     int gridWidth;
114     int gridHeight;
115 
116     int winWidth;		// keeps win. size when model was created
117     int winHeight;
118 
119     Vector scale;
120     Point scaleOrigin;
121 
122     WindowEvent forWindowEvent;
123     float topHeight;
124     float bottomHeight;
125 } Model;
126 
127 // Window properties common to multiple animation effects
128 typedef struct _AnimWindowCommon
129 {
130     float animTotalTime;
131     float animRemainingTime;
132     float timestep;		// to be used in updateWindowAttribFunc
133 
134     int animOverrideProgressDir; // 0: default dir, 1: forward, 2: backward
135 
136     WindowEvent curWindowEvent;
137     AnimEffect curAnimEffect;
138 
139     FragmentAttrib curPaintAttrib;
140 
141     Region drawRegion;
142     Bool useDrawRegion;
143 
144     XRectangle icon;
145 
146     GLushort storedOpacity;
147 
148     CompTransform transform;
149     Bool usingTransform;     // whether transform matrix is used for the current effect
150 
151     float transformStartProgress;
152     float transformProgress;
153 
154     Model *model;   // for grid engine
155 } AnimWindowCommon;
156 
157 typedef enum
158 {
159     AnimDirectionDown = 0,
160     AnimDirectionUp,
161     AnimDirectionLeft,
162     AnimDirectionRight,
163     AnimDirectionRandom,
164     AnimDirectionAuto
165 } AnimDirection;
166 #define LAST_ANIM_DIRECTION 5
167 
168 typedef void
169 (*UpdateBBProc) (CompOutput *output,
170 		 CompWindow * w,
171 		 Box *BB);
172 
173 // Base functions for extension plugins to call
174 typedef struct _AnimBaseFunctions {
175     void (*addExtension) (CompScreen *s,
176 			  ExtensionPluginInfo *extensionPluginInfo);
177     void (*removeExtension) (CompScreen *s,
178 			     ExtensionPluginInfo *extensionPluginInfo);
179     CompOptionValue * (*getPluginOptVal)
180 	(CompWindow *w, ExtensionPluginInfo *extensionPluginInfo, int optionId);
181     Bool (*getMousePointerXY) (CompScreen *s, short *x, short *y);
182     UpdateBBProc	updateBBScreen;
183     UpdateBBProc	updateBBWindow;
184     UpdateBBProc	modelUpdateBB;
185     UpdateBBProc	compTransformUpdateBB;
186     Bool (*defaultAnimInit) (CompWindow * w);
187     void (*defaultAnimStep) (CompWindow * w, float time);
188     void (*defaultUpdateWindowTransform) (CompWindow *w,
189 					  CompTransform *wTransform);
190     float (*getProgressAndCenter) (CompWindow *w,
191 				   Point *center);
192 
193     float (*defaultAnimProgress) (CompWindow *w);
194     float (*sigmoidAnimProgress) (CompWindow *w);
195     float (*decelerateProgressCustom) (float progress,
196 				       float minx,
197 				       float maxx);
198     float (*decelerateProgress) (float progress);
199     AnimDirection (*getActualAnimDirection) (CompWindow * w,
200 					     AnimDirection dir,
201 					     Bool openDir);
202     void (*expandBoxWithBox) (Box *target, Box *source);
203     void (*expandBoxWithPoint) (Box *target, float fx, float fy);
204     void (*prepareTransform) (CompScreen *s,
205 			      CompOutput *output,
206 			      CompTransform *resultTransform,
207 			      CompTransform *transform);
208     AnimWindowCommon * (*getAnimWindowCommon) (CompWindow *w);
209     Bool (*returnTrue) (CompWindow *w);
210     void (*postAnimationCleanup) (CompWindow *w);
211     void (*fxZoomUpdateWindowAttrib) (CompWindow * w,
212 				      WindowPaintAttrib * wAttrib);
213 } AnimBaseFunctions;
214 
215 
216 #define OPTION_GETTERS(extensionBaseFunctions,				\
217 		       extensionPluginInfo, firstEffectOption)		\
218 static inline CompOptionValue *						\
219 animGetOptVal (CompWindow *w,						\
220 	       int optionId)						\
221 {									\
222     return (extensionBaseFunctions)->getPluginOptVal			\
223     	(w, (extensionPluginInfo), optionId - (firstEffectOption));	\
224 }						\
225 						\
226 inline Bool					\
227 animGetB (CompWindow *w,			\
228 	  int optionId)				\
229 {						\
230     return animGetOptVal (w, optionId)->b;	\
231 }						\
232 						\
233 inline int					\
234 animGetI (CompWindow *w,			\
235 	  int optionId)				\
236 {						\
237     return animGetOptVal (w, optionId)->i;	\
238 }						\
239 						\
240 inline float					\
241 animGetF (CompWindow *w,			\
242 	  int optionId)				\
243 {						\
244     return animGetOptVal (w, optionId)->f;	\
245 }						\
246 						\
247 inline char *					\
248 animGetS (CompWindow *w,			\
249 	  int optionId)				\
250 {						\
251     return animGetOptVal (w, optionId)->s;	\
252 }						\
253 						\
254 inline unsigned short *				\
255 animGetC (CompWindow *w,			\
256 	  int optionId)				\
257 {						\
258     return animGetOptVal (w, optionId)->c;	\
259 }
260 
261 #define OPTION_GETTERS_HDR			\
262 						\
263 inline Bool					\
264 animGetB (CompWindow *w,			\
265 	  int optionId);			\
266 						\
267 inline int					\
268 animGetI (CompWindow *w,			\
269 	  int optionId);			\
270 						\
271 inline float					\
272 animGetF (CompWindow *w,			\
273 	  int optionId);			\
274 						\
275 inline char *					\
276 animGetS (CompWindow *w,			\
277 	  int optionId);			\
278 						\
279 inline unsigned short *				\
280 animGetC (CompWindow *w,			\
281 	  int optionId);
282 
283 
284 #define WIN_X(w) ((w)->attrib.x - (w)->output.left)
285 #define WIN_Y(w) ((w)->attrib.y - (w)->output.top)
286 #define WIN_W(w) ((w)->width + (w)->output.left + (w)->output.right)
287 #define WIN_H(w) ((w)->height + (w)->output.top + (w)->output.bottom)
288 
289 #define BORDER_X(w) ((w)->attrib.x - (w)->input.left)
290 #define BORDER_Y(w) ((w)->attrib.y - (w)->input.top)
291 #define BORDER_W(w) ((w)->width + (w)->input.left + (w)->input.right)
292 #define BORDER_H(w) ((w)->height + (w)->input.top + (w)->input.bottom)
293 
294 #define RAND_FLOAT() ((float)rand() / RAND_MAX)
295 
296 #define sigmoid(fx) (1.0f/(1.0f+exp(-5.0f*2*((fx)-0.5))))
297 #define sigmoid2(fx, s) (1.0f/(1.0f+exp(-(s)*2*((fx)-0.5))))
298 
299 #define NUM_OPTIONS(s) (sizeof ((s)->opt) / sizeof (CompOption))
300 
301 
302 // ratio of perceived length of animation compared to real duration
303 // to make it appear to have the same speed with other animation effects
304 
305 #define SPRINGY_ZOOM_PERCEIVED_T 0.55f
306 #define NONSPRINGY_ZOOM_PERCEIVED_T 0.6f
307 #define ZOOM_PERCEIVED_T 0.75f
308 
309 
310 #endif
311 
312