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-break.h"
36
#define xctrl(j) pCtrlPoints[2*(j)]
37
#define yctrl(j) pCtrlPoints[2*(j)+1]
38
#define xpart(j) pPart->pCoords[2*(j)]
39
#define ypart(j) pPart->pCoords[2*(j)+1]
41
gboolean cd_illusion_init_break (Icon *pIcon, CairoDock *pDock, CDIllusionData *pData)
43
int iNbCtrlPts = 4 + (2 * myConfig.iBreakNbBorderPoints) + (2 * myConfig.iBreakNbBorderPoints + 1);
44
double *pCtrlPoints = g_new0 (double, 2 * iNbCtrlPts);
45
//g_print ("iNbCtrlPts : %d\n", iNbCtrlPts);
50
double f, f0 = 1. / (myConfig.iBreakNbBorderPoints + 1); // f0 = fraction moyenne.
52
for (i = 0; i < 2*myConfig.iBreakNbBorderPoints+1; i ++, j++)
54
// un nouveau point sur l'un des cotes.
55
if (i == 2*myConfig.iBreakNbBorderPoints) // dernier coup.
58
f = f0 * (.5 + g_random_double ()); // entre .5f0 et 1.5f0, sachant que 1.5f0 <= 3/4 < 1
59
xctrl(j) = ((j>>1) & 1);
60
yctrl(j) = (1 - f) * (j > 3 ? yctrl(j-4) : yctrl(0));
61
//g_print ("yctrl(j) : %.3f (%.2f)\n", yctrl(j), f);
63
// une brisure au milieu du segment forme.
65
f = g_random_double ();
67
yctrl(j) = f * yctrl(j-1) + (1 - f) * yctrl(j-2);
69
xctrl(j) = ((j>>2) & 1); // en fait c'est toujours egal a 0.
72
pData->iNbBreakParts = 2 + (2 * myConfig.iBreakNbBorderPoints + 1);
73
pData->pBreakPart = g_new0 (CDIllusionBreak, pData->iNbBreakParts);
74
CDIllusionBreak *pPart;
75
for (i = 0; i < pData->iNbBreakParts; i ++)
77
pPart = &pData->pBreakPart[i];
98
else if (i == pData->iNbBreakParts - 1)
101
xpart(0) = xctrl(iNbCtrlPts-3);
102
ypart(0) = yctrl(iNbCtrlPts-3);
103
xpart(1) = xctrl(iNbCtrlPts-2);
104
ypart(1) = yctrl(iNbCtrlPts-2);
105
xpart(2) = xctrl(iNbCtrlPts-1);
106
ypart(2) = yctrl(iNbCtrlPts-1);
111
xpart(0) = xctrl(2*(i-1));
112
ypart(0) = yctrl(2*(i-1));
113
xpart(1) = xctrl(2*(i-1)+1);
114
ypart(1) = yctrl(2*(i-1)+1);
115
xpart(2) = xctrl(2*(i-1)+3);
116
ypart(2) = yctrl(2*(i-1)+3);
117
xpart(3) = xctrl(2*(i-1)+4);
118
ypart(3) = yctrl(2*(i-1)+4);
121
pPart->yinf = MIN (MIN (ypart(0), ypart(1)), ypart(2));
122
if (pPart->iNbPts == 4)
123
pPart->yinf = MIN (pPart->yinf, ypart(3));
124
pPart->fCrackAngle = 5 + g_random_double () * 15.; // ca separe un peu les morceaux, pour donner l'effet de brisure des le debut.
125
pPart->fRotationAngle = (pData->sens == 1 ? pPart->fCrackAngle : 91);
132
void cd_illusion_update_break (Icon *pIcon, CairoDock *pDock, CDIllusionData *pData)
135
cairo_dock_get_icon_extent (pIcon, pDock, &iWidth, &iHeight);
136
double fSizeX, fSizeY;
137
cairo_dock_get_current_icon_size (pIcon, pDock, &fSizeX, &fSizeY);
139
double t_ = (pData->fTime / myConfig.iBreakDuration); // t/T
140
pData->dh = t_ * t_; // dh = 1/2 * g * t^2, avec g = 2/T^2 (hauteur comptee unitairement).
143
CDIllusionBreak *pPart;
145
for (i = 0; i < pData->iNbBreakParts; i ++)
147
pPart = &pData->pBreakPart[i];
148
if (pPart->yinf - pData->dh < 0) // on a touche le sol.
150
pPart->fRotationAngle += pData->sens * pData->fDeltaT / (.25 * myConfig.iBreakDuration) * 90.; // formule faite a la va-vite, avec une acceleration ca serait mieux ...
151
if (pPart->fRotationAngle < pPart->fCrackAngle)
152
pPart->fRotationAngle = pPart->fCrackAngle;
156
cairo_dock_redraw_icon (pIcon, CAIRO_CONTAINER (pDock));
159
void cd_illusion_draw_break_icon (Icon *pIcon, CairoDock *pDock, CDIllusionData *pData)
161
_cairo_dock_enable_texture ();
162
_cairo_dock_set_blend_alpha ();
163
_cairo_dock_set_alpha (1.);
164
glBindTexture (GL_TEXTURE_2D, pIcon->iIconTexture);
166
double fSizeX, fSizeY;
167
cairo_dock_get_current_icon_size (pIcon, pDock, &fSizeX, &fSizeY);
170
glTranslatef (-fSizeX/2, -fSizeY/2, 0.);
171
glMatrixMode(GL_TEXTURE); // On selectionne la matrice des textures
173
glLoadIdentity(); // On la reset
174
glScalef (1., -1., 1.);
175
glMatrixMode(GL_MODELVIEW);
177
CDIllusionBreak *pPart;
178
double xt, yt; // coordonnees d'un point de texture
179
double x, y; // coordonnees du vertex associe.
180
double dh = pData->dh;
182
for (i = 0; i < pData->iNbBreakParts; i ++)
184
pPart = &pData->pBreakPart[i];
185
if (pPart->fRotationAngle > 90) // il est a plat par terre, on ne le voit plus.
188
if (pPart->fRotationAngle != 0)
191
glRotatef (pPart->fRotationAngle, 1., 0., 0.);
194
if (pPart->iNbPts == 3)
195
glBegin(GL_TRIANGLES);
199
for (j = 0; j < pPart->iNbPts; j ++)
205
if (dh > pPart->yinf)
206
y = (yt - pPart->yinf) * fSizeY;
208
y = (yt - dh) * fSizeY;
210
glTexCoord2f (xt, yt);
211
glVertex3f (x, y, 0.);
216
if (pPart->fRotationAngle != 0)
223
glMatrixMode(GL_TEXTURE); // On selectionne la matrice des textures
225
glMatrixMode(GL_MODELVIEW);
226
_cairo_dock_disable_texture ();