~ubuntu-branches/ubuntu/oneiric/cairo-dock/oneiric-201110111206

« back to all changes in this revision

Viewing changes to src/cairo-dock-graph.c

  • Committer: Bazaar Package Importer
  • Author(s): Julien Lavergne, Matthieu Baerts (matttbe), Julien Lavergne
  • Date: 2009-10-04 16:33:52 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20091004163352-ttbbjfmpb8uzl8j4
Tags: 2.0.9-0ubuntu1
[ Matthieu Baerts (matttbe) ]
* New Upstream Version. (LP: #435587)
* Added apport hook in debian/apport
 - Add debian/apport
 - debian/cairo-dock-core.install: Added debian/apport/cairo-dock.py
* Use .desktop provided by upstream
 - Removed debian/*.desktop
 - debian/cairo-dock-core.install: install upstream desktop files. 

[ Julien Lavergne ]
* Adjust debian/changelog with Daniel Holbach suggestions.
* debian/patches/01_rename_cairo-dock-package-theme.patch: drop, 
  merged upstream.
* debian/patches/01-desktop-file-category.patch:
 - Remove Encoding field and set category to Utility.
* debian/patches/02-merge-changelog.patch:
 - Merge ChangeLog and ChangeLog-2.0.9.
* debian/apport: Remove commands with grep, python doesn't like it.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/**
2
 
* Graph for Cairo-Dock
 
2
* This file is a part of the Cairo-Dock project
3
3
*
4
 
* Copyright : (C) 2009 by Fabrice Rey
5
 
* E-mail    : fabounet@users.berlios.de
 
4
* Copyright : (C) see the 'copyright' file.
 
5
* E-mail    : see the 'copyright' file.
6
6
*
7
7
* This program is free software; you can redistribute it and/or
8
8
* modify it under the terms of the GNU General Public License
13
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
15
* GNU General Public License for more details.
16
 
*   http://www.gnu.org/licenses/licenses.html#GPL
 
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/>.
17
18
*/
18
19
 
19
20
#include <string.h>
20
21
#include <stdlib.h>
21
22
#include <math.h>
22
23
 
23
 
#include <cairo-dock-struct.h>
24
 
#include <cairo-dock-log.h>
25
 
#include <cairo-dock-surface-factory.h>
26
 
#include <cairo-dock-dock-factory.h>
 
24
#include "cairo-dock-log.h"
 
25
#include "cairo-dock-surface-factory.h"
 
26
#include "cairo-dock-dock-factory.h"
27
27
#include "cairo-dock-renderer-manager.h"
28
 
#include <cairo-dock-draw-opengl.h>
29
 
#include <cairo-dock-draw.h>
30
 
#include <cairo-dock-internal-labels.h>
31
 
#include <cairo-dock-internal-icons.h>
32
 
#include <cairo-dock-internal-background.h>
 
28
#include "cairo-dock-draw-opengl.h"
 
29
#include "cairo-dock-draw.h"
 
30
#include "cairo-dock-internal-labels.h"
 
31
#include "cairo-dock-internal-icons.h"
 
32
#include "cairo-dock-internal-background.h"
33
33
#include "cairo-dock-container.h"
34
 
#include <cairo-dock-graph.h>
 
34
#include "cairo-dock-graph.h"
35
35
 
36
36
extern gboolean g_bUseOpenGL;
37
37
 
38
38
 
39
 
void cairo_dock_draw_graph (cairo_t *pCairoContext, CairoDockGraph *pGraph)
 
39
void cairo_dock_render_graph (CairoDockGraph *pGraph, cairo_t *pCairoContext)
40
40
{
41
 
        g_return_if_fail (pGraph != NULL);
 
41
        g_return_if_fail (pGraph != NULL && pCairoContext != NULL);
 
42
        g_return_if_fail (cairo_status (pCairoContext) == CAIRO_STATUS_SUCCESS);
42
43
        
43
 
        cairo_set_source_rgba (pCairoContext, 0., 0., 0., 0.);
44
 
        cairo_set_operator (pCairoContext, CAIRO_OPERATOR_SOURCE);
45
 
        cairo_paint (pCairoContext);
46
 
        cairo_set_operator (pCairoContext, CAIRO_OPERATOR_OVER);
 
44
        CairoDataRenderer *pRenderer = CAIRO_DATA_RENDERER (pGraph);
 
45
        CairoDataToRenderer *pData = cairo_data_renderer_get_data (pRenderer);
47
46
        
48
47
        if (pGraph->pBackgroundSurface != NULL)
49
48
        {
51
50
                cairo_paint (pCairoContext);
52
51
        }
53
52
        
54
 
        if (pGraph->iNbValues <= 1)
 
53
        int iNbDrawings = pData->iNbValues / pRenderer->iRank;
 
54
        if (iNbDrawings == 0)
55
55
                return;
56
56
        
57
57
        double fMargin = pGraph->fMargin;
58
 
        double fWidth = pGraph->fWidth - 2*fMargin;
59
 
        double fHeight = pGraph->fHeight - 2*fMargin;
60
 
        if (pGraph->pTabValues2 != NULL && ! pGraph->bMixDoubleGraph)
61
 
        {
62
 
                fHeight /= 2;
63
 
        }
64
 
        
65
 
        double *pTabValues;
 
58
        double fWidth = pRenderer->iWidth - 2*fMargin;
 
59
        double fHeight = pRenderer->iHeight - 2*fMargin;
 
60
        fHeight /= iNbDrawings;
 
61
 
 
62
        double fValue;
66
63
        cairo_pattern_t *pGradationPattern;
67
 
        int k;
68
 
        for (k = 0; k < (pGraph->pTabValues2 == NULL ? 1 : 2); k ++)
 
64
        int i;
 
65
        for (i = 0; i < pData->iNbValues; i ++)
69
66
        {
70
 
                if (k == 1)
71
 
                {
72
 
                        pTabValues = pGraph->pTabValues2;
73
 
                        if (! pGraph->bMixDoubleGraph)
74
 
                                cairo_translate (pCairoContext,
75
 
                                        0.,
76
 
                                        fHeight);
77
 
                        pGradationPattern = pGraph->pGradationPattern2;
78
 
                }
79
 
                else
80
 
                {
81
 
                        pTabValues = pGraph->pTabValues;
82
 
                        pGradationPattern = pGraph->pGradationPattern;
83
 
                        
84
 
                }
 
67
                if (! pGraph->bMixGraphs)
 
68
                        cairo_translate (pCairoContext,
 
69
                                0.,
 
70
                                i * fHeight);
 
71
                pGradationPattern = pGraph->pGradationPatterns[i];
85
72
                if (pGradationPattern != NULL)
86
73
                        cairo_set_source (pCairoContext, pGradationPattern);
87
74
                else
88
75
                        cairo_set_source_rgb (pCairoContext,
89
 
                                pGraph->fLowColor[0],
90
 
                                pGraph->fLowColor[1],
91
 
                                pGraph->fLowColor[2]);
92
 
                if (pGraph->iType == CAIRO_DOCK_GRAPH_LINE || pGraph->iType == CAIRO_DOCK_GRAPH_PLAIN)
 
76
                                pGraph->fLowColor[3*i+0],
 
77
                                pGraph->fLowColor[3*i+1],
 
78
                                pGraph->fLowColor[3*i+2]);
 
79
                
 
80
                if (pGraph->iType == CAIRO_DOCK_GRAPH2_LINE || pGraph->iType == CAIRO_DOCK_GRAPH2_PLAIN)
93
81
                {
94
82
                        cairo_set_line_width (pCairoContext, 1);
95
83
                        cairo_set_line_join (pCairoContext, CAIRO_LINE_JOIN_ROUND);
96
 
                        int j = pGraph->iCurrentIndex + 1;
97
 
                        if (j >= pGraph->iNbValues)
98
 
                                j -= pGraph->iNbValues;
99
 
                        cairo_move_to (pCairoContext, fMargin, fMargin + (1 - pTabValues[j]) * fHeight);
100
 
                        int i;
101
 
                        for (i = 1; i < pGraph->iNbValues; i ++)
 
84
                        fValue = cairo_data_renderer_get_normalized_current_value (pRenderer, i);
 
85
                        cairo_move_to (pCairoContext, fMargin + fWidth, fMargin + (1 - fValue) * fHeight);
 
86
                        int t, n = pData->iMemorySize - 1;
 
87
                        for (t = 1; t < pData->iMemorySize; t ++)
102
88
                        {
103
 
                                j = pGraph->iCurrentIndex + i + 1;
104
 
                                if (j >= pGraph->iNbValues)
105
 
                                        j -= pGraph->iNbValues;
 
89
                                fValue = cairo_data_renderer_get_normalized_value (pRenderer, i, -t);
106
90
                                cairo_line_to (pCairoContext,
107
 
                                        fMargin + i * fWidth / pGraph->iNbValues,
108
 
                                        fMargin + (1 - pTabValues[j]) * fHeight);
 
91
                                        fMargin + (n - t) * fWidth / n,
 
92
                                        fMargin + (1 - fValue) * fHeight);
109
93
                        }
110
 
                        if (pGraph->iType == CAIRO_DOCK_GRAPH_PLAIN)
 
94
                        if (pGraph->iType == CAIRO_DOCK_GRAPH2_PLAIN)
111
95
                        {
112
 
                                i --;
113
 
                                cairo_line_to (pCairoContext,
114
 
                                        fMargin + i * fWidth / pGraph->iNbValues,
115
 
                                        fMargin + fHeight);
116
96
                                cairo_line_to (pCairoContext,
117
97
                                        fMargin,
118
98
                                        fMargin + fHeight);
 
99
                                cairo_line_to (pCairoContext,
 
100
                                        fMargin + fWidth,
 
101
                                        fMargin + fHeight);
119
102
                                cairo_close_path (pCairoContext);
120
103
                                cairo_fill_preserve (pCairoContext);
121
104
                        }
122
105
                        cairo_stroke (pCairoContext);
123
106
                }
124
 
                else if (pGraph->iType == CAIRO_DOCK_GRAPH_BAR)
 
107
                else if (pGraph->iType == CAIRO_DOCK_GRAPH2_BAR)
125
108
                {
126
 
                        double fBarWidth = fWidth / pGraph->iNbValues / 4;
 
109
                        double fBarWidth = fWidth / pData->iMemorySize / 4;
127
110
                        cairo_set_line_width (pCairoContext, fBarWidth);
128
 
                        int i, j;
129
 
                        for (i = 1; i < pGraph->iNbValues; i ++)
 
111
                        int t, n = pData->iMemorySize - 1;
 
112
                        for (t = 0; t < pData->iMemorySize; t ++)
130
113
                        {
131
 
                                j = pGraph->iCurrentIndex + i + 1;
132
 
                                if (j >= pGraph->iNbValues)
133
 
                                        j -= pGraph->iNbValues;
 
114
                                fValue = cairo_data_renderer_get_normalized_value (pRenderer, i, -t);
134
115
                                cairo_move_to (pCairoContext,
135
 
                                        fMargin + i * fWidth / pGraph->iNbValues,
 
116
                                        fMargin + (n - t) * fWidth / n,
136
117
                                        fMargin + fHeight);
137
118
                                cairo_rel_line_to (pCairoContext,
138
119
                                        0.,
139
 
                                        - pTabValues[j] * fHeight);
 
120
                                        - fValue * fHeight);
140
121
                                cairo_stroke (pCairoContext);
141
122
                        }
142
123
                }
