17
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
20
/** Exemple of a gauge with text inside :
23
<name>Screenlets Vista'ish Default</name>
24
<author>(conversion by Nochka85)</author>
26
<file key="background">back.svg</file>
27
<file key="foreground">dialdot.svg</file>
31
<posStart>-130</posStart>
32
<posStop>130</posStop>
33
<file key="needle">dial.svg</file>
34
<offset_x>0</offset_x>
38
<x_center>-0,34</x_center>
39
<y_center>-0,47</y_center>
47
<x_center>-0,32</x_center>
48
<y_center>0,00</y_center>
57
<direction>1</direction>
58
<posStart>-128</posStart>
59
<posStop>128</posStop>
60
<file key="needle">dial2.svg</file>
61
<offset_x>0</offset_x>
65
<x_center>0,50</x_center>
66
<y_center>-0,00</y_center>
74
<x_center>0,50</x_center>
75
<y_center>0,30</y_center>
20
85
#include <string.h>
22
87
#include <libxml/tree.h>
134
207
if (pGaugeImage->pSvgHandle != NULL)
136
209
int iSize = MIN (iWidth, iHeight);
137
g_print ("size : applet : %d, image : %d\n", iSize, pGaugeImage->sizeX);
210
//g_print ("size : applet : %d, image : %d\n", iSize, pGaugeImage->sizeX);
138
211
pGaugeIndicator->fNeedleScale = (double)iSize / (double) pGaugeImage->sizeX; // car l'aiguille est a l'horizontale dans le fichier svg.
139
212
pGaugeIndicator->iNeedleWidth = (double) pGaugeIndicator->iNeedleRealWidth * pGaugeIndicator->fNeedleScale;
140
213
pGaugeIndicator->iNeedleHeight = (double) pGaugeIndicator->iNeedleRealHeight * pGaugeIndicator->fNeedleScale;
141
g_print (" + needle %dx%d\n", pGaugeIndicator->iNeedleWidth, pGaugeIndicator->iNeedleHeight);
214
//g_print (" + needle %dx%d\n", pGaugeIndicator->iNeedleWidth, pGaugeIndicator->iNeedleHeight);
143
216
cairo_surface_t *pNeedleSurface = _cairo_dock_create_blank_surface (pSourceContext, pGaugeIndicator->iNeedleWidth, pGaugeIndicator->iNeedleHeight);
144
217
g_return_if_fail (cairo_surface_status (pNeedleSurface) == CAIRO_STATUS_SUCCESS);
166
239
int iWidth = pGauge->dataRenderer.iWidth, iHeight = pGauge->dataRenderer.iHeight;
167
240
if (iWidth == 0 || iHeight == 0)
242
CairoDataRenderer *pRenderer = CAIRO_DATA_RENDERER (pGauge);
170
244
g_return_val_if_fail (cThemePath != NULL, FALSE);
171
245
xmlInitParser ();
172
246
xmlDocPtr pGaugeTheme;
173
247
xmlNodePtr pGaugeMainNode;
174
248
gchar *cXmlFile = g_strdup_printf("%s/theme.xml",cThemePath);
175
cairo_dock_xml_open_file (cXmlFile, "gauge",&pGaugeTheme,&pGaugeMainNode);
249
//cairo_dock_xml_open_file (cXmlFile, "gauge",&pGaugeTheme,&pGaugeMainNode);
250
pGaugeTheme = cairo_dock_open_xml_file (cXmlFile, "gauge", &pGaugeMainNode, NULL);
176
251
g_free (cXmlFile);
177
g_return_val_if_fail (pGaugeTheme != NULL, FALSE);
252
g_return_val_if_fail (pGaugeTheme != NULL && pGaugeMainNode != NULL, FALSE);
180
255
xmlChar *cAttribute, *cNodeContent, *cTextNodeContent;
226
301
CAIRO_DATA_RENDERER (pGauge)->iRank ++;
230
305
pGaugeIndicator = g_new0 (GaugeIndicator, 1);
231
306
pGaugeIndicator->direction = 1;
233
308
cd_debug ("gauge : On charge un indicateur");
234
309
xmlNodePtr pGaugeSubNode;
235
for (pGaugeSubNode = pGaugeNode->xmlChildrenNode; pGaugeSubNode != NULL; pGaugeSubNode = pGaugeSubNode->next)
310
for (pGaugeSubNode = pGaugeNode->children; pGaugeSubNode != NULL; pGaugeSubNode = pGaugeSubNode->next)
237
312
if (xmlStrcmp (pGaugeSubNode->name, (const xmlChar *) "text") == 0)
239
314
//g_print ("+ %s\n", pGaugeSubNode->name);
240
315
cNodeContent = xmlNodeGetContent (pGaugeSubNode);
241
316
if(xmlStrcmp (pGaugeSubNode->name, (const xmlChar *) "posX") == 0)
242
pGaugeIndicator->posX = atof (cNodeContent);
317
pGaugeIndicator->posX = _str2double (cNodeContent);
243
318
else if(xmlStrcmp (pGaugeSubNode->name, (const xmlChar *) "posY") == 0)
244
pGaugeIndicator->posY = atof (cNodeContent);
319
pGaugeIndicator->posY = _str2double (cNodeContent);
245
320
else if(xmlStrcmp (pGaugeSubNode->name, (const xmlChar *) "text_zone") == 0)
247
322
xmlNodePtr pTextSubNode;
248
for (pTextSubNode = pGaugeSubNode->xmlChildrenNode; pTextSubNode != NULL; pTextSubNode = pTextSubNode->next)
323
for (pTextSubNode = pGaugeSubNode->children; pTextSubNode != NULL; pTextSubNode = pTextSubNode->next)
250
if (xmlStrcmp (pTextSubNode->name, (const xmlChar *) "text") == 0)
252
//g_print (" + %s\n", pTextSubNode->name);
253
325
cTextNodeContent = xmlNodeGetContent (pTextSubNode);
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);
270
g_print ("pGaugeIndicator->textWidth:%.2f\n", pGaugeIndicator->textWidth);
326
if(xmlStrcmp (pTextSubNode->name, (const xmlChar *) "x_center") == 0)
327
pGaugeIndicator->textZone.fX = _str2double (cTextNodeContent);
328
else if(xmlStrcmp (pTextSubNode->name, (const xmlChar *) "y_center") == 0)
329
pGaugeIndicator->textZone.fY = _str2double (cTextNodeContent);
330
else if(xmlStrcmp (pTextSubNode->name, (const xmlChar *) "width") == 0)
331
pGaugeIndicator->textZone.fWidth = _str2double (cTextNodeContent);
332
else if(xmlStrcmp (pTextSubNode->name, (const xmlChar *) "height") == 0)
333
pGaugeIndicator->textZone.fHeight = _str2double (cTextNodeContent);
334
else if(xmlStrcmp (pTextSubNode->name, (const xmlChar *) "red") == 0)
335
pGaugeIndicator->textZone.pColor[0] = _str2double (cTextNodeContent);
336
else if(xmlStrcmp (pTextSubNode->name, (const xmlChar *) "green") == 0)
337
pGaugeIndicator->textZone.pColor[1] = _str2double (cTextNodeContent);
338
else if(xmlStrcmp (pTextSubNode->name, (const xmlChar *) "blue") == 0)
339
pGaugeIndicator->textZone.pColor[2] = _str2double (cTextNodeContent);
342
else if(xmlStrcmp (pGaugeSubNode->name, (const xmlChar *) "logo_zone") == 0)
344
xmlNodePtr pLogoSubNode;
345
for (pLogoSubNode = pGaugeSubNode->children; pLogoSubNode != NULL; pLogoSubNode = pLogoSubNode->next)
347
cTextNodeContent = xmlNodeGetContent (pLogoSubNode);
348
if(xmlStrcmp (pLogoSubNode->name, (const xmlChar *) "x_center") == 0)
349
pGaugeIndicator->emblem.fX = _str2double (cTextNodeContent);
350
else if(xmlStrcmp (pLogoSubNode->name, (const xmlChar *) "y_center") == 0)
351
pGaugeIndicator->emblem.fY = _str2double (cTextNodeContent);
352
else if(xmlStrcmp (pLogoSubNode->name, (const xmlChar *) "width") == 0)
353
pGaugeIndicator->emblem.fWidth = _str2double (cTextNodeContent);
354
else if(xmlStrcmp (pLogoSubNode->name, (const xmlChar *) "height") == 0)
355
pGaugeIndicator->emblem.fHeight = _str2double (cTextNodeContent);
356
else if(xmlStrcmp (pLogoSubNode->name, (const xmlChar *) "alpha") == 0)
357
pGaugeIndicator->emblem.fAlpha = _str2double (cTextNodeContent);
272
360
else if(xmlStrcmp (pGaugeSubNode->name, (const xmlChar *) "direction") == 0)
273
pGaugeIndicator->direction = atof (cNodeContent);
361
pGaugeIndicator->direction = _str2double (cNodeContent);
274
362
else if(xmlStrcmp (pGaugeSubNode->name, (const xmlChar *) "posStart") == 0)
275
pGaugeIndicator->posStart = atof (cNodeContent);
363
pGaugeIndicator->posStart = _str2double (cNodeContent);
276
364
else if(xmlStrcmp (pGaugeSubNode->name, (const xmlChar *) "posStop") == 0)
277
pGaugeIndicator->posStop = atof (cNodeContent);
365
pGaugeIndicator->posStop = _str2double (cNodeContent);
278
366
else if(xmlStrcmp (pGaugeSubNode->name, (const xmlChar *) "nb images") == 0)
279
367
pGaugeIndicator->iNbImages = atoi (cNodeContent);
280
368
else if(xmlStrcmp (pGaugeSubNode->name, (const xmlChar *) "offset_x") == 0)
439
529
_draw_gauge_image (pSourceContext, pGauge, pIndicator, fValue);
442
if (pIndicator->textWidth != 0 && pIndicator->textHeight != 0) // cet indicateur a un emplacement pour le texte de la valeur.
532
if (/**pRenderer->bWriteValues && */pIndicator->textZone.fWidth != 0 && pIndicator->textZone.fHeight != 0) // cet indicateur a un emplacement pour le texte de la valeur.
444
534
cairo_data_renderer_format_value (pRenderer, fValue, i);
445
535
//g_print (" >>>%s\n", pRenderer->cFormatBuffer);
446
536
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);
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);
537
cairo_set_source_rgb (pSourceContext, pIndicator->textZone.pColor[0], pIndicator->textZone.pColor[1], pIndicator->textZone.pColor[2]);
539
PangoLayout *pLayout = pango_cairo_create_layout (pSourceContext);
540
PangoFontDescription *fd = pango_font_description_from_string ("Monospace 12");
541
pango_layout_set_font_description (pLayout, fd);
543
PangoRectangle ink, log;
544
pango_layout_set_text (pLayout, pRenderer->cFormatBuffer, -1);
545
pango_layout_get_pixel_extents (pLayout, &ink, &log);
546
double fZoom = MIN (pIndicator->textZone.fWidth * pRenderer->iWidth / (log.width), pIndicator->textZone.fHeight * pRenderer->iHeight / log.height);
453
548
cairo_move_to (pSourceContext,
454
(1. + pIndicator->textX) * pRenderer->iWidth/2 - textExtents.width / 2,
455
(1. - pIndicator->textY) * pRenderer->iHeight/2 + textExtents.height);
549
floor ((1. + pIndicator->textZone.fX) * pRenderer->iWidth/2 - log.width*fZoom/2),
550
floor ((1. - pIndicator->textZone.fY) * pRenderer->iHeight/2 - log.height*fZoom/2));
456
551
cairo_scale (pSourceContext,
459
cairo_show_text (pSourceContext, pRenderer->cFormatBuffer);
554
pango_cairo_show_layout (pSourceContext, pLayout);
460
555
cairo_restore (pSourceContext);
601
696
_draw_gauge_image_opengl (pGauge, pIndicator, fValue);
604
if (pIndicator->textWidth != 0 && pIndicator->textHeight != 0) // cet indicateur a un emplacement pour le texte de la valeur.
699
if (/**pRenderer->bWriteValues && */pIndicator->textZone.fWidth != 0 && pIndicator->textZone.fHeight != 0) // cet indicateur a un emplacement pour le texte de la valeur.
606
701
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.);
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);*/
703
CairoDockGLFont *pFont = cairo_dock_get_default_data_renderer_font ();
704
glColor3f (pIndicator->textZone.pColor[0], pIndicator->textZone.pColor[1], pIndicator->textZone.pColor[2]);
707
cairo_dock_draw_gl_text_at_position_in_area (pRenderer->cFormatBuffer,
709
floor (pIndicator->textZone.fX * pRenderer->iWidth/2),
710
floor (pIndicator->textZone.fY * pRenderer->iHeight/2),
711
pIndicator->textZone.fWidth * pRenderer->iWidth,
712
pIndicator->textZone.fHeight * pRenderer->iHeight,
716
_cairo_dock_enable_texture ();
717
glColor3f (1.0, 1.0, 1.0);
804
903
return pGaugeTable;
807
gchar *cairo_dock_get_gauge_theme_path (const gchar *cThemeName)
907
gchar *cairo_dock_get_gauge_theme_path (const gchar *cThemeName, CairoDockThemeType iType) // utile pour DBus aussi.
809
if (cThemeName == NULL)
810
return g_strdup ("Turbo-night-fuel");
811
909
const gchar *cGaugeShareDir = CAIRO_DOCK_SHARE_DATA_DIR"/"CAIRO_DOCK_GAUGES_DIR;
812
910
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);
911
gchar *cGaugePath = cairo_dock_get_theme_path (cThemeName, cGaugeShareDir, cGaugeUserDir, CAIRO_DOCK_GAUGES_DIR, iType);
814
912
g_free (cGaugeUserDir);
815
913
return cGaugePath;
818
gchar *cairo_dock_get_gauge_key_value(gchar *cAppletConfFilePath, GKeyFile *pKeyFile, gchar *cGroupName, gchar *cKeyName, gboolean *bFlushConfFileNeeded, gchar *cDefaultThemeName)
916
gchar *cairo_dock_get_theme_path_for_gauge (const gchar *cAppletConfFilePath, GKeyFile *pKeyFile, const gchar *cGroupName, const gchar *cKeyName, gboolean *bFlushConfFileNeeded, const gchar *cDefaultThemeName)
820
918
gchar *cChosenThemeName = cairo_dock_get_string_key_value (pKeyFile, cGroupName, cKeyName, bFlushConfFileNeeded, cDefaultThemeName, NULL, NULL);
821
gchar *cGaugePath = cairo_dock_get_gauge_theme_path (cChosenThemeName);
919
if (cChosenThemeName == NULL)
920
return g_strdup ("Turbo-night-fuel");
922
CairoDockThemeType iType = cairo_dock_extract_theme_type_from_name (cChosenThemeName);
923
gchar *cGaugePath = cairo_dock_get_gauge_theme_path (cChosenThemeName, iType);
925
if (iType != CAIRO_DOCK_ANY_THEME)
927
g_key_file_set_string (pKeyFile, cGroupName, cKeyName, cChosenThemeName);
928
cairo_dock_write_keys_to_file (pKeyFile, cAppletConfFilePath);
930
cd_debug ("Theme de la jauge : %s", cGaugePath);
822
931
g_free (cChosenThemeName);
824
cd_debug ("Theme de la jauge : %s", cGaugePath);
825
932
return cGaugePath;