← Back to team overview

cairo-dock-team team mailing list archive

[Merge] lp:~meuarrr/cairo-dock-core/gauge-effect-new into lp:cairo-dock-core

 

Matthieu Baerts has proposed merging lp:~meuarrr/cairo-dock-core/gauge-effect-new into lp:cairo-dock-core.

Requested reviews:
  Cairo-Dock Team (cairo-dock-team)

For more details, see:
https://code.launchpad.net/~meuarrr/cairo-dock-core/gauge-effect-new/+merge/68421

**@ fabounet**: can I merge this branch into the trunk?
Even if we are in beta2? (it's not a RC ;) ) => But I see that it doesn't affect too much other parts of the code.
-- 
https://code.launchpad.net/~meuarrr/cairo-dock-core/gauge-effect-new/+merge/68421
Your team Cairo-Dock Team is requested to review the proposed merge of lp:~meuarrr/cairo-dock-core/gauge-effect-new into lp:cairo-dock-core.
=== modified file 'src/gldit/cairo-dock-data-renderer.c'
--- src/gldit/cairo-dock-data-renderer.c	2010-12-25 02:54:47 +0000
+++ src/gldit/cairo-dock-data-renderer.c	2011-07-19 16:26:40 +0000
@@ -109,15 +109,36 @@
 	//\_______________ On charge les parametres generaux.
 	pRenderer->bUpdateMinMax = pAttribute->bUpdateMinMax;
 	pRenderer->bWriteValues = pAttribute->bWriteValues;
+	pRenderer->iRotateTheme = pAttribute->iRotateTheme;
 	pRenderer->iLatencyTime = pAttribute->iLatencyTime;
 	pRenderer->iSmoothAnimationStep = 0;
 	pRenderer->format_value = pAttribute->format_value;
 	pRenderer->pFormatData = pAttribute->pFormatData;
 }
 
+void cairo_data_renderer_get_size (CairoDataRenderer *pRenderer, gint *iWidth, gint *iHeight) 
+{
+	if (pRenderer->bisRotate)
+	{
+		*iWidth = pRenderer->iHeight;
+		*iHeight = pRenderer->iWidth;
+	}
+	else
+	{
+		*iWidth = pRenderer->iWidth;
+		*iHeight = pRenderer->iHeight;
+	}
+}
+
 
 void cairo_dock_render_overlays_to_texture (CairoDataRenderer *pRenderer, int iNumValue)
 {
+	gint iWidth = pRenderer->iWidth, iHeight = pRenderer->iHeight;
+	cairo_data_renderer_get_size (pRenderer, &iWidth, &iHeight);
+	glPushMatrix ();
+	if (pRenderer->bisRotate)
+		glRotatef (90., 0., 0., 1.);
+	
 	if (pRenderer->pEmblems != NULL)
 	{
 		_cairo_dock_enable_texture ();
@@ -130,10 +151,10 @@
 			glBindTexture (GL_TEXTURE_2D, pEmblem->iTexture);
 			_cairo_dock_set_alpha (pEmblem->param.fAlpha);
 			_cairo_dock_apply_current_texture_at_size_with_offset (
-				pEmblem->param.fWidth * pRenderer->iWidth,
-				pEmblem->param.fHeight * pRenderer->iHeight,
-				pEmblem->param.fX * pRenderer->iWidth,
-				pEmblem->param.fY * pRenderer->iHeight);
+				pEmblem->param.fWidth * iWidth,
+				pEmblem->param.fHeight * iHeight,
+				pEmblem->param.fX * iWidth,
+				pEmblem->param.fY * iHeight);
 		}
 		_cairo_dock_disable_texture ();
 	}
@@ -148,7 +169,7 @@
 		pLabel = &pRenderer->pLabels[iNumValue];
 		if (pLabel->iTexture != 0)
 		{
-			double f = MIN (pLabel->param.fWidth * pRenderer->iWidth / pLabel->iTextWidth, pLabel->param.fHeight * pRenderer->iHeight / pLabel->iTextHeight);  // on garde le ratio du texte.
+			double f = MIN (pLabel->param.fWidth * iWidth / pLabel->iTextWidth, pLabel->param.fHeight * iHeight / pLabel->iTextHeight);  // on garde le ratio du texte.
 			w = pLabel->iTextWidth * f;
 			h = pLabel->iTextHeight * f;
 			dw = w & 1;
@@ -159,8 +180,8 @@
 			_cairo_dock_apply_current_texture_at_size_with_offset (
 				w + dw,
 				h + dh,
-				pLabel->param.fX * pRenderer->iWidth,
-				pLabel->param.fY * pRenderer->iHeight);
+				pLabel->param.fX * iWidth,
+				pLabel->param.fY * iHeight);
 		}
 		_cairo_dock_disable_texture ();
 	}
