[gtk-engines] hc: Replace GDK drawing API with cairo



commit b4769269cf0f4d49d4c883a7a533d046589f46dc
Author: Florian Müllner <fmuellner gnome org>
Date:   Thu Aug 12 11:30:39 2010 +0200

    hc: Replace GDK drawing API with cairo
    
    The GDK drawing API was deprecated/removed.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=626678
    
    Reviewed-by: Benjamin Otte <otte redhat com>

 engines/hc/src/hc-style.c        |  133 +++-----------------------------------
 engines/hc/src/hc_gtk2_drawing.h |   12 ----
 engines/hc/src/hc_gtk2_engine.c  |   37 -----------
 3 files changed, 9 insertions(+), 173 deletions(-)
---
diff --git a/engines/hc/src/hc-style.c b/engines/hc/src/hc-style.c
index 8e959fc..8b7d248 100644
--- a/engines/hc/src/hc-style.c
+++ b/engines/hc/src/hc-style.c
@@ -888,19 +888,21 @@ hc_draw_layout (GtkStyle        *style,
 		gint             y,
 		PangoLayout     *layout)
 {
-	GdkGC *gc;
+	cairo_t *cr;
 
 	CHECK_ARGS
 
-	gc = use_text ? style->text_gc[state_type] : style->fg_gc[state_type];
+	cr = ge_gdk_drawable_to_cairo (window, area);
 
-	if (area)
-		gdk_gc_set_clip_rectangle (gc, area);
+	if (use_text)
+		gdk_cairo_set_source_color (cr, &style->text[state_type]);
+	else
+		gdk_cairo_set_source_color (cr, &style->fg[state_type]);
 
-	gdk_draw_layout (window, gc, x, y, layout);
+	ge_cairo_transform_for_layout (cr, layout, x, y);
+	pango_cairo_show_layout (cr, layout);
 
-	if (area)
-		gdk_gc_set_clip_rectangle (gc, NULL);
+	cairo_destroy (cr);
 }
 
 void
@@ -1286,120 +1288,3 @@ hc_draw_diamond (GtkStyle      *style,
 
 	cairo_destroy(cr);
 }
-
-void
-hc_draw_polygon (GtkStyle      *style,
-		 GdkWindow     *window,
-		 GtkStateType   state_type,
-		 GtkShadowType  shadow_type,
-		 GdkRectangle  *area,
-		 GtkWidget     *widget,
-		 const gchar   *detail,
-		 GdkPoint      *points,
-		 gint           npoints,
-		 gboolean       fill)
-{
-	HcStyle *hc_style = HC_STYLE (style);
-
-	static const gdouble pi_over_4 = G_PI_4;
-	static const gdouble pi_3_over_4 = G_PI_4 * 3;
-	
-	CairoColor           *color1;
-	CairoColor           *color2;
-	CairoColor           *color3;
-	CairoColor           *color4;
-	gdouble            angle;
-	int                xadjust;
-	int                yadjust;
-	int                i;
-	cairo_t           *cr;
-
-	g_return_if_fail(style != NULL);
-	g_return_if_fail(window != NULL);
-	g_return_if_fail(points != NULL);
-	
-	switch (shadow_type) {
-	case GTK_SHADOW_IN:
-		color1 = &hc_style->color_cube.light[state_type];
-		color2 = &hc_style->color_cube.dark[state_type];
-		color3 = &hc_style->color_cube.light[state_type];
-		color4 = &hc_style->color_cube.dark[state_type];
-		break;
-	case GTK_SHADOW_ETCHED_IN:
-		color1 = &hc_style->color_cube.light[state_type];
-		color2 = &hc_style->color_cube.dark[state_type];
-		color3 = &hc_style->color_cube.dark[state_type];
-		color4 = &hc_style->color_cube.light[state_type];
-		break;
-	case GTK_SHADOW_OUT:
-		color1 = &hc_style->color_cube.dark[state_type];
-		color2 = &hc_style->color_cube.light[state_type];
-		color3 = &hc_style->color_cube.dark[state_type];
-		color4 = &hc_style->color_cube.light[state_type];
-		break;
-	case GTK_SHADOW_ETCHED_OUT:
-		color1 = &hc_style->color_cube.dark[state_type];
-		color2 = &hc_style->color_cube.light[state_type];
-		color3 = &hc_style->color_cube.light[state_type];
-		color4 = &hc_style->color_cube.dark[state_type];
-		break;
-	default:
-		return;
-	}
-
-	cr = ge_gdk_drawable_to_cairo (window, area);
-	
-	if (fill)
-		ge_cairo_polygon(cr, &hc_style->color_cube.bg[state_type], points, npoints);
-	
-	npoints--;
-	
-	for (i = 0; i < npoints; i++) {
-		if ((points[i].x == points[i + 1].x) &&
-		    (points[i].y == points[i + 1].y)) {
-			angle = 0;
-		} else {
-			angle = atan2(points[i + 1].y - points[i].y,
-				      points[i + 1].x - points[i].x);
-		}
-		
-		if ((angle > -pi_3_over_4) && (angle < pi_over_4)) {
-			if (angle > -pi_over_4) {
-				xadjust = 0;
-				yadjust = 1;
-			} else {
-				xadjust = 1;
-				yadjust = 0;
-			}
-
-			ge_cairo_line(cr, color1,
-				      points[i].x - xadjust, 
-				      points[i].y - yadjust,
-				      points[i + 1].x - xadjust, 
-				      points[i + 1].y - yadjust);
-			ge_cairo_line(cr, color3,
-				      points[i].x, points[i].y,
-				      points[i + 1].x, points[i + 1].y);
-		}
-		else {
-			if ((angle < -pi_3_over_4) || (angle > pi_3_over_4)) {
-				xadjust = 0;
-				yadjust = 1;
-			} else {
-				xadjust = 1;
-				yadjust = 0;
-			}
-			
-			ge_cairo_line(cr, color4,
-				      points[i].x + xadjust, 
-				      points[i].y + yadjust,
-				      points[i + 1].x + xadjust, 
-				      points[i + 1].y + yadjust);
-			ge_cairo_line(cr, color2,
-				      points[i].x, points[i].y,
-				      points[i + 1].x, points[i + 1].y);
-		}
-	}
-
-	cairo_destroy(cr);
-}
diff --git a/engines/hc/src/hc_gtk2_drawing.h b/engines/hc/src/hc_gtk2_drawing.h
index 7ff44f1..692b9b6 100644
--- a/engines/hc/src/hc_gtk2_drawing.h
+++ b/engines/hc/src/hc_gtk2_drawing.h
@@ -258,15 +258,3 @@ hc_draw_diamond (GtkStyle      *style,
 		 gint           width,
 		 gint           height);
 