144
125
                {
145
126
                        cairo_set_line_width (pCairoContext, 1);
146
127
                        cairo_set_line_join (pCairoContext, CAIRO_LINE_JOIN_ROUND);
147
 
                        int j = pGraph->iCurrentIndex + 1;
148
 
                        if (j >= pGraph->iNbValues)
149
 
                                j -= pGraph->iNbValues;
 
128
                        fValue = cairo_data_renderer_get_normalized_current_value (pRenderer, i);
150
129
                        double angle, radius = MIN (fWidth, fHeight)/2;
151
 
                        angle = 2*G_PI*(-.5/pGraph->iNbValues);
 
130
                        angle = -2*G_PI*(-.5/pData->iMemorySize);
152
131
                        cairo_move_to (pCairoContext,
153
 
                                fMargin + fWidth/2 + radius * (pTabValues[j] * cos (angle)),
154
 
                                fMargin + fHeight/2 + radius * (pTabValues[j] * sin (angle)));
155
 
                        angle = 2*G_PI*(.5/pGraph->iNbValues);
 
132
                                fMargin + fWidth/2 + radius * (fValue * cos (angle)),
 
133
                                fMargin + fHeight/2 + radius * (fValue * sin (angle)));
 
134
                        angle = -2*G_PI*(.5/pData->iMemorySize);
