[dia] Bug #591525 - emulate color.alpha with gdk_gc_set_stipple()



commit ae91f8e5c636bee6f83af3a0535fb5b7699089c1
Author: Hans Breuer <hans breuer org>
Date:   Sat Aug 22 15:59:35 2009 +0200

    Bug #591525 - emulate color.alpha with gdk_gc_set_stipple()

 app/render_gdk.c     |    9 +++++++++
 lib/diagdkrenderer.c |   24 ++++++++++++++++++++++++
 lib/diagdkrenderer.h |    2 ++
 3 files changed, 35 insertions(+), 0 deletions(-)
---
diff --git a/app/render_gdk.c b/app/render_gdk.c
index ddd7143..f6692dd 100644
--- a/app/render_gdk.c
+++ b/app/render_gdk.c
@@ -209,6 +209,9 @@ draw_pixel_line(DiaRenderer *object,
   
   color_convert(color, &gdkcolor);
   gdk_gc_set_foreground(gc, &gdkcolor);
+  /* reset stippling (alpha emulation) */
+  gdk_gc_set_fill(gc, GDK_SOLID);
+  renderer->current_alpha = 1.0;
   
   gdk_draw_line(renderer->pixmap, gc, x1, y1, x2, y2);
 }
@@ -233,6 +236,9 @@ draw_pixel_rect(DiaRenderer *object,
 
   color_convert(color, &gdkcolor);
   gdk_gc_set_foreground(gc, &gdkcolor);
+  /* reset stippling (alpha emulation) */
+  gdk_gc_set_fill(gc, GDK_SOLID);
+  renderer->current_alpha = 1.0;
 
   gdk_draw_rectangle (renderer->pixmap, gc, FALSE,
 		      x, y,  width, height);
@@ -256,6 +262,9 @@ fill_pixel_rect(DiaRenderer *object,
 
   color_convert(color, &gdkcolor);
   gdk_gc_set_foreground(gc, &gdkcolor);
+  /* reset stippling (alpha emulation) */
+  gdk_gc_set_fill(gc, GDK_SOLID);
+  renderer->current_alpha = 1.0;
 
   gdk_draw_rectangle (renderer->pixmap, gc, TRUE,
 		      x, y,  width, height);
diff --git a/lib/diagdkrenderer.c b/lib/diagdkrenderer.c
index aba7632..46fd068 100644
--- a/lib/diagdkrenderer.c
+++ b/lib/diagdkrenderer.c
@@ -176,6 +176,8 @@ renderer_init(DiaGdkRenderer *renderer, void* p)
   renderer->dot_length = 2;
 
   renderer->highlight_color = NULL;
+  
+  renderer->current_alpha = 1.0;
 }
 
 /** Clean up a renderer object after use.
@@ -272,6 +274,28 @@ renderer_color_convert(DiaGdkRenderer *renderer,
   } else {
     color_convert(col, gdk_col);
   }
+  if (col->alpha != renderer->current_alpha) {
+    if (col->alpha == 1.0)
+      gdk_gc_set_fill(renderer->gc, GDK_SOLID);
+    else {
+      static gchar bits[9][4] = {
+        { 0x00, 0x00, 0x00, 0x00 }, /*   0% */
+	{ 0x20, 0x02, 0x20, 0x02 },
+        { 0x42, 0x24, 0x42, 0x24 }, /*  25% */
+	{ 0x4A, 0xA4, 0x4A, 0xA4 },
+        { 0x5A, 0xA5, 0x5A, 0xA5 }, /*  50% */
+	{ 0xAB, 0xBA, 0xAB, 0xBA },
+        { 0xBE, 0xEB, 0xBE, 0xEB }, /*  75% */
+	{ 0xEF, 0xFE, 0xEF, 0xFE },
+        { 0xFF, 0xFF, 0xFF, 0xFF }, /* 100% */
+      };
+      GdkBitmap *stipple = gdk_bitmap_create_from_data (NULL, bits[(int)(9*col->alpha)], 4, 4);
+      gdk_gc_set_stipple (renderer->gc, stipple);
+      g_object_unref (stipple);
+      gdk_gc_set_fill(renderer->gc, GDK_STIPPLED);
+    }
+    renderer->current_alpha = col->alpha;
+  }
 }
 
 static void 
diff --git a/lib/diagdkrenderer.h b/lib/diagdkrenderer.h
index 144af84..6a853a5 100644
--- a/lib/diagdkrenderer.h
+++ b/lib/diagdkrenderer.h
@@ -41,6 +41,8 @@ struct _DiaGdkRenderer
 
   /** If non-NULL, this rendering is a highlighting with the given color. */
   Color *highlight_color;
+  
+  real   current_alpha;
 };
 
 struct _DiaGdkRendererClass



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