| 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 |
#include <stdlib.h> |
| 21 |
#include <string.h> |
| 22 |
#include <math.h> |
| 23 |
|
| 24 |
#include "applet-struct.h" |
| 25 |
#include "applet-evaporate.h" |
| 26 |
|
| 27 |
|
| 28 |
gboolean cd_illusion_init_evaporate (Icon *pIcon, CairoDock *pDock, CDIllusionData *pData) |
| 29 |
{ |
| 30 |
if (myData.iEvaporateTexture == 0) |
| 31 |
myData.iEvaporateTexture = cd_illusion_load_evaporate_texture (); |
| 32 |
CairoParticleSystem *pEvaporateParticleSystem = cairo_dock_create_particle_system (myConfig.iNbEvaporateParticles, |
| 33 |
myData.iEvaporateTexture, |
| 34 |
pIcon->fWidth * pIcon->fScale, |
| 35 |
pDock->container.bIsHorizontal ? pIcon->image.iHeight : pIcon->image.iWidth); |
| 36 |
g_return_val_if_fail (pEvaporateParticleSystem != NULL, FALSE); |
| 37 |
double dt = pData->fDeltaT; |
| 38 |
pEvaporateParticleSystem->dt = dt; |
| 39 |
pEvaporateParticleSystem->bAddLuminance = TRUE; |
| 40 |
pData->pEvaporateSystem = pEvaporateParticleSystem; // evaporation is always from bottom to top, independantly of the dock's orientation. it feels more natural like this. |
| 41 |
|
| 42 |
double a = myConfig.fEvaporateParticleSpeed; |
| 43 |
static double epsilon = 0.1; |
| 44 |
double r = myConfig.iEvaporateParticleSize; |
| 45 |
double fBlend; |
| 46 |
double vmax = 1. / myConfig.iEvaporateDuration; |
| 47 |
CairoParticle *p; |
| 48 |
int i; |
| 49 |
for (i = 0; i < myConfig.iNbEvaporateParticles; i ++) |
| 50 |
{ |
| 51 |
p = &(pEvaporateParticleSystem->pParticles[i]); |
| 52 |
|
| 53 |
p->x = 2 * g_random_double () - 1; |
| 54 |
p->x = p->x * p->x * (p->x > 0 ? 1 : -1); |
| 55 |
p->y = (myConfig.bEvaporateFromBottom ? 0. : 1.); |
| 56 |
p->z = 2 * g_random_double () - 1; |
| 57 |
p->fWidth = r*(p->z + 2)/3 * g_random_double (); |
| 58 |
p->fHeight = p->fWidth; |
| 59 |
|
| 60 |
p->vx = 0.; |
| 61 |
p->vy = a * vmax * ((p->z + 1)/2 + epsilon) * dt; |
| 62 |
p->iInitialLife = myConfig.iEvaporateDuration / dt; |
| 63 |
if (a > 1) |
| 64 |
p->iInitialLife = MIN (p->iInitialLife, 1. / p->vy); |
| 65 |
else |
| 66 |
p->iInitialLife = 8; |
| 67 |
p->iInitialLife *= g_random_double (); |
| 68 |
p->iLife = p->iInitialLife; |
| 69 |
|
| 70 |
if (myConfig.bMysticalEvaporate) |
| 71 |
{ |
| 72 |
p->color[0] = g_random_double (); |
| 73 |
p->color[1] = g_random_double (); |
| 74 |
p->color[2] = g_random_double (); |
| 75 |
} |
| 76 |
else |
| 77 |
{ |
| 78 |
fBlend = g_random_double (); |
| 79 |
p->color[0] = fBlend * myConfig.pEvaporateColor1[0] + (1 - fBlend) * myConfig.pEvaporateColor2[0]; |
| 80 |
p->color[1] = fBlend * myConfig.pEvaporateColor1[1] + (1 - fBlend) * myConfig.pEvaporateColor2[1]; |
| 81 |
p->color[2] = fBlend * myConfig.pEvaporateColor1[2] + (1 - fBlend) * myConfig.pEvaporateColor2[2]; |
| 82 |
} |
| 83 |
p->color[3] = 1.; |
| 84 |
|
| 85 |
p->fOscillation = G_PI * (2 * g_random_double () - 1); |
| 86 |
p->fOmega = 2*G_PI / myConfig.iEvaporateDuration * dt; // tr/s |
| 87 |
|
| 88 |
p->fSizeFactor = 1.; |
| 89 |
p->fResizeSpeed = -.5 / myConfig.iEvaporateDuration * dt; // zoom 0.5 a la fin. |
| 90 |
} |
| 91 |
|
| 92 |
return TRUE; |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
static void _cd_illusion_rewind_evaporate_particle (CairoParticle *p, CDIllusionData *pData, double dt) |
| 98 |
{ |
| 99 |
static double epsilon = 0.1; |
| 100 |
double a = myConfig.fEvaporateParticleSpeed; |
| 101 |
double r = myConfig.iEvaporateParticleSize; |
| 102 |
double vmax = 1. / myConfig.iEvaporateDuration; |
| 103 |
p->x = 2 * g_random_double () - 1; |
| 104 |
p->x = p->x * p->x * (p->x > 0 ? 1 : -1); |
| 105 |
p->y = (myConfig.bEvaporateFromBottom ? pData->fEvaporatePercent : 1 - pData->fEvaporatePercent); |
| 106 |
p->fWidth = r*(p->z + 2)/3 * g_random_double (); |
| 107 |
p->fHeight = p->fWidth; |
| 108 |
p->vy = a * vmax * ((p->z + 1)/2 * g_random_double () + epsilon) * dt; |
| 109 |
|
| 110 |
p->iInitialLife = myConfig.iEvaporateDuration / dt; |
| 111 |
if (a > 1) |
| 112 |
p->iInitialLife = MIN (p->iInitialLife, 1. / p->vy); |
| 113 |
else |
| 114 |
p->iInitialLife = 8; |
| 115 |
p->iInitialLife *= g_random_double (); |
| 116 |
p->iLife = p->iInitialLife; |
| 117 |
|
| 118 |
p->fSizeFactor = 1.; |
| 119 |
} |
| 120 |
static void cd_illusion_update_evaporate_system (CairoParticleSystem *pParticleSystem, CDIllusionData *pData) |
| 121 |
{ |
| 122 |
CairoParticle *p; |
| 123 |
int i; |
| 124 |
for (i = 0; i < pParticleSystem->iNbParticles; i ++) |
| 125 |
{ |
| 126 |
p = &(pParticleSystem->pParticles[i]); |
| 127 |
|
| 128 |
p->fOscillation += p->fOmega; |
| 129 |
p->x += p->vx + (p->z + 2)/3. * .02 * sin (p->fOscillation); // 3% |
| 130 |
p->y += p->vy; |
| 131 |
p->color[3] = 1.*p->iLife / p->iInitialLife; |
| 132 |
p->fSizeFactor += p->fResizeSpeed; |
| 133 |
if (p->iLife > 0) |
| 134 |
{ |
| 135 |
p->iLife --; |
| 136 |
if (p->iLife == 0) |
| 137 |
{ |
| 138 |
_cd_illusion_rewind_evaporate_particle (p, pData, pParticleSystem->dt); |
| 139 |
} |
| 140 |
} |
| 141 |
else |
| 142 |
_cd_illusion_rewind_evaporate_particle (p, pData, pParticleSystem->dt); |
| 143 |
} |
| 144 |
} |
| 145 |
|
| 146 |
void cd_illusion_update_evaporate (Icon *pIcon, CairoDock *pDock, CDIllusionData *pData) |
| 147 |
{ |
| 148 |
pData->fEvaporatePercent = pData->fTime / myConfig.iEvaporateDuration; |
| 149 |
|
| 150 |
cd_illusion_update_evaporate_system (pData->pEvaporateSystem, pData); |
| 151 |
pData->pEvaporateSystem->fHeight = pIcon->fHeight * pIcon->fScale; |
| 152 |
pData->pEvaporateSystem->fWidth = pIcon->fWidth * pIcon->fScale; |
| 153 |
|
| 154 |
cairo_dock_redraw_container (CAIRO_CONTAINER (pDock)); |
| 155 |
} |
| 156 |
|
| 157 |
void cd_illusion_draw_evaporate_icon (Icon *pIcon, CairoDock *pDock, CDIllusionData *pData) |
| 158 |
{ |
| 159 |
glPushMatrix (); |
| 160 |
cairo_dock_set_icon_scale (pIcon, CAIRO_CONTAINER (pDock), 1.); |
| 161 |
|
| 162 |
_cairo_dock_enable_texture (); |
| 163 |
_cairo_dock_set_alpha (pIcon->fAlpha); |
| 164 |
_cairo_dock_set_blend_over (); |
| 165 |
|
| 166 |
glBindTexture(GL_TEXTURE_2D, pIcon->image.iTexture); |
| 167 |
|
| 168 |
glNormal3f(0,0,1); |
| 169 |
glBegin(GL_QUADS); |
| 170 |
if (myConfig.bEvaporateFromBottom) |
| 171 |
{ |
| 172 |
glTexCoord2f(0., 0.); glVertex3f(-.5, .5, 0.); // Bottom Left Of The Texture and Quad |
| 173 |
glTexCoord2f(1., 0.); glVertex3f( .5, .5, 0.); // Bottom Right Of The Texture and Quad |
| 174 |
glTexCoord2f(1., 1 - pData->fEvaporatePercent); glVertex3f( .5, -.5 + pData->fEvaporatePercent, 0.); // Top Right Of The Texture and Quad |
| 175 |
glTexCoord2f(0., 1 - pData->fEvaporatePercent); glVertex3f(-.5, -.5 + pData->fEvaporatePercent, 0.); // Top Left Of The Texture and Quad |
| 176 |
} |
| 177 |
else |
| 178 |
{ |
| 179 |
glTexCoord2f(0., pData->fEvaporatePercent); glVertex3f(-.5, .5 - pData->fEvaporatePercent, 0.); // Bottom Left Of The Texture and Quad |
| 180 |
glTexCoord2f(1., pData->fEvaporatePercent); glVertex3f( .5, .5 - pData->fEvaporatePercent, 0.); // Bottom Right Of The Texture and Quad |
| 181 |
glTexCoord2f(1., 1.); glVertex3f( .5, -.5, 0.); // Top Right Of The Texture and Quad |
| 182 |
glTexCoord2f(0., 1.); glVertex3f(-.5, -.5, 0.); // Top Left Of The Texture and Quad |
| 183 |
} |
| 184 |
glEnd(); |
| 185 |
|
| 186 |
glPopMatrix (); |
| 187 |
|
| 188 |
/*if (pDock->bUseReflect) |
| 189 |
{ |
| 190 |
glPushMatrix (); |
| 191 |
double x0, y0, x1, y1; |
| 192 |
double fReflectRatio = pDock->iIconSize * myIconsParam.fReflectHeightRatio * pDock->container.fRatio / pIcon->fHeight / pIcon->fScale; |
| 193 |
double fOffsetY = pIcon->fHeight * pIcon->fScale/2 + (pDock->iIconSize * myIconsParam.fReflectHeightRatio/2 + pIcon->fDeltaYReflection) * pDock->container.fRatio; |
| 194 |
if (pDock->bIsHorizontal) |
| 195 |
{ |
| 196 |
if (pDock->bDirectionUp) |
| 197 |
{ |
| 198 |
fOffsetY = pIcon->fHeight * pIcon->fScale + pIcon->fDeltaYReflection; |
| 199 |
glTranslatef (0., - fOffsetY, 0.); |
| 200 |
glScalef (pIcon->fWidth * pIcon->fWidthFactor * pIcon->fScale, - pIcon->fHeight * pIcon->fScale, 1.); // taille du reflet et on se retourne. |
| 201 |
x0 = 0.; |
| 202 |
y0 = 1. - fReflectRatio; |
| 203 |
x1 = 1.; |
| 204 |
y1 = 1.; |
| 205 |
} |
| 206 |
else |
| 207 |
{ |
| 208 |
glTranslatef (0., fOffsetY, 0.); |
| 209 |
glScalef (pIcon->fWidth * pIcon->fWidthFactor * pIcon->fScale, pDock->iIconSize * myIconsParam.fReflectHeightRatio * pDock->container.fRatio, 1.); |
| 210 |
x0 = 0.; |
| 211 |
y0 = fReflectRatio; |
| 212 |
x1 = 1.; |
| 213 |
y1 = 0.; |
| 214 |
} |
| 215 |
} |
| 216 |
else |
| 217 |
{ |
| 218 |
if (pDock->bDirectionUp) |
| 219 |
{ |
| 220 |
glTranslatef (fOffsetY, 0., 0.); |
| 221 |
glScalef (- pDock->iIconSize * myIconsParam.fReflectHeightRatio * pDock->container.fRatio, pIcon->fWidth * pIcon->fWidthFactor * pIcon->fScale, 1.); |
| 222 |
x0 = 1. - fReflectRatio; |
| 223 |
y0 = 0.; |
| 224 |
x1 = 1.; |
| 225 |
y1 = 1.; |
| 226 |
} |
| 227 |
else |
| 228 |
{ |
| 229 |
glTranslatef (- fOffsetY, 0., 0.); |
| 230 |
glScalef (pDock->iIconSize * myIconsParam.fReflectHeightRatio * pDock->container.fRatio, pIcon->fWidth * pIcon->fWidthFactor * pIcon->fScale, 1.); |
| 231 |
x0 = fReflectRatio; |
| 232 |
y0 = 0.; |
| 233 |
x1 = 0.; |
| 234 |
y1 = 1.; |
| 235 |
} |
| 236 |
} |
| 237 |
//glEnableClientState(GL_COLOR_ARRAY); |
| 238 |
|
| 239 |
//glColorPointer(4, GL_FLOAT, 0, pData->pColors); |
| 240 |
//glDrawArrays (GL_TRIANGLE_FAN, 0, pData->iNumActiveNodes); |
| 241 |
|
| 242 |
//glDisableClientState(GL_COLOR_ARRAY); |
| 243 |
|
| 244 |
|
| 245 |
glActiveTexture(GL_TEXTURE0_ARB); // Go pour le multitexturing 1ere passe |
| 246 |
glEnable(GL_TEXTURE_2D); // On active le texturing sur cette passe |
| 247 |
glBindTexture(GL_TEXTURE_2D, pIcon->iIconTexture); |
| 248 |
|
| 249 |
glColor4f(1., 1., 1., myIconsParam.fAlbedo * pIcon->fAlpha); // transparence du reflet. |
| 250 |
glEnable(GL_BLEND); |
| 251 |
glBlendFunc (1, 0); |
| 252 |
glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); |
| 253 |
|
| 254 |
glActiveTexture(GL_TEXTURE1_ARB); // Go pour le texturing 2eme passe |
| 255 |
glEnable(GL_TEXTURE_2D); |
| 256 |
glBindTexture(GL_TEXTURE_2D, g_pGradationTexture[pDock->bIsHorizontal]); |
| 257 |
glColor4f(1., 1., 1., 1.); // transparence du reflet. |
| 258 |
glEnable(GL_BLEND); |
| 259 |
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
| 260 |
glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); // Le mode de combinaison des textures |
| 261 |
glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_MODULATE); // multiplier les alpha. |
| 262 |
glEnableClientState (GL_TEXTURE_COORD_ARRAY); |
| 263 |
glEnableClientState (GL_VERTEX_ARRAY); |
| 264 |
|
| 265 |
glTexCoordPointer (2, GL_FLOAT, 0, pData->pCoords); |
| 266 |
glVertexPointer (3, GL_FLOAT, 0, pData->pVertices); |
| 267 |
|
| 268 |
glDrawArrays (GL_TRIANGLE_FAN, 0, pData->iNumActiveNodes); |
| 269 |
|
| 270 |
glActiveTexture(GL_TEXTURE1_ARB); |
| 271 |
glDisable(GL_TEXTURE_2D); |
| 272 |
glDisableClientState (GL_TEXTURE_COORD_ARRAY); |
| 273 |
glDisableClientState (GL_VERTEX_ARRAY); |
| 274 |
glDisable(GL_TEXTURE_GEN_S); |
| 275 |
glDisable(GL_TEXTURE_GEN_T); |
| 276 |
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); |
| 277 |
glActiveTexture(GL_TEXTURE0_ARB); |
| 278 |
glDisable(GL_TEXTURE_2D); |
| 279 |
glDisable(GL_TEXTURE_GEN_S); |
| 280 |
glDisable(GL_TEXTURE_GEN_T); |
| 281 |
|
| 282 |
glPopMatrix (); |
| 283 |
}*/ |
| 284 |
|
| 285 |
_cairo_dock_disable_texture (); |
| 286 |
|
| 287 |
if (pData->fEvaporatePercent < 1 && pData->fEvaporatePercent > 0) |
| 288 |
{ |
| 289 |
glPushMatrix (); |
| 290 |
glTranslatef (0., - pIcon->fHeight * pIcon->fScale/2, 0.); |
| 291 |
cairo_dock_render_particles (pData->pEvaporateSystem); |
| 292 |
glPopMatrix (); |
| 293 |
} |
| 294 |
} |