~ubuntu-branches/ubuntu/saucy/cairo-dock-plug-ins/saucy

« back to all changes in this revision

Viewing changes to Animated-icons/src/applet-rotation.c

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2009-08-26 21:07:39 UTC
  • Revision ID: james.westby@ubuntu.com-20090826210739-gyjuuqezrzuluao4
Tags: upstream-2.0.8.1
ImportĀ upstreamĀ versionĀ 2.0.8.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
* This file is a part of the Cairo-Dock project
 
3
*
 
4
* Copyright : (C) see the 'copyright' file.
 
5
* E-mail    : see the 'copyright' file.
 
6
*
 
7
* This program is free software; you can redistribute it and/or
 
8
* modify it under the terms of the GNU General Public License
 
9
* as published by the Free Software Foundation; either version 3
 
10
* of the License, or (at your option) any later version.
 
11
*
 
12
* This program is distributed in the hope that it will be useful,
 
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
* GNU General Public License for more details.
 
16
* You should have received a copy of the GNU General Public License
 
17
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
*/
 
19
 
 
20
/******************************************************************************
 
21
 
 
22
This file is a part of the cairo-dock program, 
 
23
released under the terms of the GNU General Public License.
 
24
 
 
25
Written by Fabrice Rey (for any bug report, please mail me to fabounet@users.berlios.de)
 
26
 
 
27
******************************************************************************/
 
28
 
 
29
#include <math.h>
 
30
#include <stdlib.h>
 
31
#include <string.h>
 
32
 
 
33
#include "applet-struct.h"
 
34
#include "applet-mesh-factory.h"
 
35
#include "applet-rotation.h"
 
36
 
 
37
static float fCapsuleObjectPlaneS[4] = { 0.59f*2, 0., 0., 0. }; // pour un plaquages propre des textures
 
38
static float fCapsuleObjectPlaneT[4] = { 0., 0.59f*2, 0., 0. };  // le 2 c'est le 'c'.
 
39
 
 
40
void cd_animations_init_rotation (CDAnimationData *pData, double dt, gboolean bUseOpenGL)
 
41
{
 
42
        if (bUseOpenGL)
 
43
        {
 
44
                if (myData.iChromeTexture == 0)
 
45
                        myData.iChromeTexture = cd_animation_load_chrome_texture ();
 
46
                if (myData.iCallList[myConfig.iMeshType] == 0)
 
47
                        myData.iCallList[myConfig.iMeshType] = cd_animations_load_mesh (myConfig.iMeshType);
 
48
        }
 
49
        else
 
50
                pData->fRotateWidthFactor = 1.;
 
51
        pData->fRotationSpeed = 360. / myConfig.iRotationDuration * dt;
 
52
        pData->fRotationBrake = 1.;
 
53
        pData->fAdjustFactor = 0.;
 
54
        pData->bRotationBeginning = TRUE;
 
55
}
 
56
 
 
57
 
 
58
void cd_animation_render_capsule (Icon *pIcon, CairoDock *pDock, gboolean bInvisibleBackground)
 
59
{
 
60
        glEnable(GL_DEPTH_TEST);
 
61
        glEnable (GL_BLEND);
 
62
        /*if (bInvisibleBackground)
 
63
                _cairo_dock_set_blend_alpha ();  // rend la capsule transparente.
 
64
        else
 
65
                glBlendFunc (GL_SRC_ALPHA, GL_ONE);  // la capsule "ecrase" le fond.*/
 
66
        glEnable(GL_TEXTURE);
 
67
        
 
68
        glActiveTexture(GL_TEXTURE0); // Go pour le multitexturing 1ere passe
 
69
        glEnable(GL_TEXTURE_2D); // On active le texturing sur cette passe
 
70
        glBindTexture(GL_TEXTURE_2D, myData.iChromeTexture);
 
71
        glEnable(GL_TEXTURE_GEN_S);                                // oui je veux une generation en S
 
72
        glEnable(GL_TEXTURE_GEN_T);
 
73
        glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); // type de generation des coordonnees de la texture
 