@@ -184,8 +205,8 @@
 			dh = h & 1;
 			cairo_dock_draw_gl_text_at_position_in_area (pRenderer->cFormatBuffer,
 				pFont,
-				floor (pText->fX * pRenderer->iWidth) + .5*dw,
-				floor (pText->fY * pRenderer->iHeight) + .5*dh,
+				floor (pText->fX * iWidth) + .5*dw,
+				floor (pText->fY * iHeight) + .5*dh,
 				w,
 				h,
 				TRUE);
@@ -194,6 +215,7 @@
 			glColor3f (1.0, 1.0, 1.0);
 		}
 	}
+	glPopMatrix ();
 }
 
 static void _cairo_dock_render_to_texture (CairoDataRenderer *pRenderer, Icon *pIcon, CairoContainer *pContainer)
@@ -203,11 +225,10 @@
 	
 	//\________________ On dessine.
 	glPushMatrix ();
-	if (!pContainer->bIsHorizontal && pRenderer->bRotateWithContainer)
+	if ((pRenderer->iRotateTheme == CD_RENDERER_ROTATE_WITH_CONTAINER && pContainer->bIsHorizontal == CAIRO_DOCK_VERTICAL) || pRenderer->iRotateTheme == CD_RENDERER_ROTATE_YES)
 	{
-		glTranslatef (pRenderer->iWidth/2, pRenderer->iHeight/2, 0.);
 		glRotatef (-90., 0., 0., 1.);
-		glTranslatef (-pRenderer->iHeight/2, -pRenderer->iWidth/2, 0.);
+		pRenderer->bisRotate = TRUE;
 	}
 	
 	glPushMatrix ();
@@ -308,11 +329,12 @@
 	
 	//\________________ On dessine.
 	cairo_save (pCairoContext);
-	if (!pContainer->bIsHorizontal && pRenderer->bRotateWithContainer)
+	if ((pRenderer->iRotateTheme == CD_RENDERER_ROTATE_WITH_CONTAINER && pContainer->bIsHorizontal == CAIRO_DOCK_VERTICAL) || pRenderer->iRotateTheme == CD_RENDERER_ROTATE_YES)
 	{
-		cairo_translate (pCairoContext, pRenderer->iWidth/2, pRenderer->iHeight/2);
+		//cairo_translate (pCairoContext, pRenderer->iWidth/2, pRenderer->iHeight/2);
 		cairo_rotate (pCairoContext, G_PI/2);
-		cairo_translate (pCairoContext, -pRenderer->iHeight/2, -pRenderer->iWidth/2);
+		pRenderer->bisRotate = TRUE;
+		//cairo_translate (pCairoContext, -pRenderer->iHeight/2, -pRenderer->iWidth/2);
 	}
 	
 	cairo_save (pCairoContext);

=== modified file 'src/gldit/cairo-dock-data-renderer.h'
--- src/gldit/cairo-dock-data-renderer.h	2010-12-12 01:39:17 +0000
+++ src/gldit/cairo-dock-data-renderer.h	2011-07-19 16:26:40 +0000
@@ -36,6 +36,13 @@
 * To remove the Data Renderer from an icon, use /ref cairo_dock_remove_data_renderer_on_icon.
 */
 
+typedef enum _RendererRotateTheme {
+	CD_RENDERER_ROTATE_NO=0,
+	CD_RENDERER_ROTATE_WITH_CONTAINER,
+	CD_RENDERER_ROTATE_YES,
+	CD_RENDERER_NB_ROTATE
+	} RendererRotateTheme; 
+
 //
 // Structures
 //
@@ -66,6 +73,8 @@
 	gboolean bUpdateMinMax;
 	/// whether to write the values on the icon. [false by default].
 	gboolean bWriteValues;
