~ubuntu-branches/ubuntu/saucy/cairo-dock-plug-ins/saucy

« back to all changes in this revision

Viewing changes to Animated-icons/src/applet-bounce.c

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2009-08-26 21:07:39 UTC
  • Revision ID: james.westby@ubuntu.com-20090826210739-gyjuuqezrzuluao4
Tags: upstream-2.0.8.1
ImportĀ upstreamĀ versionĀ 2.0.8.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
/******************************************************************************
 
21
 
 
22
This file is a part of the cairo-dock program, 
 
23
released under the terms of the GNU General Public License.
 
24
 
 
25
Written by Fabrice Rey (for any bug report, please mail me to fabounet@users.berlios.de)
 
26
 
 
27
******************************************************************************/
 
28
 
 
29
#include <stdlib.h>
 
30
#include <string.h>
 
31
#include <math.h>
 
32
 
 
33
#include "applet-struct.h"
 
34
#include "applet-bounce.h"
 
35
 
 
36
 
 
37
void cd_animations_init_bounce (CairoDock *pDock, CDAnimationData *pData, double dt)
 
38
{
 
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;
 
46
}
 
47
 
 
48
 
 
49
gboolean cd_animations_update_bounce (Icon *pIcon, CairoDock *pDock, CDAnimationData *pData, double dt, gboolean bUseOpenGL, gboolean bWillContinue)
 
50
{
 
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);
 
56
        
 
57
        double fPrevElevation = pData->fElevation;
 
58
        double fPrevDeltaY = pIcon->fDeltaYReflection;
 
59
        if (k > 0)
 
60
        {
 
61
                if (pData->iBounceCount == 1 && ! bWillContinue)
 
62
                        pData->fResizeFactor = 1.;
 
63
                else if (pData->fResizeFactor > myConfig.fBounceResize)
 
64
                {
 
65
                        pData->fResizeFactor -= (1 - myConfig.fBounceResize) / (n/2);
 
66
                }
 
67
                
 
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)
 
70
                {
 
71
                        pData->fElevation = 0.;
 
72
                        pIcon->fDeltaYReflection = 0.;
 
73
                }
 
74
                else
 
75
                {
 
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)
 
81
                        {
 
82
                                pData->fElevation -= (1 - pData->fResizeFactor) * pIcon->fHeight*pIcon->fScale/2;
 
83
                        }
 
84
                }
 
85
                //g_print (" ^ pData->fElevation : %.2f (x%.2f)\n", pData->fElevation, pData->fResizeFactor);
 
86
                pData->fFlattenFactor = 1.;
 
87
        }
 
88
        else  // on commence par s'aplatir.
 
89
        {
 
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;
 
93
                
 
94
                pIcon->fDeltaYReflection = pData->fElevation;
 
95
                if (! bUseOpenGL)
 
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)
 
98
                {
 
99
                        pData->fElevation = - (1 - pData->fResizeFactor * pData->fFlattenFactor) * pIcon->fHeight*pIcon->fScale/2;
 
100
                }
 
101
                //g_print (" v pData->fElevation : %.2f (x%.2f)\n", pData->fElevation, pData->fFlattenFactor);
 
102
        }
 
103
        
 
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'.
 
105
        
 
106
        if (! bUseOpenGL && ! pDock->bIsShrinkingDown && ! pDock->bIsGrowingUp)
 
107
        {
 
108
                double fDamageWidthFactor = pIcon->fWidthFactor;
 
109
                double fDamageHeightFactor = pIcon->fHeightFactor;
 
110
                double fDeltaYReflection = pIcon->fDeltaYReflection;
 
111
                
 
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;
 
119
                
 
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;
 
127
        }
 
128
        
 
129
        return (pData->iBounceCount > 0);
 
130
}
 
131
 
 
132
 
 
133
void cd_animations_draw_bounce_icon (Icon *pIcon, CairoDock *pDock, CDAnimationData *pData, int sens)
 
134
{
 
135
        if (sens == 1)
 
136
                pIcon->fHeightFactor *= pData->fFlattenFactor;
 
137
        else
 
138
                pIcon->fHeightFactor /= pData->fFlattenFactor;
 
139
        
 
140
        if (sens == 1)
 
141
        {
 
142
                pIcon->fHeightFactor *= pData->fResizeFactor;
 
143
                pIcon->fWidthFactor *= pData->fResizeFactor;
 
144
        }
 
145
        else
 
146
        {
 
147
                pIcon->fHeightFactor /= pData->fResizeFactor;
 
148
                pIcon->fWidthFactor /= pData->fResizeFactor;
 
149
        }
 
150
        
 
151
        if (pDock->bHorizontalDock)
 
152
                glTranslatef (0., (pDock->bDirectionUp ? 1 : -1) * pData->fElevation * sens, 0.);
 
153
        else
 
154
                glTranslatef ((pDock->bDirectionUp ? -1 : 1) * pData->fElevation * sens, 0., 0.);
 
155
}
 
156
 
 
157
 
 
158
void cd_animations_draw_bounce_cairo (Icon *pIcon, CairoDock *pDock, CDAnimationData *pData, cairo_t *pCairoContext, int sens)
 
159
{
 
160
        if (sens == 1)
 
161
                pIcon->fHeightFactor *= pData->fFlattenFactor;
 
162
        else
 
163
                pIcon->fHeightFactor /= pData->fFlattenFactor;
 
164
        
 
165
        if (sens == 1)
 
166
        {
 
167
                pIcon->fHeightFactor *= pData->fResizeFactor;
 
168
                pIcon->fWidthFactor *= pData->fResizeFactor;
 
169
        }
 
170
        else
 
171
        {
 
172
                pIcon->fHeightFactor /= pData->fResizeFactor;
 
173
                pIcon->fWidthFactor /= pData->fResizeFactor;
 
174
        }
 
175
        
 
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);
 
180
        else
 
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);
 
184
        
 
185
        if (pDock->bHorizontalDock)
 
186
                cairo_translate (pCairoContext,
 
187
                        0.,
 
188
                        - (pDock->bDirectionUp ? 1 : -1) * pData->fElevation * sens);
 
189
        else
 
190
                cairo_translate (pCairoContext,
 
191
                        - (pDock->bDirectionUp ? 1 : -1) * pData->fElevation * sens,
 
192
                        0.);
 
193
}
 
194