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-bounce.h"
37
void cd_animations_init_bounce (CairoDock *pDock, CDAnimationData *pData, double dt)
39
int m = (1 - myConfig.fBounceFlatten) / .1;
40
pData->iBounceCount = myConfig.iBounceDuration / dt - 1 + m;
41
if (pData->fResizeFactor == 0)
42
pData->fResizeFactor = 1.;
43
if (pData->fFlattenFactor == 0)
44
pData->fFlattenFactor = 1.;
45
pData->bIsBouncing = TRUE;
49
gboolean cd_animations_update_bounce (Icon *pIcon, CairoDock *pDock, CDAnimationData *pData, double dt, gboolean bUseOpenGL, gboolean bWillContinue)
51
int m = (1 - myConfig.fBounceFlatten) / .1; // pas de 0.1
52
int n = myConfig.iBounceDuration / dt + m; // nbre d'iteration pour 1 aplatissement+montree+descente.
53
int k = n - (pData->iBounceCount % n) - m; // m iterations pour s'aplatir.
54
n -= m; // nbre d'iteration pour 1 montree+descente.
55
//g_print ("%s (%d)\n", __func__, pData->iBounceCount);
57
double fPrevElevation = pData->fElevation;
58
double fPrevDeltaY = pIcon->fDeltaYReflection;
61
if (pData->iBounceCount == 1 && ! bWillContinue)
62
pData->fResizeFactor = 1.;
63
else if (pData->fResizeFactor > myConfig.fBounceResize)
65
pData->fResizeFactor -= (1 - myConfig.fBounceResize) / (n/2);
68
double fPossibleDeltaY = MIN (50, (pDock->bDirectionUp ? pIcon->fDrawY : pDock->iCurrentHeight - (pIcon->fDrawY + pIcon->fHeight * pIcon->fScale)) + (1-pData->fResizeFactor)*pIcon->fHeight*pIcon->fScale); // on borne a 50 pixels pour les rendus qui ont des fenetres grandes..
69
if (pData->iBounceCount == 1 && ! bWillContinue)
71
pData->fElevation = 0.;
72
pIcon->fDeltaYReflection = 0.;
76
pData->fElevation = 1.*k / (n/2) * fPossibleDeltaY * (2 - 1.*k/(n/2)) - (pDock->bDirectionUp ? (1 - pData->fResizeFactor) * pIcon->fHeight*pIcon->fScale/2 : 0);
77
pIcon->fDeltaYReflection = 1.40 * pData->fElevation; // le reflet "rebondira" de 40% de la hauteur au sol.
78
if (! bUseOpenGL) // on prend en compte la translation du au fHeightFactor.
79
pIcon->fDeltaYReflection -= (pDock->bHorizontalDock ? pIcon->fHeight * pIcon->fScale * pIcon->fHeightFactor * (1 - pData->fResizeFactor) / (pDock->bDirectionUp ? 2:1) : pIcon->fWidth * pIcon->fScale * (1 - pData->fResizeFactor) / 2);
80
else if (! pDock->bDirectionUp)
82
pData->fElevation -= (1 - pData->fResizeFactor) * pIcon->fHeight*pIcon->fScale/2;
85
//g_print (" ^ pData->fElevation : %.2f (x%.2f)\n", pData->fElevation, pData->fResizeFactor);
86
pData->fFlattenFactor = 1.;
88
else // on commence par s'aplatir.
90
pData->fFlattenFactor = - (1. - myConfig.fBounceFlatten) / m * k + myConfig.fBounceFlatten; // varie de 1. exclus a f inclus.
91
if (pDock->bDirectionUp)
92
pData->fElevation = - (1. - pData->fFlattenFactor * pData->fResizeFactor) / 2 * pIcon->fHeight * pIcon->fScale;
94
pIcon->fDeltaYReflection = pData->fElevation;
96
pIcon->fDeltaYReflection -= (pDock->bHorizontalDock ? pIcon->fHeight * pIcon->fScale * (1 - pData->fResizeFactor * pData->fFlattenFactor) / (pDock->bDirectionUp ? 2:1) : pIcon->fWidth * pIcon->fScale * (1 - pData->fResizeFactor * pData->fFlattenFactor) / 2);
97
else if (! pDock->bDirectionUp)
99
pData->fElevation = - (1 - pData->fResizeFactor * pData->fFlattenFactor) * pIcon->fHeight*pIcon->fScale/2;
101
//g_print (" v pData->fElevation : %.2f (x%.2f)\n", pData->fElevation, pData->fFlattenFactor);
104
pData->iBounceCount --; // c'est une loi de type acceleration dans le champ de pesanteur. 'g' et 'v0' n'interviennent pas directement, car s'expriment en fonction de 'fPossibleDeltaY' et 'n'.
106
if (! bUseOpenGL && ! pDock->bIsShrinkingDown && ! pDock->bIsGrowingUp)
108
double fDamageWidthFactor = pIcon->fWidthFactor;
109
double fDamageHeightFactor = pIcon->fHeightFactor;
110
double fDeltaYReflection = pIcon->fDeltaYReflection;
112
fPrevDeltaY = MAX (fPrevDeltaY, pIcon->fDeltaYReflection);
113
pIcon->fDeltaYReflection = fPrevDeltaY;
114
fPrevElevation = MAX (fPrevElevation, pData->fElevation);
115
pIcon->fWidthFactor = 1.;
116
pIcon->fHeightFactor = 1.;
117
pIcon->fDrawY -= (pDock->bDirectionUp ? 1 : 0) * fPrevElevation;
118
pIcon->fHeight += fPrevElevation;
120
cairo_dock_redraw_my_icon (pIcon, CAIRO_CONTAINER (pDock));
121
//cairo_dock_redraw_container (pDock);
122
pIcon->fDrawY += (pDock->bDirectionUp ? 1 : 0) * fPrevElevation;
123
pIcon->fWidthFactor = fDamageWidthFactor;
124
pIcon->fHeightFactor = fDamageHeightFactor;
125
pIcon->fDeltaYReflection = fDeltaYReflection;
126
pIcon->fHeight -= fPrevElevation;
129
return (pData->iBounceCount > 0);
133
void cd_animations_draw_bounce_icon (Icon *pIcon, CairoDock *pDock, CDAnimationData *pData, int sens)
136
pIcon->fHeightFactor *= pData->fFlattenFactor;
138
pIcon->fHeightFactor /= pData->fFlattenFactor;
142
pIcon->fHeightFactor *= pData->fResizeFactor;
143
pIcon->fWidthFactor *= pData->fResizeFactor;
147
pIcon->fHeightFactor /= pData->fResizeFactor;
148
pIcon->fWidthFactor /= pData->fResizeFactor;
151
if (pDock->bHorizontalDock)
152
glTranslatef (0., (pDock->bDirectionUp ? 1 : -1) * pData->fElevation * sens, 0.);
154
glTranslatef ((pDock->bDirectionUp ? -1 : 1) * pData->fElevation * sens, 0., 0.);
158
void cd_animations_draw_bounce_cairo (Icon *pIcon, CairoDock *pDock, CDAnimationData *pData, cairo_t *pCairoContext, int sens)
161
pIcon->fHeightFactor *= pData->fFlattenFactor;
163
pIcon->fHeightFactor /= pData->fFlattenFactor;
167
pIcon->fHeightFactor *= pData->fResizeFactor;
168
pIcon->fWidthFactor *= pData->fResizeFactor;
172
pIcon->fHeightFactor /= pData->fResizeFactor;
173
pIcon->fWidthFactor /= pData->fResizeFactor;
176
if (pDock->bHorizontalDock)
177
cairo_translate (pCairoContext,
178
pIcon->fWidth * pIcon->fScale * (1 - pIcon->fWidthFactor) / 2 * sens,
179
(pDock->bDirectionUp ? 1 : 0) * pIcon->fHeight * pIcon->fScale * (1 - pIcon->fHeightFactor) / 2 * sens);
181
cairo_translate (pCairoContext,
182
(pDock->bDirectionUp ? 1 : 0) * pIcon->fHeight * pIcon->fScale * (1 - pIcon->fHeightFactor) / 2 * sens,
183
pIcon->fWidth * pIcon->fScale * (1 - pIcon->fWidthFactor) / 2 * sens);
185
if (pDock->bHorizontalDock)
186
cairo_translate (pCairoContext,
188
- (pDock->bDirectionUp ? 1 : -1) * pData->fElevation * sens);
190
cairo_translate (pCairoContext,
191
- (pDock->bDirectionUp ? 1 : -1) * pData->fElevation * sens,