1 /*
2  * Animation plugin for compiz/beryl
3  *
4  * animation.c
5  *
6  * Copyright : (C) 2006 Erkin Bahceci
7  * E-mail    : erkinbah@gmail.com
8  *
9  * Based on Wobbly and Minimize plugins by
10  *           : David Reveman
11  * E-mail    : davidr@novell.com>
12  *
13  * Particle system added by : (C) 2006 Dennis Kasprzyk
14  * E-mail                   : onestone@beryl-project.org
15  *
16  * Beam-Up added by : Florencio Guimaraes
17  * E-mail           : florencio@nexcorp.com.br
18  *
19  * Hexagon tessellator added by : Mike Slegeir
20  * E-mail                       : mikeslegeir@mail.utexas.edu>
21  *
22  * This program is free software; you can redistribute it and/or
23  * modify it under the terms of the GNU General Public License
24  * as published by the Free Software Foundation; either version 2
25  * of the License, or (at your option) any later version.
26  *
27  * This program is distributed in the hope that it will be useful,
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
30  * GNU General Public License for more details.
31  *
32  * You should have received a copy of the GNU General Public License
33  * along with this program; if not, write to the Free Software
34  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
35  */
36 
37 #include "animation-internal.h"
38 
39 // =====================  Effect: Roll Up  =========================
40 
41 void
fxRollUpInitGrid(CompWindow * w,int * gridWidth,int * gridHeight)42 fxRollUpInitGrid(CompWindow *w,
43 		 int *gridWidth, int *gridHeight)
44 {
45     ANIM_WINDOW(w);
46 
47     *gridWidth = 2;
48     if (aw->com.curWindowEvent == WindowEventShade ||
49 	aw->com.curWindowEvent == WindowEventUnshade)
50 	*gridHeight = 4;
51     else
52 	*gridHeight = 2;
53 }
54 
55 static void inline
fxRollUpModelStepObject(CompWindow * w,Model * model,Object * object,float forwardProgress,Bool fixedInterior)56 fxRollUpModelStepObject(CompWindow * w,
57 			Model * model,
58 			Object * object,
59 			float forwardProgress, Bool fixedInterior)
60 {
61     ANIM_WINDOW(w);
62 
63     float origx = WIN_X(w) + WIN_W(w) * object->gridPosition.x;
64 
65     if (aw->com.curWindowEvent == WindowEventShade ||
66 	aw->com.curWindowEvent == WindowEventUnshade)
67     {
68 	// Execute shade mode
69 
70 	// find position in window contents
71 	// (window contents correspond to 0.0-1.0 range)
72 	float relPosInWinContents =
73 	    (object->gridPosition.y * WIN_H(w) -
74 	     model->topHeight) / w->height;
75 
76 	if (object->gridPosition.y == 0)
77 	{
78 	    object->position.x = origx;
79 	    object->position.y = WIN_Y(w);
80 	}
81 	else if (object->gridPosition.y == 1)
82 	{
83 	    object->position.x = origx;
84 	    object->position.y =
85 		(1 - forwardProgress) *
86 		(WIN_Y(w) +
87 		 WIN_H(w) * object->gridPosition.y) +
88 		forwardProgress * (WIN_Y(w) +
89 				   model->topHeight +
90 				   model->bottomHeight);
91 	}
92 	else
93 	{
94 	    object->position.x = origx;
95 
96 	    if (relPosInWinContents > forwardProgress)
97 	    {
98 		object->position.y =
99 		    (1 - forwardProgress) *
100 		    (WIN_Y(w) +
101 		     WIN_H(w) * object->gridPosition.y) +
102 		    forwardProgress * (WIN_Y(w) + model->topHeight);
103 
104 		if (fixedInterior)
105 		    object->offsetTexCoordForQuadBefore.y =
106 			-forwardProgress * w->height;
107 	    }
108 	    else
109 	    {
110 		object->position.y = WIN_Y(w) + model->topHeight;
111 		if (!fixedInterior)
112 		    object->offsetTexCoordForQuadAfter.
113 			y =
114 			(forwardProgress -
115 			 relPosInWinContents) * w->height;
116 	    }
117 	}
118     }
119 }
120 
121 void
fxRollUpModelStep(CompWindow * w,float time)122 fxRollUpModelStep (CompWindow *w, float time)
123 {
124     defaultAnimStep (w, time);
125 
126     ANIM_WINDOW(w);
127 
128     Model *model = aw->com.model;
129 
130     float forwardProgress = sigmoidAnimProgress (w);
131     Bool fixedInterior = animGetB (w, ANIM_SCREEN_OPTION_ROLLUP_FIXED_INTERIOR);
132 
133     Object *object = model->objects;
134     int i;
135     for (i = 0; i < model->numObjects; i++, object++)
136 	fxRollUpModelStepObject
137 	    (w,
138 	     model,
139 	     object,
140 	     forwardProgress,
141 	     fixedInterior);
142 }
143 
144 Bool
fxRollUpAnimInit(CompWindow * w)145 fxRollUpAnimInit (CompWindow * w)
146 {
147     ANIM_WINDOW(w);
148 
149     aw->com.animTotalTime /= ROLLUP_PERCEIVED_T;
150     aw->com.animRemainingTime = aw->com.animTotalTime;
151 
152     return TRUE;
153 }
154 
155