[gtk+] Added internal GdkRGBA support for GtkTextTag::paragraph-background-rgba



commit cefb95011000ad12d9f2cc71c6b9175e1d9746dd
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date:   Mon Feb 14 15:27:42 2011 +0900

    Added internal GdkRGBA support for GtkTextTag::paragraph-background-rgba
    
    Added the remaining implementation bits for rendering paragraph backgrounds
    with rgba values and updated the test case.

 gtk/gtktextattributes.c |    8 +++++
 gtk/gtktextdisplay.c    |    6 ++--
 gtk/gtktextlayout.c     |   10 +++++-
 gtk/gtktextlayout.h     |    2 +-
 tests/testtextview.c    |   79 ++++++++++++++++++++++++----------------------
 5 files changed, 62 insertions(+), 43 deletions(-)
---
diff --git a/gtk/gtktextattributes.c b/gtk/gtktextattributes.c
index 67c3db3..8aca3b8 100644
--- a/gtk/gtktextattributes.c
+++ b/gtk/gtktextattributes.c
@@ -279,11 +279,19 @@ _gtk_text_attributes_fill_from_tags (GtkTextAttributes *dest,
 	    {
 	      gdk_rgba_free (dest->pg_bg_rgba);
 	      dest->pg_bg_rgba = NULL;
+	    }
 
+	  if (dest->pg_bg_color)
+	    {
+	      gdk_color_free (dest->pg_bg_color);
+	      dest->pg_bg_color = NULL;
 	    }
 
 	  if (vals->pg_bg_rgba)
 	    dest->pg_bg_rgba = gdk_rgba_copy (vals->pg_bg_rgba);
+
+	  if (vals->pg_bg_color)
+	    dest->pg_bg_color = gdk_color_copy (vals->pg_bg_color);
         }
 
       if (vals->font)
diff --git a/gtk/gtktextdisplay.c b/gtk/gtktextdisplay.c
index dea9ae4..6c2eddf 100644
--- a/gtk/gtktextdisplay.c
+++ b/gtk/gtktextdisplay.c
@@ -649,13 +649,13 @@ render_para (GtkTextRenderer    *text_renderer,
         }
       else
         {
-          if (line_display->pg_bg_color)
+          if (line_display->pg_bg_rgba)
             {
               cairo_t *cr = text_renderer->cr;
 
               cairo_save (cr);
-
-              gdk_cairo_set_source_color (cr, line_display->pg_bg_color);
+ 
+	      gdk_cairo_set_source_rgba (text_renderer->cr, line_display->pg_bg_rgba);
               cairo_rectangle (cr, 
                                line_display->left_margin, selection_y,
                                screen_width, selection_height);
diff --git a/gtk/gtktextlayout.c b/gtk/gtktextlayout.c
index f19ab61..7d48a3d 100644
--- a/gtk/gtktextlayout.c
+++ b/gtk/gtktextlayout.c
@@ -1408,7 +1408,12 @@ set_para_values (GtkTextLayout      *layout,
   if (style->pg_bg_color)
     display->pg_bg_color = gdk_color_copy (style->pg_bg_color);
   else
-    display->pg_bg_color = NULL;  
+    display->pg_bg_color = NULL;
+
+  if (style->pg_bg_rgba)
+    display->pg_bg_rgba = gdk_rgba_copy (style->pg_bg_rgba);
+  else
+    display->pg_bg_rgba = NULL;
 }
 
 static PangoAttribute *
@@ -2533,6 +2538,9 @@ gtk_text_layout_free_line_display (GtkTextLayout      *layout,
       if (display->pg_bg_color)
         gdk_color_free (display->pg_bg_color);
 
+      if (display->pg_bg_rgba)
+        gdk_rgba_free (display->pg_bg_rgba);
+
       g_free (display);
     }
 }
diff --git a/gtk/gtktextlayout.h b/gtk/gtktextlayout.h
index 09ca01c..78ec750 100644
--- a/gtk/gtktextlayout.h
+++ b/gtk/gtktextlayout.h
@@ -264,7 +264,7 @@ struct _GtkTextLineDisplay
   guint cursor_at_line_end : 1;
   guint size_only : 1;
 
-  gpointer padding1;
+  GdkRGBA *pg_bg_rgba;
 };
 
 #ifdef GTK_COMPILATION
diff --git a/tests/testtextview.c b/tests/testtextview.c
index 2a7701f..a8b5c70 100644
--- a/tests/testtextview.c
+++ b/tests/testtextview.c
@@ -23,6 +23,9 @@ create_tags (GtkTextBuffer *buffer)
   gtk_text_buffer_create_tag (buffer, "semi_red_background",
                               "background", "rgba(255,0,0,0.5)", NULL);
 