74
        glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
 
75
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);  // pour les bouts de textures qui depassent.
 
76
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
 
77
        
 
78
        glActiveTexture(GL_TEXTURE1); // Go pour le texturing 2eme passe
 
79
        glEnable(GL_TEXTURE_2D);
 
80
        glBindTexture(GL_TEXTURE_2D, pIcon->iIconTexture);
 
81
        //glColor4f(1., 1., 1., pIcon->fAlpha);
 
82
        glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); // la je veux un mapping tout ce qu'il y a de plus classique
 
83
        glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
 
84
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);  // pour les bouts de textures qui depassent.
 
85
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
 
86
        glTexGenfv(GL_S, GL_OBJECT_PLANE, fCapsuleObjectPlaneS); // Je decale un peu la texture
 
87
        glTexGenfv(GL_T, GL_OBJECT_PLANE, fCapsuleObjectPlaneT);
 
88
        glEnable(GL_TEXTURE_GEN_S);                                // generation texture en S
 
89
        glEnable(GL_TEXTURE_GEN_T);        // et en T
 
90
        glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT); // Le mode de combinaison des textures
 
91
        glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_ADD);  /// ca sature ...
 
92
        //glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_MODULATE);
 
93
        //glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE, 1.3);  // booster la combinaison.
 
94
        
 
95
        glPolygonMode (GL_FRONT, GL_FILL);
 
96
        glCallList (myData.iCallList[CD_CAPSULE_MESH]);
 
97
        
 
98
        glActiveTexture(GL_TEXTURE1);
 
99
        glDisable(GL_TEXTURE_2D);
 
100
        glDisable(GL_TEXTURE_GEN_S);
 
101
        glDisable(GL_TEXTURE_GEN_T);
 
102
        glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE, 1.);
 
103
        glActiveTexture(GL_TEXTURE0);
 
104
        glDisable(GL_TEXTURE_2D);
 
105
        glDisable(GL_TEXTURE_GEN_S);
 
106
        glDisable(GL_TEXTURE_GEN_T);
 
107
        glDisable (GL_DEPTH_TEST);
 
108
        glDisable (GL_BLEND);
 
109
}
 
110
 
 
111
 
 
112
void cd_animation_render_cube (Icon *pIcon, CairoDock *pDock, gboolean bInvisibleBackground)
 
113
{
 
114
        glEnable(GL_DEPTH_TEST);
 
115
        glEnable (GL_BLEND);
 
116
        /*if (bInvisibleBackground)
 
117
                _cairo_dock_set_blend_alpha ();  // rend la capsule transparente.
 
118
        else
 
119
                glBlendFunc (GL_SRC_ALPHA, GL_ONE);  // la capsule "ecrase" le fond.
 
120
        _cairo_dock_set_blend_alpha ();*/
 
121
        glEnable(GL_TEXTURE);
 
122
        
 
123
        glActiveTexture(GL_TEXTURE0); // Go pour le multitexturing 1ere passe
 
124
        glEnable(GL_TEXTURE_2D); // On active le texturing sur cette passe
 
125
        glBindTexture(GL_TEXTURE_2D, myData.iChromeTexture);
 
126
        glEnable(GL_TEXTURE_GEN_S);                                // oui je veux une generation en S
 
127
        glEnable(GL_TEXTURE_GEN_T);
 
128
        glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); // type de generation des coordonnees de la texture
 
129
        glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
 
130
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);  // pour les bouts de textures qui depassent.
 
131
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
 
132
        
 
133
        glActiveTexture(GL_TEXTURE1); // Go pour le texturing 2eme passe
 
134
        glEnable(GL_TEXTURE_2D);
 
135
        glBindTexture(GL_TEXTURE_2D, pIcon->iIconTexture);
 
136
        glColor4f(1., 1., 1., pIcon->fAlpha);
 