+	/// an option to rotate applet, no, automatic or always.
+	RendererRotateTheme iRotateTheme;
 	/// time needed to update to the new values. The update is smooth in OpenGL mode. [0 by default]
 	gint iLatencyTime;
 	/// a function used to format the values into a string. Only useful if you make te DataRenderer write the values [optionnal, by default the values are formatted with 2 decimals].
@@ -156,6 +165,10 @@
 	gboolean bCanRenderValueAsText;
 	/// set to TRUE <=> the drawing will be rotated if the container is vertical.
 	gboolean bRotateWithContainer;
+	/// an option to rotate applet, no, automatic or always.
+	RendererRotateTheme iRotateTheme;
+	/// set to TRUE <=> the theme images are rotated 90° clockwise.
+	gboolean bisRotate;
 	/// an optionnal list of labels to be displayed on the Data Renderer to indicate the nature of each value. Same size as the set of values.
 	CairoDataRendererText *pLabels;
 	/// an optionnal list of emblems to be displayed on the Data Renderer to indicate the nature of each value. Same size as the set of values.
@@ -220,6 +233,7 @@
 
 void cairo_dock_render_overlays_to_texture (CairoDataRenderer *pRenderer, int iNumValue);
 
+void cairo_data_renderer_get_size (CairoDataRenderer *pRenderer, gint *iWidth, gint *iHeight);
 
 ///
 /// Structure Access

=== modified file 'src/gldit/cairo-dock-draw-opengl.h'
--- src/gldit/cairo-dock-draw-opengl.h	2010-12-31 01:33:30 +0000
+++ src/gldit/cairo-dock-draw-opengl.h	2011-07-19 16:26:40 +0000
@@ -156,6 +156,13 @@
 	glTexCoord2f(1., 1.); glVertex3f( .5*w, -.5*h, 0.);\
 	glTexCoord2f(0., 1.); glVertex3f(-.5*w, -.5*h, 0.);\
 	glEnd(); } while (0)
+#define _cairo_dock_apply_current_texture_at_size_crop(iTexture, w, h, ratio) do { \
+	glBegin(GL_QUADS);\
+	glTexCoord2f(0., 1-ratio); glVertex3f(-.5*w,  (ratio -.5)*h, 0.);\
+	glTexCoord2f(1., 1-ratio); glVertex3f( .5*w,  (ratio -.5)*h, 0.);\
+	glTexCoord2f(1., 1); glVertex3f( .5*w, -.5*h, 0.);\
+	glTexCoord2f(0., 1); glVertex3f(-.5*w, -.5*h, 0.);\
+	glEnd(); } while (0)
 #define _cairo_dock_apply_current_texture_at_size_with_offset(w, h, x, y) do { \
 	glBegin(GL_QUADS);\
 	glTexCoord2f(0., 0.); glVertex3f(x-.5*w, y+.5*h, 0.);\

=== modified file 'src/implementations/cairo-dock-gauge.c'
--- src/implementations/cairo-dock-gauge.c	2011-05-08 00:08:01 +0000
+++ src/implementations/cairo-dock-gauge.c	2011-07-19 16:26:40 +0000
@@ -45,6 +45,16 @@
 	GLuint iTexture;
 } GaugeImage;
 
+// Effect applied on Indicator image.
+typedef enum {
+	CD_GAUGE_EFFECT_NONE=0,
+	CD_GAUGE_EFFECT_CROP,
+	CD_GAUGE_EFFECT_STRETCH,
+	CD_GAUGE_EFFECT_ZOOM,
+	CD_GAUGE_EFFECT_FADE,
+	CD_GAUGE_NB_EFFECTS
+	} GaugeIndicatorEffect; 
+
 typedef struct {
 	// needle
 	gdouble posX, posY;
@@ -65,14 +75,24 @@
 	CairoDataRendererEmblemParam emblem;
 	// label text zone
 	CairoDataRendererTextParam labelZone;
+	// indicator image effect
+	GaugeIndicatorEffect iEffect;
 } GaugeIndicator;
 
