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)
282
pGaugeIndicator->iNeedleOffsetX = atoi (cNodeContent);
284
else if(xmlStrcmp (pGaugeSubNode->name, (const xmlChar *) "width") == 0)
286
pGaugeIndicator->iNeedleRealWidth = atoi (cNodeContent);
288
else if(xmlStrcmp (pGaugeSubNode->name, (const xmlChar *) "height") == 0)
290
pGaugeIndicator->iNeedleRealHeight = atoi (cNodeContent);
291
pGaugeIndicator->iNeedleOffsetY = .5 * pGaugeIndicator->iNeedleRealHeight;
197
293
else if(xmlStrcmp (pGaugeSubNode->name, (const xmlChar *) "file") == 0)
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)
204
300
g_string_printf (sImagePath, "%s/%s", cThemePath, cNodeContent);
205
pGaugeImage = cairo_dock_init_gauge_image(sImagePath->str);
207
pGaugeIndicator->imageNeedle = pGaugeImage;
301
pGaugeIndicator->pImageNeedle = _cairo_dock_new_gauge_image (sImagePath->str);
209
303
else if (strcmp (cAttribute,"image") == 0)
211
if (pGaugeIndicator->nbImage == 0)
305
if (pGaugeIndicator->iNbImages == 0)
213
pGaugeIndicator->nbImage = 1;
307
pGaugeIndicator->iNbImages = 1;
215
309
for (node = pGaugeSubNode->next; node != NULL; node = node->next)
217
311
if (xmlStrcmp (node->name, (const xmlChar *) "file") == 0)
218
pGaugeIndicator->nbImage ++;
312
pGaugeIndicator->iNbImages ++;
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);
225
//pGaugeIndicator->nbImage++;
227
pGaugeIndicator->imageList = g_list_append (pGaugeIndicator->imageList, pGaugeImage);
315
if (pGaugeIndicator->pImageList == NULL)
316
pGaugeIndicator->pImageList = g_new0 (GaugeImage, pGaugeIndicator->iNbImages);
318
if (pGaugeIndicator->iNbImageLoaded < pGaugeIndicator->iNbImages)
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 ++;
229
327
xmlFree (cAttribute);
231
329
xmlFree (cNodeContent);
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.
333
if (pGaugeIndicator->iNeedleRealHeight == 0)
335
pGaugeIndicator->iNeedleRealHeight = .12*pGaugeIndicator->pImageNeedle->sizeY; // 12px utiles sur les 100
336
pGaugeIndicator->iNeedleOffsetY = pGaugeIndicator->iNeedleRealHeight/2;
338
if (pGaugeIndicator->iNeedleRealWidth == 0)
340
pGaugeIndicator->iNeedleRealWidth = pGaugeIndicator->pImageNeedle->sizeY; // 100px utiles sur les 100
341
pGaugeIndicator->iNeedleOffsetX = 10;
343
if (g_bUseOpenGL) // meme remarque.
344
_cairo_dock_load_gauge_needle (pSourceContext, pGaugeIndicator, iWidth, iHeight);
346
pGauge->pIndicatorList = g_list_append (pGauge->pIndicatorList, pGaugeIndicator);
236
349
xmlFreeDoc (pGaugeTheme);
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);
243
350
xmlCleanupParser ();
244
351
g_string_free (sImagePath, TRUE);
250
GaugeImage *cairo_dock_init_gauge_image (gchar *cImagePath)
252
cd_debug ("%s (%s)", __func__, cImagePath);
253
GaugeImage *pGaugeImage = g_new0 (GaugeImage, 1);
255
pGaugeImage->svgNeedle = rsvg_handle_new_from_file (cImagePath, NULL);
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;
266
void cairo_dock_load_gauge_image (cairo_t *pSourceContext, GaugeImage *pGaugeImage, int iWidth, int iHeight)
268
cd_message ("%s (%dx%d)", __func__, iWidth, iHeight);
269
if (pGaugeImage->cairoSurface != NULL)
270
cairo_surface_destroy (pGaugeImage->cairoSurface);
272
if (pGaugeImage->svgNeedle != NULL)
274
pGaugeImage->cairoSurface = cairo_surface_create_similar (cairo_get_target (pSourceContext),
275
CAIRO_CONTENT_COLOR_ALPHA,
279
cairo_t* pDrawingContext = cairo_create (pGaugeImage->cairoSurface);
281
cairo_scale (pDrawingContext,
282
(double) iWidth / (double) pGaugeImage->sizeX,
283
(double) iHeight / (double) pGaugeImage->sizeY);
285
rsvg_handle_render_cairo (pGaugeImage->svgNeedle, pDrawingContext);
286
cairo_destroy (pDrawingContext);
289
pGaugeImage->cairoSurface = NULL;
294
void cairo_dock_render_gauge(cairo_t *pSourceContext, CairoContainer *pContainer, Icon *pIcon, Gauge *pGauge, double fValue)
297
pList = g_list_prepend (pList, &fValue);
299
cairo_dock_render_gauge_multi_value(pSourceContext,pContainer,pIcon,pGauge,pList);
304
void cairo_dock_render_gauge_multi_value(cairo_t *pSourceContext, CairoContainer *pContainer, Icon *pIcon, Gauge *pGauge, GList *valueList)
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);
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);
316
GaugeImage *pGaugeImage;
317
//\________________ On affiche le fond.
318
if(pGauge->imageBackground != NULL)
320
pGaugeImage = pGauge->imageBackground;
321
cairo_set_source_surface (pSourceContext, pGaugeImage->cairoSurface, 0.0f, 0.0f);
322
cairo_paint (pSourceContext);
325
//\________________ On represente l'indicateur de chaque valeur.
326
GList *pIndicatorElement;
329
GaugeIndicator *pIndicator;
330
pIndicatorElement = pGauge->indicatorList;
331
for (pValueList = valueList; pValueList != NULL && pIndicatorElement != NULL; pValueList = pValueList->next, pIndicatorElement = pIndicatorElement->next)
333
pValue = pValueList->data;
334
pIndicator = pIndicatorElement->data;
336
if(*pValue > 1) *pValue = 1;
337
else if(*pValue < 0) *pValue = 0;
339
if (pIndicator->imageNeedle != NULL) // c'est une aiguille.
341
draw_cd_Gauge_needle(pSourceContext, pGauge, pIndicatorElement->data, *pValue);
343
else // c'est une image.
345
draw_cd_Gauge_image(pSourceContext, pIndicator, *pValue);
348
if (pIndicator->textWidth != 0 && pIndicator->textHeight != 0) // cet indicateur a un emplacement pour le texte de la valeur.
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.);
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);
367
//\________________ On affiche le fond
368
if(pGauge->imageForeground != NULL)
370
pGaugeImage = pGauge->imageForeground;
371
cairo_set_source_surface (pSourceContext, pGaugeImage->cairoSurface, 0.0f, 0.0f);
372
cairo_paint (pSourceContext);
375
cairo_restore (pSourceContext);
377
//\________________ On cree le reflet.
378
if (CAIRO_DOCK_IS_DOCK (pContainer) && CAIRO_DOCK (pContainer)->bUseReflect)
380
double fMaxScale = cairo_dock_get_max_scale (pContainer);
382
cairo_surface_destroy (pIcon->pReflectionBuffer);
383
pIcon->pReflectionBuffer = cairo_dock_create_reflection_surface (pIcon->pIconBuffer,
385
(pContainer->bIsHorizontal ? pIcon->fWidth : pIcon->fHeight) * fMaxScale / pContainer->fRatio,
386
(pContainer->bIsHorizontal ? pIcon->fHeight : pIcon->fWidth) * fMaxScale / pContainer->fRatio,
387
pContainer->bIsHorizontal,
389
pContainer->bDirectionUp);
392
if (CAIRO_DOCK_CONTAINER_IS_OPENGL (pContainer))
393
cairo_dock_update_icon_texture (pIcon);
395
cairo_dock_redraw_icon (pIcon, pContainer);
398
void draw_cd_Gauge_needle(cairo_t *pSourceContext, Gauge *pGauge, GaugeIndicator *pGaugeIndicator, double fValue)
400
//cd_debug("gauge : %s\n",__func__);
402
if(pGaugeIndicator->imageNeedle != NULL)
404
GaugeImage *pGaugeImage;
407
double physicValue = ((fValue * (pGaugeIndicator->posStop - pGaugeIndicator->posStart)) + pGaugeIndicator->posStart) / 360;
409
int direction = pGaugeIndicator->direction >= 0 ? 1 : -1;
410
//cd_debug("gauge : Direction(%i)",direction);
412
//On affiche l'aiguille
413
pGaugeImage = pGaugeIndicator->imageNeedle;
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);
358
static void cairo_dock_load_gauge (Gauge *pGauge, cairo_t *pSourceContext, CairoContainer *pContainer, CairoGaugeAttribute *pAttribute)
360
_cairo_dock_load_gauge_theme (pGauge, pSourceContext, pAttribute->cThemePath);
363
////////////////////////////////////////////
364
////////////// RENDER GAUGE ////////////////
365
////////////////////////////////////////////
366
static void _draw_gauge_needle (cairo_t *pSourceContext, Gauge *pGauge, GaugeIndicator *pGaugeIndicator, double fValue)
368
GaugeImage *pGaugeImage = pGaugeIndicator->pImageNeedle;
369
if(pGaugeImage != NULL)
371
double fAngle = (pGaugeIndicator->posStart + fValue * (pGaugeIndicator->posStop - pGaugeIndicator->posStart)) * G_PI / 180.;
372
if (pGaugeIndicator->direction < 0)
375
double fHalfX = pGauge->pImageBackground->sizeX / 2.0f * (1 + pGaugeIndicator->posX);
376
double fHalfY = pGauge->pImageBackground->sizeY / 2.0f * (1 - pGaugeIndicator->posY);
418
378
cairo_save (pSourceContext);
420
380
cairo_scale (pSourceContext,
421
(double) pGauge->sizeX / (double) pGaugeImage->sizeX,
422
(double) pGauge->sizeY / (double) pGaugeImage->sizeY);
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);
427
rsvg_handle_render_cairo (pGaugeImage->svgNeedle, pSourceContext);
386
rsvg_handle_render_cairo (pGaugeImage->pSvgHandle, pSourceContext);
429
388
cairo_restore (pSourceContext);
433
void draw_cd_Gauge_image(cairo_t *pSourceContext, GaugeIndicator *pGaugeIndicator, double fValue)
435
GaugeImage *pGaugeImage;
437
double imageWidthZone;
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);
443
pGaugeImage = g_list_nth_data (pGaugeIndicator->imageList, trueImage);
444
if (pGaugeImage != NULL)
446
cairo_set_source_surface (pSourceContext, pGaugeImage->cairoSurface, 0.0f, 0.0f);
447
cairo_paint (pSourceContext);
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)
393
int iNumImage = fValue * (pGaugeIndicator->iNbImages - 1) + 0.5;
394
g_return_if_fail (iNumImage < pGaugeIndicator->iNbImages);
396
GaugeImage *pGaugeImage = &pGaugeIndicator->pImageList[iNumImage];
397
if (pGaugeImage->pSurface == NULL)
399
int iWidth = pGauge->dataRenderer.iWidth, iHeight = pGauge->dataRenderer.iHeight;
400
_cairo_dock_load_gauge_image (pSourceContext, pGaugeImage, iWidth, iHeight);
403
if (pGaugeImage->pSurface != NULL)
405
cairo_set_source_surface (pSourceContext, pGaugeImage->pSurface, 0.0f, 0.0f);
406
cairo_paint (pSourceContext);
409
static void cairo_dock_draw_one_gauge (cairo_t *pSourceContext, Gauge *pGauge, int iDataOffset)
411
GaugeImage *pGaugeImage;
412
//\________________ On affiche le fond.
413
if(pGauge->pImageBackground != NULL)
415
pGaugeImage = pGauge->pImageBackground;
416
cairo_set_source_surface (pSourceContext, pGaugeImage->pSurface, 0.0f, 0.0f);
417
cairo_paint (pSourceContext);
420
//\________________ On represente l'indicateur de chaque valeur.
421
GList *pIndicatorElement;
424
GaugeIndicator *pIndicator;
425
CairoDataRenderer *pRenderer = CAIRO_DATA_RENDERER (pGauge);
426
CairoDataToRenderer *pData = cairo_data_renderer_get_data (pRenderer);
428
for (i = iDataOffset, pIndicatorElement = pGauge->pIndicatorList; i < pData->iNbValues && pIndicatorElement != NULL; i++, pIndicatorElement = pIndicatorElement->next)
430
pIndicator = pIndicatorElement->data;
431
fValue = cairo_data_renderer_get_normalized_current_value (pRenderer, i);
433
if (pIndicator->pImageNeedle != NULL) // c'est une aiguille.
435
_draw_gauge_needle (pSourceContext, pGauge, pIndicator, fValue);
437
else // c'est une image.
439
_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.
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);
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,
459
cairo_show_text (pSourceContext, pRenderer->cFormatBuffer);
460
cairo_restore (pSourceContext);
464
//\________________ On affiche l'avant-plan.
465
if(pGauge->pImageForeground != NULL)
467
pGaugeImage = pGauge->pImageForeground;
468
cairo_set_source_surface (pSourceContext, pGaugeImage->pSurface, 0.0f, 0.0f);
469
cairo_paint (pSourceContext);
472
void cairo_dock_render_gauge (Gauge *pGauge, cairo_t *pCairoContext)
474
g_return_if_fail (pGauge != NULL && pGauge->pIndicatorList != NULL && pCairoContext != NULL);
475
g_return_if_fail (cairo_status (pCairoContext) == CAIRO_STATUS_SUCCESS);
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 ++)
483
if (iNbDrawings > 1) // on va dessiner la jauges plusieurs fois, la 1ere en grand et les autres en petit autour.
485
cairo_save (pCairoContext);
488
cairo_scale (pCairoContext, 2./3, 2./3);
492
cairo_translate (pCairoContext, 2 * pRenderer->iWidth / 3, 2 * pRenderer->iHeight / 3);
493
cairo_scale (pCairoContext, 1./3, 1./3);
497
cairo_translate (pCairoContext, 2 * pRenderer->iWidth / 3, 0.);
498
cairo_scale (pCairoContext, 1./3, 1./3);
502
cairo_translate (pCairoContext, 0., 2 * pRenderer->iHeight / 3);
503
cairo_scale (pCairoContext, 1./3, 1./3);
505
else // 5 valeurs faut pas pousser non plus.
509
cairo_dock_draw_one_gauge (pCairoContext, pGauge, iDataOffset);
512
cairo_restore (pCairoContext);
514
iDataOffset += pRenderer->iRank;
518
///////////////////////////////////////////////
519
/////////////// RENDER OPENGL /////////////////
520
///////////////////////////////////////////////
521
static void _draw_gauge_image_opengl (Gauge *pGauge, GaugeIndicator *pGaugeIndicator, double fValue)
523
int iNumImage = fValue * (pGaugeIndicator->iNbImages - 1) + 0.5;
524
g_return_if_fail (iNumImage < pGaugeIndicator->iNbImages);
526
GaugeImage *pGaugeImage = &pGaugeIndicator->pImageList[iNumImage];
527
int iWidth = pGauge->dataRenderer.iWidth, iHeight = pGauge->dataRenderer.iHeight;
528
/*if (pGaugeImage->iTexture == 0)
530
_cairo_dock_load_gauge_image (NULL, pGaugeImage, iWidth, iHeight); // pas besoin d'un cairo_context pour creer une cairo_image_surface.
534
if (pGaugeImage->iTexture != 0)
536
_cairo_dock_apply_texture_at_size (pGaugeImage->iTexture, iWidth, iHeight);
539
static void _draw_gauge_needle_opengl (Gauge *pGauge, GaugeIndicator *pGaugeIndicator, double fValue)
541
GaugeImage *pGaugeImage = pGaugeIndicator->pImageNeedle;
542
g_return_if_fail (pGaugeImage != NULL);
544
int iWidth = pGauge->dataRenderer.iWidth, iHeight = pGauge->dataRenderer.iHeight;
545
/*if (pGaugeImage->iTexture == 0)
547
_cairo_dock_load_gauge_needle (NULL, pGaugeIndicator, iWidth, iHeight); // pas besoin d'un cairo_context pour creer une cairo_image_surface.
551
if(pGaugeImage->iTexture != 0)
553
double fAngle = (pGaugeIndicator->posStart + fValue * (pGaugeIndicator->posStop - pGaugeIndicator->posStart));
554
if (pGaugeIndicator->direction < 0)
556
double fHalfX = iWidth / 2.0f * (0 + pGaugeIndicator->posX);
557
double fHalfY = iHeight / 2.0f * (0 + pGaugeIndicator->posY);
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);
569
static void cairo_dock_draw_one_gauge_opengl (Gauge *pGauge, int iDataOffset)
571
int iWidth = pGauge->dataRenderer.iWidth, iHeight = pGauge->dataRenderer.iHeight;
572
GaugeImage *pGaugeImage;
574
//\________________ On affiche le fond.
575
if(pGauge->pImageBackground != NULL)
577
pGaugeImage = pGauge->pImageBackground;
578
if (pGaugeImage->iTexture != 0)
579
_cairo_dock_apply_texture_at_size (pGaugeImage->iTexture, iWidth, iHeight);
582
//\________________ On represente l'indicateur de chaque valeur.
583
GList *pIndicatorElement;
586
GaugeIndicator *pIndicator;
587
CairoDataRenderer *pRenderer = CAIRO_DATA_RENDERER (pGauge);
588
CairoDataToRenderer *pData = cairo_data_renderer_get_data (pRenderer);
590
for (i = iDataOffset, pIndicatorElement = pGauge->pIndicatorList; i < pData->iNbValues && pIndicatorElement != NULL; i++, pIndicatorElement = pIndicatorElement->next)
592
pIndicator = pIndicatorElement->data;
593
fValue = cairo_data_renderer_get_normalized_current_value_with_latency (pRenderer, i);
595
if (pIndicator->pImageNeedle != NULL) // c'est une aiguille.
597
_draw_gauge_needle_opengl (pGauge, pIndicator, fValue);
599
else // c'est une image.
601
_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.
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.);
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);*/
622
//\________________ On affiche l'avant-plan.
623
if(pGauge->pImageForeground != NULL)
625
pGaugeImage = pGauge->pImageForeground;
626
if (pGaugeImage->iTexture != 0)
627
_cairo_dock_apply_texture_at_size (pGaugeImage->iTexture, iWidth, iHeight);
630
static void cairo_dock_render_gauge_opengl (Gauge *pGauge)
632
g_return_if_fail (pGauge != NULL && pGauge->pIndicatorList != NULL);
634
_cairo_dock_enable_texture ();
635
_cairo_dock_set_blend_pbuffer (); // ceci reste un mystere...
636
_cairo_dock_set_alpha (1.);
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 ++)
644
if (iNbDrawings > 1) // on va dessiner la jauges plusieurs fois, la 1ere en grand et les autres en petit autour.
649
glTranslatef (-pRenderer->iWidth / 6, pRenderer->iHeight / 6, 0.);
650
glScalef (2./3, 2./3, 1.);
654
glTranslatef (pRenderer->iWidth / 3, - pRenderer->iHeight / 3, 0.);
655
glScalef (1./3, 1./3, 1.);
659
glTranslatef (pRenderer->iWidth / 3, pRenderer->iHeight / 3, 0.);
660
glScalef (1./3, 1./3, 1.);
664
glTranslatef (-pRenderer->iWidth / 3, -pRenderer->iHeight / 3, 0.);
665
glScalef (1./3, 1./3, 1.);
667
else // 5 valeurs faut pas pousser non plus.
671
cairo_dock_draw_one_gauge_opengl (pGauge, iDataOffset);
676
iDataOffset += pRenderer->iRank;
678
_cairo_dock_disable_texture ();
682
//////////////////////////////////////////////
683
/////////////// RELOAD GAUGE /////////////////
684
//////////////////////////////////////////////
685
static void cairo_dock_reload_gauge (Gauge *pGauge, cairo_t *pSourceContext)
455
687
//g_print ("%s (%dx%d)\n", __func__, iWidth, iHeight);
456
688
g_return_if_fail (pGauge != NULL);
458
pGauge->sizeX = iWidth;
459
pGauge->sizeY = iHeight;
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)
463
cairo_dock_load_gauge_image (pSourceContext, pGauge->imageBackground, iWidth, iHeight);
694
_cairo_dock_load_gauge_image (pSourceContext, pGauge->pImageBackground, iWidth, iHeight);
466
if (pGauge->imageForeground != NULL)
697
if (pGauge->pImageForeground != NULL)
468
cairo_dock_load_gauge_image (pSourceContext, pGauge->imageForeground, iWidth, iHeight);
699
_cairo_dock_load_gauge_image (pSourceContext, pGauge->pImageForeground, iWidth, iHeight);
471
702
GaugeIndicator *pGaugeIndicator;
472
703
GaugeImage *pGaugeImage;
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)
476
708
pGaugeIndicator = pElement->data;
477
for (pElement2 = pGaugeIndicator->imageList; pElement2 != NULL; pElement2 = pElement2->next)
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 ++)
711
pGaugeImage = &pGaugeIndicator->pImageList[i];
712
_cairo_dock_load_gauge_image (pSourceContext, pGaugeImage, iWidth, iHeight);
714
if (g_bUseOpenGL && pGaugeIndicator->pImageNeedle)
716
_cairo_dock_load_gauge_needle (pSourceContext, pGaugeIndicator, iWidth, iHeight);
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)
490
726
if (pGaugeImage == NULL)
493
if(pGaugeImage->svgNeedle != NULL)
495
rsvg_handle_free (pGaugeImage->svgNeedle);
497
if(pGaugeImage->cairoSurface != NULL)
499
cairo_surface_destroy (pGaugeImage->cairoSurface);
502
g_free (pGaugeImage);
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);
738
g_free (pGaugeImage);
505
static void cairo_dock_free_gauge_indicator(GaugeIndicator *pGaugeIndicator)
740
static void _cairo_dock_free_gauge_indicator(GaugeIndicator *pGaugeIndicator)
508
742
if (pGaugeIndicator == NULL)
747
for (i = 0; i < pGaugeIndicator->iNbImages; i ++)
749
_cairo_dock_free_gauge_image (&pGaugeIndicator->pImageList[i], FALSE);
751
g_free (pGaugeIndicator->pImageList);
753
_cairo_dock_free_gauge_image (pGaugeIndicator->pImageNeedle, TRUE);
755
g_free (pGaugeIndicator);
757
static void cairo_dock_free_gauge (Gauge *pGauge)
763
_cairo_dock_free_gauge_image(pGauge->pImageBackground, TRUE);
764
_cairo_dock_free_gauge_image(pGauge->pImageForeground, TRUE);
512
for (pElement = pGaugeIndicator->imageList; pElement != NULL; pElement = pElement->next)
514
cairo_dock_free_gauge_image(pElement->data);
516
g_list_free (pGaugeIndicator->imageList);
518
cairo_dock_free_gauge_image(pGaugeIndicator->imageNeedle);
520
g_free (pGaugeIndicator);
523
void cairo_dock_free_gauge(Gauge *pGauge)
529
if(pGauge->themeName != NULL) g_free(pGauge->themeName);
531
if(pGauge->imageBackground != NULL) cairo_dock_free_gauge_image(pGauge->imageBackground);
532
if(pGauge->imageForeground != NULL) cairo_dock_free_gauge_image(pGauge->imageForeground);
535
for (pElement = pGauge->indicatorList; pElement != NULL; pElement = pElement->next)
537
cairo_dock_free_gauge_indicator(pElement->data);
539
g_list_free (pGauge->indicatorList);
767
for (pElement = pGauge->pIndicatorList; pElement != NULL; pElement = pElement->next)
769
_cairo_dock_free_gauge_indicator (pElement->data);
771
g_list_free (pGauge->pIndicatorList);
777
//////////////////////////////////////////
778
/////////////// RENDERER /////////////////
779
//////////////////////////////////////////
780
Gauge *cairo_dock_new_gauge (void)
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;
793
/////////////////////////////////////////////////
794
/////////////// LIST OF THEMES /////////////////
795
/////////////////////////////////////////////////
796
GHashTable *cairo_dock_list_available_gauges (void)
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);
802
g_free (cGaugeShareDir);
803
g_free (cGaugeUserDir);
807
gchar *cairo_dock_get_gauge_theme_path (const gchar *cThemeName)
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);
545
818
gchar *cairo_dock_get_gauge_key_value(gchar *cAppletConfFilePath, GKeyFile *pKeyFile, gchar *cGroupName, gchar *cKeyName, gboolean *bFlushConfFileNeeded, gchar *cDefaultThemeName)
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);
554
/*if (s_pGaugeTable == NULL)
555
cairo_dock_list_available_gauges ();
557
const gchar *cGaugePath = NULL;
558
if (cChosenThemeName != NULL)
560
CairoDockTheme *pTheme = g_hash_table_lookup (s_pGaugeTable, cChosenThemeName);
562
cGaugePath = pTheme->cThemePath;
563
g_free (cChosenThemeName);
566
cd_debug("Theme de la jauge : %s",cGaugePath);
821
gchar *cGaugePath = cairo_dock_get_gauge_theme_path (cChosenThemeName);
822
g_free (cChosenThemeName);
824
cd_debug ("Theme de la jauge : %s", cGaugePath);
568
825
return cGaugePath;
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)
573
832
g_return_if_fail (pGauge != NULL && cImagePath != NULL);
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);
577
if (pGauge->imageBackground == NULL)
837
if (pGauge->pImageBackground == NULL)
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;
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,
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);
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);
595
855
cairo_destroy (pCairoContext);
597
857
cairo_surface_destroy (pWatermarkSurface);
602
gboolean cairo_dock_gauge_can_draw_text_value (Gauge *pGauge)
604
if (pGauge->indicatorList == NULL)
606
GaugeIndicator *pIndicator = pGauge->indicatorList->data;
607
return (pIndicator->textWidth != 0 && pIndicator->textHeight != 0);