137
        glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT); // Le mode de combinaison des textures
 
138
        glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_ADD);  /// ca sature ...
 
139
        //glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_MODULATE);
 
140
        //glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE, 1.3);  // booster la combinaison.
 
141
        
 
142
        glPolygonMode (GL_FRONT, GL_FILL);
 
143
        glCallList (myData.iCallList[CD_CUBE_MESH]);
 
144
        
 
145
        glActiveTexture(GL_TEXTURE1);
 
146
        glDisable(GL_TEXTURE_2D);
 
147
        glDisable(GL_TEXTURE_GEN_S);
 
148
        glDisable(GL_TEXTURE_GEN_T);
 
149
        glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE, 1.);
 
150
        glActiveTexture(GL_TEXTURE0);
 
151
        glDisable(GL_TEXTURE_2D);
 
152
        glDisable(GL_TEXTURE_GEN_S);
 
153
        glDisable(GL_TEXTURE_GEN_T);
 
154
        glDisable (GL_DEPTH_TEST);
 
155
        glDisable (GL_BLEND);
 
156
}
 
157
 
 
158
 
 
159
void cd_animation_render_square (Icon *pIcon, CairoDock *pDock, gboolean bInvisibleBackground)
 
160
{
 
161
        glEnable (GL_BLEND);
 
162
        /*if (bInvisibleBackground)
 
163
                _cairo_dock_set_blend_alpha ();  // rend la capsule transparente.
 
164
        else
 
165
                glBlendFunc (GL_SRC_ALPHA, GL_ONE);  // la capsule "ecrase" le fond.*/
 
166
        glEnable(GL_TEXTURE);
 
167
        
 
168
        glActiveTexture(GL_TEXTURE0); // Go pour le multitexturing 1ere passe
 
169
        glEnable(GL_TEXTURE_2D); // On active le texturing sur cette passe
 
170
        glBindTexture(GL_TEXTURE_2D, myData.iChromeTexture);
 
171
        glEnable(GL_TEXTURE_GEN_S);                                // oui je veux une generation en S
 
172
        glEnable(GL_TEXTURE_GEN_T);
 
173
        glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); // type de generation des coordonnees de la texture
 
174
        glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
 
175
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);  // pour les bouts de textures qui depassent.
 
176
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
 
177
        
 
178
        glActiveTexture(GL_TEXTURE1); // Go pour le texturing 2eme passe
 
179
        glEnable(GL_TEXTURE_2D);
 
180
        glBindTexture(GL_TEXTURE_2D, pIcon->iIconTexture);
 
181
        //glColor4f(1., 1., 1., pIcon->fAlpha);
 
182
        glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT); // Le mode de combinaison des textures
 
183
        glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_ADD);
 
184
        //glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_MODULATE);
 
185
        //glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE, 1.2);  // booster la combinaison.
 
186
        
 
187
        glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
 
188
        glCallList (myData.iCallList[CD_SQUARE_MESH]);
 
189
        
 
190
        glActiveTexture(GL_TEXTURE1);
 
191
        glDisable(GL_TEXTURE_2D);
 
192
        glDisable(GL_TEXTURE_GEN_S);
 
193
        glDisable(GL_TEXTURE_GEN_T);
 
194
        glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE, 1.);
 
195
        glActiveTexture(GL_TEXTURE0);
 
196
        glDisable(GL_TEXTURE_2D);
 
197
        glDisable(GL_TEXTURE_GEN_S);
 
198
        glDisable(GL_TEXTURE_GEN_T);
 
199
        glDisable (GL_BLEND);
 
200
}
 
201
 
 
202
 
 
203
static void _draw_rotating_icon (Icon *pIcon, CairoDock *pDock, CDAnimationData *pData, double fScaleFactor)
 
