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

« back to all changes in this revision

Viewing changes to src/cairo-dock-gauge.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
 
* Gauge 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>
 
21
#include <math.h>
20
22
#include <libxml/tree.h>
21
23
#include <libxml/parser.h>
22
24
 
23
25
//#include <cairo-dock-struct.h>
24
 
#include <cairo-dock-log.h>
25
 
#include <cairo-dock-applet-facility.h>
26
 
#include <cairo-dock-draw.h>
27
 
#include <cairo-dock-draw-opengl.h>
28
 
#include <cairo-dock-themes-manager.h>
29
 
#include <cairo-dock-surface-factory.h>
30
 
#include <cairo-dock-dock-factory.h>
31
 
#include <cairo-dock-keyfile-utilities.h>
32
 
#include <cairo-dock-config.h>
33
 
#include <cairo-dock-renderer-manager.h>
34
 
#include <cairo-dock-internal-icons.h>
35
 
#include <cairo-dock-gui-factory.h>
36
 
#include "cairo-dock-container.h"
37
 
#include <cairo-dock-gauge.h>
 
26
#include "cairo-dock-log.h"
 
27
#include "cairo-dock-draw.h"
 
28
#include "cairo-dock-draw-opengl.h"
 
29
#include "cairo-dock-themes-manager.h"
 
30
#include "cairo-dock-surface-factory.h"
 
31
#include "cairo-dock-dock-factory.h"
 
32
#include "cairo-dock-keyfile-utilities.h"
 
33
#include "cairo-dock-config.h"
 
34
#include "cairo-dock-renderer-manager.h"
 
35
#include "cairo-dock-internal-icons.h"
 
36
#include "cairo-dock-gui-factory.h"
 
37
#include "cairo-dock-gauge.h"
38
38
 
39
39
extern gchar *g_cCairoDockDataDir;
40
40
extern gboolean g_bUseOpenGL;
41
41
 
42
 
GHashTable *cairo_dock_list_available_gauges (void)
43
 
{
44
 
        gchar *cGaugeShareDir = g_strdup_printf ("%s/%s", CAIRO_DOCK_SHARE_DATA_DIR, CAIRO_DOCK_GAUGES_DIR);
45
 
        gchar *cGaugeUserDir = g_strdup_printf ("%s/%s/%s", g_cCairoDockDataDir, CAIRO_DOCK_EXTRAS_DIR, CAIRO_DOCK_GAUGES_DIR);
46
 
        GHashTable *pGaugeTable = cairo_dock_list_themes (cGaugeShareDir, cGaugeUserDir, CAIRO_DOCK_GAUGES_DIR);
47
 
        
48
 
        g_free (cGaugeShareDir);
49
 
        g_free (cGaugeUserDir);
50
 
        return pGaugeTable;
51
 
}
52
 
 
53
 
 
54
 
 
55
 
void cairo_dock_xml_open_file (gchar *filePath, const gchar *mainNodeName,xmlDocPtr *myXmlDoc,xmlNodePtr *myXmlNode)
 
42
  ////////////////////////////////////////////
 
43
 /////////////// LOAD GAUGE /////////////////
 
44
////////////////////////////////////////////
 
