gimp r26137 - in trunk: . app/display



Author: martinn
Date: Fri Jul 11 19:31:45 2008
New Revision: 26137
URL: http://svn.gnome.org/viewvc/gimp?rev=26137&view=rev

Log:
2008-07-11  Martin Nordholts  <martinn svn gnome org>

	* app/display/gimpdisplayshell-scroll.c
	(gimp_display_shell_get_scaled_image_viewport_offset): New
	function to replace any occurance of

	  shell->disp_[xy]offset - shell->offset_[xy]

	that is just an implementation specific way of saying the same
	thing.

	* app/display/gimpdisplayshell-draw.c
	* app/display/gimpdisplayshell-transform.c: Make the code less
	implementation dependant by using the new function.


Modified:
   trunk/ChangeLog
   trunk/app/display/gimpdisplayshell-draw.c
   trunk/app/display/gimpdisplayshell-scroll.c
   trunk/app/display/gimpdisplayshell-scroll.h
   trunk/app/display/gimpdisplayshell-transform.c

Modified: trunk/app/display/gimpdisplayshell-draw.c
==============================================================================
--- trunk/app/display/gimpdisplayshell-draw.c	(original)
+++ trunk/app/display/gimpdisplayshell-draw.c	Fri Jul 11 19:31:45 2008
@@ -534,8 +534,7 @@
   level_height = tile_manager_height (tiles);
 
   /*  the size and position of the image viewport coordinates  */
-  sx = shell->disp_xoffset - shell->offset_x;
-  sy = shell->disp_yoffset - shell->offset_y;
+  gimp_display_shell_get_scaled_image_viewport_offset (shell, &sx, &sy);
   sw = PROJ_ROUND (level_width  * (shell->scale_x * (1 << level)));
   sh = PROJ_ROUND (level_height * (shell->scale_y * (1 << level)));
 

Modified: trunk/app/display/gimpdisplayshell-scroll.c
==============================================================================
--- trunk/app/display/gimpdisplayshell-scroll.c	(original)
+++ trunk/app/display/gimpdisplayshell-scroll.c	Fri Jul 11 19:31:45 2008
@@ -184,3 +184,21 @@
   if (w) *w = shell->disp_width  / shell->scale_x;
   if (h) *h = shell->disp_height / shell->scale_y;
 }
+
+/**
+ * gimp_display_shell_get_scaled_image_viewport_offset:
+ * @shell:
+ * @x:
+ * @y:
+ *
+ * Gets the scaled image offset in viewport coordinates
+ *
+ **/
+void
+gimp_display_shell_get_scaled_image_viewport_offset (GimpDisplayShell *shell,
+                                                     gint             *x,
+                                                     gint             *y)
+{
+  if (x) *x = shell->disp_xoffset - shell->offset_x;
+  if (y) *y = shell->disp_yoffset - shell->offset_y;
+}

Modified: trunk/app/display/gimpdisplayshell-scroll.h
==============================================================================
--- trunk/app/display/gimpdisplayshell-scroll.h	(original)
+++ trunk/app/display/gimpdisplayshell-scroll.h	Fri Jul 11 19:31:45 2008
@@ -20,23 +20,27 @@
 #define __GIMP_DISPLAY_SHELL_SCROLL_H__
 
 
-void       gimp_display_shell_scroll               (GimpDisplayShell *shell,
-                                                    gdouble           x_offset_into_image,
-                                                    gdouble           y_offset_into_image);
-
-void       gimp_display_shell_scroll_clamp_offsets (GimpDisplayShell *shell);
-
-void       gimp_display_shell_get_scaled_viewport  (GimpDisplayShell *shell,
-                                                    gint             *x,
-                                                    gint             *y,
-                                                    gint             *w,
-                                                    gint             *h);
-
-void       gimp_display_shell_get_viewport         (GimpDisplayShell *shell,
-                                                    gdouble          *x,
-                                                    gdouble          *y,
-                                                    gdouble          *w,
-                                                    gdouble          *h);
+void       gimp_display_shell_scroll                           (GimpDisplayShell *shell,
+                                                                gdouble           x_offset_into_image,
+                                                                gdouble           y_offset_into_image);
+
+void       gimp_display_shell_scroll_clamp_offsets             (GimpDisplayShell *shell);
+
+void       gimp_display_shell_get_scaled_viewport              (GimpDisplayShell *shell,
+                                                                gint             *x,
+                                                                gint             *y,
+                                                                gint             *w,
+                                                                gint             *h);
+
+void       gimp_display_shell_get_viewport                     (GimpDisplayShell *shell,
+                                                                gdouble          *x,
+                                                                gdouble          *y,
+                                                                gdouble          *w,
+                                                                gdouble          *h);
+
+void       gimp_display_shell_get_scaled_image_viewport_offset (GimpDisplayShell *shell,
+                                                                gint             *x,
+                                                                gint             *y);
 
 
 #endif  /*  __GIMP_DISPLAY_SHELL_SCROLL_H__  */