156
135
                        cairo_line_to (pCairoContext,
157
 
                                fMargin + fWidth/2 + radius * (pTabValues[j] * cos (angle)),
158
 
                                fMargin + fHeight/2 + radius * (pTabValues[j] * sin (angle)));
159
 
                        int i;
160
 
                        for (i = 1; i < pGraph->iNbValues; i ++)
 
136
                                fMargin + fWidth/2 + radius * (fValue * cos (angle)),
 
137
                                fMargin + fHeight/2 + radius * (fValue * sin (angle)));
 
138
                        int t;
 
139
                        for (t = 1; t < pData->iMemorySize; t ++)
161
140
                        {
162
 
                                j = pGraph->iCurrentIndex + i + 1;
163
 
                                if (j >= pGraph->iNbValues)
164
 
                                        j -= pGraph->iNbValues;
165
 
                                angle = 2*G_PI*((i-.5)/pGraph->iNbValues);
166
 
                                cairo_line_to (pCairoContext,
167
 
                                        fMargin + fWidth/2 + radius * (pTabValues[j] * cos (angle)),
168
 
                                        fMargin + fHeight/2 + radius * (pTabValues[j] * sin (angle)));
169
 
                                angle = 2*G_PI*((i+.5)/pGraph->iNbValues);
170
 
                                cairo_line_to (pCairoContext,
171
 
                                        fMargin + fWidth/2 + radius * (pTabValues[j] * cos (angle)),
172
 
                                        fMargin + fHeight/2 + radius * (pTabValues[j] * sin (angle)));
 
141
                                fValue = cairo_data_renderer_get_normalized_value (pRenderer, i, -t);
 
142
                                angle = -2*G_PI*((t-.5)/pData->iMemorySize);
 
143
                                cairo_line_to (pCairoContext,
 
144
                                        fMargin + fWidth/2 + radius * (fValue * cos (angle)),
 
145
                                        fMargin + fHeight/2 + radius * (fValue * sin (angle)));
 
146
                                angle = -2*G_PI*((t+.5)/pData->iMemorySize);
 
147
                                cairo_line_to (pCairoContext,
 
148
                                        fMargin + fWidth/2 + radius * (fValue * cos (angle)),
 
149
                                        fMargin + fHeight/2 + radius * (fValue * sin (angle)));
173
150
                        }
