| 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-lightning.h" |
| 26 |
|
| 27 |
#include "evaporate-tex.h" |
| 28 |
|
| 29 |
gboolean cd_illusion_init_lightning (Icon *pIcon, CairoDock *pDock, CDIllusionData *pData) |
| 30 |
{ |
| 31 |
pData->iNbSources = myConfig.iLightningNbSources; |
| 32 |
pData->pLightnings = g_new0 (CDIllusionLightning, pData->iNbSources); |
| 33 |
pData->iNbVertex = myConfig.iLightningNbCtrlPts + 2; |
| 34 |
|
| 35 |
CDIllusionLightning *l; |
| 36 |
int i, j; |
| 37 |
for (i = 0; i < pData->iNbSources; i ++) |
| 38 |
{ |
| 39 |
l = &pData->pLightnings[i]; |
| 40 |
l->iNbCurrentVertex = 2; |
| 41 |
l->pVertexTab = g_new0 (GLfloat, 2 * pData->iNbVertex); |
| 42 |
for (j = 0; j < pData->iNbVertex; j ++) |
| 43 |
{ |
| 44 |
l->pVertexTab[2*j+1] = - (double) j / (pData->iNbVertex-1); // on part d'en haut et on descend. |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
if (myData.iLightningTexture == 0) |
| 49 |
myData.iLightningTexture = cairo_dock_create_texture_from_raw_data (evaporateTex, 32, 1); |
| 50 |
|
| 51 |
return TRUE; |
| 52 |
} |
| 53 |
|
| 54 |
|
| 55 |
void cd_illusion_update_lightning (Icon *pIcon, CairoDock *pDock, CDIllusionData *pData) |
| 56 |
{ |
| 57 |
int iWidth, iHeight; |
| 58 |
cairo_dock_get_icon_extent (pIcon, &iWidth, &iHeight); |
| 59 |
double fSizeX, fSizeY; |
| 60 |
cairo_dock_get_current_icon_size (pIcon, CAIRO_CONTAINER (pDock), &fSizeX, &fSizeY); |
| 61 |
|
| 62 |
double f = 1 - MIN (1., pData->fTime / myConfig.iLightningDuration); |
| 63 |
CDIllusionLightning *l; |
| 64 |
double xbase, dx = .05; // 5% de la largeur a chaque petite branche. |
| 65 |
double xsource, ximpact; |
| 66 |
double alpha_s, alpha_t; // correction pour aller plus a gauche ou plus a droite. |
| 67 |
int sign; |
| 68 |
int dt = cairo_dock_get_animation_delta_t (CAIRO_CONTAINER (pDock)); |
| 69 |
int Nt = myConfig.iLightningDuration / dt, Nv = pData->iNbVertex; |
| 70 |
double xt, xs; |
| 71 |
int i, j; |
| 72 |
for (i = 0; i < pData->iNbSources; i ++) |
| 73 |
{ |
| 74 |
l = &pData->pLightnings[i]; |
| 75 |
|
| 76 |
xbase = (pData->iNbSources != 1 ? 2. * i / (pData->iNbSources - 1) - 1 : 0.); // [-1, 1] |
| 77 |
xsource = f*xbase/2; |
| 78 |
ximpact = f*xbase; |
| 79 |
sign = (xbase < 0 ? -1 : 1); |
| 80 |
|
| 81 |
alpha_t = 2 * (xbase/2) / (Nt * dx); // correlation temporelle. |
| 82 |
alpha_s = 2 * (ximpact - xsource) / (Nv * dx); // correlation spatiale. |
| 83 |
|
| 84 |
l->pVertexTab[2*0] = xsource; |
| 85 |
for (j = 1; j < pData->iNbVertex; j ++) |
| 86 |
{ |
| 87 |
xt = l->pVertexTab[2*j] + sign * (g_random_boolean () ? 1 + alpha_t * j/Nv : -1) * dx; // correlation temporelle. |
| 88 |
xs = l->pVertexTab[2*(j-1)] + (g_random_boolean () ? 1 + alpha_s : -1) * dx; // correlation spatiale. |
| 89 |
l->pVertexTab[2*j] = (xs + xt) / 2; // correlation spatio-temporelle (et ouais). |
| 90 |
} |
| 91 |
l->pVertexTab[2*j] = ximpact; |
| 92 |
l->iNbCurrentVertex = MIN (pData->iNbVertex, l->iNbCurrentVertex+1); |
| 93 |
} |
| 94 |
|
| 95 |
pData->fLightningAlpha = MIN (1, .2 + sqrt (f)); |
| 96 |
|
| 97 |
cairo_dock_redraw_container (CAIRO_CONTAINER (pDock)); |
| 98 |
} |
| 99 |
|
| 100 |
void cd_illusion_draw_lightning_icon (Icon *pIcon, CairoDock *pDock, CDIllusionData *pData) |
| 101 |
{ |
| 102 |
//pIcon->fAlpha = pData->fLightningAlpha; |
| 103 |
//cairo_dock_draw_icon_texture (pIcon, CAIRO_CONTAINER (pDock)); |
| 104 |
_cairo_dock_enable_texture (); |
| 105 |
_cairo_dock_set_alpha (pIcon->fAlpha); |
| 106 |
_cairo_dock_set_blend_over (); |
| 107 |
|
| 108 |
glBindTexture(GL_TEXTURE_2D, pIcon->image.iTexture); |
| 109 |
|
| 110 |
double fSizeX, fSizeY; |
| 111 |
cairo_dock_get_current_icon_size (pIcon, CAIRO_CONTAINER (pDock), &fSizeX, &fSizeY); |
| 112 |
double f = pData->fLightningAlpha; |
| 113 |
_cairo_dock_apply_current_texture_portion_at_size_with_offset(0, 0, |
| 114 |
1, f, |
| 115 |
fSizeX, f * fSizeY, |
| 116 |
0, 0); |
| 117 |
|
| 118 |
_cairo_dock_disable_texture (); |
| 119 |
|
| 120 |
|
| 121 |
int iWidth, iHeight; |
| 122 |
cairo_dock_get_icon_extent (pIcon, &iWidth, &iHeight); |
| 123 |
|
| 124 |
glPushMatrix (); |
| 125 |
glTranslatef (0., - fSizeY/2, 0.); // en bas au milieu. |
| 126 |
double fDockMagnitude = cairo_dock_calculate_magnitude (pDock->iMagnitudeIndex); |
| 127 |
double fScale = (1 + fDockMagnitude * myIconsParam.fAmplitude) / (1 + myIconsParam.fAmplitude); |
| 128 |
glTranslatef (0., iHeight * fScale, 0.); // en haut du dock, au milieu de l'icone. |
| 129 |
|
| 130 |
glScalef (iWidth/2 * fScale, iHeight * fScale, 1.); |
| 131 |
|
| 132 |
|
| 133 |
glPolygonMode(GL_FRONT, GL_LINE); |
| 134 |
glEnable (GL_LINE_SMOOTH); |
| 135 |
glHint (GL_LINE_SMOOTH_HINT, GL_NICEST); |
| 136 |
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
| 137 |
glEnable(GL_BLEND); |
| 138 |
_cairo_dock_set_blend_over (); |
| 139 |
glLineWidth (1); |
| 140 |
glColor4f (myConfig.fLightningColor1[0], myConfig.fLightningColor1[1], myConfig.fLightningColor1[2], myConfig.fLightningColor1[3]); |
| 141 |
glEnableClientState(GL_VERTEX_ARRAY); |
| 142 |
|
| 143 |
//glEnable(GL_TEXTURE_1D); |
| 144 |
//glBindTexture (GL_TEXTURE_1D, myData.iLightningTexture); |
| 145 |
|
| 146 |
CDIllusionLightning *l; |
| 147 |
int i; |
| 148 |
for (i = 0; i < pData->iNbSources; i ++) |
| 149 |
{ |
| 150 |
l = &pData->pLightnings[i]; |
| 151 |
|
| 152 |
///_cairo_dock_set_vertex_pointer (l->pVertexTab); |
| 153 |
glDrawArrays (GL_LINE_STRIP, 0, l->iNbCurrentVertex); |
| 154 |
} |
| 155 |
|
| 156 |
glDisableClientState(GL_VERTEX_ARRAY); |
| 157 |
glDisable(GL_LINE_SMOOTH); |
| 158 |
glDisable(GL_BLEND); |
| 159 |
|
| 160 |
//glDisable(GL_TEXTURE_1D); |
| 161 |
|
| 162 |
glPopMatrix (); |
| 163 |
} |