+// Multi gauge position options.
+typedef enum {
+	CD_GAUGE_MULTI_DISPLAY_SCATTERED=0,
+	CD_GAUGE_MULTI_DISPLAY_SHARED,
+	CD_GAUGE_NB_MULTI_DISPLAY
+	} GaugeMultiDisplay; 
+
 typedef struct {
 	CairoDataRenderer dataRenderer;
 	gchar *cThemeName;
 	GaugeImage *pImageBackground;
 	GaugeImage *pImageForeground;
 	GList *pIndicatorList;
+	GaugeMultiDisplay iMultiDisplay;
 } Gauge;
 
 
@@ -250,6 +270,11 @@
 			xmlFree (cNodeContent);
 			xmlFree (cAttribute);
 		}
+		else if(xmlStrcmp (pGaugeNode->name, (const xmlChar *) "multi_display") == 0)
+		{
+			cNodeContent = xmlNodeGetContent (pGaugeNode);
+			pGauge->iMultiDisplay = atoi (cNodeContent);
+		}
 		else if (xmlStrcmp (pGaugeNode->name, (const xmlChar *) "indicator") == 0)
 		{
 			if (pRenderer->iRank == 0)
@@ -368,6 +393,8 @@
 					pGaugeIndicator->iNeedleRealHeight = atoi (cNodeContent);
 					pGaugeIndicator->iNeedleOffsetY = .5 * pGaugeIndicator->iNeedleRealHeight;
 				}
+				else if(xmlStrcmp (pGaugeSubNode->name, (const xmlChar *) "effect") == 0)
+					pGaugeIndicator->iEffect = atoi (cNodeContent);
 				else if(xmlStrcmp (pGaugeSubNode->name, (const xmlChar *) "file") == 0)
 				{
 					ap = xmlHasProp(pGaugeSubNode, "key");
@@ -620,11 +647,33 @@
 	g_return_if_fail (iNumImage < pGaugeIndicator->iNbImages);
 	
 	GaugeImage *pGaugeImage = &pGaugeIndicator->pImageList[iNumImage];
-	int iWidth = pGauge->dataRenderer.iWidth, iHeight = pGauge->dataRenderer.iHeight;
+	int iWidth, iHeight;
+	cairo_data_renderer_get_size (CAIRO_DATA_RENDERER (pGauge), &iWidth, &iHeight);
 	
 	if (pGaugeImage->iTexture != 0)
 	{
-		_cairo_dock_apply_texture_at_size (pGaugeImage->iTexture, iWidth, iHeight);
+		glBindTexture (GL_TEXTURE_2D, pGaugeImage->iTexture);\
+		switch (pGaugeIndicator->iEffect)
+		{
+			case CD_GAUGE_EFFECT_CROP :
+				_cairo_dock_apply_current_texture_at_size_crop (pGaugeImage->iTexture, iWidth, iHeight, fValue);
+			break;
+
+			case CD_GAUGE_EFFECT_STRETCH :
+				_cairo_dock_apply_current_texture_portion_at_size_with_offset (0. , 0., 1., 1., iWidth, iHeight * fValue, 0., iHeight * (fValue - 1)/2);
+			break;
+
+			case CD_GAUGE_EFFECT_ZOOM :
+				_cairo_dock_apply_current_texture_portion_at_size_with_offset (0. , 0., 1., 1., iWidth * fValue, iHeight * fValue, 0., 0.);
+			break;
+
+			case CD_GAUGE_EFFECT_FADE :
+				_cairo_dock_set_alpha(fValue); // no break, we need the default texture draw
+
+			default :
+				_cairo_dock_apply_current_texture_at_size (iWidth, iHeight);
+			break;
+		}
 	}
 }
 static void _draw_gauge_needle_opengl (Gauge *pGauge, GaugeIndicator *pGaugeIndicator, double fValue)
@@ -657,7 +706,10 @@
 	_cairo_dock_set_blend_pbuffer ();  // ceci reste un mystere...
 	_cairo_dock_set_alpha (1.);
 	
-	int iWidth = pGauge->dataRenderer.iWidth, iHeight = pGauge->dataRenderer.iHeight;
+	CairoDataRenderer *pRenderer = CAIRO_DATA_RENDERER (pGauge);
+	CairoDataToRenderer *pData = cairo_data_renderer_get_data (pRenderer);
+	int iWidth, iHeight;
+	cairo_data_renderer_get_size (pRenderer, &iWidth, &iHeight);
 	GaugeImage *pGaugeImage;
 	
 	//\________________ On affiche le fond.