45
void cairo_dock_xml_open_file (const gchar *filePath, const gchar *mainNodeName,xmlDocPtr *myXmlDoc,xmlNodePtr *myXmlNode)
56
46
{
57
47
        xmlDocPtr doc = xmlParseFile (filePath);
58
 
        
59
48
        if (doc == NULL)
60
49
        {
61
50
                cd_warning ("Impossible de lire le fichier XML.");
65
54
        }
66
55
        
67
56
        xmlNodePtr node = xmlDocGetRootElement (doc);
68
 
        
69
57
        if (node == NULL || xmlStrcmp (node->name, (const xmlChar *) mainNodeName) != 0)
70
58
        {
71
59
                cd_warning ("Le format du fichier XML n'est pas valide.");
78
66
        *myXmlNode = node;
79
67
}
80
68
 
81
 
Gauge *cairo_dock_load_gauge(cairo_t *pSourceContext, const gchar *cThemePath, int iWidth, int iHeight)
82
 
{
83
 
        cd_debug ("%s (%dx%d, %s)", __func__, iWidth, iHeight, cThemePath);
 
69
static void _cairo_dock_init_gauge_image (const gchar *cImagePath, GaugeImage *pGaugeImage)
 
70
{
 
71
        // chargement du fichier.
 
72
        pGaugeImage->pSvgHandle = rsvg_handle_new_from_file (cImagePath, NULL);
 
73
        
 
74
        //On récupère la taille de l'image.
 
75
        RsvgDimensionData SizeInfo;
 
76
        rsvg_handle_get_dimensions (pGaugeImage->pSvgHandle, &SizeInfo);
 
77
        pGaugeImage->sizeX = SizeInfo.width;
 
78
        pGaugeImage->sizeY = SizeInfo.height;
 
79
}
 
80
static GaugeImage *_cairo_dock_new_gauge_image (const gchar *cImagePath)
 
81
{
 
82
        cd_debug ("%s (%s)", __func__, cImagePath);
 
83
        GaugeImage *pGaugeImage = g_new0 (GaugeImage, 1);
 
84
        
 
85
        _cairo_dock_init_gauge_image (cImagePath, pGaugeImage);
 
86
        
 
87
        return pGaugeImage;
 
88
}
 
89
static void _cairo_dock_load_gauge_image (cairo_t *pSourceContext, GaugeImage *pGaugeImage, int iWidth, int iHeight)
 
90
{
 
91
        cd_message ("%s (%dx%d)", __func__, iWidth, iHeight);
 
92
        if (pGaugeImage->pSurface != NULL)
 
93
                cairo_surface_destroy (pGaugeImage->pSurface);
 
94
        if (pGaugeImage->iTexture != 0)
 
95
                _cairo_dock_delete_texture (pGaugeImage->iTexture);
 
96
        
 
97
        if (pGaugeImage->pSvgHandle != NULL)
 
98
        {
 
99
                pGaugeImage->pSurface = _cairo_dock_create_blank_surface (pSourceContext,
 
100
                        iWidth,
 
101
                        iHeight);
 
102
                
 
103
                cairo_t* pDrawingContext = cairo_create (pGaugeImage->pSurface);
 
104
                
 
105
                cairo_scale (pDrawingContext,
 
106
                        (double) iWidth / (double) pGaugeImage->sizeX,
 
107
                        (double) iHeight / (double) pGaugeImage->sizeY);
 
108
                
 
109
                rsvg_handle_render_cairo (pGaugeImage->pSvgHandle, pDrawingContext);
 
110
                cairo_destroy (pDrawingContext);
 
111
                
 
112
                if (g_bUseOpenGL)
 
113
                {
 
114
                        pGaugeImage->iTexture = cairo_dock_create_texture_from_surface (pGaugeImage->pSurface);
 
115
                }
 
116
        }
 
117
        else
 
118
        {
 
119
                pGaugeImage->pSurface = NULL;
 
120
                pGaugeImage->iTexture = 0;
 
121
        }
 
122
}
 
123
static void _cairo_dock_load_gauge_needle (cairo_t *pSourceContext, GaugeIndicator *pGaugeIndicator, int iWidth, int iHeight)
 
124
{
 
125
        cd_message ("%s (%dx%d)", __func__, iWidth, iHeight);
 
126
        GaugeImage *pGaugeImage = pGaugeIndicator->pImageNeedle;
 
127
        g_return_if_fail (pGaugeImage != NULL);
 
128
        
 
129
        if (pGaugeImage->pSurface != NULL)
 
130
                cairo_surface_destroy (pGaugeImage->pSurface);
 
131
        if (pGaugeImage->iTexture != 0)
 
132
                _cairo_dock_delete_texture (pGaugeImage->iTexture);
 
133
        
 
134
        if (pGaugeImage->pSvgHandle != NULL)
 
135
        {
 
136
                int iSize = MIN (iWidth, iHeight);
 
137
                g_print ("size : applet : %d, image : %d\n", iSize, pGaugeImage->sizeX);
 
138
                pGaugeIndicator->fNeedleScale = (double)iSize / (double) pGaugeImage->sizeX;  // car l'aiguille est a l'horizontale dans le fichier svg.
 
139
                pGaugeIndicator->iNeedleWidth = (double) pGaugeIndicator->iNeedleRealWidth * pGaugeIndicator->fNeedleScale;
 
140
                pGaugeIndicator->iNeedleHeight = (double) pGaugeIndicator->iNeedleRealHeight * pGaugeIndicator->fNeedleScale;
 
141
                g_print (" + needle %dx%d\n", pGaugeIndicator->iNeedleWidth, pGaugeIndicator->iNeedleHeight);
 
142
                
 
143
                cairo_surface_t *pNeedleSurface = _cairo_dock_create_blank_surface (pSourceContext, pGaugeIndicator->iNeedleWidth, pGaugeIndicator->iNeedleHeight);
 
144
                g_return_if_fail (cairo_surface_status (pNeedleSurface) == CAIRO_STATUS_SUCCESS);
 
145
                
 
146
                cairo_t* pDrawingContext = cairo_create (pNeedleSurface);
 
147
                g_return_if_fail (cairo_status (pDrawingContext) == CAIRO_STATUS_SUCCESS);
 
148
                
 
149
                cairo_scale (pDrawingContext, pGaugeIndicator->fNeedleScale, pGaugeIndicator->fNeedleScale);
 
150
                cairo_translate (pDrawingContext, pGaugeIndicator->iNeedleOffsetX, pGaugeIndicator->iNeedleOffsetY);
 
151
                rsvg_handle_render_cairo (pGaugeImage->pSvgHandle, pDrawingContext);
 
152
                cairo_destroy (pDrawingContext);
 
153
                
 
154
                pGaugeImage->iTexture = cairo_dock_create_texture_from_surface (pNeedleSurface);
 
155
                cairo_surface_destroy (pNeedleSurface);
 
156
        }
 
157
        else
 
158
        {
 
159
                pGaugeImage->pSurface = NULL;
 
160
                pGaugeImage->iTexture = 0;
 
161
        }
 
162
}
 
163
static gboolean _cairo_dock_load_gauge_theme (Gauge *pGauge, cairo_t *pSourceContext, const gchar *cThemePath)
 
164
{
 
165
        cd_debug ("%s (%s)", __func__, cThemePath);
 
166
        int iWidth = pGauge->dataRenderer.iWidth, iHeight = pGauge->dataRenderer.iHeight;
84
167
        if (iWidth == 0 || iHeight == 0)
85
 
                return NULL;
86
 
        g_return_val_if_fail (cThemePath != NULL, NULL);
87
 
        Gauge *pGauge = NULL;
88
 
        
89
 
        GString *sImagePath = g_string_new ("");
90
 
        GaugeImage *pGaugeImage;
91
 
        
 
168
                return FALSE;
 
169
        
 
170
        g_return_val_if_fail (cThemePath != NULL, FALSE);
92
171
        xmlInitParser ();
93
172
        xmlDocPtr pGaugeTheme;
94
173
        xmlNodePtr pGaugeMainNode;
95
 
        
96
174
        gchar *cXmlFile = g_strdup_printf("%s/theme.xml",cThemePath);
97
 
        cairo_dock_xml_open_file(cXmlFile, "gauge",&pGaugeTheme,&pGaugeMainNode);
 
175
        cairo_dock_xml_open_file (cXmlFile, "gauge",&pGaugeTheme,&pGaugeMainNode);
98
176
        g_free (cXmlFile);
99
 
        
100
 
        g_return_val_if_fail (pGaugeTheme != NULL, NULL);
101
 
        
102
 
        pGauge = g_new0 (Gauge, 1);
103
 
        pGauge->sizeX = iWidth;
104
 
        pGauge->sizeY = iHeight;
105
 
        
106
 
        xmlNodePtr pGaugeNode;
 
177
        g_return_val_if_fail (pGaugeTheme != NULL, FALSE);
 
178
        
107
179
        xmlAttrPtr ap;
108
180
        xmlChar *cAttribute, *cNodeContent, *cTextNodeContent;
109
 
        
 
181
        GString *sImagePath = g_string_new ("");
 
182
        GaugeImage *pGaugeImage;
 
183
        GaugeIndicator *pGaugeIndicator = NULL;
 
184
        xmlNodePtr pGaugeNode;
110
185
        for (pGaugeNode = pGaugeMainNode->xmlChildrenNode; pGaugeNode != NULL; pGaugeNode = pGaugeNode->next)
111
186
        {
112
187
                if (xmlStrcmp (pGaugeNode->name, (const xmlChar *) "name") == 0)
113
188
                {
114
 
                        pGauge->themeName = xmlNodeGetContent(pGaugeNode);
115
 
                        cd_debug("gauge : Nom du theme(%s)",pGauge->themeName);
 
189
                        pGauge->cThemeName = xmlNodeGetContent(pGaugeNode);
 
190
                        cd_debug("gauge : Nom du theme(%s)",pGauge->pIndicatorList);
116
191
                }
117
192
                else if (xmlStrcmp (pGaugeNode->name, (const xmlChar *) "rank") == 0)
118
193
                {
119
194
                        cNodeContent = xmlNodeGetContent (pGaugeNode);
120
 
                        pGauge->iRank = atoi (cNodeContent);
 
195
                        CAIRO_DATA_RENDERER (pGauge)->iRank = atoi (cNodeContent);
121
196
                        xmlFree (cNodeContent);
122
197
                }
123
198
                else if (xmlStrcmp (pGaugeNode->name, (const xmlChar *) "file") == 0)
126
201
                        g_string_printf (sImagePath, "%s/%s", cThemePath, cNodeContent);
127
202
                        ap = xmlHasProp (pGaugeNode, "key");
128
203
                        cAttribute = xmlNodeGetContent(ap->xmlChildrenNode);
129
 
                        if (xmlStrcmp (cAttribute,"background") == 0)
 
204
                        if (xmlStrcmp (cAttribute, "background") == 0)
130
205
                        {
131
 
                                pGauge->imageBackground = cairo_dock_init_gauge_image (sImagePath->str);
132
 
                                cairo_dock_load_gauge_image (pSourceContext, pGauge->imageBackground, iWidth, iHeight);
 
206
                                pGauge->pImageBackground = _cairo_dock_new_gauge_image (sImagePath->str);
 
207
                                _cairo_dock_load_gauge_image (pSourceContext, pGauge->pImageBackground, iWidth, iHeight);
133
208
                        }
134
209
                        else if (xmlStrcmp (cAttribute, "foreground") == 0)
135
210
                        {
136
 
                                pGauge->imageForeground = cairo_dock_init_gauge_image (sImagePath->str);
137
 
                                cairo_dock_load_gauge_image (pSourceContext, pGauge->imageForeground, iWidth, iHeight);
 
211
                                pGauge->pImageForeground = _cairo_dock_new_gauge_image (sImagePath->str);
 
212
                                _cairo_dock_load_gauge_image (pSourceContext, pGauge->pImageForeground, iWidth, iHeight);
138
213
                        }
139
214
                        xmlFree (cNodeContent);
140
215
                        xmlFree (cAttribute);
141
216
                }
142
217
                else if (xmlStrcmp (pGaugeNode->name, (const xmlChar *) "indicator") == 0)
143
218
                {
144
 
                        if (pGauge->iRank == 0)
 
219
                        if (CAIRO_DATA_RENDERER (pGauge)->iRank == 0)
145
220
                        {
146
 
                                pGauge->iRank = 1;
 
221
                                CAIRO_DATA_RENDERER (pGauge)->iRank = 1;
147
222
                                xmlNodePtr node;
148
223
                                for (node = pGaugeNode->next; node != NULL; node = node->next)
149
224
                                {
150
225
                                        if (xmlStrcmp (node->name, (const xmlChar *) "indicator") == 0)
151
 
                                                pGauge->iRank ++;
 
226
                                                CAIRO_DATA_RENDERER (pGauge)->iRank ++;
152
227
                                }
153
228
                        }
154
229
 
155
 
                        GaugeIndicator *pGaugeIndicator = g_new0 (GaugeIndicator, 1);
 
230
                        pGaugeIndicator = g_new0 (GaugeIndicator, 1);
156
231
                        pGaugeIndicator->direction = 1;
157
232
                        
158
233
                        cd_debug ("gauge : On charge un indicateur");
159
234
                        xmlNodePtr pGaugeSubNode;
160
235
                        for (pGaugeSubNode = pGaugeNode->xmlChildrenNode; pGaugeSubNode != NULL; pGaugeSubNode = pGaugeSubNode->next)
161
236
                        {
 
237
                                if (xmlStrcmp (pGaugeSubNode->name, (const xmlChar *) "text") == 0)
 
238
                                        continue;
 
239
                                //g_print ("+ %s\n", pGaugeSubNode->name);
162
240
                                cNodeContent = xmlNodeGetContent (pGaugeSubNode);
163
241
                                if(xmlStrcmp (pGaugeSubNode->name, (const xmlChar *) "posX") == 0)
164
242
                                        pGaugeIndicator->posX = atof (cNodeContent);
165
243
                                else if(xmlStrcmp (pGaugeSubNode->name, (const xmlChar *) "posY") == 0)
166
244
                                        pGaugeIndicator->posY = atof (cNodeContent);
167
 
                                else if(xmlStrcmp (pGaugeSubNode->name, (const xmlChar *) "text") == 0)
 
245
                                else if(xmlStrcmp (pGaugeSubNode->name, (const xmlChar *) "text_zone") == 0)
168
246
                                {
169
247
                                        xmlNodePtr pTextSubNode;
170
248
                                        for (pTextSubNode = pGaugeSubNode->xmlChildrenNode; pTextSubNode != NULL; pTextSubNode = pTextSubNode->next)
171
249
                                        {
 
250
                                                if (xmlStrcmp (pTextSubNode->name, (const xmlChar *) "text") == 0)
 
251
                                                        continue;
 
252
                                                //g_print ("  + %s\n", pTextSubNode->name);
172
253
                                                cTextNodeContent = xmlNodeGetContent (pTextSubNode);
173
 
                                                if(xmlStrcmp (pGaugeSubNode->name, (const xmlChar *) "textX") == 0)
174
 
                                                        pGaugeIndicator->textX = atof (cNodeContent);
175
 
                                                else if(xmlStrcmp (pGaugeSubNode->name, (const xmlChar *) "textY") == 0)
176
 
                                                        pGaugeIndicator->textY = atof (cNodeContent);
177
 
                                                else if(xmlStrcmp (pGaugeSubNode->name, (const xmlChar *) "textWidth") == 0)
178
 
                                                        pGaugeIndicator->textWidth = atof (cNodeContent);
179
 
                                                else if(xmlStrcmp (pGaugeSubNode->name, (const xmlChar *) "textHeight") == 0)
180
 
                                                        pGaugeIndicator->textHeight = atof (cNodeContent);
181
 
                                                else if(xmlStrcmp (pGaugeSubNode->name, (const xmlChar *) "textColorR") == 0)
182
 
                                                        pGaugeIndicator->textColor[0] = atof (cNodeContent);
183
 
                                                else if(xmlStrcmp (pGaugeSubNode->name, (const xmlChar *) "textColorG") == 0)
184
 
                                                        pGaugeIndicator->textColor[1] = atof (cNodeContent);
185
 
                                                else if(xmlStrcmp (pGaugeSubNode->name, (const xmlChar *) "textColorB") == 0)
186
 
                                                        pGaugeIndicator->textColor[2] = atof (cNodeContent);
 
254
                                                //g_print ("     -> '%s'\n", cTextNodeContent);
 
255
                                                if(xmlStrcmp (pTextSubNode->name, (const xmlChar *) "textX") == 0)
 
256
                                                        pGaugeIndicator->textX = atof (cTextNodeContent);
 
257
                                                else if(xmlStrcmp (pTextSubNode->name, (const xmlChar *) "textY") == 0)
 
258
                                                        pGaugeIndicator->textY = atof (cTextNodeContent);
 
259
                                                else if(xmlStrcmp (pTextSubNode->name, (const xmlChar *) "textWidth") == 0)
 
260
                                                        pGaugeIndicator->textWidth = atof (cTextNodeContent);
 
261
                                                else if(xmlStrcmp (pTextSubNode->name, (const xmlChar *) "textHeight") == 0)
 
262
                                                        pGaugeIndicator->textHeight = atof (cTextNodeContent);
 
263
                                                else if(xmlStrcmp (pTextSubNode->name, (const xmlChar *) "textColorR") == 0)
 
264
                                                        pGaugeIndicator->textColor[0] = atof (cTextNodeContent);
 
265
                                                else if(xmlStrcmp (pTextSubNode->name, (const xmlChar *) "textColorG") == 0)
 
266
                                                        pGaugeIndicator->textColor[1] = atof (cTextNodeContent);
 
267
                                                else if(xmlStrcmp (pTextSubNode->name, (const xmlChar *) "textColorB") == 0)
 
268
                                                        pGaugeIndicator->textColor[2] = atof (cTextNodeContent);
187
269
                                        }
 
270
                                        g_print ("pGaugeIndicator->textWidth:%.2f\n", pGaugeIndicator->textWidth);
188
271
                                }
189
272
                                else if(xmlStrcmp (pGaugeSubNode->name, (const xmlChar *) "direction") == 0)
190
273
                                        pGaugeIndicator->direction = atof (cNodeContent);
193
276
                                else if(xmlStrcmp (pGaugeSubNode->name, (const xmlChar *) "posStop") == 0)
194
277
                                        pGaugeIndicator->posStop = atof (cNodeContent);
195
278
                                else if(xmlStrcmp (pGaugeSubNode->name, (const xmlChar *) "nb images") == 0)
196
 
                                        pGaugeIndicator->nbImage = atoi (cNodeContent);
 
279
                                        pGaugeIndicator->iNbImages = atoi (cNodeContent);
 
280
                                else if(xmlStrcmp (pGaugeSubNode->name, (const xmlChar *) "offset_x") == 0)
 
281
                                {
 
282
                                        pGaugeIndicator->iNeedleOffsetX = atoi (cNodeContent);
 
283
                                }
 
284
                                else if(xmlStrcmp (pGaugeSubNode->name, (const xmlChar *) "width") == 0)
 
285
                                {
 
286
                                        pGaugeIndicator->iNeedleRealWidth = atoi (cNodeContent);
 
287
                                }
 
288
                                else if(xmlStrcmp (pGaugeSubNode->name, (const xmlChar *) "height") == 0)
 
289
                                {
 
290
                                        pGaugeIndicator->iNeedleRealHeight = atoi (cNodeContent);
 
291
                                        pGaugeIndicator->iNeedleOffsetY = .5 * pGaugeIndicator->iNeedleRealHeight;
 
292
                                }
197
293
                                else if(xmlStrcmp (pGaugeSubNode->name, (const xmlChar *) "file") == 0)
198
294
                                {
199
 
                                        cd_debug("gauge : On charge un fichier(%s)",cNodeContent);
 
295
                                        cd_debug("gauge : On charge un fichier (%s)",cNodeContent);
200
296
                                        ap = xmlHasProp(pGaugeSubNode, "key");
201
297
                                        cAttribute = xmlNodeGetContent(ap->xmlChildrenNode);
202
 
                                        if (strcmp (cAttribute, "needle") == 0 && pGaugeIndicator->imageNeedle == NULL)
 
298
                                        if (strcmp (cAttribute, "needle") == 0 && pGaugeIndicator->pImageNeedle == NULL)
203
299
                                        {
204
300
                                                g_string_printf (sImagePath, "%s/%s", cThemePath, cNodeContent);
205
 
                                                pGaugeImage = cairo_dock_init_gauge_image(sImagePath->str);
206
 
                                                
207
 
                                                pGaugeIndicator->imageNeedle = pGaugeImage;
 
301
                                                pGaugeIndicator->pImageNeedle = _cairo_dock_new_gauge_image (sImagePath->str);
208
302
                                        }
209
303
                                        else if (strcmp (cAttribute,"image") == 0)
210
304
                                        {
211
 
                                                if (pGaugeIndicator->nbImage == 0)
 
305
                                                if (pGaugeIndicator->iNbImages == 0)
212
306
                                                {
213
 
                                                        pGaugeIndicator->nbImage = 1;
 
307
                                                        pGaugeIndicator->iNbImages = 1;
214
308
                                                        xmlNodePtr node;
215
309
                                                        for (node = pGaugeSubNode->next; node != NULL; node = node->next)
216
310
                                                        {
217
311
                                                                if (xmlStrcmp (node->name, (const xmlChar *) "file") == 0)
218
 
                                                                        pGaugeIndicator->nbImage ++;
 
312
                                                                        pGaugeIndicator->iNbImages ++;
219
313
                                                        }
220
314
                                                }
221
 
                                                g_string_printf (sImagePath, "%s/%s", cThemePath, cNodeContent);
222
 
                                                pGaugeImage = cairo_dock_init_gauge_image(sImagePath->str);
223
 
                                                cairo_dock_load_gauge_image(pSourceContext, pGaugeImage, iWidth, iHeight);
224
 
                                                
225
 
                                                //pGaugeIndicator->nbImage++;
226
 
                                                
227
 
                                                pGaugeIndicator->imageList = g_list_append (pGaugeIndicator->imageList, pGaugeImage);
 
315
                                                if (pGaugeIndicator->pImageList == NULL)
 
316
                                                        pGaugeIndicator->pImageList = g_new0 (GaugeImage, pGaugeIndicator->iNbImages);
 
317
                                                
 
318
                                                if (pGaugeIndicator->iNbImageLoaded < pGaugeIndicator->iNbImages)
 
319
                                                {
 
320
                                                        g_string_printf (sImagePath, "%s/%s", cThemePath, cNodeContent);
 
321
                                                        _cairo_dock_init_gauge_image (sImagePath->str, &pGaugeIndicator->pImageList[pGaugeIndicator->iNbImageLoaded]);
 
322
                                                        if (g_bUseOpenGL)  // il faut les charger maintenant, car on ne peut pas le faire durant le dessin sur le pbuffer (le chargement n'est pas effectif tout de suite et ca donne des textures blanches).
 
323
                                                                _cairo_dock_load_gauge_image (pSourceContext, &pGaugeIndicator->pImageList[pGaugeIndicator->iNbImageLoaded], iWidth, iHeight);
 
324
                                                        pGaugeIndicator->iNbImageLoaded ++;
 
325
                                                }
228
326
                                        }
229
327
                                        xmlFree (cAttribute);
230
328
                                }
231
329
                                xmlFree (cNodeContent);
232
330
                        }
233
 
                        pGauge->indicatorList = g_list_append(pGauge->indicatorList,pGaugeIndicator);
 
331
                        if (pGaugeIndicator->pImageNeedle != NULL)  // on gere le cas d'une aiguille dont la taille est non fournie.
 
332
                        {
 
333
                                if (pGaugeIndicator->iNeedleRealHeight == 0)
 
334
                                {
 
335
                                        pGaugeIndicator->iNeedleRealHeight = .12*pGaugeIndicator->pImageNeedle->sizeY;  // 12px utiles sur les 100
 
336
                                        pGaugeIndicator->iNeedleOffsetY = pGaugeIndicator->iNeedleRealHeight/2;
 
337
                                }
 
338
                                if (pGaugeIndicator->iNeedleRealWidth == 0)
 
339
                                {
 
340
                                        pGaugeIndicator->iNeedleRealWidth = pGaugeIndicator->pImageNeedle->sizeY;  // 100px utiles sur les 100
 
341
                                        pGaugeIndicator->iNeedleOffsetX = 10;
 
342
                                }
 
343
                                if (g_bUseOpenGL)  // meme remarque.
 
344
                                        _cairo_dock_load_gauge_needle (pSourceContext, pGaugeIndicator, iWidth, iHeight);
 
345
                        }
 
346
                        pGauge->pIndicatorList = g_list_append (pGauge->pIndicatorList, pGaugeIndicator);
234
347
                }
235
348
        }
236
349
        xmlFreeDoc (pGaugeTheme);
237
 
        
238
 
        
239
 
        g_return_val_if_fail (pGauge->iRank != 0, NULL);
240
 
        pGauge->pCurrentValues = g_new0 (double, pGauge->iRank);
241
 
        pGauge->pOldValues = g_new0 (double, pGauge->iRank);
242
 
 
243
350
        xmlCleanupParser ();
244
351
        g_string_free (sImagePath, TRUE);
245
352
        
246
 
        return pGauge;
247
 
}
248
 
 
249
 
 
250
 
GaugeImage *cairo_dock_init_gauge_image (gchar *cImagePath)
251
 
{
252
 
        cd_debug ("%s (%s)", __func__, cImagePath);
253
 
        GaugeImage *pGaugeImage = g_new0 (GaugeImage, 1);
254
 
        
255
 
        pGaugeImage->svgNeedle = rsvg_handle_new_from_file (cImagePath, NULL);
256
 
        
257
 
        //On récupère la taille de l'image
258
 
        RsvgDimensionData SizeInfo;
259
 
        rsvg_handle_get_dimensions (pGaugeImage->svgNeedle, &SizeInfo);
260
 
        pGaugeImage->sizeX = SizeInfo.width;
261
 
        pGaugeImage->sizeY = SizeInfo.height;
262
 
        
263
 
        return pGaugeImage;
264
 
}
265
 
 
266
 
void cairo_dock_load_gauge_image (cairo_t *pSourceContext, GaugeImage *pGaugeImage, int iWidth, int iHeight)
267
 
{
268
 
        cd_message ("%s (%dx%d)", __func__, iWidth, iHeight);
269
 
        if (pGaugeImage->cairoSurface != NULL)
270
 
                cairo_surface_destroy (pGaugeImage->cairoSurface);
271
 
        
272
 
        if (pGaugeImage->svgNeedle != NULL)
273
 
        {
274
 
                pGaugeImage->cairoSurface = cairo_surface_create_similar (cairo_get_target (pSourceContext),
275
 
                        CAIRO_CONTENT_COLOR_ALPHA,
276
 
                        iWidth,
277
 
                        iHeight);
278
 
                
279
 
                cairo_t* pDrawingContext = cairo_create (pGaugeImage->cairoSurface);
280
 
                
281
 
                cairo_scale (pDrawingContext,
282
 
                        (double) iWidth / (double) pGaugeImage->sizeX,
283
 
                        (double) iHeight / (double) pGaugeImage->sizeY);
284
 
                
285
 
                rsvg_handle_render_cairo (pGaugeImage->svgNeedle, pDrawingContext);
286
 
                cairo_destroy (pDrawingContext);
287
 
        }
288
 
        else
289
 
                pGaugeImage->cairoSurface = NULL;
290
 
}
291
 
 
292
 
 
293
 
 
294
 
void cairo_dock_render_gauge(cairo_t *pSourceContext, CairoContainer *pContainer, Icon *pIcon, Gauge *pGauge, double fValue)
295
 
{
296
 
        GList *pList = NULL;
297
 
        pList = g_list_prepend (pList, &fValue);
298
 
        
299
 
        cairo_dock_render_gauge_multi_value(pSourceContext,pContainer,pIcon,pGauge,pList);
300
 
        
301
 
        g_list_free (pList);
302
 
}
303
 
 
304
 
void cairo_dock_render_gauge_multi_value(cairo_t *pSourceContext, CairoContainer *pContainer, Icon *pIcon, Gauge *pGauge, GList *valueList)
305
 
{
306
 
        g_return_if_fail (pGauge != NULL && pGauge->indicatorList != NULL && pContainer != NULL && pSourceContext != NULL);
307
 
        g_return_if_fail (cairo_status (pSourceContext) == CAIRO_STATUS_SUCCESS);
308
 
        
309
 
        //\________________ On efface tout.
310
 
        cairo_save (pSourceContext);
311
 
        cairo_set_source_rgba (pSourceContext, 0.0, 0.0, 0.0, 0.0);
312
 
        cairo_set_operator (pSourceContext, CAIRO_OPERATOR_SOURCE);
313
 
        cairo_paint (pSourceContext);
314
 
        cairo_set_operator (pSourceContext, CAIRO_OPERATOR_OVER);
315
 
        
316
 
        GaugeImage *pGaugeImage;
317
 
        //\________________ On affiche le fond.
318
 
        if(pGauge->imageBackground != NULL)
319
 
        {
320
 
                pGaugeImage = pGauge->imageBackground;
321
 
                cairo_set_source_surface (pSourceContext, pGaugeImage->cairoSurface, 0.0f, 0.0f);
322
 
                cairo_paint (pSourceContext);
323
 
        }
324
 
        
325
 
        //\________________ On represente l'indicateur de chaque valeur.
326
 
        GList *pIndicatorElement;
327
 
        GList *pValueList;
328
 
        double *pValue;
329
 
        GaugeIndicator *pIndicator;
330
 
        pIndicatorElement = pGauge->indicatorList;
331
 
        for (pValueList = valueList; pValueList != NULL && pIndicatorElement != NULL; pValueList = pValueList->next, pIndicatorElement = pIndicatorElement->next)
332
 
        {
333
 
                pValue = pValueList->data;
334
 
                pIndicator = pIndicatorElement->data;
335
 
                
336
 
                if(*pValue > 1) *pValue = 1;
337
 
                else if(*pValue < 0) *pValue = 0;
338
 
                
339
 
                if (pIndicator->imageNeedle != NULL)  // c'est une aiguille.
340
 
                {
341
 
                        draw_cd_Gauge_needle(pSourceContext, pGauge, pIndicatorElement->data, *pValue);
342
 
                }
343
 
                else  // c'est une image.
344
 
                {
345
 
                        draw_cd_Gauge_image(pSourceContext, pIndicator, *pValue);
346
 
                }
347
 
 
348
 
                if (pIndicator->textWidth != 0 && pIndicator->textHeight != 0)  // cet indicateur a un emplacement pour le texte de la valeur.
349
 
                {
350
 
                        gchar *cValueFormat = g_strdup_printf (*pValue < .1 ? "%.1f%%" : "%.0f", *pValue * 100);
351
 
                        g_print ("%s\n", cValueFormat);
352
 
                        cairo_save (pSourceContext);
353
 
                        cairo_set_source_rgb (pSourceContext, pIndicator->textColor[0], pIndicator->textColor[1], pIndicator->textColor[2]);
354
 
                        cairo_set_line_width (pSourceContext, 20.);
355
 
                        
356
 
                        cairo_text_extents_t textExtents;
357
 
                        cairo_text_extents (pSourceContext, cValueFormat, &textExtents);
358
 
                        cairo_move_to (pSourceContext,
359
 
                                pIndicator->textX * pGauge->sizeX - textExtents.width / 2,
360
 
                                pIndicator->textY * pGauge->sizeY + textExtents.height / 2);
361
 
                        cairo_show_text (pSourceContext, cValueFormat);
362
 
                        cairo_restore (pSourceContext);
363
 
                        g_free (cValueFormat);
364
 
                }
365
 
        }
366
 
        
367
 
        //\________________ On affiche le fond
368
 
        if(pGauge->imageForeground != NULL)
369
 
        {
370
 
                pGaugeImage = pGauge->imageForeground;
371
 
                cairo_set_source_surface (pSourceContext, pGaugeImage->cairoSurface, 0.0f, 0.0f);
372
 
                cairo_paint (pSourceContext);
373
 
        }
374
 
        
375
 
        cairo_restore (pSourceContext);
376
 
        
377
 
        //\________________ On cree le reflet.
378
 
        if (CAIRO_DOCK_IS_DOCK (pContainer) && CAIRO_DOCK (pContainer)->bUseReflect)
379
 
        {
380
 
                double fMaxScale = cairo_dock_get_max_scale (pContainer);
381
 
                
382
 
                cairo_surface_destroy (pIcon->pReflectionBuffer);
383
 
                pIcon->pReflectionBuffer = cairo_dock_create_reflection_surface (pIcon->pIconBuffer,
384
 
                        pSourceContext,
385
 
                        (pContainer->bIsHorizontal ? pIcon->fWidth : pIcon->fHeight) * fMaxScale / pContainer->fRatio,
386
 
                        (pContainer->bIsHorizontal ? pIcon->fHeight : pIcon->fWidth) * fMaxScale / pContainer->fRatio,
387
 
                        pContainer->bIsHorizontal,
388
 
                        fMaxScale,
389
 
                        pContainer->bDirectionUp);
390
 
        }
391
 
        
392
 
        if (CAIRO_DOCK_CONTAINER_IS_OPENGL (pContainer))
393
 
                cairo_dock_update_icon_texture (pIcon);
394
 
        
395
 
        cairo_dock_redraw_icon (pIcon, pContainer);
396
 
}
397
 
 
398
 
void draw_cd_Gauge_needle(cairo_t *pSourceContext, Gauge *pGauge, GaugeIndicator *pGaugeIndicator, double fValue)
399
 
{
400
 
        //cd_debug("gauge : %s\n",__func__);
401
 
        
402
 
        if(pGaugeIndicator->imageNeedle != NULL)
403
 
        {
404
 
                GaugeImage *pGaugeImage;
405
 
                double fHalfX;
406
 
                double fHalfY;
407
 
                double physicValue = ((fValue * (pGaugeIndicator->posStop - pGaugeIndicator->posStart)) + pGaugeIndicator->posStart) / 360;
408
 
                
409
 
                int direction = pGaugeIndicator->direction >= 0 ? 1 : -1;
410
 
                //cd_debug("gauge : Direction(%i)",direction);
411
 
                
412
 
                //On affiche l'aiguille
413
 
                pGaugeImage = pGaugeIndicator->imageNeedle;
414
 
                
415
 
                fHalfX = pGauge->imageBackground->sizeX / 2.0f * (1 + pGaugeIndicator->posX);
416
 
                fHalfY = pGauge->imageBackground->sizeY / 2.0f * (1 - pGaugeIndicator->posY);
 
353
        g_return_val_if_fail (CAIRO_DATA_RENDERER (pGauge)->iRank != 0 && pGaugeIndicator != NULL, FALSE);
 
354
        CAIRO_DATA_RENDERER (pGauge)->bCanRenderValueAsText = (pGaugeIndicator->textWidth != 0 && pGaugeIndicator->textHeight != 0);
 
355
        
 
356
        return TRUE;
 
357
}
 
358
static void cairo_dock_load_gauge (Gauge *pGauge, cairo_t *pSourceContext, CairoContainer *pContainer, CairoGaugeAttribute *pAttribute)
 
359
{
 
360
        _cairo_dock_load_gauge_theme (pGauge, pSourceContext, pAttribute->cThemePath);
 
361
}
 
362
 
 
363
  ////////////////////////////////////////////
 
364
 ////////////// RENDER GAUGE ////////////////
 
365
////////////////////////////////////////////
 
366
static void _draw_gauge_needle (cairo_t *pSourceContext, Gauge *pGauge, GaugeIndicator *pGaugeIndicator, double fValue)
 
367
{
 
368
        GaugeImage *pGaugeImage = pGaugeIndicator->pImageNeedle;
 
369
        if(pGaugeImage != NULL)
 
370
        {
 
371
                double fAngle = (pGaugeIndicator->posStart + fValue * (pGaugeIndicator->posStop - pGaugeIndicator->posStart)) * G_PI / 180.;
 
372
                if (pGaugeIndicator->direction < 0)
 
373
                        fAngle = - fAngle;
 
374
                
 
375
                double fHalfX = pGauge->pImageBackground->sizeX / 2.0f * (1 + pGaugeIndicator->posX);
 
376
                double fHalfY = pGauge->pImageBackground->sizeY / 2.0f * (1 - pGaugeIndicator->posY);
417
377
                
418
378
                cairo_save (pSourceContext);
419
379
                
420
380
                cairo_scale (pSourceContext,
421
 
                        (double) pGauge->sizeX / (double) pGaugeImage->sizeX,
422
 
                        (double) pGauge->sizeY / (double) pGaugeImage->sizeY);
423
 
                
 
381
                        (double) CAIRO_DATA_RENDERER (pGauge)->iWidth / (double) pGaugeImage->sizeX,
 
382
                        (double) CAIRO_DATA_RENDERER (pGauge)->iHeight / (double) pGaugeImage->sizeY);
424
383
                cairo_translate (pSourceContext, fHalfX, fHalfY);
425
 
                cairo_rotate (pSourceContext, -G_PI/2.0f + G_PI*physicValue*direction*2.0f);
 
384
                cairo_rotate (pSourceContext, -G_PI/2 + fAngle);
426
385
                
427
 
                rsvg_handle_render_cairo (pGaugeImage->svgNeedle, pSourceContext);
 
386
                rsvg_handle_render_cairo (pGaugeImage->pSvgHandle, pSourceContext);
428
387
                
429
388
                cairo_restore (pSourceContext);
430
389
        }
431
390
}
432
 
 
433
 
void draw_cd_Gauge_image(cairo_t *pSourceContext, GaugeIndicator *pGaugeIndicator, double fValue)
434
 
{
435
 
        GaugeImage *pGaugeImage;
436
 
        int trueImage;
437
 
        double imageWidthZone;
438
 
        
439
 
        //Equation donnant la bonne image.
440
 
        trueImage = fValue * (pGaugeIndicator->nbImage - 1) + 0.5;
441
 
        //cd_debug("gauge : La bonne image est : %d / %d (%d)",trueImage,pGaugeIndicator->nbImage,imageWidthZone);
442
 
        
443
 
        pGaugeImage = g_list_nth_data (pGaugeIndicator->imageList, trueImage);
444
 
        if (pGaugeImage != NULL)
445
 
        {
446
 
                cairo_set_source_surface (pSourceContext, pGaugeImage->cairoSurface, 0.0f, 0.0f);
447
 
                cairo_paint (pSourceContext);
448
 
        }
449
 
}
450
 
 
451
 
 
452
 
 
453
 
void cairo_dock_reload_gauge (cairo_t *pSourceContext, Gauge *pGauge, int iWidth, int iHeight)
 
391
static void _draw_gauge_image (cairo_t *pSourceContext, Gauge *pGauge, GaugeIndicator *pGaugeIndicator, double fValue)
 
392
{
 
393
        int iNumImage = fValue * (pGaugeIndicator->iNbImages - 1) + 0.5;
 
394
        g_return_if_fail (iNumImage < pGaugeIndicator->iNbImages);
 
395
        
 
396
        GaugeImage *pGaugeImage = &pGaugeIndicator->pImageList[iNumImage];
 
397
        if (pGaugeImage->pSurface == NULL)
 
398
        {
 
399
                int iWidth = pGauge->dataRenderer.iWidth, iHeight = pGauge->dataRenderer.iHeight;
 
400
                _cairo_dock_load_gauge_image (pSourceContext, pGaugeImage, iWidth, iHeight);
 
401
        }
 
402
        
 
403
        if (pGaugeImage->pSurface != NULL)
 
404
        {
 
405
                cairo_set_source_surface (pSourceContext, pGaugeImage->pSurface, 0.0f, 0.0f);
 
406
                cairo_paint (pSourceContext);
 
407
        }
 
408
}
 
409
static void cairo_dock_draw_one_gauge (cairo_t *pSourceContext, Gauge *pGauge, int iDataOffset)
 
410
{
 
411
        GaugeImage *pGaugeImage;
 
412
        //\________________ On affiche le fond.
 
413
        if(pGauge->pImageBackground != NULL)
 
414
        {
 
415
                pGaugeImage = pGauge->pImageBackground;
 
416
                cairo_set_source_surface (pSourceContext, pGaugeImage->pSurface, 0.0f, 0.0f);
 
417
                cairo_paint (pSourceContext);
 
418
        }
 
419
        
 
420
        //\________________ On represente l'indicateur de chaque valeur.
 
421
        GList *pIndicatorElement;
 
422
        GList *pValueList;
 
423
        double fValue;
 
424
        GaugeIndicator *pIndicator;
 
425
        CairoDataRenderer *pRenderer = CAIRO_DATA_RENDERER (pGauge);
 
426
        CairoDataToRenderer *pData = cairo_data_renderer_get_data (pRenderer);
 
427
        int i;
 
428
        for (i = iDataOffset, pIndicatorElement = pGauge->pIndicatorList; i < pData->iNbValues && pIndicatorElement != NULL; i++, pIndicatorElement = pIndicatorElement->next)
 
429
        {
 
430
                pIndicator = pIndicatorElement->data;
 
431
                fValue = cairo_data_renderer_get_normalized_current_value (pRenderer, i);
 
432
                
 
433
                if (pIndicator->pImageNeedle != NULL)  // c'est une aiguille.
 
434
                {
 
435
                        _draw_gauge_needle (pSourceContext, pGauge, pIndicator, fValue);
 
436
                }
 
437
                else  // c'est une image.
 
438
                {
 
439
                        _draw_gauge_image (pSourceContext, pGauge, pIndicator, fValue);
 
440
                }
 
441
 
 
442
                if (pIndicator->textWidth != 0 && pIndicator->textHeight != 0)  // cet indicateur a un emplacement pour le texte de la valeur.
 
443
                {
 
444
                        cairo_data_renderer_format_value (pRenderer, fValue, i);
 
445
                        //g_print (" >>>%s\n", pRenderer->cFormatBuffer);
 
446
                        cairo_save (pSourceContext);
 
447
                        cairo_set_source_rgb (pSourceContext, pIndicator->textColor[0], pIndicator->textColor[1], pIndicator->textColor[2]);
 
448
                        cairo_set_line_width (pSourceContext, 20);
 
449
                        
 
450
                        cairo_text_extents_t textExtents;
 
451
                        cairo_text_extents (pSourceContext, pRenderer->cFormatBuffer, &textExtents);
 
452
                        double fZoom = MIN (pIndicator->textWidth * pRenderer->iWidth / textExtents.width, pIndicator->textHeight * pRenderer->iHeight / textExtents.height);
 
453
                        cairo_move_to (pSourceContext,
 
454
                                (1. + pIndicator->textX) * pRenderer->iWidth/2 - textExtents.width / 2,
 
455
                                (1. - pIndicator->textY) * pRenderer->iHeight/2 + textExtents.height);
 
456
                        cairo_scale (pSourceContext,
 
457
                                fZoom,
 
458
                                fZoom);
 
459
                        cairo_show_text (pSourceContext, pRenderer->cFormatBuffer);
 
460
                        cairo_restore (pSourceContext);
 
461
                }
 
462
        }
 
463
        
 
464
        //\________________ On affiche l'avant-plan.
 
465
        if(pGauge->pImageForeground != NULL)
 
466
        {
 
467
                pGaugeImage = pGauge->pImageForeground;
 
468
                cairo_set_source_surface (pSourceContext, pGaugeImage->pSurface, 0.0f, 0.0f);
 
469
                cairo_paint (pSourceContext);
 
470
        }
 
471
}
 
472
void cairo_dock_render_gauge (Gauge *pGauge, cairo_t *pCairoContext)
 
473
{
 
474
        g_return_if_fail (pGauge != NULL && pGauge->pIndicatorList != NULL && pCairoContext != NULL);
 
475
        g_return_if_fail (cairo_status (pCairoContext) == CAIRO_STATUS_SUCCESS);
 
476
        
 
477
        CairoDataRenderer *pRenderer = CAIRO_DATA_RENDERER (pGauge);
 
478
        CairoDataToRenderer *pData = cairo_data_renderer_get_data (pRenderer);
 
479
        int iNbDrawings = (int) ceil (1. * pData->iNbValues / pRenderer->iRank);
 
480
        int i, iDataOffset = 0;
 
481
        for (i = 0; i < iNbDrawings; i ++)
 
482
        {
 
483
                if (iNbDrawings > 1)  // on va dessiner la jauges plusieurs fois, la 1ere en grand et les autres en petit autour.
 
484
                {
 
485
                        cairo_save (pCairoContext);
 
486
                        if (i == 0)
 
487
                        {
 
488
                                cairo_scale (pCairoContext, 2./3, 2./3);
 
489
                        }
 
490
                        else if (i == 1)
 
491
                        {
 
492
                                cairo_translate (pCairoContext, 2 * pRenderer->iWidth / 3, 2 * pRenderer->iHeight / 3);
 
493
                                cairo_scale (pCairoContext, 1./3, 1./3);
 
494
                        }
 
495
                        else if (i == 2)
 
496
                        {
 
497
                                cairo_translate (pCairoContext, 2 * pRenderer->iWidth / 3, 0.);
 
498
                                cairo_scale (pCairoContext, 1./3, 1./3);
 
499
                        }
 
500
                        else if (i == 3)
 
501
                        {
 
502
                                cairo_translate (pCairoContext, 0., 2 * pRenderer->iHeight / 3);
 
503
                                cairo_scale (pCairoContext, 1./3, 1./3);
 
504
                        }
 
505
                        else  // 5 valeurs faut pas pousser non plus.
 
506
                                break ;
 
507
                }
 
508
                
 
509
                cairo_dock_draw_one_gauge (pCairoContext, pGauge, iDataOffset);
 
510
                
 
511
                if (iNbDrawings > 1)
 
512
                        cairo_restore (pCairoContext);
 
513
                
 
514
                iDataOffset += pRenderer->iRank;
 
515
        }
 
516
}
 
517
 
 
518
  ///////////////////////////////////////////////
 
519
 /////////////// RENDER OPENGL /////////////////
 
520
///////////////////////////////////////////////
 
521
static void _draw_gauge_image_opengl (Gauge *pGauge, GaugeIndicator *pGaugeIndicator, double fValue)
 
522
{
 
523
        int iNumImage = fValue * (pGaugeIndicator->iNbImages - 1) + 0.5;
 
524
        g_return_if_fail (iNumImage < pGaugeIndicator->iNbImages);
 
525
        
 
526
        GaugeImage *pGaugeImage = &pGaugeIndicator->pImageList[iNumImage];
 
527
        int iWidth = pGauge->dataRenderer.iWidth, iHeight = pGauge->dataRenderer.iHeight;
 
528
        /*if (pGaugeImage->iTexture == 0)
 
529
        {
 
530
                _cairo_dock_load_gauge_image (NULL, pGaugeImage, iWidth, iHeight);  // pas besoin d'un cairo_context pour creer une cairo_image_surface.
 
531
                return ;
 
532
        }*/
 
533
        
 
534
        if (pGaugeImage->iTexture != 0)
 
535
        {
 
536
                _cairo_dock_apply_texture_at_size (pGaugeImage->iTexture, iWidth, iHeight);
 
537
        }
 
538
}
 
539
static void _draw_gauge_needle_opengl (Gauge *pGauge, GaugeIndicator *pGaugeIndicator, double fValue)
 
540
{
 
541
        GaugeImage *pGaugeImage = pGaugeIndicator->pImageNeedle;
 
542
        g_return_if_fail (pGaugeImage != NULL);
 
543
        
 
544
        int iWidth = pGauge->dataRenderer.iWidth, iHeight = pGauge->dataRenderer.iHeight;
 
545
        /*if (pGaugeImage->iTexture == 0)
 
546
        {
 
547
                _cairo_dock_load_gauge_needle (NULL, pGaugeIndicator, iWidth, iHeight);  // pas besoin d'un cairo_context pour creer une cairo_image_surface.
 
548
                return ;
 
549
        }*/
 
550
        
 
551
        if(pGaugeImage->iTexture != 0)
 
552
        {
 
553
                double fAngle = (pGaugeIndicator->posStart + fValue * (pGaugeIndicator->posStop - pGaugeIndicator->posStart));
 
554
                if (pGaugeIndicator->direction < 0)
 
555
                        fAngle = - fAngle;
 
556
                double fHalfX = iWidth / 2.0f * (0 + pGaugeIndicator->posX);
 
557
                double fHalfY = iHeight / 2.0f * (0 + pGaugeIndicator->posY);
 
558
                
 
559
                glPushMatrix ();
 
560
                
 
561
                glTranslatef (fHalfX, fHalfY, 0.);
 
562
                glRotatef (90. - fAngle, 0., 0., 1.);
 
563
                glTranslatef (pGaugeIndicator->iNeedleWidth/2 - pGaugeIndicator->fNeedleScale * pGaugeIndicator->iNeedleOffsetX, 0., 0.);
 
564
                _cairo_dock_apply_texture_at_size (pGaugeImage->iTexture, pGaugeIndicator->iNeedleWidth, pGaugeIndicator->iNeedleHeight);
 
565
                
 
566
                glPopMatrix ();
 
567
        }
 
568
}
 
569
static void cairo_dock_draw_one_gauge_opengl (Gauge *pGauge, int iDataOffset)
 
570
{
 
571
        int iWidth = pGauge->dataRenderer.iWidth, iHeight = pGauge->dataRenderer.iHeight;
 
572
        GaugeImage *pGaugeImage;
 
573
        
 
574
        //\________________ On affiche le fond.
 
575
        if(pGauge->pImageBackground != NULL)
 
576
        {
 
577
                pGaugeImage = pGauge->pImageBackground;
 
578
                if (pGaugeImage->iTexture != 0)
 
579
                        _cairo_dock_apply_texture_at_size (pGaugeImage->iTexture, iWidth, iHeight);
 
580
        }
 
581
        
 
582
        //\________________ On represente l'indicateur de chaque valeur.
 
583
        GList *pIndicatorElement;
 
584
        GList *pValueList;
 
585
        double fValue;
 
586
        GaugeIndicator *pIndicator;
 
587
        CairoDataRenderer *pRenderer = CAIRO_DATA_RENDERER (pGauge);
 
588
        CairoDataToRenderer *pData = cairo_data_renderer_get_data (pRenderer);
 
589
        int i;
 
590
        for (i = iDataOffset, pIndicatorElement = pGauge->pIndicatorList; i < pData->iNbValues && pIndicatorElement != NULL; i++, pIndicatorElement = pIndicatorElement->next)
 
591
        {
 
592
                pIndicator = pIndicatorElement->data;
 
593
                fValue = cairo_data_renderer_get_normalized_current_value_with_latency (pRenderer, i);
 
594
                
 
595
                if (pIndicator->pImageNeedle != NULL)  // c'est une aiguille.
 
596
                {
 
597
                        _draw_gauge_needle_opengl (pGauge, pIndicator, fValue);
 
598
                }
 
599
                else  // c'est une image.
 
600
                {
 
601
                        _draw_gauge_image_opengl (pGauge, pIndicator, fValue);
 
602
                }
 
603
 
 
604
                if (pIndicator->textWidth != 0 && pIndicator->textHeight != 0)  // cet indicateur a un emplacement pour le texte de la valeur.
 
605
                {
 
606
                        cairo_data_renderer_format_value (pRenderer, fValue, i);
 
607
                        //g_print (" >>>%s\n", pRenderer->cFormatBuffer);
 
608
                        /*cairo_save (pSourceContext);
 
609
                        cairo_set_source_rgb (pSourceContext, pIndicator->textColor[0], pIndicator->textColor[1], pIndicator->textColor[2]);
 
610
                        cairo_set_line_width (pSourceContext, 20.);
 
611
                        
 
612
                        cairo_text_extents_t textExtents;
 
613
                        cairo_text_extents (pSourceContext, pRenderer->cFormatBuffer, &textExtents);
 
614
                        cairo_move_to (pSourceContext,
 
615
                                pIndicator->textX * pRenderer->iWidth - textExtents.width / 2,
 
616
                                pIndicator->textY * pRenderer->iHeight + textExtents.height / 2);
 
617
                        cairo_show_text (pSourceContext, pRenderer->cFormatBuffer);
 
618
                        cairo_restore (pSourceContext);*/
 
619
                }
 
620
        }
 
621
        
 
622
        //\________________ On affiche l'avant-plan.
 
623
        if(pGauge->pImageForeground != NULL)
 
624
        {
 
625
                pGaugeImage = pGauge->pImageForeground;
 
626
                if (pGaugeImage->iTexture != 0)
 
627
                        _cairo_dock_apply_texture_at_size (pGaugeImage->iTexture, iWidth, iHeight);
 
628
        }
 
629
}
 
630
static void cairo_dock_render_gauge_opengl (Gauge *pGauge)
 
631
{
 
632
        g_return_if_fail (pGauge != NULL && pGauge->pIndicatorList != NULL);
 
633
        
 
634
        _cairo_dock_enable_texture ();
 
635
        _cairo_dock_set_blend_pbuffer ();  // ceci reste un mystere...
 
636
        _cairo_dock_set_alpha (1.);
 
637
        
 
638
        CairoDataRenderer *pRenderer = CAIRO_DATA_RENDERER (pGauge);
 
639
        CairoDataToRenderer *pData = cairo_data_renderer_get_data (pRenderer);
 
640
        int iNbDrawings = (int) ceil (1. * pData->iNbValues / pRenderer->iRank);
 
641
        int i, iDataOffset = 0;
 
642
        for (i = 0; i < iNbDrawings; i ++)
 
643
        {
 
644
                if (iNbDrawings > 1)  // on va dessiner la jauges plusieurs fois, la 1ere en grand et les autres en petit autour.
 
645
                {
 
646
                        glPushMatrix ();
 
647
                        if (i == 0)
 
648
                        {
 
649
                                glTranslatef (-pRenderer->iWidth / 6, pRenderer->iHeight / 6, 0.);
 
650
                                glScalef (2./3, 2./3, 1.);
 
651
                        }
 
652
                        else if (i == 1)
 
653
                        {
 
654
                                glTranslatef (pRenderer->iWidth / 3, - pRenderer->iHeight / 3, 0.);
 
655
                                glScalef (1./3, 1./3, 1.);
 
656
                        }
 
657
                        else if (i == 2)
 
658
                        {
 
659
                                glTranslatef (pRenderer->iWidth / 3, pRenderer->iHeight / 3, 0.);
 
660
                                glScalef (1./3, 1./3, 1.);
 
661
                        }
 
662
                        else if (i == 3)
 
663
                        {
 
664
                                glTranslatef (-pRenderer->iWidth / 3, -pRenderer->iHeight / 3, 0.);
 
665
                                glScalef (1./3, 1./3, 1.);
 
666
                        }
 
667
                        else  // 5 valeurs faut pas pousser non plus.
 
668
                                break ;
 
669
                }
 
670
                
 
671
                cairo_dock_draw_one_gauge_opengl (pGauge, iDataOffset);
 
672
                
 
673
                if (iNbDrawings > 1)
 
674
                        glPopMatrix ();
 
675
                
 
676
                iDataOffset += pRenderer->iRank;
 
677
        }
 
678
        _cairo_dock_disable_texture ();
 
679
}
 
680
 
 
681
 
 
682
  //////////////////////////////////////////////
 
683
 /////////////// RELOAD GAUGE /////////////////
 
684
//////////////////////////////////////////////
 
685
static void cairo_dock_reload_gauge (Gauge *pGauge, cairo_t *pSourceContext)
454
686
{
455
687
        //g_print ("%s (%dx%d)\n", __func__, iWidth, iHeight);
456
688
        g_return_if_fail (pGauge != NULL);
457
689
        
458
 
        pGauge->sizeX = iWidth;
459
 
        pGauge->sizeY = iHeight;
460
 
        
461
 
        if (pGauge->imageBackground != NULL)
 
690
        CairoDataRenderer *pRenderer = CAIRO_DATA_RENDERER (pGauge);
 
691
        int iWidth = pGauge->dataRenderer.iWidth, iHeight = pGauge->dataRenderer.iHeight;
 
692
        if (pGauge->pImageBackground != NULL)
462
693
        {
463
 
                cairo_dock_load_gauge_image (pSourceContext, pGauge->imageBackground, iWidth, iHeight);
 
694
                _cairo_dock_load_gauge_image (pSourceContext, pGauge->pImageBackground, iWidth, iHeight);
464
695
        }
465
696
        
466
 
        if (pGauge->imageForeground != NULL)
 
697
        if (pGauge->pImageForeground != NULL)
467
698
        {
468
 
                cairo_dock_load_gauge_image (pSourceContext, pGauge->imageForeground, iWidth, iHeight);
 
699
                _cairo_dock_load_gauge_image (pSourceContext, pGauge->pImageForeground, iWidth, iHeight);
469
700
        }
470
701
        
471
702
        GaugeIndicator *pGaugeIndicator;
472
703
        GaugeImage *pGaugeImage;
 
704
        int i;
473
705
        GList *pElement, *pElement2;
474
 
        for (pElement = pGauge->indicatorList; pElement != NULL; pElement = pElement->next)
 
706
        for (pElement = pGauge->pIndicatorList; pElement != NULL; pElement = pElement->next)
475
707
        {
476
708
                pGaugeIndicator = pElement->data;
477
 
                for (pElement2 = pGaugeIndicator->imageList; pElement2 != NULL; pElement2 = pElement2->next)
478
 
                {
479
 
                        pGaugeImage = pElement2->data;
480
 
                        cairo_dock_load_gauge_image (pSourceContext, pGaugeImage, iWidth, iHeight);  // si c'est une image on la recharge, pour une aiguille SVG c'est inutile.
 
709
                for (i = 0; i < pGaugeIndicator->iNbImages; i ++)
 
710
                {
 
711
                        pGaugeImage = &pGaugeIndicator->pImageList[i];
 
712
                        _cairo_dock_load_gauge_image (pSourceContext, pGaugeImage, iWidth, iHeight);
 
713
                }
 
714
                if (g_bUseOpenGL && pGaugeIndicator->pImageNeedle)
 
715
                {
 
716
                        _cairo_dock_load_gauge_needle (pSourceContext, pGaugeIndicator, iWidth, iHeight);
481
717
                }
482
718
        }
483
719
}
484
720
 
485
 
 
486
 
 
487
 
static void cairo_dock_free_gauge_image(GaugeImage *pGaugeImage)
 
721
  ////////////////////////////////////////////
 
722
 /////////////// FREE GAUGE /////////////////
 
723
////////////////////////////////////////////
 
724
static void _cairo_dock_free_gauge_image(GaugeImage *pGaugeImage, gboolean bFree)
488
725
{
489
 
        cd_debug("");
490
726
        if (pGaugeImage == NULL)
491
727
                return ;
492
 
        
493
 
        if(pGaugeImage->svgNeedle != NULL)
494
 
        {
495
 
                rsvg_handle_free (pGaugeImage->svgNeedle);
496
 
        }
497
 
        if(pGaugeImage->cairoSurface != NULL)
498
 
        {
499
 
                cairo_surface_destroy (pGaugeImage->cairoSurface);
500
 
        }
501
 
        
502
 
        g_free (pGaugeImage);
 
728
        cd_debug("");
 
729
 
 
730
        if(pGaugeImage->pSvgHandle != NULL)
 
731
                rsvg_handle_free (pGaugeImage->pSvgHandle);
 
732
        if(pGaugeImage->pSurface != NULL)
 
733
                cairo_surface_destroy (pGaugeImage->pSurface);
 
734
        if (pGaugeImage->iTexture != 0)
 
735
                _cairo_dock_delete_texture (pGaugeImage->iTexture);
 
736
        
 
737
        if (bFree)
 
738
                g_free (pGaugeImage);
503
739
}
504
 
 
505
 
static void cairo_dock_free_gauge_indicator(GaugeIndicator *pGaugeIndicator)
 
740
static void _cairo_dock_free_gauge_indicator(GaugeIndicator *pGaugeIndicator)
506
741
{
507
 
        cd_debug("");
508
742
        if (pGaugeIndicator == NULL)
509
743
                return ;
 
744
        cd_debug("");
 
745
        
 
746
        int i;
 
747
        for (i = 0; i < pGaugeIndicator->iNbImages; i ++)
 
748
        {
 
749
                _cairo_dock_free_gauge_image (&pGaugeIndicator->pImageList[i], FALSE);
 
750
        }
 
751
        g_free (pGaugeIndicator->pImageList);
 
752
        
 
753
        _cairo_dock_free_gauge_image (pGaugeIndicator->pImageNeedle, TRUE);
 
754
        
 
755
        g_free (pGaugeIndicator);
 
756
}
 
757
static void cairo_dock_free_gauge (Gauge *pGauge)
 
758
{
 
759
        cd_debug("");
 
760
        if(pGauge == NULL)
 
761
                return ;
 
762
        
 
763
        _cairo_dock_free_gauge_image(pGauge->pImageBackground, TRUE);
 
764
        _cairo_dock_free_gauge_image(pGauge->pImageForeground, TRUE);
510
765
        
511
766
        GList *pElement;
512
 
        for (pElement = pGaugeIndicator->imageList; pElement != NULL; pElement = pElement->next)
513
 
        {
514
 
                cairo_dock_free_gauge_image(pElement->data);
515
 
        }
516
 
        g_list_free (pGaugeIndicator->imageList);
517
 
        
518
 
        cairo_dock_free_gauge_image(pGaugeIndicator->imageNeedle);
519
 
        
520
 
        g_free (pGaugeIndicator);
521
 
}
522
 
 
523
 
void cairo_dock_free_gauge(Gauge *pGauge)
524
 
{
525
 
        cd_debug("");
526
 
        
527
 
        if(pGauge != NULL)
528
 
        {
529
 
                if(pGauge->themeName != NULL) g_free(pGauge->themeName);
530
 
                
531
 
                if(pGauge->imageBackground != NULL) cairo_dock_free_gauge_image(pGauge->imageBackground);
532
 
                if(pGauge->imageForeground != NULL) cairo_dock_free_gauge_image(pGauge->imageForeground);
533
 
                
534
 
                GList *pElement;
535
 
                for (pElement = pGauge->indicatorList; pElement != NULL; pElement = pElement->next)
536
 
                {
537
 
                        cairo_dock_free_gauge_indicator(pElement->data);
538
 
                }
539
 
                g_list_free (pGauge->indicatorList);
540
 
                
541
 
                g_free (pGauge);
542
 
        }
 
767
        for (pElement = pGauge->pIndicatorList; pElement != NULL; pElement = pElement->next)
 
768
        {
 
769
                _cairo_dock_free_gauge_indicator (pElement->data);
 
770
        }
 
771
        g_list_free (pGauge->pIndicatorList);
 
772
        
 
773
        g_free (pGauge);
 
774
}
 
775
 
 
776
 
 
777
  //////////////////////////////////////////
 
778
 /////////////// RENDERER /////////////////
 
779
//////////////////////////////////////////
 
780
Gauge *cairo_dock_new_gauge (void)
 
781
{
 
782
        Gauge *pGauge = g_new0 (Gauge, 1);
 
783
        pGauge->dataRenderer.interface.new                              = (CairoDataRendererNewFunc) cairo_dock_new_gauge;
 
784
        pGauge->dataRenderer.interface.load                             = (CairoDataRendererLoadFunc) cairo_dock_load_gauge;
 
785
        pGauge->dataRenderer.interface.render                   = (CairoDataRendererRenderFunc) cairo_dock_render_gauge;
 
786
        pGauge->dataRenderer.interface.render_opengl    = (CairoDataRendererRenderOpenGLFunc) cairo_dock_render_gauge_opengl;
 
787
        pGauge->dataRenderer.interface.reload                   = (CairoDataRendererReloadFunc) cairo_dock_reload_gauge;
 
788
        pGauge->dataRenderer.interface.free                             = (CairoDataRendererFreeFunc) cairo_dock_free_gauge;
 
789
        return pGauge;
 
790
}
 
791
 
 
792
 
 
793
  /////////////////////////////////////////////////
 
794
 /////////////// LIST OF THEMES  /////////////////
 
795
/////////////////////////////////////////////////
 
796
GHashTable *cairo_dock_list_available_gauges (void)
 
797
{
 
798
        gchar *cGaugeShareDir = g_strdup_printf ("%s/%s", CAIRO_DOCK_SHARE_DATA_DIR, CAIRO_DOCK_GAUGES_DIR);
 
799
        gchar *cGaugeUserDir = g_strdup_printf ("%s/%s/%s", g_cCairoDockDataDir, CAIRO_DOCK_EXTRAS_DIR, CAIRO_DOCK_GAUGES_DIR);
 
800
        GHashTable *pGaugeTable = cairo_dock_list_themes (cGaugeShareDir, cGaugeUserDir, CAIRO_DOCK_GAUGES_DIR);
 
801
        
 
802
        g_free (cGaugeShareDir);
 
803
        g_free (cGaugeUserDir);
 
804
        return pGaugeTable;
 
805
}
 
806
 
 
807
gchar *cairo_dock_get_gauge_theme_path (const gchar *cThemeName)
 
808
{
 
809
        if (cThemeName == NULL)
 
810
                return g_strdup ("Turbo-night-fuel");
 
811
        const gchar *cGaugeShareDir = CAIRO_DOCK_SHARE_DATA_DIR"/"CAIRO_DOCK_GAUGES_DIR;
 
812
        gchar *cGaugeUserDir = g_strdup_printf ("%s/%s", g_cCairoDockDataDir, CAIRO_DOCK_EXTRAS_DIR"/"CAIRO_DOCK_GAUGES_DIR);
 
813
        gchar *cGaugePath = cairo_dock_get_theme_path (cThemeName, cGaugeShareDir, cGaugeUserDir, CAIRO_DOCK_GAUGES_DIR);
 
814
        g_free (cGaugeUserDir);
 
815
        return cGaugePath;
543
816
}
544
817
 
545
818
gchar *cairo_dock_get_gauge_key_value(gchar *cAppletConfFilePath, GKeyFile *pKeyFile, gchar *cGroupName, gchar *cKeyName, gboolean *bFlushConfFileNeeded, gchar *cDefaultThemeName)
546
819
{
547
820
        gchar *cChosenThemeName = cairo_dock_get_string_key_value (pKeyFile, cGroupName, cKeyName, bFlushConfFileNeeded, cDefaultThemeName, NULL, NULL);
548
 
        gchar *cGaugeShareDir = g_strdup_printf ("%s/%s", CAIRO_DOCK_SHARE_DATA_DIR, CAIRO_DOCK_GAUGES_DIR);
549
 
        gchar *cGaugeUserDir = g_strdup_printf ("%s/%s/%s", g_cCairoDockDataDir, CAIRO_DOCK_EXTRAS_DIR, CAIRO_DOCK_GAUGES_DIR);
550
 
        gchar *cGaugePath = cairo_dock_get_theme_path (cChosenThemeName, cGaugeShareDir, cGaugeUserDir, CAIRO_DOCK_GAUGES_DIR);
551
 
        g_free (cGaugeShareDir);
552
 
        g_free (cGaugeUserDir);
553
 
        
554
 
        /*if (s_pGaugeTable == NULL)
555
 
                cairo_dock_list_available_gauges ();
556
 
        
557
 
        const gchar *cGaugePath = NULL;
558
 
        if (cChosenThemeName != NULL)
559
 
        {
560
 
                CairoDockTheme *pTheme = g_hash_table_lookup (s_pGaugeTable, cChosenThemeName);
561
 
                if (pTheme != NULL)
562
 
                        cGaugePath = pTheme->cThemePath;
563
 
                g_free (cChosenThemeName);
564
 
        }*/
565
 
        
566
 
        cd_debug("Theme de la jauge : %s",cGaugePath);
567
 
        
 
821
        gchar *cGaugePath = cairo_dock_get_gauge_theme_path (cChosenThemeName);
 
822
        g_free (cChosenThemeName);
 
823
        
 
824
        cd_debug ("Theme de la jauge : %s", cGaugePath);
568
825
        return cGaugePath;
569
826
}
570
827
 
 
828
 
 
829
/// deprecated ... to be added in the DataRenderer API.
571
830
void cairo_dock_add_watermark_on_gauge (cairo_t *pSourceContext, Gauge *pGauge, gchar *cImagePath, double fAlpha)
572
831
{
573
832
        g_return_if_fail (pGauge != NULL && cImagePath != NULL);
574
833
        
575
 
        cairo_surface_t *pWatermarkSurface = cairo_dock_create_surface_for_icon (cImagePath, pSourceContext, pGauge->sizeX/2, pGauge->sizeY/2);
 
834
        CairoDataRenderer *pRenderer = CAIRO_DATA_RENDERER (pGauge);
 
835
        cairo_surface_t *pWatermarkSurface = cairo_dock_create_surface_for_icon (cImagePath, pSourceContext, pRenderer->iWidth/2, pRenderer->iHeight/2);
576
836
        
577
 
        if (pGauge->imageBackground == NULL)
 
837
        if (pGauge->pImageBackground == NULL)
578
838
        {
579
 
                pGauge->imageBackground = g_new0 (GaugeImage, 1);
580
 
                pGauge->imageBackground->sizeX = pGauge->sizeX;
581
 
                pGauge->imageBackground->sizeY = pGauge->sizeY;
 
839
                pGauge->pImageBackground = g_new0 (GaugeImage, 1);
 
840
                pGauge->pImageBackground->sizeX = pRenderer->iWidth;
 
841
                pGauge->pImageBackground->sizeY = pRenderer->iHeight;
582
842
                
583
 
                pGauge->imageBackground->cairoSurface = cairo_surface_create_similar (cairo_get_target (pSourceContext),
 
843
                pGauge->pImageBackground->pSurface = cairo_surface_create_similar (cairo_get_target (pSourceContext),
584
844
                        CAIRO_CONTENT_COLOR_ALPHA,
585
 
                        pGauge->sizeX,
586
 
                        pGauge->sizeY);
 
845
                        pRenderer->iWidth,
 
846
                        pRenderer->iHeight);
587
847
        }
588
848
        
589
 
        cairo_t *pCairoContext = cairo_create (pGauge->imageBackground->cairoSurface);
 
849
        cairo_t *pCairoContext = cairo_create (pGauge->pImageBackground->pSurface);
590
850
        cairo_set_operator (pCairoContext, CAIRO_OPERATOR_OVER);
591
851
        
592
 
        cairo_set_source_surface (pCairoContext, pWatermarkSurface, pGauge->sizeX/4, pGauge->sizeY/4);
 
852
        cairo_set_source_surface (pCairoContext, pWatermarkSurface, pRenderer->iWidth/4, pRenderer->iHeight/4);
593
853
        cairo_paint_with_alpha (pCairoContext, fAlpha);
594
854
        
595
855
        cairo_destroy (pCairoContext);
596
856
        
597
857
        cairo_surface_destroy (pWatermarkSurface);
598
858
}
599
 
 
600
 
 
601
 
 
602
 
gboolean cairo_dock_gauge_can_draw_text_value (Gauge *pGauge)
603
 
{
604
 
        if (pGauge->indicatorList == NULL)
605
 
                return FALSE;
606
 
        GaugeIndicator *pIndicator = pGauge->indicatorList->data;
607
 
        return (pIndicator->textWidth != 0 && pIndicator->textHeight != 0);
608
 
}