[gimp] app: don't access GimpSamplePoint members directly



commit 2a43ab240b0414deaa601ac7941231741d7a9b92
Author: Michael Natterer <mitch gimp org>
Date:   Mon Jan 4 22:06:27 2016 +0100

    app: don't access GimpSamplePoint members directly
    
    Use the new accessors instead. Clean up guide and sample point code in
    image crop and resize a bit.

 app/core/gimpimage-crop.c               |   30 +++++++++++++++++-------------
 app/core/gimpimage-duplicate.c          |    9 +++++----
 app/core/gimpimage-flip.c               |   14 ++++++++------
 app/core/gimpimage-resize.c             |   18 +++++++++++-------
 app/core/gimpimage-rotate.c             |   18 ++++++++++--------
 app/core/gimpimage-scale.c              |    8 ++++++--
 app/display/gimpdisplayshell-handlers.c |   15 ++++++++++-----
 app/tests/test-xcf.c                    |   26 ++++++++++++++++----------
 app/tools/gimpcolortool.c               |   14 ++++++++------
 app/widgets/gimpsamplepointeditor.c     |   15 +++++++++++----
 app/xcf/xcf-save.c                      |    3 +--
 11 files changed, 103 insertions(+), 67 deletions(-)
---
diff --git a/app/core/gimpimage-crop.c b/app/core/gimpimage-crop.c
index 48537d0..7a0d455 100644
--- a/app/core/gimpimage-crop.c
+++ b/app/core/gimpimage-crop.c
@@ -149,7 +149,7 @@ gimp_image_crop (GimpImage   *image,
         }
     }
 
-  /*  Reposition or remove all guides  */
+  /*  Reposition or remove guides  */
   list = gimp_image_get_guides (image);
 
   while (list)
