[gimp] app: don't pass "GdkRectangle *draw_area" to gimp_view_renderer_draw()



commit 090a465362ff8158f915aac97b9bb9eb790e478b
Author: Michael Natterer <mitch gimp org>
Date:   Wed Oct 20 18:04:18 2010 +0200

    app: don't pass "GdkRectangle *draw_area" to gimp_view_renderer_draw()
    
    Instead, handle the drawing offset generically by offsetting the
    cairo_t in two places in the callers, and only pass the width and
    height available for drawing.

 app/widgets/gimpcellrendererviewable.c |    6 +++-
 app/widgets/gimpview.c                 |    6 +++-
 app/widgets/gimpviewrenderer.c         |   43 +++++++++++++++++--------------
 app/widgets/gimpviewrenderer.h         |   24 +++++++++--------
 app/widgets/gimpviewrendererbrush.c    |   38 +++++++++++++++------------
 app/widgets/gimpviewrenderervectors.c  |   22 +++++++++-------
 6 files changed, 80 insertions(+), 59 deletions(-)
---
diff --git a/app/widgets/gimpcellrendererviewable.c b/app/widgets/gimpcellrendererviewable.c
index 9a181aa..c490b19 100644
--- a/app/widgets/gimpcellrendererviewable.c
+++ b/app/widgets/gimpcellrendererviewable.c
@@ -311,7 +311,11 @@ gimp_cell_renderer_viewable_render (GtkCellRenderer      *cell,
       gdk_cairo_rectangle (cr, expose_area);
       cairo_clip (cr);
 
-      gimp_view_renderer_draw (cellviewable->renderer, widget, cr, cell_area);
+      cairo_translate (cr, cell_area->x, cell_area->y);
+
+      gimp_view_renderer_draw (cellviewable->renderer, widget, cr,
+                               cell_area->width,
+                               cell_area->height);
 
       cairo_destroy (cr);
     }
diff --git a/app/widgets/gimpview.c b/app/widgets/gimpview.c
index 045ef77..22465dd 100644
--- a/app/widgets/gimpview.c
+++ b/app/widgets/gimpview.c
@@ -395,8 +395,12 @@ gimp_view_expose_event (GtkWidget      *widget,
       gdk_cairo_region (cr, event->region);
       cairo_clip (cr);
 
+      cairo_translate (cr, allocation.x, allocation.y);
+
       gimp_view_renderer_draw (GIMP_VIEW (widget)->renderer,
-                               widget, cr, &allocation);
+                               widget, cr,
+                               allocation.width,
+                               allocation.height);
 
       cairo_destroy (cr);
     }
diff --git a/app/widgets/gimpviewrenderer.c b/app/widgets/gimpviewrenderer.c
index 3dae375..9f3f94f 100644
--- a/app/widgets/gimpviewrenderer.c
+++ b/app/widgets/gimpviewrenderer.c
@@ -61,7 +61,8 @@ static void      gimp_view_renderer_real_invalidate   (GimpViewRenderer   *rende
 static void      gimp_view_renderer_real_draw         (GimpViewRenderer   *renderer,
                                                        GtkWidget          *widget,
                                                        cairo_t            *cr,
-                                                       const GdkRectangle *draw_area);
+                                                       gint                available_width,
+                                                       gint                available_height);
 static void      gimp_view_renderer_real_render       (GimpViewRenderer   *renderer,
                                                        GtkWidget          *widget);
 
@@ -571,15 +572,15 @@ gimp_view_renderer_remove_idle (GimpViewRenderer *renderer)
 }
 
 void
