[gimp] Don't use gimpimage-private.h undoing guide/sample point removals



commit 004b96ac6cdc22bfdde73ed85338595135066fd3
Author: Michael Natterer <mitch gimp org>
Date:   Fri Feb 5 16:14:04 2010 +0100

    Don't use gimpimage-private.h undoing guide/sample point removals
    
    Instead, use the proper "add" APIs and remove checks for the guides /
    sample points being at the right positions (they might be out of image
    when an image resize or rotation is undone). Add comments to make
    clear that these functions are internal API, also add comments to the
    proper public APIs so it's clear which one to use in which situation.

 app/core/gimpguideundo.c           |   16 ++--------------
 app/core/gimpimage-guides.c        |    6 ------
 app/core/gimpimage-guides.h        |    6 ++++++
 app/core/gimpimage-sample-points.c |    4 ----
 app/core/gimpimage-sample-points.h |    8 ++++++++
 app/core/gimpsamplepointundo.c     |   24 ++++--------------------
 6 files changed, 20 insertions(+), 44 deletions(-)
---
diff --git a/app/core/gimpguideundo.c b/app/core/gimpguideundo.c
index da9958e..8db26f2 100644
--- a/app/core/gimpguideundo.c
+++ b/app/core/gimpguideundo.c
@@ -23,7 +23,6 @@
 
 #include "gimpimage.h"
 #include "gimpimage-guides.h"
-#include "gimpimage-private.h"
 #include "gimpguide.h"
 #include "gimpguideundo.h"
 