@@ -163,17 +163,15 @@ gimp_image_crop (GimpImage   *image,
       switch (gimp_guide_get_orientation (guide))
         {
         case GIMP_ORIENTATION_HORIZONTAL:
-          if ((position < y) || (position > (y + height)))
+          position -= y;
+          if ((position < 0) || (position > height))
             remove_guide = TRUE;
-          else
-            position -= y;
           break;
 
         case GIMP_ORIENTATION_VERTICAL:
-          if ((position < x) || (position > (x + width)))
+          position -= x;
+          if ((position < 0) || (position > width))
             remove_guide = TRUE;
-          else
-            position -= x;
           break;
 
         default:
@@ -193,22 +191,28 @@ gimp_image_crop (GimpImage   *image,
     {
       GimpSamplePoint *sample_point        = list->data;
       gboolean         remove_sample_point = FALSE;
-      gint             new_x               = sample_point->x;
-      gint             new_y               = sample_point->y;
+      gint             old_x;
+      gint             old_y;
+      gint             new_x;
+      gint             new_y;
 
       list = g_list_next (list);
 
+      gimp_sample_point_get_position (sample_point, &old_x, &old_y);
+      new_x = old_x;
+      new_y = old_y;
+
       new_y -= y;
-      if ((sample_point->y < y) || (sample_point->y > (y + height)))
-        remove_sample_point = TRUE;
+      if ((new_y < 0) || (new_y > height))
+       remove_sample_point = TRUE;
 
       new_x -= x;
-      if ((sample_point->x < x) || (sample_point->x > (x + width)))
+      if ((new_x < 0) || (new_x > width))
         remove_sample_point = TRUE;
 
       if (remove_sample_point)
         gimp_image_remove_sample_point (image, sample_point, TRUE);
-      else if (new_x != sample_point->x || new_y != sample_point->y)
+      else if (new_x != old_x || new_y != old_y)
         gimp_image_move_sample_point (image, sample_point,
                                       new_x, new_y, TRUE);
     }
diff --git a/app/core/gimpimage-duplicate.c b/app/core/gimpimage-duplicate.c
index 95d8993..ba934b2 100644
--- a/app/core/gimpimage-duplicate.c
+++ b/app/core/gimpimage-duplicate.c
@@ -461,11 +461,12 @@ gimp_image_duplicate_sample_points (GimpImage *image,
        list = g_list_next (list))
     {
       GimpSamplePoint *sample_point = list->data;
+      gint             x;
+      gint             y;
 
-      gimp_image_add_sample_point_at_pos (new_image,
-                                          sample_point->x,
-                                          sample_point->y,
-                                          FALSE);
+      gimp_sample_point_get_position (sample_point, &x, &y);
+
+      gimp_image_add_sample_point_at_pos (new_image, x, y, FALSE);
     }
 }
 
diff --git a/app/core/gimpimage-flip.c b/app/core/gimpimage-flip.c
index 0eefa8d..e4c3b87 100644
--- a/app/core/gimpimage-flip.c
+++ b/app/core/gimpimage-flip.c
@@ -157,19 +157,21 @@ gimp_image_flip (GimpImage           *image,
        list = g_list_next (list))
     {
       GimpSamplePoint *sample_point = list->data;
+      gint             x;
+      gint             y;
+
+      gimp_sample_point_get_position (sample_point, &x, &y);
 
       if (flip_type == GIMP_ORIENTATION_VERTICAL)
         gimp_image_move_sample_point (image, sample_point,
-                                      sample_point->x,
-                                      gimp_image_get_height (image) -
-                                      sample_point->y,
+                                      x,
+                                      gimp_image_get_height (image) - y,
                                       TRUE);
 
       if (flip_type == GIMP_ORIENTATION_HORIZONTAL)
         gimp_image_move_sample_point (image, sample_point,
-                                      gimp_image_get_width (image) -
-                                      sample_point->x,
-                                      sample_point->y,
+                                      gimp_image_get_width (image) - x,
+                                      y,
                                       TRUE);
     }
 
diff --git a/app/core/gimpimage-resize.c b/app/core/gimpimage-resize.c
index a96f334..e0cf590 100644
--- a/app/core/gimpimage-resize.c
+++ b/app/core/gimpimage-resize.c
@@ -228,22 +228,26 @@ gimp_image_resize_with_layers (GimpImage    *image,
     {
       GimpSamplePoint *sample_point        = list->data;
       gboolean         remove_sample_point = FALSE;
-      gint             new_x               = sample_point->x;
-      gint             new_y               = sample_point->y;
+      gint             old_x;
+      gint             old_y;
+      gint             new_x;
+      gint             new_y;
 
       list = g_list_next (list);
 
-      new_y += offset_y;
-      if ((sample_point->y < 0) || (sample_point->y > new_height))
+      gimp_sample_point_get_position (sample_point, &old_x, &old_y);
+
+      new_y = old_y + offset_y;
+      if ((new_y < 0) || (new_y > new_height))
         remove_sample_point = TRUE;
 
-      new_x += offset_x;
-      if ((sample_point->x < 0) || (sample_point->x > new_width))
+      new_x = old_x + offset_x;
+      if ((new_x < 0) || (new_x > new_width))
         remove_sample_point = TRUE;
 
       if (remove_sample_point)
         gimp_image_remove_sample_point (image, sample_point, TRUE);
-      else if (new_x != sample_point->x || new_y != sample_point->y)
+      else if (new_x != old_x || new_y != old_y)
         gimp_image_move_sample_point (image, sample_point,
                                       new_x, new_y, TRUE);
     }
diff --git a/app/core/gimpimage-rotate.c b/app/core/gimpimage-rotate.c
index 686ee10..7b6021b 100644
--- a/app/core/gimpimage-rotate.c
+++ b/app/core/gimpimage-rotate.c
@@ -375,24 +375,26 @@ gimp_image_rotate_sample_points (GimpImage        *image,
 
       gimp_image_undo_push_sample_point (image, NULL, sample_point);
 
-      old_x = sample_point->x;
-      old_y = sample_point->y;
+      gimp_sample_point_get_position (sample_point, &old_x, &old_y);
 
       switch (rotate_type)
         {
         case GIMP_ROTATE_90:
-          sample_point->x = gimp_image_get_height (image) - old_y;
-          sample_point->y = old_x;
+          gimp_sample_point_set_position (sample_point,
+                                          gimp_image_get_height (image) - old_y,
+                                          old_x);
           break;
 
         case GIMP_ROTATE_180:
-          sample_point->x = gimp_image_get_width  (image) - old_x;
-          sample_point->y = gimp_image_get_height (image) - old_y;
+          gimp_sample_point_set_position (sample_point,
+                                          gimp_image_get_width  (image) - old_x,
+                                          gimp_image_get_height (image) - old_y);
           break;
 
         case GIMP_ROTATE_270:
-          sample_point->x = old_y;
-          sample_point->y = gimp_image_get_width (image) - old_x;
+          gimp_sample_point_set_position (sample_point,
+                                          old_y,
+                                          gimp_image_get_width (image) - old_x);
           break;
         }
     }
diff --git a/app/core/gimpimage-scale.c b/app/core/gimpimage-scale.c
index eb78c15..6a517a7 100644
--- a/app/core/gimpimage-scale.c
+++ b/app/core/gimpimage-scale.c
@@ -210,10 +210,14 @@ gimp_image_scale (GimpImage             *image,
        list = g_list_next (list))
     {
       GimpSamplePoint *sample_point = list->data;
+      gint             x;
+      gint             y;
+
+      gimp_sample_point_get_position (sample_point, &x, &y);
 
       gimp_image_move_sample_point (image, sample_point,
-                                    sample_point->x * new_width  / old_width,
-                                    sample_point->y * new_height / old_height,
+                                    x * new_width  / old_width,
+                                    y * new_height / old_height,
                                     TRUE);
     }
 
diff --git a/app/display/gimpdisplayshell-handlers.c b/app/display/gimpdisplayshell-handlers.c
index 37c218e..fd23e16 100644
--- a/app/display/gimpdisplayshell-handlers.c
+++ b/app/display/gimpdisplayshell-handlers.c
@@ -665,12 +665,13 @@ gimp_display_shell_sample_point_add_handler (GimpImage        *image,
   GimpCanvasProxyGroup *group = GIMP_CANVAS_PROXY_GROUP (shell->sample_points);
   GimpCanvasItem       *item;
   GList                *list;
+  gint                  x;
+  gint                  y;
   gint                  i;
 
-  item = gimp_canvas_sample_point_new (shell,
-                                       sample_point->x,
-                                       sample_point->y,
-                                       0, TRUE);
+  gimp_sample_point_get_position (sample_point, &x, &y);
+
+  item = gimp_canvas_sample_point_new (shell, x, y, 0, TRUE);
 
   gimp_canvas_proxy_group_add_item (group, sample_point, item);
   g_object_unref (item);
@@ -724,10 +725,14 @@ gimp_display_shell_sample_point_move_handler (GimpImage        *image,
 {
   GimpCanvasProxyGroup *group = GIMP_CANVAS_PROXY_GROUP (shell->sample_points);
   GimpCanvasItem       *item;
+  gint                  x;
+  gint                  y;
 
   item = gimp_canvas_proxy_group_get_item (group, sample_point);
 
-  gimp_canvas_sample_point_set (item, sample_point->x, sample_point->y);
+  gimp_sample_point_get_position (sample_point, &x, &y);
+
+  gimp_canvas_sample_point_set (item, x, y);
 }
 
 static void
diff --git a/app/tests/test-xcf.c b/app/tests/test-xcf.c
index 1e27a70..6195321 100644
--- a/app/tests/test-xcf.c
+++ b/app/tests/test-xcf.c
@@ -711,6 +711,8 @@ gimp_assert_mainimage (GimpImage *image,
   GList              *iter                   = NULL;
   GimpGuide          *guide                  = NULL;
   GimpSamplePoint    *sample_point           = NULL;
+  gint                sample_point_x         = 0;
+  gint                sample_point_y         = 0;
   gdouble             xres                   = 0.0;
   gdouble             yres                   = 0.0;
   GimpGrid           *grid                   = NULL;
@@ -783,25 +785,25 @@ gimp_assert_mainimage (GimpImage *image,
   /* Guides, note that we rely on internal ordering */
   iter = gimp_image_get_guides (image);
   g_assert (iter != NULL);
-  guide = GIMP_GUIDE (iter->data);
+  guide = iter->data;
   g_assert_cmpint (gimp_guide_get_position (guide),
                    ==,
                    GIMP_MAINIMAGE_VGUIDE1_POS);
   iter = g_list_next (iter);
   g_assert (iter != NULL);
-  guide = GIMP_GUIDE (iter->data);
+  guide = iter->data;
   g_assert_cmpint (gimp_guide_get_position (guide),
                    ==,
                    GIMP_MAINIMAGE_VGUIDE2_POS);
   iter = g_list_next (iter);
   g_assert (iter != NULL);
-  guide = GIMP_GUIDE (iter->data);
+  guide = iter->data;
   g_assert_cmpint (gimp_guide_get_position (guide),
                    ==,
                    GIMP_MAINIMAGE_HGUIDE1_POS);
   iter = g_list_next (iter);
   g_assert (iter != NULL);
-  guide = GIMP_GUIDE (iter->data);
+  guide = iter->data;
   g_assert_cmpint (gimp_guide_get_position (guide),
                    ==,
                    GIMP_MAINIMAGE_HGUIDE2_POS);
@@ -813,20 +815,24 @@ gimp_assert_mainimage (GimpImage *image,
    */
   iter = gimp_image_get_sample_points (image);
   g_assert (iter != NULL);
-  sample_point = (GimpSamplePoint *) iter->data;
-  g_assert_cmpint (sample_point->x,
+  sample_point = iter->data;
+  gimp_sample_point_get_position (sample_point,
+                                  &sample_point_x, &sample_point_y);
+  g_assert_cmpint (sample_point_x,
                    ==,
                    GIMP_MAINIMAGE_SAMPLEPOINT1_X);
-  g_assert_cmpint (sample_point->y,
+  g_assert_cmpint (sample_point_y,
                    ==,
                    GIMP_MAINIMAGE_SAMPLEPOINT1_Y);
   iter = g_list_next (iter);
   g_assert (iter != NULL);
-  sample_point = (GimpSamplePoint *) iter->data;
-  g_assert_cmpint (sample_point->x,
+  sample_point = iter->data;
+  gimp_sample_point_get_position (sample_point,
+                                  &sample_point_x, &sample_point_y);
+  g_assert_cmpint (sample_point_x,
                    ==,
                    GIMP_MAINIMAGE_SAMPLEPOINT2_X);
-  g_assert_cmpint (sample_point->y,
+  g_assert_cmpint (sample_point_y,
                    ==,
                    GIMP_MAINIMAGE_SAMPLEPOINT2_Y);
   iter = g_list_next (iter);
diff --git a/app/tools/gimpcolortool.c b/app/tools/gimpcolortool.c
index c2dbee7..5656865 100644
--- a/app/tools/gimpcolortool.c
+++ b/app/tools/gimpcolortool.c
@@ -221,8 +221,9 @@ gimp_color_tool_button_press (GimpTool            *tool,
   if (color_tool->sample_point)
     {
       color_tool->moving_sample_point = TRUE;
-      color_tool->sample_point_x      = color_tool->sample_point->x;
-      color_tool->sample_point_y      = color_tool->sample_point->y;
+      gimp_sample_point_get_position (color_tool->sample_point,
+                                      &color_tool->sample_point_x,
+                                      &color_tool->sample_point_y);
 
       gimp_tool_control_set_scroll_lock (tool->control, TRUE);
 
@@ -542,14 +543,15 @@ gimp_color_tool_draw (GimpDrawTool *draw_tool)
           GimpImage      *image = gimp_display_get_image (draw_tool->display);
           GimpCanvasItem *item;
           gint            index;
+          gint            x;
+          gint            y;
+
+          gimp_sample_point_get_position (color_tool->sample_point, &x, &y);
 
           index = g_list_index (gimp_image_get_sample_points (image),
                                 color_tool->sample_point) + 1;
 
-          item = gimp_draw_tool_add_sample_point (draw_tool,
-                                                  color_tool->sample_point->x,
-                                                  color_tool->sample_point->y,
-                                                  index);
+          item = gimp_draw_tool_add_sample_point (draw_tool, x, y, index);
           gimp_canvas_item_set_highlight (item, TRUE);
         }
 
diff --git a/app/widgets/gimpsamplepointeditor.c b/app/widgets/gimpsamplepointeditor.c
index 1dd6242..330c165 100644
--- a/app/widgets/gimpsamplepointeditor.c
+++ b/app/widgets/gimpsamplepointeditor.c
@@ -385,9 +385,13 @@ gimp_sample_point_editor_proj_update (GimpImage             *image,
        i++, list = g_list_next (list))
     {
       GimpSamplePoint *sample_point = list->data;
+      gint             sp_x;
+      gint             sp_y;
 
-      if (sample_point->x >= x && sample_point->x < (x + width) &&
-          sample_point->y >= y && sample_point->y < (y + height))
+      gimp_sample_point_get_position (sample_point, &sp_x, &sp_y);
+
+      if (sp_x >= x && sp_x < (x + width) &&
+          sp_y >= y && sp_y < (y + height))
         {
           gimp_sample_point_editor_dirty (editor, i);
         }
@@ -469,14 +473,17 @@ gimp_sample_point_editor_update (GimpSamplePointEditor *editor)
           const Babl      *format;
           guchar           pixel[32];
           GimpRGB          color;
+          gint             x;
+          gint             y;
 
           editor->dirty[i] = FALSE;
 
           color_frame = GIMP_COLOR_FRAME (editor->color_frames[i]);
 
+          gimp_sample_point_get_position (sample_point, &x, &y);
+
           if (gimp_image_pick_color (image_editor->image, NULL,
-                                     sample_point->x,
-                                     sample_point->y,
+                                     x, y,
                                      editor->sample_merged,
                                      FALSE, 0.0,
                                      &format,
diff --git a/app/xcf/xcf-save.c b/app/xcf/xcf-save.c
index 5ada022..4a61026 100644
--- a/app/xcf/xcf-save.c
+++ b/app/xcf/xcf-save.c
@@ -947,8 +947,7 @@ xcf_save_prop (XcfInfo    *info,
             GimpSamplePoint *sample_point = sample_points->data;
             gint32           x, y;
 
-            x = sample_point->x;
-            y = sample_point->y;
+            gimp_sample_point_get_position (sample_point, &x, &y);
 
             xcf_write_int32_check_error (info, (guint32 *) &x, 1);
             xcf_write_int32_check_error (info, (guint32 *) &y, 1);


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