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/>.
24
#include "applet-struct.h"
25
#include "applet-notifications.h"
26
#include "applet-wave.h"
28
static inline void _init_wave (GLfloat *pVertices, GLfloat *pCoords)
55
static void init (Icon *pIcon, CairoDock *pDock, CDAnimationData *pData, double dt, gboolean bUseOpenGL)
57
if (!bUseOpenGL) // no cairo rendering (yet).
60
_init_wave (pData->pVertices, pData->pCoords);
62
pData->iNumActiveNodes = 4;
63
pData->fWavePosition = - myConfig.fWaveWidth / 2 + .01; // on rajoute epsilon pour commencer avec 2 points.
67
static gboolean update (Icon *pIcon, CairoDock *pDock, CDAnimationData *pData, double dt, gboolean bUseOpenGL, gboolean bRepeat)
69
if (!bUseOpenGL) // no cairo rendering (yet).
72
GLfloat *pVertices = pData->pVertices;
73
GLfloat *pCoords = pData->pCoords;
75
double p = pData->fWavePosition, w = myConfig.fWaveWidth;
76
if (p + w/2 < 0 || p - w/2 > 1) // la vague est entierement en-dehors du cote.
78
_init_wave (pVertices, pCoords); // on s'assure d'avoir au moins un carre.
79
pData->iNumActiveNodes = 4;
83
int j = 0; // nombre de points calcules.
84
if (p - w/2 > 0) // la vague n'englobe pas le point du bas.
93
double x, x_, y; // position du point et du point precedent.
94
double a, a_; // position sur la vague dans [-1, 1].
95
int n = CD_WAVE_NB_POINTS / 2; // nbre de points pour une demi-vague (N est impair).
97
for (i = 0; i < CD_WAVE_NB_POINTS; i ++) // on discretise la vague.
99
a = 1. * (i-n) / (n); // position courante sur la vague, dans [-1, 1].
100
x = p + a * w/2; // abscisse correspondante.
102
a = 1. * (i-n) / n; // position courante sur la vague, dans [-1, 1].
103
x = p + a * w/2; // abscisse correspondante.
104
if (x < 0) // le point sort par le bas.
106
a_ = 1. * (i+1-n) / n;
108
if (x_ > 0) // le point suivant est dedans.
110
y = myConfig.fWaveAmplitude * cos (G_PI/2 * a - x / (w/2) * G_PI/2); // on depasse de x, donc on dephase d'autant.
111
x = 0.; // coin de la texture.
113
else // tout le segment est dehors, on zappe.
116
else if (x > 1) // le point sort par le haut.
118
a_ = 1. * (i-1-n) / n;
120
if (x_ < 1) // le point precedent est dedans.
122
y = myConfig.fWaveAmplitude * cos (G_PI/2 * a - (x-1) / (w/2) * G_PI/2); // on depasse de x-1, donc on dephase d'autant.
123
x = 1.; // coin de la texture.
125
else // tout le segment est dehors, on zappe.
128
else // le point est dans l'icone.
129
y = myConfig.fWaveAmplitude * cos (G_PI/2 * a);
131
pVertices[4*j] = -.5 - y;
132
pVertices[4*j+1] = x - .5;
134
pCoords[4*j+1] = 1. - x;
138
if (p + w/2 < 1) // la vague n'englobe pas le point du haut.
140
pVertices[4*j] = -.5;
141
pVertices[4*j+1] = .5;
147
for (i = 0; i < j; i ++) // on complete l'autre cote symetriquement.
149
pVertices[4*i+2] = - pVertices[4*i];
150
pVertices[4*i+3] = pVertices[4*i+1];
152
pCoords[4*i+3] = pCoords[4*i+1];
154
pData->iNumActiveNodes = 2*j;
157
pData->fWavePosition += dt / myConfig.iWaveDuration;
159
cairo_dock_redraw_container (CAIRO_CONTAINER (pDock));
161
gboolean bContinue = (pData->fWavePosition - w/2 < 1);
162
if (! bContinue && bRepeat)
163
pData->fWavePosition = - myConfig.fWaveWidth / 2;
168
static void render (Icon *pIcon, CairoDock *pDock, CDAnimationData *pData, cairo_t *pCairoContext)
170
if (pCairoContext != NULL) // no cairo rendering (yet).
174
cairo_dock_set_icon_scale (pIcon, CAIRO_CONTAINER (pDock), 1.);
176
glColor4f (1., 1., 1., pIcon->fAlpha);
178
if (pIcon->fAlpha == 1)
179
_cairo_dock_set_blend_pbuffer ();
181
_cairo_dock_set_blend_over ();
183
glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
185
glEnable(GL_TEXTURE_2D); // Je veux de la texture
186
glBindTexture(GL_TEXTURE_2D, pIcon->image.iTexture);
187
glPolygonMode(GL_FRONT, GL_FILL);
189
glEnableClientState (GL_TEXTURE_COORD_ARRAY);
190
glEnableClientState (GL_VERTEX_ARRAY);
192
glTexCoordPointer (2, GL_FLOAT, 0, pData->pCoords);
193
glVertexPointer (2, GL_FLOAT, 0, pData->pVertices);
195
glDrawArrays (GL_QUAD_STRIP, 0, pData->iNumActiveNodes);
199
if (pDock->container.bUseReflect)
202
// double fReflectRatio = pDock->iIconSize * myIconsParam.fReflectHeightRatio * pDock->container.fRatio / pIcon->fHeight / pIcon->fScale;
203
double fOffsetY = pIcon->fHeight * pIcon->fScale/2 + (pDock->iIconSize * myIconsParam.fReflectHeightRatio/2 + pIcon->fDeltaYReflection) * pDock->container.fRatio;
204
if (pDock->container.bIsHorizontal)
206
if (pDock->container.bDirectionUp)
208
fOffsetY = pIcon->fHeight * pIcon->fScale + pIcon->fDeltaYReflection;
209
glTranslatef (0., - fOffsetY, 0.);
210
glScalef (pIcon->fWidth * pIcon->fWidthFactor * pIcon->fScale, - pIcon->fHeight * pIcon->fScale, 1.); // taille du reflet et on se retourne.
214
glTranslatef (0., fOffsetY, 0.);
215
glScalef (pIcon->fWidth * pIcon->fWidthFactor * pIcon->fScale, pDock->iIconSize * myIconsParam.fReflectHeightRatio * pDock->container.fRatio, 1.);
220
if (pDock->container.bDirectionUp)
222
glTranslatef (fOffsetY, 0., 0.);
223
glScalef (- pDock->iIconSize * myIconsParam.fReflectHeightRatio * pDock->container.fRatio, pIcon->fWidth * pIcon->fWidthFactor * pIcon->fScale, 1.);
227
glTranslatef (- fOffsetY, 0., 0.);
228
glScalef (pDock->iIconSize * myIconsParam.fReflectHeightRatio * pDock->container.fRatio, pIcon->fWidth * pIcon->fWidthFactor * pIcon->fScale, 1.);
232
glActiveTexture(GL_TEXTURE0_ARB); // Go pour le multitexturing 1ere passe
233
glEnable(GL_TEXTURE_2D); // On active le texturing sur cette passe
234
glBindTexture(GL_TEXTURE_2D, pIcon->image.iTexture);
236
glColor4f(1., 1., 1., myIconsParam.fAlbedo * pIcon->fAlpha); // transparence du reflet.
239
glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
241
glActiveTexture(GL_TEXTURE1_ARB); // Go pour le texturing 2eme passe
242
glEnable(GL_TEXTURE_2D);
243
glBindTexture(GL_TEXTURE_2D, g_pGradationTexture[pDock->container.bIsHorizontal]);
244
glColor4f(1., 1., 1., 1.); // transparence du reflet.
246
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
247
glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); // Le mode de combinaison des textures
248
glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_MODULATE); // multiplier les alpha.
249
/*glEnable(GL_TEXTURE_GEN_S); // generation texture en S
250
glEnable(GL_TEXTURE_GEN_T); // et en T
251
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); // la je veux un mapping tout ce qu'il y a de plus classique
252
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);*/
253
glEnableClientState (GL_TEXTURE_COORD_ARRAY);
254
glEnableClientState (GL_VERTEX_ARRAY);
256
glTexCoordPointer (2, GL_FLOAT, 0, pData->pCoords);
257
glVertexPointer (2, GL_FLOAT, 0, pData->pVertices);
259
glDrawArrays (GL_QUAD_STRIP, 0, pData->iNumActiveNodes);
261
glActiveTexture(GL_TEXTURE1_ARB);
262
glDisable(GL_TEXTURE_2D);
263
glDisableClientState (GL_TEXTURE_COORD_ARRAY);
264
glDisableClientState (GL_VERTEX_ARRAY);
265
glDisable(GL_TEXTURE_GEN_S);
266
glDisable(GL_TEXTURE_GEN_T);
267
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
268
glActiveTexture(GL_TEXTURE0_ARB);
269
glDisable(GL_TEXTURE_2D);
270
glDisable(GL_TEXTURE_GEN_S);
271
glDisable(GL_TEXTURE_GEN_T);
276
glDisableClientState (GL_TEXTURE_COORD_ARRAY);
277
glDisableClientState (GL_VERTEX_ARRAY);
278
glDisable (GL_TEXTURE_2D);
279
glDisable (GL_BLEND);
283
void cd_animations_register_wave (void)
285
CDAnimation *pAnimation = &myData.pAnimations[CD_ANIMATIONS_WAVE];
286
pAnimation->cName = "wave";
287
pAnimation->cDisplayedName = D_("Wave");
288
pAnimation->id = CD_ANIMATIONS_WAVE;
289
pAnimation->bDrawIcon = TRUE;
290
pAnimation->bDrawReflect = FALSE;
291
pAnimation->init = init;
292
pAnimation->update = update;
293
pAnimation->render = render;
294
pAnimation->post_render = NULL;
295
cd_animations_register_animation (pAnimation);