@@ -673,8 +725,6 @@
 	GList *pValueList;
 	double fValue;
 	GaugeIndicator *pIndicator;
-	CairoDataRenderer *pRenderer = CAIRO_DATA_RENDERER (pGauge);
-	CairoDataToRenderer *pData = cairo_data_renderer_get_data (pRenderer);
 	int i;
 	for (i = iDataOffset, pIndicatorElement = pGauge->pIndicatorList; i < pData->iNbValues && pIndicatorElement != NULL; i++, pIndicatorElement = pIndicatorElement->next)
 	{
@@ -713,36 +763,56 @@
 	CairoDataToRenderer *pData = cairo_data_renderer_get_data (pRenderer);
 	int iNbDrawings = (int) ceil (1. * pData->iNbValues / pRenderer->iRank);
 	int i, iDataOffset = 0;
+	float ratio = (float) 1 / iNbDrawings;
+	int iWidth, iHeight;
+	cairo_data_renderer_get_size (pRenderer, &iWidth, &iHeight);
+	gboolean bDisplay = TRUE;
 	for (i = 0; i < iNbDrawings; i ++)
 	{
 		if (iNbDrawings > 1)  // on va dessiner la jauges plusieurs fois, la 1ere en grand et les autres en petit autour.
 		{
 			glPushMatrix ();
-			if (i == 0)  /// tester avec 1/2, 1/2
-			{
-				glTranslatef (-pRenderer->iWidth / 6, pRenderer->iHeight / 6, 0.);
-				glScalef (2./3, 2./3, 1.);
-			}
-			else if (i == 1)
-			{
-				glTranslatef (pRenderer->iWidth / 3, - pRenderer->iHeight / 3, 0.);
-				glScalef (1./3, 1./3, 1.);
-			}
-			else if (i == 2)
-			{
-				glTranslatef (pRenderer->iWidth / 3, pRenderer->iHeight / 3, 0.);
-				glScalef (1./3, 1./3, 1.);
-			}
-			else if (i == 3)
-			{
-				glTranslatef (-pRenderer->iWidth / 3, -pRenderer->iHeight / 3, 0.);
-				glScalef (1./3, 1./3, 1.);
-			}
-			else  // 5 valeurs faut pas pousser non plus.
-				break ;
+			switch (pGauge->iMultiDisplay)
+			{
+				case CD_GAUGE_MULTI_DISPLAY_SHARED :
+					/** box positions : 
+					* change axis to left border : -w / 2
+					* move to box #i : w * i / n
+					* move 1/2 box left : -w / 2n 
+					* =w(-0.5 +i/n -1/2n)
+					*/
+					glTranslatef (iWidth * (i * ratio - 0.5 + ratio / 2), 0., 0.);
+					glScalef (ratio, 1., 1.);
+					break;
+	
+				case CD_GAUGE_MULTI_DISPLAY_SCATTERED :
+					if (i == 0)  /// tester avec 1/2, 1/2
+					{
+						glTranslatef (-iWidth / 6, iHeight / 6, 0.);
+						glScalef (2./3, 2./3, 1.);
+					}
+					else if (i == 1)
+					{
+						glTranslatef (iWidth / 3, - iHeight / 3, 0.);
+						glScalef (1./3, 1./3, 1.);
+					}
+					else if (i == 2)
+					{
+						glTranslatef (iWidth / 3, iHeight / 3, 0.);
+						glScalef (1./3, 1./3, 1.);
+					}
+					else if (i == 3)
+					{
+						glTranslatef (-iWidth / 3, -iHeight / 3, 0.);
+						glScalef (1./3, 1./3, 1.);
+					}
+					else  // 5 valeurs faut pas pousser non plus.
+						bDisplay = FALSE;
+			}
 		}
 		
-		cairo_dock_draw_one_gauge_opengl (pGauge, iDataOffset);
+		if (bDisplay)
+			cairo_dock_draw_one_gauge_opengl (pGauge, iDataOffset);
 		
 		if (iNbDrawings > 1)
 			glPopMatrix ();


Follow ups