Modified: trunk/app/display/gimpdisplayshell-transform.c
==============================================================================
--- trunk/app/display/gimpdisplayshell-transform.c	(original)
+++ trunk/app/display/gimpdisplayshell-transform.c	Fri Jul 11 19:31:45 2008
@@ -31,6 +31,7 @@
 
 #include "gimpdisplay.h"
 #include "gimpdisplayshell.h"
+#include "gimpdisplayshell-scroll.h"
 #include "gimpdisplayshell-transform.h"
 
 
@@ -48,6 +49,9 @@
                                          GimpCoords       *image_coords,
                                          GimpCoords       *display_coords)
 {
+  gint scaled_image_viewport_offset_x;
+  gint scaled_image_viewport_offset_y;
+
   g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
   g_return_if_fail (image_coords != NULL);
   g_return_if_fail (display_coords != NULL);
@@ -57,8 +61,12 @@
   display_coords->x = SCALEX (shell, image_coords->x);
   display_coords->y = SCALEY (shell, image_coords->y);
 
-  display_coords->x += - shell->offset_x + shell->disp_xoffset;
-  display_coords->y += - shell->offset_y + shell->disp_yoffset;
+  gimp_display_shell_get_scaled_image_viewport_offset (shell,
+                                                       &scaled_image_viewport_offset_x,
+                                                       &scaled_image_viewport_offset_y);
+
+  display_coords->x += scaled_image_viewport_offset_x;
+  display_coords->y += scaled_image_viewport_offset_y;
 }
 
 /**
@@ -75,14 +83,21 @@
                                            GimpCoords       *display_coords,
                                            GimpCoords       *image_coords)
 {
+  gint scaled_image_viewport_offset_x;
+  gint scaled_image_viewport_offset_y;
+
   g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell));
   g_return_if_fail (display_coords != NULL);
   g_return_if_fail (image_coords != NULL);
 
   *image_coords = *display_coords;
 
-  image_coords->x = display_coords->x - shell->disp_xoffset + shell->offset_x;
-  image_coords->y = display_coords->y - shell->disp_yoffset + shell->offset_y;
+  gimp_display_shell_get_scaled_image_viewport_offset (shell,
+                                                       &scaled_image_viewport_offset_x,
+                                                       &scaled_image_viewport_offset_y);
+
+  image_coords->x = display_coords->x - scaled_image_viewport_offset_x;
+  image_coords->y = display_coords->y - scaled_image_viewport_offset_y;
 
   image_coords->x /= shell->scale_x;
   image_coords->y /= shell->scale_y;
@@ -96,6 +111,8 @@
                                  gint             *ny,
                                  gboolean          use_offsets)
 {
+  gint   scaled_image_viewport_offset_x;
+  gint   scaled_image_viewport_offset_y;
   gint   offset_x = 0;
   gint   offset_y = 0;
   gint64 tx;
@@ -119,8 +136,11 @@
   tx = ((gint64) x * shell->x_src_dec) / shell->x_dest_inc;
   ty = ((gint64) y * shell->y_src_dec) / shell->y_dest_inc;
 
-  tx += shell->disp_xoffset - shell->offset_x;
-  ty += shell->disp_yoffset - shell->offset_y;
+  gimp_display_shell_get_scaled_image_viewport_offset (shell,
+                                                       &scaled_image_viewport_offset_x,
+                                                       &scaled_image_viewport_offset_y);
+  tx += scaled_image_viewport_offset_x;
+  ty += scaled_image_viewport_offset_y;
 
   /* The projected coordinates might overflow a gint in the case of big
      images at high zoom levels, so we clamp them here to avoid problems.  */
@@ -153,6 +173,8 @@
                                    gboolean          round,
                                    gboolean          use_offsets)
 {
+  gint   scaled_image_viewport_offset_x;
+  gint   scaled_image_viewport_offset_y;
   gint   offset_x = 0;
   gint   offset_y = 0;
   gint64 tx;
@@ -170,8 +192,11 @@
       gimp_item_offsets (item, &offset_x, &offset_y);
     }
 
