2
* This file is a part of the Cairo-Dock project
4
* Copyright : (C) see the 'copyright' file.
5
* E-mail : see the 'copyright' file.
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.
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/>.
20
/******************************************************************************
22
This file is a part of the cairo-dock program,
23
released under the terms of the GNU General Public License.
25
Written by Fabrice Rey (for any bug report, please mail me to fabounet@users.berlios.de)
27
******************************************************************************/
33
#include "applet-struct.h"
34
#include "applet-mesh-factory.h"
35
#include "applet-rotation.h"
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'.
40
void cd_animations_init_rotation (CDAnimationData *pData, double dt, gboolean bUseOpenGL)
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);
50
pData->fRotateWidthFactor = 1.;
51
pData->fRotationSpeed = 360. / myConfig.iRotationDuration * dt;
52
pData->fRotationBrake = 1.;
53
pData->fAdjustFactor = 0.;
54
pData->bRotationBeginning = TRUE;
58
void cd_animation_render_capsule (Icon *pIcon, CairoDock *pDock, gboolean bInvisibleBackground)
60
glEnable(GL_DEPTH_TEST);
62
/*if (bInvisibleBackground)
63
_cairo_dock_set_blend_alpha (); // rend la capsule transparente.
65
glBlendFunc (GL_SRC_ALPHA, GL_ONE); // la capsule "ecrase" le fond.*/
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);
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.
95
glPolygonMode (GL_FRONT, GL_FILL);
96
glCallList (myData.iCallList[CD_CAPSULE_MESH]);
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);
112
void cd_animation_render_cube (Icon *pIcon, CairoDock *pDock, gboolean bInvisibleBackground)
114
glEnable(GL_DEPTH_TEST);
116
/*if (bInvisibleBackground)
117
_cairo_dock_set_blend_alpha (); // rend la capsule transparente.
119
glBlendFunc (GL_SRC_ALPHA, GL_ONE); // la capsule "ecrase" le fond.
120
_cairo_dock_set_blend_alpha ();*/
121
glEnable(GL_TEXTURE);
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);
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.
142
glPolygonMode (GL_FRONT, GL_FILL);
143
glCallList (myData.iCallList[CD_CUBE_MESH]);
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);
159
void cd_animation_render_square (Icon *pIcon, CairoDock *pDock, gboolean bInvisibleBackground)
162
/*if (bInvisibleBackground)
163
_cairo_dock_set_blend_alpha (); // rend la capsule transparente.
165
glBlendFunc (GL_SRC_ALPHA, GL_ONE); // la capsule "ecrase" le fond.*/
166
glEnable(GL_TEXTURE);
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);
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.
187
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
188
glCallList (myData.iCallList[CD_SQUARE_MESH]);
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);
203
static void _draw_rotating_icon (Icon *pIcon, CairoDock *pDock, CDAnimationData *pData, double fScaleFactor)
205
gboolean bInvisibleBackground = TRUE;
207
glRotatef (pData->fRotationAngle, 0., 1., 0.);
208
switch (myConfig.iMeshType)
210
case CD_SQUARE_MESH :
212
cairo_dock_set_icon_scale (pIcon, CAIRO_CONTAINER (pDock), fScaleFactor);
213
cd_animation_render_square (pIcon, pDock, bInvisibleBackground);
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);
220
case CD_CAPSULE_MESH :
221
cairo_dock_set_icon_scale (pIcon, CAIRO_CONTAINER (pDock), fScaleFactor);
222
cd_animation_render_capsule (pIcon, pDock, bInvisibleBackground);
227
void cd_animations_draw_rotating_icon (Icon *pIcon, CairoDock *pDock, CDAnimationData *pData)
229
double fAlpha = pIcon->fAlpha;
230
if (pData->fPulseAlpha != 0 && myConfig.bPulseSameShape)
232
_cairo_dock_set_alpha (pIcon->fAlpha * (1. - .5 * pData->fPulseAlpha));
233
///pIcon->fAlpha *= 1. - .5 * pData->fPulseAlpha;
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);
240
//glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
241
_cairo_dock_set_blend_alpha ();
242
_draw_rotating_icon (pIcon, pDock, pData, 1.);
244
if (pData->fPulseAlpha != 0 && myConfig.bPulseSameShape)
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);
254
if (pDock->bUseReflect)
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)
261
if (pDock->bDirectionUp)
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.
269
glTranslatef (0., fOffsetY, 0.);
270
//glScalef (pIcon->fWidth * pIcon->fWidthFactor * pIcon->fScale, myIcons.fReflectSize * pDock->fRatio, 1.);
272
glScalef (1., -1., 1.);
276
if (pDock->bDirectionUp)
278
glTranslatef (fOffsetY, 0., 0.);
279
//glScalef (- myIcons.fReflectSize * pDock->fRatio, pIcon->fWidth * pIcon->fWidthFactor * pIcon->fScale, 1.);
283
glTranslatef (- fOffsetY, 0., 0.);
284
//glScalef (myIcons.fReflectSize * pDock->fRatio, pIcon->fWidth * pIcon->fWidthFactor * pIcon->fScale, 1.);
286
glScalef (-1., 1., 1.);
289
_cairo_dock_set_blend_alpha ();
290
_draw_rotating_icon (pIcon, pDock, pData, 1.);
293
pIcon->fAlpha = fAlpha;
296
void cd_animations_draw_rotating_cairo (Icon *pIcon, CairoDock *pDock, CDAnimationData *pData, cairo_t *pCairoContext)
298
double fWidthFactor = pData->fRotateWidthFactor;
299
pIcon->fWidthFactor *= fWidthFactor;
300
cairo_save (pCairoContext);
302
if (pDock->bHorizontalDock)
303
cairo_translate (pCairoContext,
304
pIcon->fWidth * pIcon->fScale * (1 - fWidthFactor) / 2,
307
cairo_translate (pCairoContext,
309
pIcon->fWidth * pIcon->fScale * (1 - fWidthFactor) / 2);
311
cairo_dock_draw_icon_cairo (pIcon, pDock, pCairoContext);
313
cairo_restore (pCairoContext);
315
pIcon->fWidthFactor /= fWidthFactor;
319
void cd_animations_update_rotating_cairo (Icon *pIcon, CairoDock *pDock, CDAnimationData *pData)
321
double fDamageWidthFactor = pData->fRotateWidthFactor;
322
pData->fRotateWidthFactor = cos (pData->fRotationAngle/180.*G_PI);
323
if (fabs (pData->fRotateWidthFactor) < .01)
324
pData->fRotateWidthFactor = .01;
326
if (! pDock->bIsShrinkingDown && ! pDock->bIsGrowingUp)
328
fDamageWidthFactor = MAX (fabs (fDamageWidthFactor), fabs (pData->fRotateWidthFactor));
329
pIcon->fWidthFactor *= fDamageWidthFactor;
331
cairo_dock_redraw_my_icon (pIcon, CAIRO_CONTAINER (pDock));
333
pIcon->fWidthFactor /= fDamageWidthFactor;