204
{
 
205
        gboolean bInvisibleBackground = TRUE;
 
206
        glPushMatrix ();
 
207
        glRotatef (pData->fRotationAngle, 0., 1., 0.);
 
208
        switch (myConfig.iMeshType)
 
209
        {
 
210
                case CD_SQUARE_MESH :
 
211
                default :
 
212
                        cairo_dock_set_icon_scale (pIcon, CAIRO_CONTAINER (pDock), fScaleFactor);
 
213
                        cd_animation_render_square (pIcon, pDock, bInvisibleBackground);
 
214
                break;
 
215
                case CD_CUBE_MESH :
 
216
                        glRotatef (fabs (pData->fRotationAngle/4), 1., 0., 0.);
 
217
                        cairo_dock_set_icon_scale (pIcon, CAIRO_CONTAINER (pDock), (1. + pData->fAdjustFactor * (sqrt (2) - 1)) * fScaleFactor);
 
218
                        cd_animation_render_cube (pIcon, pDock, bInvisibleBackground);
 
219
                break;
 
220
                case CD_CAPSULE_MESH :
 
221
                        cairo_dock_set_icon_scale (pIcon, CAIRO_CONTAINER (pDock), fScaleFactor);
 
222
                        cd_animation_render_capsule (pIcon, pDock, bInvisibleBackground);
 
223
                break;
 
224
        }
 
225
        glPopMatrix ();
 
226
}
 
227
void cd_animations_draw_rotating_icon (Icon *pIcon, CairoDock *pDock, CDAnimationData *pData)
 
228
{
 
229
        double fAlpha = pIcon->fAlpha;
 
230
        if (pData->fPulseAlpha != 0 && myConfig.bPulseSameShape)
 
231
        {
 
232
                _cairo_dock_set_alpha (pIcon->fAlpha * (1. - .5 * pData->fPulseAlpha));
 
233
                ///pIcon->fAlpha *= 1. - .5 * pData->fPulseAlpha;
 
234
        }
 
235
        else
 
236
                glColor4f(myConfig.pMeshColor[0], myConfig.pMeshColor[1], myConfig.pMeshColor[2], pIcon->fAlpha);  // ici on peut donner une teinte aux reflets chrome.
 
237
        if (myConfig.pMeshColor[3] == 1)
 
238
                glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
 
239
        else
 
240
                //glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 
241
                _cairo_dock_set_blend_alpha ();
 
242
        _draw_rotating_icon (pIcon, pDock, pData, 1.);
 
243
        
 
244
        if (pData->fPulseAlpha != 0 && myConfig.bPulseSameShape)
 
245
        {
 
246
                _cairo_dock_set_alpha (pData->fPulseAlpha);
 
247
                double fScaleFactor = (1 - myConfig.fPulseZoom) * pData->fPulseAlpha + myConfig.fPulseZoom;
 
248
                glTranslatef (0., 0., -fScaleFactor * pIcon->fHeight * pIcon->fScale/2);
 
249
                _cairo_dock_set_blend_alpha ();
 
250
                _draw_rotating_icon (pIcon, pDock, pData, fScaleFactor);
 
251
                glTranslatef (0., 0., fScaleFactor * pIcon->fHeight * pIcon->fScale/2);
 
252
        }
 
253
        
 
254
        if (pDock->bUseReflect)
 
255
        {
 
256
                glPushMatrix ();
 
257
                _cairo_dock_set_alpha (myIcons.fAlbedo * sqrt (myIcons.fAlbedo) * pIcon->fAlpha);  // transparence du reflet, arrange pour essayer de cacher l'absence de degrade :p
 
258
                double fOffsetY = pIcon->fHeight * pIcon->fScale + (0 + pIcon->fDeltaYReflection) * pDock->fRatio;
 
259
                if (pDock->bHorizontalDock)
 
260
                {
 
261
                        if (pDock->bDirectionUp)
 
262
                        {
 
263
                                fOffsetY = pIcon->fHeight * pIcon->fScale + pIcon->fDeltaYReflection;
 
264
                                glTranslatef (0., - fOffsetY, 0.);
 
265
                                //glScalef (pIcon->fWidth * pIcon->fWidthFactor * pIcon->fScale, - pIcon->fHeight * pIcon->fScale, 1.);  // taille du reflet et on se retourne.
 
266
                        }
 
267
                        else
 
268
                        {
 
269
                                glTranslatef (0., fOffsetY, 0.);
 
270
                                //glScalef (pIcon->fWidth * pIcon->fWidthFactor * pIcon->fScale, myIcons.fReflectSize * pDock->fRatio, 1.);
 
271
                        }
 
272
                        glScalef (1., -1., 1.);
 
273
                }
 
274
                else
 
275
                {
 
276
                        if (pDock->bDirectionUp)
 
277
                        {
 
278
                                glTranslatef (fOffsetY, 0., 0.);
 
279
                                //glScalef (- myIcons.fReflectSize * pDock->fRatio, pIcon->fWidth * pIcon->fWidthFactor * pIcon->fScale, 1.);
 
280
                        }
 
281
                        else
 
282
                        {
 
283
                                glTranslatef (- fOffsetY, 0., 0.);
 
284
                                //glScalef (myIcons.fReflectSize * pDock->fRatio, pIcon->fWidth * pIcon->fWidthFactor * pIcon->fScale, 1.);
 
285
                        }
 
286
                        glScalef (-1., 1., 1.);
 
287
                }
 
288
                
 
289
                _cairo_dock_set_blend_alpha ();
 
290
                _draw_rotating_icon (pIcon, pDock, pData, 1.);
 
291
                glPopMatrix ();
 
292
        }
 
293
        pIcon->fAlpha = fAlpha;
 
294
}
 