+  gtk_text_buffer_create_tag (buffer, "semi_orange_paragraph_background",
+                              "paragraph-background", "rgba(255,165,0,0.5)", NULL);
+
   gtk_text_buffer_create_tag (buffer, "word_wrap",
                               "wrap_mode", GTK_WRAP_WORD, NULL);
 }
@@ -31,8 +34,9 @@ create_tags (GtkTextBuffer *buffer)
 static void
 insert_text (GtkTextBuffer *buffer)
 {
-  GtkTextIter iter;
-  GtkTextIter start, end;
+  GtkTextIter  iter;
+  GtkTextIter  start, end;
+  GtkTextMark *para_start;
 
   /* get start of buffer; each insertion will revalidate the
    * iterator to point to just after the inserted text.
@@ -59,33 +63,42 @@ insert_text (GtkTextBuffer *buffer)
 					    "semi_red_background",
 					    "x-large",
 					    NULL);
-  gtk_text_buffer_insert (buffer, &iter, ".", -1);
+  gtk_text_buffer_insert (buffer, &iter, ".\n\n", -1);
+
+  /* Store the beginning of the other paragraph */
+  para_start = gtk_text_buffer_create_mark (buffer, "para_start", &iter, TRUE);
+
+  gtk_text_buffer_insert (buffer, &iter,
+      "Paragraph background colors can also be set with rgba color values .\n", -1);
+
+  gtk_text_buffer_insert (buffer, &iter, "For instance, you can have ", -1);
+  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
+                                            "bold translucent blue text", -1,
+                                            "bold", 
+					    "semi_blue_foreground",
+					    "x-large",
+					    NULL);
+
+  gtk_text_buffer_insert (buffer, &iter, ", or ", -1);
+
+  gtk_text_buffer_insert (buffer, &iter, ", ", -1);
+  gtk_text_buffer_insert_with_tags_by_name (buffer, &iter,
+                                            "italic text with translucent red background", -1,
+                                            "italic", 
+					    "semi_red_background",
+					    "x-large",
+					    NULL);
+
+  gtk_text_buffer_insert (buffer, &iter, " all rendered onto a translucent orange paragraph background.\n", -1);
 
-  /* Apply word_wrap tag to whole buffer */
   gtk_text_buffer_get_bounds (buffer, &start, &end);
-  gtk_text_buffer_apply_tag_by_name (buffer, "word_wrap", &start, &end);
-}
 
+  gtk_text_buffer_get_iter_at_mark (buffer, &iter, para_start);
+  gtk_text_buffer_apply_tag_by_name (buffer, "semi_orange_paragraph_background", &iter, &end);
 
-static cairo_pattern_t *
-get_pattern (void)
-{
-  static cairo_pattern_t *static_pattern = NULL;
-
-  if (!static_pattern)
-    {
-      cairo_surface_t *surface = 
-	cairo_image_surface_create_from_png ("gradient1.png");
-
-      if (surface)
-	{
-	  static_pattern = cairo_pattern_create_for_surface (surface);
-	  cairo_pattern_set_extend (static_pattern, CAIRO_EXTEND_REFLECT);
-	}
-      else 
-	g_warning ("Failed to create surface for gradient1.png\n");
-    }
-  return static_pattern;
+  /* Apply word_wrap tag to whole buffer */
+  gtk_text_buffer_get_bounds (buffer, &start, &end);
+  gtk_text_buffer_apply_tag_by_name (buffer, "word_wrap", &start, &end);
 }
 
 static void
@@ -98,26 +111,14 @@ draw_background (GtkWidget *widget, cairo_t *cr)
 
   cairo_save (cr);
 
-#if 0
-  pat = cairo_pattern_create_linear (0.0, 0.0,  30.0, 30.0);
+  pat = cairo_pattern_create_linear (0.0, 0.0,  allocation.width, allocation.height);
   cairo_pattern_add_color_stop_rgba (pat, 1, 0, 0, 0, 1);
   cairo_pattern_add_color_stop_rgba (pat, 0, 1, 1, 1, 1);
-  cairo_pattern_set_extend (pat, CAIRO_EXTEND_REPEAT);
   cairo_rectangle (cr, 0, 0, allocation.width, allocation.height);
   cairo_set_source (cr, pat);
   cairo_fill (cr);
   cairo_pattern_destroy (pat);
 
-#else
-
-  if (get_pattern ())
-    {
-      cairo_rectangle (cr, 0, 0, allocation.width, allocation.height);
-      cairo_set_source (cr, get_pattern ());
-      cairo_fill (cr);
-    }
-#endif
-
   cairo_restore (cr);
 }
 
@@ -133,6 +134,8 @@ main (int argc, char **argv)
   textview = gtk_text_view_new ();
   buffer   = gtk_text_view_get_buffer (GTK_TEXT_VIEW (textview));
 
+  gtk_window_set_default_size (GTK_WINDOW (window), 400, -1);
+
   create_tags (buffer);
   insert_text (buffer);
   



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