-gimp_view_renderer_draw (GimpViewRenderer   *renderer,
-                         GtkWidget          *widget,
-                         cairo_t            *cr,
-                         const GdkRectangle *draw_area)
+gimp_view_renderer_draw (GimpViewRenderer *renderer,
+                         GtkWidget        *widget,
+                         cairo_t          *cr,
+                         gint              available_width,
+                         gint              available_height)
 {
   g_return_if_fail (GIMP_IS_VIEW_RENDERER (renderer));
   g_return_if_fail (GTK_IS_WIDGET (widget));
   g_return_if_fail (cr != NULL);
-  g_return_if_fail (draw_area != NULL);
 
   if (G_UNLIKELY (renderer->context == NULL))
     g_warning ("%s: renderer->context is NULL", G_STRFUNC);
@@ -591,8 +592,9 @@ gimp_view_renderer_draw (GimpViewRenderer   *renderer,
     {
       cairo_save (cr);
 
-      GIMP_VIEW_RENDERER_GET_CLASS (renderer)->draw (renderer,
-                                                     widget, cr, draw_area);
+      GIMP_VIEW_RENDERER_GET_CLASS (renderer)->draw (renderer, widget, cr,
+                                                     available_width,
+                                                     available_height);
 
       cairo_restore (cr);
     }
@@ -608,7 +610,9 @@ gimp_view_renderer_draw (GimpViewRenderer   *renderer,
 
       g_type_class_unref (viewable_class);
 
-      gimp_view_renderer_real_draw (renderer, widget, cr, draw_area);
+      gimp_view_renderer_real_draw (renderer, widget, cr,
+                                    available_width,
+                                    available_height);
     }
 
   if (renderer->border_width > 0)
@@ -621,8 +625,8 @@ gimp_view_renderer_draw (GimpViewRenderer   *renderer,
       cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
       gimp_cairo_set_source_rgb (cr, &renderer->border_color);
 
-      x = draw_area->x + (draw_area->width  - width)  / 2.0;
-      y = draw_area->y + (draw_area->height - height) / 2.0;
+      x = (available_width  - width)  / 2.0;
+      y = (available_height - height) / 2.0;
 
       cairo_rectangle (cr, x, y, width, height);
       cairo_stroke (cr);
@@ -662,10 +666,11 @@ gimp_view_renderer_real_invalidate (GimpViewRenderer *renderer)
 }
 
 static void
-gimp_view_renderer_real_draw (GimpViewRenderer   *renderer,
-                              GtkWidget          *widget,
-                              cairo_t            *cr,
-                              const GdkRectangle *area)
+gimp_view_renderer_real_draw (GimpViewRenderer *renderer,
+                              GtkWidget        *widget,
+                              cairo_t          *cr,
+                              gint              available_width,
+                              gint              available_height)
 {
   if (renderer->needs_render)
     GIMP_VIEW_RENDERER_GET_CLASS (renderer)->render (renderer, widget);
@@ -686,8 +691,8 @@ gimp_view_renderer_real_draw (GimpViewRenderer   *renderer,
           cairo_paint (cr);
         }
 
-      x = area->x + (area->width  - width)  / 2;
-      y = area->y + (area->height - height) / 2;
+      x = (available_width  - width)  / 2;
+      y = (available_height - height) / 2;
 
       gdk_cairo_set_source_pixbuf (cr, renderer->pixbuf, x, y);
       cairo_rectangle (cr, x, y, width, height);
@@ -698,8 +703,8 @@ gimp_view_renderer_real_draw (GimpViewRenderer   *renderer,
       cairo_content_t content  = cairo_surface_get_content (renderer->surface);
       gint            width    = renderer->width;
       gint            height   = renderer->height;
-      gint            offset_x = area->x + (area->width  - width)  / 2;
-      gint            offset_y = area->y + (area->height - height) / 2;
+      gint            offset_x = (available_width  - width)  / 2;
+      gint            offset_y = (available_height - height) / 2;
 
       cairo_translate (cr, offset_x, offset_y);
 
diff --git a/app/widgets/gimpviewrenderer.h b/app/widgets/gimpviewrenderer.h
index d56912d..a7e096c 100644
--- a/app/widgets/gimpviewrenderer.h
+++ b/app/widgets/gimpviewrenderer.h
@@ -77,18 +77,19 @@ struct _GimpViewRendererClass
   gint           frame_top;
 
   /*  signals  */
-  void (* update)      (GimpViewRenderer   *renderer);
+  void (* update)      (GimpViewRenderer *renderer);
 
   /*  virtual functions  */
-  void (* set_context) (GimpViewRenderer   *renderer,
-                        GimpContext        *context);
-  void (* invalidate)  (GimpViewRenderer   *renderer);
-  void (* draw)        (GimpViewRenderer   *renderer,
-                        GtkWidget          *widget,
-                        cairo_t            *cr,
-                        const GdkRectangle *area);
-  void (* render)      (GimpViewRenderer   *renderer,
-                        GtkWidget          *widget);
+  void (* set_context) (GimpViewRenderer *renderer,
+                        GimpContext      *context);
+  void (* invalidate)  (GimpViewRenderer *renderer);
+  void (* draw)        (GimpViewRenderer *renderer,
+                        GtkWidget        *widget,
+                        cairo_t          *cr,
+                        gint              available_width,
+                        gint              available_height);
+  void (* render)      (GimpViewRenderer *renderer,
+                        GtkWidget        *widget);
 };
 
 
@@ -134,7 +135,8 @@ void   gimp_view_renderer_remove_idle      (GimpViewRenderer   *renderer);
 void   gimp_view_renderer_draw             (GimpViewRenderer   *renderer,
                                             GtkWidget          *widget,
                                             cairo_t            *cr,
-                                            const GdkRectangle *draw_area);
+                                            gint                available_width,
+                                            gint                available_height);
 
 /*  protected  */
 
diff --git a/app/widgets/gimpviewrendererbrush.c b/app/widgets/gimpviewrendererbrush.c
index a5d8c22..01033a0 100644
--- a/app/widgets/gimpviewrendererbrush.c
+++ b/app/widgets/gimpviewrendererbrush.c
@@ -32,13 +32,14 @@
 #include "gimpviewrendererbrush.h"
 
 
-static void   gimp_view_renderer_brush_finalize (GObject            *object);
-static void   gimp_view_renderer_brush_render   (GimpViewRenderer   *renderer,
-                                                 GtkWidget          *widget);
-static void   gimp_view_renderer_brush_draw     (GimpViewRenderer   *renderer,
-                                                 GtkWidget          *widget,
-                                                 cairo_t            *cr,
-                                                 const GdkRectangle *area);
+static void   gimp_view_renderer_brush_finalize (GObject          *object);
+static void   gimp_view_renderer_brush_render   (GimpViewRenderer *renderer,
+                                                 GtkWidget        *widget);
+static void   gimp_view_renderer_brush_draw     (GimpViewRenderer *renderer,
+                                                 GtkWidget        *widget,
+                                                 cairo_t          *cr,
+                                                 gint              available_width,
+                                                 gint              available_height);
 
 static gboolean gimp_view_renderer_brush_render_timeout (gpointer    data);
 
@@ -182,12 +183,15 @@ gimp_view_renderer_brush_render_timeout (gpointer data)
 }
 
 static void
-gimp_view_renderer_brush_draw (GimpViewRenderer   *renderer,
-                               GtkWidget          *widget,
-                               cairo_t            *cr,
-                               const GdkRectangle *area)
+gimp_view_renderer_brush_draw (GimpViewRenderer *renderer,
+                               GtkWidget        *widget,
+                               cairo_t          *cr,
+                               gint              available_width,
+                               gint              available_height)
 {
-  GIMP_VIEW_RENDERER_CLASS (parent_class)->draw (renderer, widget, cr, area);
+  GIMP_VIEW_RENDERER_CLASS (parent_class)->draw (renderer, widget, cr,
+                                                 available_width,
+                                                 available_height);
 
 #define INDICATOR_WIDTH  7
 #define INDICATOR_HEIGHT 7
@@ -202,7 +206,7 @@ gimp_view_renderer_brush_draw (GimpViewRenderer   *renderer,
 
       if (generated || pipe)
         {
-          cairo_move_to (cr, area->x + area->width, area->y + area->height);
+          cairo_move_to (cr, available_width, available_height);
           cairo_rel_line_to (cr, - INDICATOR_WIDTH, 0);
           cairo_rel_line_to (cr, INDICATOR_WIDTH, - INDICATOR_HEIGHT);
           cairo_rel_line_to (cr, 0, INDICATOR_HEIGHT);
@@ -220,13 +224,13 @@ gimp_view_renderer_brush_draw (GimpViewRenderer   *renderer,
       if (renderer->width < brush_width || renderer->height < brush_height)
         {
           cairo_move_to (cr,
-                         area->x + area->width  - INDICATOR_WIDTH + 1,
-                         area->y + area->height - INDICATOR_HEIGHT / 2.0);
+                         available_width  - INDICATOR_WIDTH + 1,
+                         available_height - INDICATOR_HEIGHT / 2.0);
           cairo_rel_line_to (cr, INDICATOR_WIDTH - 2, 0);
 
           cairo_move_to (cr,
-                         area->x + area->width  - INDICATOR_WIDTH / 2.0,
-                         area->y + area->height - INDICATOR_HEIGHT + 1);
+                         available_width  - INDICATOR_WIDTH / 2.0,
+                         available_height - INDICATOR_HEIGHT + 1);
           cairo_rel_line_to (cr, 0, INDICATOR_WIDTH - 2);
 
           cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
diff --git a/app/widgets/gimpviewrenderervectors.c b/app/widgets/gimpviewrenderervectors.c
index 5a928c9..0b9d428 100644
--- a/app/widgets/gimpviewrenderervectors.c
+++ b/app/widgets/gimpviewrenderervectors.c
@@ -38,10 +38,11 @@
 #include "gimpviewrenderervectors.h"
 
 
-static void   gimp_view_renderer_vectors_draw (GimpViewRenderer   *renderer,
-                                               GtkWidget          *widget,
-                                               cairo_t            *cr,
-                                               const GdkRectangle *area);
+static void   gimp_view_renderer_vectors_draw (GimpViewRenderer *renderer,
+                                               GtkWidget        *widget,
+                                               cairo_t          *cr,
+                                               gint              available_width,
+                                               gint              available_height);
 
 
 G_DEFINE_TYPE (GimpViewRendererVectors, gimp_view_renderer_vectors,
@@ -64,10 +65,11 @@ gimp_view_renderer_vectors_init (GimpViewRendererVectors *renderer)
 }
 
 static void
-gimp_view_renderer_vectors_draw (GimpViewRenderer   *renderer,
-                                 GtkWidget          *widget,
-                                 cairo_t            *cr,
-                                 const GdkRectangle *area)
+gimp_view_renderer_vectors_draw (GimpViewRenderer *renderer,
+                                 GtkWidget        *widget,
+                                 cairo_t          *cr,
+                                 gint              available_width,
+                                 gint              available_height)
 {
   GtkStyle             *style   = gtk_widget_get_style (widget);
   GimpVectors          *vectors = GIMP_VECTORS (renderer->viewable);
@@ -76,8 +78,8 @@ gimp_view_renderer_vectors_draw (GimpViewRenderer   *renderer,
   gdk_cairo_set_source_color (cr, &style->white);
 
   cairo_translate (cr,
-                   area->x + (area->width  - renderer->width)  / 2,
-                   area->y + (area->height - renderer->height) / 2);
+                   (available_width  - renderer->width)  / 2,
+                   (available_height - renderer->height) / 2);
   cairo_rectangle (cr, 0, 0, renderer->width, renderer->height);
   cairo_clip_preserve (cr);
   cairo_fill (cr);



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