-GE_INTERNAL void
-hc_draw_polygon (GtkStyle      *style,
-		 GdkWindow     *window,
-		 GtkStateType   state_type,
-		 GtkShadowType  shadow_type,
-		 GdkRectangle  *area,
-		 GtkWidget     *widget,
-		 const gchar   *detail,
-		 GdkPoint      *points,
-		 gint           npoints,
-		 gboolean       fill);
-
diff --git a/engines/hc/src/hc_gtk2_engine.c b/engines/hc/src/hc_gtk2_engine.c
index 1d6a107..4962e20 100644
--- a/engines/hc/src/hc_gtk2_engine.c
+++ b/engines/hc/src/hc_gtk2_engine.c
@@ -222,10 +222,6 @@ static void
 hc_style_realize (GtkStyle *style)
 {
   HcStyle *hc_style = HC_STYLE (style);
-
-  GdkGCValues gc_values;
-  GdkGCValuesMask gc_values_mask;
-  
   gint i;
 
   for (i = 0; i < 5; i++)
@@ -257,14 +253,6 @@ hc_style_realize (GtkStyle *style)
   style->white.blue = 0xffff;
   gdk_colormap_alloc_color (style->colormap, &style->white, FALSE, TRUE);
 
-  gc_values_mask = GDK_GC_FOREGROUND;
-  
-  gc_values.foreground = style->black;
-  style->black_gc = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
-  
-  gc_values.foreground = style->white;
-  style->white_gc = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
-  
   for (i = 0; i < 5; i++)
     {
       if (!gdk_colormap_alloc_color (style->colormap, &style->fg[i], FALSE, TRUE))
@@ -291,30 +279,6 @@ hc_style_realize (GtkStyle *style)
       if (!gdk_colormap_alloc_color (style->colormap, &style->text_aa[i], FALSE, TRUE))
         g_warning ("unable to allocate color: ( %d %d %d )",
                    style->text_aa[i].red, style->text_aa[i].green, style->text_aa[i].blue);
-      
-      gc_values.foreground = style->fg[i];
-      style->fg_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
-      
-      gc_values.foreground = style->bg[i];
-      style->bg_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
-      
-      gc_values.foreground = style->light[i];
-      style->light_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
-      
-      gc_values.foreground = style->dark[i];
-      style->dark_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
-      
-      gc_values.foreground = style->mid[i];
-      style->mid_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
-      
-      gc_values.foreground = style->text[i];
-      style->text_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
-      
-      gc_values.foreground = style->base[i];
-      style->base_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
-
-      gc_values.foreground = style->text_aa[i];
-      style->text_aa_gc[i] = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
     }
 
   ge_gtk_style_to_cairo_color_cube (style, &hc_style->color_cube);
@@ -377,7 +341,6 @@ hc_style_class_init (HcStyleClass *klass)
   style_class->draw_vline = hc_draw_vline; 
   style_class->draw_expander = hc_draw_expander;
   style_class->draw_diamond = hc_draw_diamond;
-  style_class->draw_polygon = hc_draw_polygon;
 }
 
 static void



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]