174
 
                        if (pGraph->iType == CAIRO_DOCK_GRAPH_CIRCLE_PLAIN)
 
151
                        if (pGraph->iType == CAIRO_DOCK_GRAPH2_CIRCLE_PLAIN)
175
152
                        {
176
153
                                cairo_close_path (pCairoContext);
177
154
                                cairo_fill_preserve (pCairoContext);
181
158
        }
182
159
}
183
160
 
184
 
void cairo_dock_render_graph (cairo_t *pSourceContext, CairoContainer *pContainer, Icon *pIcon, CairoDockGraph *pGraph)
 
161
 
 
162
static void cairo_dock_render_graph_opengl (CairoDockGraph *pGraph)
185
163
{
186
 
        cairo_save (pSourceContext);
187
 
        
188
 
        cairo_dock_draw_graph (pSourceContext, pGraph);
189
 
        
190
 
        cairo_restore (pSourceContext);
191
 
        
192
 
        // On cree le reflet.
193
 
        if (CAIRO_DOCK_IS_DOCK (pContainer) && CAIRO_DOCK (pContainer)->bUseReflect)
 
164
        g_return_if_fail (pGraph != NULL);
 
165
        
 
166
        CairoDataRenderer *pRenderer = CAIRO_DATA_RENDERER (pGraph);
 
167
        CairoDataToRenderer *pData = cairo_data_renderer_get_data (pRenderer);
 
168
        
 
169
        if (pGraph->iBackgroundTexture != 0)
194
170
        {
195
 
                double fMaxScale = cairo_dock_get_max_scale (pContainer);
196
 
                
197
 
                cairo_surface_destroy (pIcon->pReflectionBuffer);
198
 
                pIcon->pReflectionBuffer = cairo_dock_create_reflection_surface (pIcon->pIconBuffer,
199
 
                        pSourceContext,
200
 
                        (pContainer->bIsHorizontal ? pIcon->fWidth : pIcon->fHeight) * fMaxScale,
201
 
                        (pContainer->bIsHorizontal ? pIcon->fHeight : pIcon->fWidth) * fMaxScale,
202
 
                        pContainer->bIsHorizontal,
203
 
                        fMaxScale,
204
 
                        pContainer->bDirectionUp);
 
171
                _cairo_dock_enable_texture ();
 
172
                _cairo_dock_set_blend_pbuffer ();  // ceci reste un mystere...
 
173
                _cairo_dock_set_alpha (1.);
 
174
                _cairo_dock_apply_texture_at_size_with_alpha (pGraph->iBackgroundTexture, pRenderer->iWidth, pRenderer->iHeight, 1.);
 
175
                _cairo_dock_disable_texture ();
205
176
        }
206
177
        
207
 
        if (CAIRO_DOCK_CONTAINER_IS_OPENGL (pContainer))
208
 
                cairo_dock_update_icon_texture (pIcon);
209
178
        
210
 
        cairo_dock_redraw_icon (pIcon, pContainer);
211
179
}
212
180
 
213
 
static cairo_surface_t *_cairo_dock_create_graph_background (cairo_t *pSourceContext, double fWidth, double fHeight, int iRadius, gdouble *pBackGroundColor, CairoDockTypeGraph iType)
 