@@ -158,21 +157,10 @@ gimp_guide_undo_pop (GimpUndo              *undo,
   orientation = gimp_guide_get_orientation (guide_undo->guide);
   position    = gimp_guide_get_position (guide_undo->guide);
 
-  /*  add and move guides manually (nor using the gimp_image_guide
-   *  API), because we might be in the middle of an image resizing
-   *  undo group and the guide's position might be temporarily out of
-   *  image.
-   */
-
   if (position == -1)
     {
-      GimpImagePrivate *private = GIMP_IMAGE_GET_PRIVATE (undo->image);
-
-      private->guides = g_list_prepend (private->guides,
-                                        guide_undo->guide);
-      gimp_guide_set_position (guide_undo->guide, guide_undo->position);
-      g_object_ref (guide_undo->guide);
-      gimp_image_update_guide (undo->image, guide_undo->guide);
+      gimp_image_add_guide (undo->image,
+                            guide_undo->guide, guide_undo->position);
     }
   else if (guide_undo->position == -1)
     {
diff --git a/app/core/gimpimage-guides.c b/app/core/gimpimage-guides.c
index 3e46da3..47825c2 100644
--- a/app/core/gimpimage-guides.c
+++ b/app/core/gimpimage-guides.c
@@ -88,15 +88,9 @@ gimp_image_add_guide (GimpImage *image,
 
   g_return_if_fail (GIMP_IS_IMAGE (image));
   g_return_if_fail (GIMP_IS_GUIDE (guide));
-  g_return_if_fail (position >= 0);
 
   private = GIMP_IMAGE_GET_PRIVATE (image);
 
-  if (gimp_guide_get_orientation (guide) == GIMP_ORIENTATION_HORIZONTAL)
-    g_return_if_fail (position <= gimp_image_get_height (image));
-  else
-    g_return_if_fail (position <= gimp_image_get_width (image));
-
   private->guides = g_list_prepend (private->guides, guide);
 
   gimp_guide_set_position (guide, position);
diff --git a/app/core/gimpimage-guides.h b/app/core/gimpimage-guides.h
index ad6c5c4..874bbfa 100644
--- a/app/core/gimpimage-guides.h
+++ b/app/core/gimpimage-guides.h
@@ -19,6 +19,8 @@
 #define __GIMP_IMAGE_GUIDES_H__
 
 
+/*  public guide adding API
+ */
 GimpGuide * gimp_image_add_hguide     (GimpImage *image,
                                        gint       position,
                                        gboolean   push_undo);
@@ -26,9 +28,13 @@ GimpGuide * gimp_image_add_vguide     (GimpImage *image,
                                        gint       position,
                                        gboolean   push_undo);
 
+/*  internal guide adding API, does not check the guide's position and
+ *  is publically declared only to be used from undo
+ */
 void        gimp_image_add_guide      (GimpImage *image,
                                        GimpGuide *guide,
                                        gint       position);
+
 void        gimp_image_remove_guide   (GimpImage *image,
                                        GimpGuide *guide,
                                        gboolean   push_undo);
diff --git a/app/core/gimpimage-sample-points.c b/app/core/gimpimage-sample-points.c
index ee38201..ee8b798 100644
--- a/app/core/gimpimage-sample-points.c
+++ b/app/core/gimpimage-sample-points.c
@@ -69,10 +69,6 @@ gimp_image_add_sample_point (GimpImage       *image,
 
   g_return_if_fail (GIMP_IS_IMAGE (image));
   g_return_if_fail (sample_point != NULL);
-  g_return_if_fail (x >= 0);
-  g_return_if_fail (y >= 0);
-  g_return_if_fail (x < gimp_image_get_width  (image));
-  g_return_if_fail (y < gimp_image_get_height (image));
 
   private = GIMP_IMAGE_GET_PRIVATE (image);
 
diff --git a/app/core/gimpimage-sample-points.h b/app/core/gimpimage-sample-points.h
index 02025ff..bbd1c3a 100644
--- a/app/core/gimpimage-sample-points.h
+++ b/app/core/gimpimage-sample-points.h
@@ -19,14 +19,22 @@
 #define __GIMP_IMAGE_SAMPLE_POINTS_H__
 
 
+/*  public sample point adding API
+ */
 GimpSamplePoint * gimp_image_add_sample_point_at_pos (GimpImage        *image,
                                                       gint              x,
                                                       gint              y,
                                                       gboolean          push_undo);
+
+/*  internal sample point adding API, does not check the sample
+ *  point's position and is publically declared only to be used from
+ *  undo
+ */
 void              gimp_image_add_sample_point        (GimpImage       *image,
                                                       GimpSamplePoint *sample_point,
                                                       gint             x,
                                                       gint             y);
+
 void              gimp_image_remove_sample_point     (GimpImage       *image,
                                                       GimpSamplePoint *sample_point,
                                                       gboolean         push_undo);
diff --git a/app/core/gimpsamplepointundo.c b/app/core/gimpsamplepointundo.c
index b1d55ff..7068791 100644
--- a/app/core/gimpsamplepointundo.c
+++ b/app/core/gimpsamplepointundo.c
@@ -22,7 +22,6 @@
 #include "core-types.h"
 
 #include "gimpimage.h"
-#include "gimpimage-private.h"
 #include "gimpimage-sample-points.h"
 #include "gimpsamplepoint.h"
 #include "gimpsamplepointundo.h"
@@ -158,27 +157,12 @@ gimp_sample_point_undo_pop (GimpUndo              *undo,
   x = sample_point_undo->sample_point->x;
   y = sample_point_undo->sample_point->y;
 
-  /*  add and move sample points manually (nor using the
-   *  gimp_image_sample_point API), because we might be in the middle
-   *  of an image resizing undo group and the sample point's position
-   *  might be temporarily out of image.
-   */
-
   if (x == -1)
     {
-      GimpImagePrivate *private = GIMP_IMAGE_GET_PRIVATE (undo->image);
-
-      private->sample_points = g_list_append (private->sample_points,
-                                              sample_point_undo->sample_point);
-
-      sample_point_undo->sample_point->x = sample_point_undo->x;
-      sample_point_undo->sample_point->y = sample_point_undo->y;
-      gimp_sample_point_ref (sample_point_undo->sample_point);
-
-      gimp_image_sample_point_added (undo->image,
-                                     sample_point_undo->sample_point);
-      gimp_image_update_sample_point (undo->image,
-                                      sample_point_undo->sample_point);
+      gimp_image_add_sample_point (undo->image,
+                                   sample_point_undo->sample_point,
+                                   sample_point_undo->x,
+                                   sample_point_undo->y);
     }
   else if (sample_point_undo->x == -1)
     {



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