-  tx = (gint64) x + shell->offset_x - shell->disp_xoffset;
-  ty = (gint64) y + shell->offset_y - shell->disp_yoffset;
+  gimp_display_shell_get_scaled_image_viewport_offset (shell,
+                                                       &scaled_image_viewport_offset_x,
+                                                       &scaled_image_viewport_offset_y);
+  tx = (gint64) x - scaled_image_viewport_offset_x;
+  ty = (gint64) y - scaled_image_viewport_offset_y;
 
   tx *= shell->x_dest_inc;
   ty *= shell->y_dest_inc;
@@ -308,17 +333,22 @@
 
   for (i = 0; i < n_points ; i++)
     {
+      gint    scaled_image_viewport_offset_x;
+      gint    scaled_image_viewport_offset_y;
       gdouble x = points[i].x + offset_x;
       gdouble y = points[i].y + offset_y;
 
       x = x * shell->x_src_dec / shell->x_dest_inc;
       y = y * shell->y_src_dec / shell->y_dest_inc;
 
+      gimp_display_shell_get_scaled_image_viewport_offset (shell,
+                                                           &scaled_image_viewport_offset_x,
+                                                           &scaled_image_viewport_offset_y);
       coords[i].x = CLAMP (PROJ_ROUND64 (x) +
-                           shell->disp_xoffset - shell->offset_x,
+                           scaled_image_viewport_offset_x,
                            G_MININT, G_MAXINT);
       coords[i].y = CLAMP (PROJ_ROUND64 (y) +
-                           shell->disp_yoffset - shell->offset_y,
+                           scaled_image_viewport_offset_y,
                            G_MININT, G_MAXINT);
     }
 }
@@ -358,17 +388,22 @@
 
   for (i = 0; i < n_coords ; i++)
     {
+      gint    scaled_image_viewport_offset_x;
+      gint    scaled_image_viewport_offset_y;
       gdouble x = image_coords[i].x + offset_x;
       gdouble y = image_coords[i].y + offset_y;
 
       x = x * shell->x_src_dec / shell->x_dest_inc;
       y = y * shell->y_src_dec / shell->y_dest_inc;
 
+      gimp_display_shell_get_scaled_image_viewport_offset (shell,
+                                                           &scaled_image_viewport_offset_x,
+                                                           &scaled_image_viewport_offset_y);
       disp_coords[i].x = CLAMP (PROJ_ROUND64 (x) +
-                                shell->disp_xoffset - shell->offset_x,
+                                scaled_image_viewport_offset_x,
                                 G_MININT, G_MAXINT);
       disp_coords[i].y = CLAMP (PROJ_ROUND64 (y) +
-                                shell->disp_yoffset - shell->offset_y,
+                                scaled_image_viewport_offset_y,
                                 G_MININT, G_MAXINT);
     }
 }
@@ -408,6 +443,8 @@
 
   for (i = 0; i < n_segs ; i++)
     {
+      gint   scaled_image_viewport_offset_x;
+      gint   scaled_image_viewport_offset_y;
       gint64 x1, x2;
       gint64 y1, y2;
 
@@ -421,13 +458,17 @@
       y1 = (y1 * shell->y_src_dec) / shell->y_dest_inc;
       y2 = (y2 * shell->y_src_dec) / shell->y_dest_inc;
 
-      dest_segs[i].x1 = CLAMP (x1 + shell->disp_xoffset - shell->offset_x,
+      gimp_display_shell_get_scaled_image_viewport_offset (shell,
+                                                           &scaled_image_viewport_offset_x,
+                                                           &scaled_image_viewport_offset_y);
+
+      dest_segs[i].x1 = CLAMP (x1 + scaled_image_viewport_offset_x,
                                G_MININT, G_MAXINT);
-      dest_segs[i].x2 = CLAMP (x2 + shell->disp_xoffset - shell->offset_x,
+      dest_segs[i].x2 = CLAMP (x2 + scaled_image_viewport_offset_x,
                                G_MININT, G_MAXINT);
-      dest_segs[i].y1 = CLAMP (y1 + shell->disp_yoffset - shell->offset_y,
+      dest_segs[i].y1 = CLAMP (y1 + scaled_image_viewport_offset_y,
                                G_MININT, G_MAXINT);
-      dest_segs[i].y2 = CLAMP (y2 + shell->disp_yoffset - shell->offset_y,
+      dest_segs[i].y2 = CLAMP (y2 + scaled_image_viewport_offset_y,
                                G_MININT, G_MAXINT);
     }
 }



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