[gtk+/rendering-cleanup: 29/30] textview: API: change gtk_text_layout_draw() to take a cairo_t



commit 122f85913a45fa71a82e17639c537cb75c3d4726
Author: Benjamin Otte <otte redhat com>
Date:   Sun Aug 15 19:41:51 2010 +0200

    textview: API: change gtk_text_layout_draw() to take a cairo_t
    
    This simplifies the API a lot and allows more magic to happen later.

 gtk/gtktextdisplay.c |   44 ++++++++++++--------------------------------
 gtk/gtktextdisplay.h |   16 +++-------------
 gtk/gtktextutil.c    |   12 ++++++------
 gtk/gtktextview.c    |   18 ++++++++++++------
 4 files changed, 33 insertions(+), 57 deletions(-)
---
diff --git a/gtk/gtktextdisplay.c b/gtk/gtktextdisplay.c
index 5f79ce4..41c53fe 100644
--- a/gtk/gtktextdisplay.c
+++ b/gtk/gtktextdisplay.c
@@ -789,22 +789,9 @@ get_text_renderer (void)
 void
 gtk_text_layout_draw (GtkTextLayout *layout,
                       GtkWidget *widget,
-                      GdkDrawable *drawable,
-		      gpointer     cursor_gc,
-                      /* Location of the drawable
-                         in layout coordinates */
-                      gint x_offset,
-                      gint y_offset,
-                      /* Region of the layout to
-                         render */
-                      gint x,
-                      gint y,
-                      gint width,
-                      gint height,
-                      /* widgets to expose */
+                      cairo_t *cr,
                       GList **widgets)
 {
-  GdkRectangle clip;
   gint current_y;
   GSList *cursor_list;
   GtkTextRenderer *text_renderer;
@@ -813,27 +800,21 @@ gtk_text_layout_draw (GtkTextLayout *layout,
   GSList *line_list;
   GSList *tmp_list;
   GList *tmp_widgets;
-  cairo_t *cr;
+  double x, y, width, height;
   
   g_return_if_fail (GTK_IS_TEXT_LAYOUT (layout));
   g_return_if_fail (layout->default_style != NULL);
   g_return_if_fail (layout->buffer != NULL);
-  g_return_if_fail (drawable != NULL);
-  g_return_if_fail (width >= 0);
-  g_return_if_fail (height >= 0);
+  g_return_if_fail (cr != NULL);
 
-  if (width == 0 || height == 0)
-    return;
+  cairo_clip_extents (cr, &x, &y, &width, &height);
 
-  line_list =  gtk_text_layout_get_lines (layout, y + y_offset, y + y_offset + height, &current_y);
-  current_y -= y_offset;
+  line_list =  gtk_text_layout_get_lines (layout, y, y + height, &current_y);
 
   if (line_list == NULL)
     return; /* nothing on the screen */
 
-  cr = gdk_cairo_create (drawable);
-  cairo_rectangle (cr, x, y, width, height);
-  cairo_clip (cr);
+  cairo_save (cr);
 
   gdk_cairo_set_source_color (cr, &widget->style->text[widget->state]);
 
@@ -893,8 +874,7 @@ gtk_text_layout_draw (GtkTextLayout *layout,
             }
 
           render_para (text_renderer, line_display,
-                       - x_offset,
-                       current_y,
+                       0, current_y,
                        selection_start_index, selection_end_index);
 
           /* We paint the cursors last, because they overlap another chunk
@@ -929,14 +909,14 @@ gtk_text_layout_draw (GtkTextLayout *layout,
  		    dir = (dir == GTK_TEXT_DIR_RTL) ? GTK_TEXT_DIR_LTR : GTK_TEXT_DIR_RTL;
  		}
  
- 	      cursor_location.x = line_display->x_offset + cursor->x - x_offset;
+ 	      cursor_location.x = line_display->x_offset + cursor->x;
  	      cursor_location.y = current_y + line_display->top_margin + cursor->y;
  	      cursor_location.width = 0;
  	      cursor_location.height = cursor->height;
 
-	      gtk_draw_insertion_cursor (widget, drawable, &clip, &cursor_location,
-					 cursor->is_strong,
-					 dir, have_strong && have_weak);
+	      gtk_cairo_draw_insertion_cursor (widget, cr, &cursor_location,
+                                               cursor->is_strong,
+                                               dir, have_strong && have_weak);
 
               cursor_list = cursor_list->next;
             }
@@ -959,7 +939,7 @@ gtk_text_layout_draw (GtkTextLayout *layout,
       g_list_free (tmp_widgets);
     }
 
-  cairo_destroy (cr);
+  cairo_restore (cr);
 
   g_slist_free (line_list);
 }
diff --git a/gtk/gtktextdisplay.h b/gtk/gtktextdisplay.h
index 3b6e96c..d7127e3 100644
--- a/gtk/gtktextdisplay.h
+++ b/gtk/gtktextdisplay.h
@@ -87,23 +87,13 @@ G_BEGIN_DECLS
 
 /* The drawable should be pre-initialized to your preferred background.
  * widget            - Widget to grab some style info from
- * drawable          - Drawable to render to
- * cursor_gc         - Graphics context to use for cursor
- * x_offset/y_offset - Position of the drawable in layout coordinates
- * x/y/width/height  - Region of the layout to render. x,y must be inside
- *                     the drawable.
+ * cr                - Context to render to, matrix set so that (0, 0)
+ *                     is the top left of the layout
  * widgets           - list of widgets that need exposing
  */
 void gtk_text_layout_draw (GtkTextLayout        *layout,
                            GtkWidget            *widget,
-                           GdkDrawable          *drawable,
-			   gpointer              cursor_gc,
-                           gint                  x_offset,
-                           gint                  y_offset,
-                           gint                  x,
-                           gint                  y,
-                           gint                  width,
-                           gint                  height,
+                           cairo_t              *cr,
                            GList               **widgets);
 
 
diff --git a/gtk/gtktextutil.c b/gtk/gtktextutil.c
index 6a582dc..08980fe 100644
--- a/gtk/gtktextutil.c
+++ b/gtk/gtktextutil.c
@@ -358,12 +358,12 @@ _gtk_text_util_create_rich_drag_icon (GtkWidget     *widget,
    gdk_cairo_set_source_color (cr, &widget->style->base [gtk_widget_get_state (widget)]);
    cairo_paint (cr);
 
-   gtk_text_layout_draw (layout, widget, drawable,
-                         NULL,
-                         - (1 + DRAG_ICON_LAYOUT_BORDER),
-                         - (1 + DRAG_ICON_LAYOUT_BORDER),
-                         0, 0,
-                         pixmap_width, pixmap_height, NULL);
+   cairo_save (cr);
+
+   cairo_translate (cr, 1 + DRAG_ICON_LAYOUT_BORDER, 1 + DRAG_ICON_LAYOUT_BORDER);
+   gtk_text_layout_draw (layout, widget, cr, NULL);
+
+   cairo_restore (cr);
 
    cairo_set_source_rgb (cr, 0, 0, 0);
    cairo_rectangle (cr, 0.5, 0.5, pixmap_width + 1, pixmap_height + 1);
diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c
index 1446473..5baa390 100644
--- a/gtk/gtktextview.c
+++ b/gtk/gtktextview.c
@@ -4788,6 +4788,7 @@ gtk_text_view_paint (GtkWidget      *widget,
   GtkTextViewPrivate *priv;
   GList *child_exposes;
   GList *tmp_list;
+  cairo_t *cr;
   
   text_view = GTK_TEXT_VIEW (widget);
   priv = text_view->priv;
@@ -4816,16 +4817,21 @@ gtk_text_view_paint (GtkWidget      *widget,
 #endif
 
   child_exposes = NULL;
+
+  cr = gdk_cairo_create (priv->text_window->bin_window);
+
+  gdk_cairo_region (cr, event->region);
+  cairo_clip (cr);
+
+  cairo_translate (cr, -priv->xoffset, -priv->yoffset);
+
   gtk_text_layout_draw (priv->layout,
                         widget,
-                        priv->text_window->bin_window,
-			NULL,
-                        priv->xoffset,
-                        priv->yoffset,
-                        area->x, area->y,
-                        area->width, area->height,
+                        cr,
                         &child_exposes);
 
+  cairo_destroy (cr);
+
   tmp_list = child_exposes;
   while (tmp_list != NULL)
     {



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