295
 
 
296
void cd_animations_draw_rotating_cairo (Icon *pIcon, CairoDock *pDock, CDAnimationData *pData, cairo_t *pCairoContext)
 
297
{
 
298
        double fWidthFactor = pData->fRotateWidthFactor;
 
299
        pIcon->fWidthFactor *= fWidthFactor;
 
300
        cairo_save (pCairoContext);
 
301
        
 
302
        if (pDock->bHorizontalDock)
 
303
                cairo_translate (pCairoContext,
 
304
                        pIcon->fWidth * pIcon->fScale * (1 - fWidthFactor) / 2,
 
305
                        1.);
 
306
        else
 
307
                cairo_translate (pCairoContext,
 
308
                        1.,
 
309
                        pIcon->fWidth * pIcon->fScale * (1 - fWidthFactor) / 2);
 
310
        
 
311
        cairo_dock_draw_icon_cairo (pIcon, pDock, pCairoContext);
 
312
        
 
313
        cairo_restore (pCairoContext);
 
314
        
 
315
        pIcon->fWidthFactor /= fWidthFactor;
 
316
}
 
317
 
 
318
 
 
319
void cd_animations_update_rotating_cairo (Icon *pIcon, CairoDock *pDock, CDAnimationData *pData)
 
320
{
 
321
        double fDamageWidthFactor = pData->fRotateWidthFactor;
 
322
        pData->fRotateWidthFactor = cos (pData->fRotationAngle/180.*G_PI);
 
323
        if (fabs (pData->fRotateWidthFactor) < .01)
 
324
                pData->fRotateWidthFactor = .01;
 
325
        
 
326
        if (! pDock->bIsShrinkingDown && ! pDock->bIsGrowingUp)
 
327
        {
 
328
                fDamageWidthFactor = MAX (fabs (fDamageWidthFactor), fabs (pData->fRotateWidthFactor));
 
329
                pIcon->fWidthFactor *= fDamageWidthFactor;
 
330
                
 
331
                cairo_dock_redraw_my_icon (pIcon, CAIRO_CONTAINER (pDock));
 
332
                
 
333
                pIcon->fWidthFactor /= fDamageWidthFactor;
 
334
        }
 
335
}