181
 
 
182
static inline cairo_surface_t *_cairo_dock_create_graph_background (cairo_t *pSourceContext, double fWidth, double fHeight, int iRadius, double fMargin, gdouble *pBackGroundColor, CairoDockTypeGraph iType, int iNbDrawings)
214
183
{
 
184
        // on cree la surface.
215
185
        cairo_surface_t *pBackgroundSurface = cairo_surface_create_similar (cairo_get_target (pSourceContext),
216
186
                CAIRO_CONTENT_COLOR_ALPHA,
217
187
                fWidth,
218
188
                fHeight);
219
189
        cairo_t *pCairoContext = cairo_create (pBackgroundSurface);
 
190
        
 
191
        // on trace le fond : un rectangle au coin arrondi.
220
192
        cairo_set_operator (pCairoContext, CAIRO_OPERATOR_OVER);
221
193
        cairo_set_source_rgba (pCairoContext,
222
194
                pBackGroundColor[0],
232
204
        cairo_rel_line_to (pCairoContext, 0, fHeight - (fRadius));
233
205
        cairo_rel_line_to (pCairoContext, -(fWidth - (fRadius)) ,0);
234
206
        cairo_close_path (pCairoContext);
235
 
        cairo_stroke (pCairoContext);
 
207
        cairo_stroke (pCairoContext);  // on trace d'abord les contours arrondis.
236
208
        
237
209
        cairo_rectangle (pCairoContext, fRadius, fRadius, (fWidth - 2*fRadius), (fHeight - 2*fRadius));
238
 
        cairo_fill (pCairoContext);
239
 
        
240
 
        
 
210
        cairo_fill (pCairoContext);  // puis on rempli l'interieur.
 
211
        
 
212
        // on trace les axes.
241
213
        cairo_set_operator (pCairoContext, CAIRO_OPERATOR_OVER);
242
 
        double fMargin = fRadius * (1. - sqrt(2)/2);
243
 
        cairo_set_source_rgb (pCairoContext, myLabels.quickInfoTextDescription.fBackgroundColor[0], myLabels.quickInfoTextDescription.fBackgroundColor[1], myLabels.quickInfoTextDescription.fBackgroundColor[2]);  // meme couleur que le fond des info-rapides.
 
214
        cairo_set_source_rgb (pCairoContext,
 
215
                myLabels.quickInfoTextDescription.fBackgroundColor[0],
 
216
                myLabels.quickInfoTextDescription.fBackgroundColor[1],
 
217
                myLabels.quickInfoTextDescription.fBackgroundColor[2]);  // meme couleur que le fond des info-rapides, mais opaque.
244
218
        cairo_set_line_width (pCairoContext, 1.);
245
 
        if (iType == CAIRO_DOCK_GRAPH_CIRCLE || iType == CAIRO_DOCK_GRAPH_CIRCLE_PLAIN)
 
219
        if (iType == CAIRO_DOCK_GRAPH2_CIRCLE || iType == CAIRO_DOCK_GRAPH2_CIRCLE_PLAIN)
246
220
        {
247
 
                cairo_arc (pCairoContext,
248
 
                        fWidth/2,
249
 
                        fHeight/2,
250
 
                        MIN (fWidth, fHeight)/2 - fMargin,
251
 
                        0.,
252
 
                        360.);
 
221
                double r = .5 * MIN (fWidth - 2*fMargin, (fHeight - 2*fMargin) / iNbDrawings);
 
222
                int i;
 
223
                for (i = 0; i < iNbDrawings; i ++)
 
224
                {
 
225
                        cairo_arc (pCairoContext,
 
226
                                fWidth/2,
 
227
                                fMargin + r * (2 * i + 1),
 
228
                                r,
 
229
                                0.,
 
230
                                360.);
 
231
                        cairo_move_to (pCairoContext, fWidth/2, fMargin + r * (2 * i + 1));
 
232
                        cairo_rel_line_to (pCairoContext, r, 0.);
 
233
                        cairo_stroke (pCairoContext);
 
234
                }
253
235
        }
254
236
        else
255
237
        {
256
238
                cairo_move_to (pCairoContext, fMargin, fMargin);
257
239
                cairo_rel_line_to (pCairoContext, 0., fHeight - 2*fMargin);
258
 
                cairo_rel_line_to (pCairoContext, fWidth - 2*fMargin, 0.);
 
240
                cairo_stroke (pCairoContext);
 
241
                int i;
 
242
                for (i = 0; i < iNbDrawings; i ++)
 
243
                {
 
244
                        cairo_move_to (pCairoContext, fMargin, (fHeight - 2 * fMargin) * (i + 1) / iNbDrawings + fMargin);
 
245
                        cairo_rel_line_to (pCairoContext, fWidth - 2*fMargin, 0.);
 
246
                        cairo_stroke (pCairoContext);
 
247
                }
259
248
        }
260
 
        cairo_stroke (pCairoContext);
261
 
        
262
249
        
263
250
        cairo_destroy (pCairoContext);
264
251
        return  pBackgroundSurface;
266
253
static cairo_pattern_t *_cairo_dock_create_graph_pattern (CairoDockGraph *pGraph, gdouble *fLowColor, gdouble *fHighColor, double fOffsetY)
267
254
{
268
255
        cairo_pattern_t *pGradationPattern = NULL;
269
 
        if (fLowColor[0] != fHighColor[0] || fLowColor[1] != fHighColor[1] || fLowColor[2] != fHighColor[2])
 
256
        if (fLowColor[0] != fHighColor[0] || fLowColor[1] != fHighColor[1] || fLowColor[2] != fHighColor[2])  // un degrade existe.
270
257
        {
271
258
                double fMargin = pGraph->fMargin;
272
 
                double fWidth = pGraph->fWidth - 2*fMargin;
273
 
                double fHeight = pGraph->fHeight - 2*fMargin;
274
 
                if (pGraph->pTabValues2 != NULL && ! pGraph->bMixDoubleGraph)
275
 
                {
276
 
                        fHeight /= 2;
277
 
                }
 
259
                double fWidth = pGraph->dataRenderer.iWidth - 2*fMargin;
 
260
                double fHeight = pGraph->dataRenderer.iHeight - 2*fMargin;
 
261
                fHeight /= (pGraph->dataRenderer.data.iNbValues / pGraph->dataRenderer.iRank);
278
262
                
279
 
                if (pGraph->iType == CAIRO_DOCK_GRAPH_CIRCLE || pGraph->iType == CAIRO_DOCK_GRAPH_CIRCLE_PLAIN)
 
263
                if (pGraph->iType == CAIRO_DOCK_GRAPH2_CIRCLE || pGraph->iType == CAIRO_DOCK_GRAPH2_CIRCLE_PLAIN)
280
264
                {
281
265
                        double radius = MIN (fWidth, fHeight)/2;
282
 
                        pGradationPattern = cairo_pattern_create_radial (fMargin + radius,
 
266
                        pGradationPattern = cairo_pattern_create_radial (fWidth/2,
283
267
                                fMargin + radius + fOffsetY,
284
268
                                0.,
285
 
                                fMargin + radius,
 
269
                                fWidth/2,
286
270
                                fMargin + radius + fOffsetY,
287
271
                                radius);
288
272
                }
293
277
                                fMargin + fOffsetY);
294
278
                g_return_val_if_fail (cairo_pattern_status (pGradationPattern) == CAIRO_STATUS_SUCCESS, NULL);  
295
279
                
296
 
                cairo_pattern_set_extend (pGradationPattern, CAIRO_EXTEND_NONE);
 
280
                cairo_pattern_set_extend (pGradationPattern, CAIRO_EXTEND_PAD);
297
281
                cairo_pattern_add_color_stop_rgba (pGradationPattern,
298
282
                        0.,
299
283
                        fLowColor[0],
309
293
        }
310
294
        return pGradationPattern;
311
295
}
312
 
CairoDockGraph* cairo_dock_create_graph (cairo_t *pSourceContext, int iNbValues, CairoDockTypeGraph iType, double fWidth, double fHeight, gdouble *pLowColor, gdouble *pHighColor, gdouble *pBackGroundColor, gdouble *pLowColor2, gdouble *pHighColor2)
 
296
static void cairo_dock_load_graph (CairoDockGraph *pGraph, cairo_t *pSourceContext, CairoContainer *pContainer, CairoGraphAttribute *pAttribute)
313
297
{
314
 
        g_return_val_if_fail (iNbValues > 0, NULL);
315
 
        CairoDockGraph *pGraph = g_new0 (CairoDockGraph, 1);
316
 
        pGraph->iNbValues = iNbValues;
317
 
        pGraph->pTabValues = g_new0 (double, iNbValues);
318
 
        if (iType & CAIRO_DOCK_DOUBLE_GRAPH)
319
 
                pGraph->pTabValues2 = g_new0 (double, iNbValues);
320
 
        pGraph->iType = iType & CAIRO_DOCK_TYPE_GRAPH_MASK;
321
 
        
322
 
        if (pLowColor != NULL)
323
 
                memcpy (pGraph->fLowColor, pLowColor, sizeof (pGraph->fLowColor));
324
 
        if (pHighColor != NULL)
325
 
                memcpy (pGraph->fHighColor, pHighColor, sizeof (pGraph->fHighColor));
326
 
        if (pBackGroundColor != NULL)
327
 
                memcpy (pGraph->fBackGroundColor, pBackGroundColor, sizeof (pGraph->fBackGroundColor));
328
 
        if (pLowColor2 != NULL)
329
 
                memcpy (pGraph->fLowColor2, pLowColor2, sizeof (pGraph->fLowColor2));
330
 
        if (pHighColor2 != NULL)
331
 
                memcpy (pGraph->fHighColor2, pHighColor2, sizeof (pGraph->fHighColor2));
332
 
        
333
 
        pGraph->fWidth = fWidth;
334
 
        pGraph->fHeight = fHeight;
335
 
        pGraph->iRadius = myBackground.iDockRadius;  // memes arrondis que le dock et les desklets.
 
298
        CairoDataRenderer *pRenderer = CAIRO_DATA_RENDERER (pGraph);
 
299
        CairoDataToRenderer *pData = cairo_data_renderer_get_data (pRenderer);
 
300
        
 
301
        int iWidth = pRenderer->iWidth, iHeight = pRenderer->iHeight;
 
302
        if (iWidth == 0 || iHeight == 0)
 
303
                return ;
 
304
        
 
305
        pGraph->iType = pAttribute->iType;
 
306
        pGraph->bMixGraphs = pAttribute->bMixGraphs;
 
307
        pGraph->dataRenderer.iRank = (pAttribute->bMixGraphs ? pData->iNbValues : 1);
 
308
        
 
309
        pGraph->fHighColor = g_new0 (double, 3 * pData->iNbValues);
 
310
        if (pAttribute->fHighColor != NULL)
 
311
                memcpy (pGraph->fHighColor, pAttribute->fHighColor, 3 * pData->iNbValues * sizeof (double));
 
312
        pGraph->fLowColor = g_new0 (double, 3 * pData->iNbValues);
 
313
        if (pAttribute->fLowColor != NULL)
 
314
                memcpy (pGraph->fLowColor, pAttribute->fLowColor, 3 * pData->iNbValues * sizeof (double));
 
315
 
 
316
        int i;
 
317
        pGraph->pGradationPatterns = g_new (cairo_pattern_t *, pData->iNbValues);
 
318
        for (i = 0; i < pData->iNbValues; i ++)
 
319
        {
 
320
                pGraph->pGradationPatterns[i] = _cairo_dock_create_graph_pattern (pGraph,
 
321
                        &pGraph->fLowColor[3*i],
 
322
                        &pGraph->fHighColor[3*i],
 
323
                        0.);
 
324
        }
 
325
        
 
326
        pGraph->iRadius = pAttribute->iRadius;
336
327
        pGraph->fMargin = pGraph->iRadius * (1. - sqrt(2)/2);
337
 
        pGraph->bMixDoubleGraph = (iType & CAIRO_DOCK_MIX_DOUBLE_GRAPH);
338
 
        
339
 
        pGraph->pBackgroundSurface = _cairo_dock_create_graph_background (pSourceContext, fWidth, fHeight, myBackground.iDockRadius, pGraph->fBackGroundColor, iType);
340
 
        
341
 
        pGraph->pGradationPattern = _cairo_dock_create_graph_pattern (pGraph, pGraph->fLowColor, pGraph->fHighColor, 0.);
342
 
        if (pGraph->pTabValues2 != NULL)
343
 
                pGraph->pGradationPattern2 = _cairo_dock_create_graph_pattern (pGraph, pGraph->fLowColor2, pGraph->fHighColor2, 0.);
344
 
        
345
 
        return pGraph;
 
328
        if (pAttribute->fBackGroundColor != NULL)
 
329
                memcpy (pGraph->fBackGroundColor, pAttribute->fBackGroundColor, 4 * sizeof (double));
 
330
        pGraph->pBackgroundSurface = _cairo_dock_create_graph_background (pSourceContext,
 
331
                iWidth,
 
332
                iHeight,
 
333
                pGraph->iRadius,
 
334
                pGraph->fMargin,
 
335
                pGraph->fBackGroundColor,
 
336
                pGraph->iType,
 
337
                pData->iNbValues / pRenderer->iRank);
 
338
        if (g_bUseOpenGL)
 
339
                pGraph->iBackgroundTexture = cairo_dock_create_texture_from_surface (pGraph->pBackgroundSurface);
346
340
}
347
341
 
348
 
void cairo_dock_reload_graph (cairo_t *pSourceContext, CairoDockGraph *pGraph, int iWidth, int iHeight)
 
342
 
 
343
static void cairo_dock_reload_graph (CairoDockGraph *pGraph, cairo_t *pSourceContext)
349
344
{
 
345
        CairoDataRenderer *pRenderer = CAIRO_DATA_RENDERER (pGraph);
 
346
        CairoDataToRenderer *pData = cairo_data_renderer_get_data (pRenderer);
 
347
        int iWidth = pRenderer->iWidth, iHeight = pRenderer->iHeight;
350
348
        if (pGraph->pBackgroundSurface != NULL)
351
349
                cairo_surface_destroy (pGraph->pBackgroundSurface);
352
 
        if (pGraph->pGradationPattern != NULL)
353
 
                cairo_pattern_destroy (pGraph->pGradationPattern);
354
 
        if (pGraph->pGradationPattern2 != NULL)
355
 
                cairo_pattern_destroy (pGraph->pGradationPattern2);
356
 
        pGraph->fWidth = iWidth;
357
 
        pGraph->fHeight = iHeight;
358
 
        pGraph->iRadius = myBackground.iDockRadius;
359
 
        pGraph->pBackgroundSurface = _cairo_dock_create_graph_background (pSourceContext, pGraph->fWidth, pGraph->fHeight, pGraph->iRadius, pGraph->fBackGroundColor, pGraph->iType);
360
 
        pGraph->pGradationPattern = _cairo_dock_create_graph_pattern (pGraph, pGraph->fLowColor, pGraph->fHighColor, 0.);
361
 
        if (pGraph->pTabValues2 != NULL)
362
 
                pGraph->pGradationPattern2 = _cairo_dock_create_graph_pattern (pGraph, pGraph->fLowColor2, pGraph->fHighColor2, 0.);
363
 
        
 
350
        pGraph->pBackgroundSurface = _cairo_dock_create_graph_background (pSourceContext, iWidth, iHeight, pGraph->iRadius, pGraph->fMargin, pGraph->fBackGroundColor, pGraph->iType, pData->iNbValues / pRenderer->iRank);
 
351
        if (pGraph->iBackgroundTexture != 0)
 
352
                _cairo_dock_delete_texture (pGraph->iBackgroundTexture);
 
353
        if (g_bUseOpenGL)
 
354
                pGraph->iBackgroundTexture = cairo_dock_create_texture_from_surface (pGraph->pBackgroundSurface);
 
355
        else
 
356
                pGraph->iBackgroundTexture = 0;
 
357
        int i;
 
358
        for (i = 0; i < pGraph->dataRenderer.data.iNbValues; i ++)
 
359
        {
 
360
                if (pGraph->pGradationPatterns[i] != NULL)
 
361
                        cairo_pattern_destroy (pGraph->pGradationPatterns[i]);
 
362
                pGraph->pGradationPatterns[i] = _cairo_dock_create_graph_pattern (pGraph, &pGraph->fLowColor[3*i], &pGraph->fHighColor[3*i], 0.);
 
363
        }
364
364
}
365
365
 
366
366
 
367
 
void cairo_dock_free_graph (CairoDockGraph *pGraph)
 
367
static void cairo_dock_free_graph (CairoDockGraph *pGraph)
368
368
{
369
369
        cd_debug ("");
370
370
        if (pGraph == NULL)
371
371
                return ;
372
 
        g_free (pGraph->pTabValues);
373
 
        g_free (pGraph->pTabValues2);
374
372
        if (pGraph->pBackgroundSurface != NULL)
375
373
                cairo_surface_destroy (pGraph->pBackgroundSurface);
376
 
        if (pGraph->pGradationPattern != NULL)
377
 
                cairo_pattern_destroy (pGraph->pGradationPattern);
378
 
        if (pGraph->pGradationPattern2 != NULL)
379
 
                cairo_pattern_destroy (pGraph->pGradationPattern2);
 
374
        if (pGraph->iBackgroundTexture != 0)
 
375
                _cairo_dock_delete_texture (pGraph->iBackgroundTexture);
 
376
        int i;
 
377
        for (i = 0; i < pGraph->dataRenderer.data.iNbValues; i ++)
 
378
        {
 
379
                if (pGraph->pGradationPatterns[i] != NULL)
 
380
                        cairo_pattern_destroy (pGraph->pGradationPatterns[i]);
 
381
        }
 
382
        
 
383
        g_free (pGraph->pGradationPatterns);
 
384
        g_free (pGraph->fHighColor);
 
385
        g_free (pGraph->fLowColor);
380
386
        g_free (pGraph);
381
387
}
382
388
 
383
389
 
384
 
void cairo_dock_update_graph (CairoDockGraph *pGraph, double fNewValue)
385
 
{
386
 
        g_return_if_fail (pGraph != NULL && pGraph->iNbValues > 0);
387
 
        fNewValue = MIN (MAX (fNewValue, 0.), 1.);
388
 
        pGraph->iCurrentIndex ++;
389
 
        if (pGraph->iCurrentIndex >= pGraph->iNbValues)
390
 
                pGraph->iCurrentIndex -= pGraph->iNbValues;
391
 
        
392
 
        pGraph->pTabValues[pGraph->iCurrentIndex] = fNewValue;
393
 
}
394
 
void cairo_dock_update_double_graph (CairoDockGraph *pGraph, double fNewValue, double fNewValue2)
395
 
{
396
 
        g_return_if_fail (pGraph != NULL && pGraph->iNbValues > 0);
397
 
        cairo_dock_update_graph (pGraph, fNewValue);
398
 
        
399
 
        fNewValue2 = MIN (MAX (fNewValue2, 0.), 1.);
400
 
        if (pGraph->pTabValues2 != NULL)
401
 
                pGraph->pTabValues2[pGraph->iCurrentIndex] = fNewValue2;
402
 
}
403
 
 
404
 
 
405
 
void cairo_dock_add_watermark_on_graph (cairo_t *pSourceContext, CairoDockGraph *pGraph, gchar *cImagePath, double fAlpha)
406
 
{
407
 
        g_return_if_fail (pGraph != NULL && pGraph->pBackgroundSurface != NULL && cImagePath != NULL);
408
 
        
409
 
        cairo_surface_t *pWatermarkSurface = cairo_dock_create_surface_for_icon (cImagePath, pSourceContext, pGraph->fWidth/2, pGraph->fHeight/2);
410
 
        
411
 
        cairo_t *pCairoContext = cairo_create (pGraph->pBackgroundSurface);
412
 
        cairo_set_operator (pCairoContext, CAIRO_OPERATOR_OVER);
413
 
        
414
 
        cairo_set_source_surface (pCairoContext, pWatermarkSurface, pGraph->fWidth/4, pGraph->fHeight/4);
415
 
        cairo_paint_with_alpha (pCairoContext, fAlpha);
416
 
        
417
 
        cairo_destroy (pCairoContext);
418
 
        
419
 
        cairo_surface_destroy (pWatermarkSurface);
 
390
 
 
391
  //////////////////////////////////////////
 
392
 /////////////// RENDERER /////////////////
 
393
//////////////////////////////////////////
 
394
CairoDockGraph *cairo_dock_new_graph (void)
 
395
{
 
396
        CairoDockGraph *pGraph = g_new0 (CairoDockGraph, 1);
 
397
        pGraph->dataRenderer.interface.new                              = (CairoDataRendererNewFunc) cairo_dock_new_graph;
 
398
        pGraph->dataRenderer.interface.load                             = (CairoDataRendererLoadFunc) cairo_dock_load_graph;
 
399
        pGraph->dataRenderer.interface.render                   = (CairoDataRendererRenderFunc) cairo_dock_render_graph;
 
400
        pGraph->dataRenderer.interface.render_opengl    = (CairoDataRendererRenderOpenGLFunc) NULL;
 
401
        pGraph->dataRenderer.interface.reload                   = (CairoDataRendererReloadFunc) cairo_dock_reload_graph;
 
402
        pGraph->dataRenderer.interface.free                             = (CairoDataRendererFreeFunc) cairo_dock_free_graph;
 
403
        return pGraph;
420
404
}