[gimp/multi-stroke: 10/31] app: better API for gimpimage-symmetry.h.



commit a0affd9b53d7fc414c89b97542627e2bae0a724a
Author: Jehan <jehan girinstud io>
Date:   Sun Mar 22 00:43:01 2015 +0100

    app: better API for gimpimage-symmetry.h.

 app/core/gimpcontext.c           |    2 +-
 app/core/gimpimage-private.h     |    1 -
 app/core/gimpimage-symmetry.c    |  102 +++++++++++++++++++-------------------
 app/core/gimpimage-symmetry.h    |   22 +++-----
 app/core/gimpimage.c             |    8 ---
 app/core/gimpsymmetry-mirror.c   |    2 +-
 app/paint/gimppaintcore.c        |    5 +--
 app/paint/gimppaintoptions.c     |   13 ++---
 app/tools/gimppaintoptions-gui.c |    4 +-
 app/xcf/xcf-load.c               |    6 +--
 app/xcf/xcf-save.c               |    8 ++--
 11 files changed, 75 insertions(+), 98 deletions(-)
---
diff --git a/app/core/gimpcontext.c b/app/core/gimpcontext.c
index 4805c60..e6e29f5 100644
--- a/app/core/gimpcontext.c
+++ b/app/core/gimpcontext.c
@@ -1927,7 +1927,7 @@ gimp_context_real_set_image (GimpContext *context,
       paint_options = GIMP_PAINT_OPTIONS (context->tool_info->tool_options);
 
       if (image)
-        sym = gimp_image_get_selected_symmetry (image);
+        sym = gimp_image_symmetry_selected (image);
 
       g_object_set (paint_options, "symmetry",
                     sym ? sym->type : G_TYPE_NONE,
diff --git a/app/core/gimpimage-private.h b/app/core/gimpimage-private.h
index 5b4029c..5fc38eb 100644
--- a/app/core/gimpimage-private.h
+++ b/app/core/gimpimage-private.h
@@ -89,7 +89,6 @@ struct _GimpImagePrivate
 
   GList             *symmetries;            /*  Painting symmetries          */
   GimpSymmetry      *selected_symmetry;     /*  Selected symmetry            */
-  GimpSymmetry      *id_symmetry;           /*  The base "Single" stroke     */
 
   GList             *guides;                /*  guides                       */
   GimpGrid          *grid;                  /*  grid                         */
diff --git a/app/core/gimpimage-symmetry.c b/app/core/gimpimage-symmetry.c
index dff9aa7..9b4af60 100644
--- a/app/core/gimpimage-symmetry.c
+++ b/app/core/gimpimage-symmetry.c
@@ -32,25 +32,15 @@
 #include "gimpsymmetry-mirror.h"
 #include "gimpsymmetry-tiling.h"
 
-GList *
-gimp_image_symmetry_list (void)
-{
-  GList *list = NULL;
+static GimpSymmetry * gimp_image_symmetry_new (GimpImage *image,
+                                               GType      type);
 
-  list = g_list_prepend (list, GINT_TO_POINTER (GIMP_TYPE_MIRROR));
-  list = g_list_prepend (list, GINT_TO_POINTER (GIMP_TYPE_TILING));
-  return list;
-}
-
-GimpSymmetry *
+static GimpSymmetry *
 gimp_image_symmetry_new (GimpImage *image,
                          GType      type)
 {
   GimpSymmetry *sym = NULL;
 
-  g_return_val_if_fail (g_type_is_a (type, GIMP_TYPE_SYMMETRY),
-                        NULL);
-
   if (type != G_TYPE_NONE)
     {
       sym = g_object_new (type,
@@ -62,32 +52,50 @@ gimp_image_symmetry_new (GimpImage *image,
   return sym;
 }
 
+/*** Public Functions ***/
+
+GList *
+gimp_image_symmetry_list (void)
+{
+  GList *list = NULL;
+
+  list = g_list_prepend (list, GINT_TO_POINTER (GIMP_TYPE_MIRROR));
+  list = g_list_prepend (list, GINT_TO_POINTER (GIMP_TYPE_TILING));
+  return list;
+}
+
 /**
- * gimp_image_add_symmetry:
- * @image:   the #GimpImage
- * @sym: the #GimpSymmetry
+ * gimp_image_symmetry_add:
+ * @image: the #GimpImage
+ * @type:  the #GType of the symmetry
  *
- * Add a symmetry transformation to @image and make it the
+ * Add a symmetry of type @type to @image and make it the
  * selected transformation.
  **/
-void
-gimp_image_add_symmetry (GimpImage    *image,
-                         GimpSymmetry *sym)
+GimpSymmetry *
+gimp_image_symmetry_add (GimpImage *image,
+                         GType      type)
 {
   GimpImagePrivate *private;
+  GimpSymmetry     *sym;
 
-  g_return_if_fail (GIMP_IS_IMAGE (image));
-  g_return_if_fail (GIMP_IS_SYMMETRY (sym));
+  g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
+  g_return_val_if_fail (g_type_is_a (type, GIMP_TYPE_SYMMETRY), NULL);
+
+
+  sym = gimp_image_symmetry_new (image, type);
 
   private = GIMP_IMAGE_GET_PRIVATE (image);
 
   private->symmetries = g_list_prepend (private->symmetries,
-                                        g_object_ref (sym));
+                                        sym);
   private->selected_symmetry = sym;
+
+  return sym;
 }
 
 /**
- * gimp_image_remove_symmetry:
+ * gimp_image_symmetry_remove:
  * @image:   the #GimpImage
  * @sym: the #GimpSymmetry
  *
@@ -95,7 +103,7 @@ gimp_image_add_symmetry (GimpImage    *image,
  * If it was the selected transformation, unselect it first.
  **/
 void
-gimp_image_remove_symmetry (GimpImage    *image,
+gimp_image_symmetry_remove (GimpImage    *image,
                             GimpSymmetry *sym)
 {
   GimpImagePrivate *private;
@@ -113,14 +121,14 @@ gimp_image_remove_symmetry (GimpImage    *image,
 }
 
 /**
- * gimp_image_get_symmetry:
+ * gimp_image_symmetry_get:
  * @image: the #GimpImage
  *
- * Returns a list of #GimpSymmetry set on @image.
+ * Returns the list of #GimpSymmetry set on @image.
  * The returned list belongs to @image and should not be freed.
  **/
 GList *
-gimp_image_get_symmetrys (GimpImage *image)
+gimp_image_symmetry_get (GimpImage *image)
 {
   GimpImagePrivate *private;
 
@@ -132,7 +140,7 @@ gimp_image_get_symmetrys (GimpImage *image)
 }
 
 /**
- * gimp_image_select_symmetry:
+ * gimp_image_symmetry_select:
  * @image: the #GimpImage
  * @type:  the #GType of the symmetry
  *
@@ -143,7 +151,7 @@ gimp_image_get_symmetrys (GimpImage *image)
  * Returns TRUE on success, FALSE if no such symmetry was found.
  **/
 gboolean
-gimp_image_select_symmetry (GimpImage *image,
+gimp_image_symmetry_select (GimpImage *image,
                             GType      type)
 {
   GimpImagePrivate *private;
@@ -174,37 +182,29 @@ gimp_image_select_symmetry (GimpImage *image,
 }
 
 /**
- * gimp_image_get_selected_symmetry:
+ * gimp_image_symmetry_selected:
  * @image: the #GimpImage
  *
  * Returns the #GimpSymmetry transformation selected on @image.
  **/
 GimpSymmetry *
-gimp_image_get_selected_symmetry (GimpImage *image)
+gimp_image_symmetry_selected (GimpImage *image)
 {
-  GimpImagePrivate *private;
+  static GimpImage    *last_image = NULL;
+  static GimpSymmetry *identity = NULL;
+  GimpImagePrivate    *private;
 
   g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
 
-  private = GIMP_IMAGE_GET_PRIVATE (image);
-
-  return private->selected_symmetry;
-}
-
-/**
- * gimp_image_symmetry_get_id:
- * @image: the #GimpImage
- *
- * Returns the basic "single stroke" #GimpSymmetry.
- **/
-GimpSymmetry *
-gimp_image_symmetry_get_id (GimpImage *image)
-{
-  GimpImagePrivate *private;
-
-  g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
+  if (last_image != image)
+    {
+      if (identity)
+        g_object_unref (identity);
+      identity = gimp_image_symmetry_new (image,
+                                          GIMP_TYPE_SYMMETRY);
+    }
 
   private = GIMP_IMAGE_GET_PRIVATE (image);
 
-  return private->id_symmetry;
+  return private->selected_symmetry ? private->selected_symmetry : identity;
 }
diff --git a/app/core/gimpimage-symmetry.h b/app/core/gimpimage-symmetry.h
index 7ebeaf7..b9dacc9 100644
--- a/app/core/gimpimage-symmetry.h
+++ b/app/core/gimpimage-symmetry.h
@@ -21,20 +21,16 @@
 #ifndef __GIMP_IMAGE_SYMMETRY_H__
 #define __GIMP_IMAGE_SYMMETRY_H__
 
-GList        * gimp_image_symmetry_list (void);
+GList        * gimp_image_symmetry_list      (void);
 
-GimpSymmetry * gimp_image_symmetry_new          (GimpImage    *image,
-                                                 GType         type);
+GimpSymmetry * gimp_image_symmetry_add       (GimpImage    *image,
+                                              GType         type);
+void           gimp_image_symmetry_remove    (GimpImage    *image,
+                                              GimpSymmetry *sym);
+GList        * gimp_image_symmetry_get       (GimpImage    *image);
 
-void           gimp_image_add_symmetry          (GimpImage    *image,
-                                                 GimpSymmetry *sym);
-void           gimp_image_remove_symmetry       (GimpImage    *image,
-                                                 GimpSymmetry *sym);
-GList        * gimp_image_get_symmetrys         (GimpImage    *image);
-
-gboolean       gimp_image_select_symmetry       (GimpImage    *image,
-                                                 GType         type);
-GimpSymmetry * gimp_image_get_selected_symmetry (GimpImage    *image);
-GimpSymmetry * gimp_image_symmetry_get_id       (GimpImage    *image);
+gboolean       gimp_image_symmetry_select    (GimpImage    *image,
+                                              GType         type);
+GimpSymmetry * gimp_image_symmetry_selected  (GimpImage    *image);
 
 #endif  /*  __GIMP_IMAGE_SYMMETRY_H__  */
diff --git a/app/core/gimpimage.c b/app/core/gimpimage.c
index 3c211f5..9d245cd 100644
--- a/app/core/gimpimage.c
+++ b/app/core/gimpimage.c
@@ -701,8 +701,6 @@ gimp_image_init (GimpImage *image)
 
   private->symmetries          = NULL;
   private->selected_symmetry   = NULL;
-  private->id_symmetry         = gimp_image_symmetry_new (image,
-                                                          GIMP_TYPE_SYMMETRY);
 
   private->guides              = NULL;
   private->grid                = NULL;
@@ -1064,12 +1062,6 @@ gimp_image_finalize (GObject *object)
       private->symmetries = NULL;
     }
 
-  if (private->id_symmetry)
-    {
-      g_object_unref (private->id_symmetry);
-      private->id_symmetry = NULL;
-    }
-
   if (private->grid)
     {
       g_object_unref (private->grid);
diff --git a/app/core/gimpsymmetry-mirror.c b/app/core/gimpsymmetry-mirror.c
index 0819d3f..6a192bd 100644
--- a/app/core/gimpsymmetry-mirror.c
+++ b/app/core/gimpsymmetry-mirror.c
@@ -434,7 +434,7 @@ gimp_mirror_guide_removed_cb (GObject    *object,
       GimpSymmetry *sym;
 
       sym = GIMP_SYMMETRY (mirror);
-      gimp_image_remove_symmetry (sym->image,
+      gimp_image_symmetry_remove (sym->image,
                                   GIMP_SYMMETRY (mirror));
     }
   else
diff --git a/app/paint/gimppaintcore.c b/app/paint/gimppaintcore.c
index fab9736..71bf152 100644
--- a/app/paint/gimppaintcore.c
+++ b/app/paint/gimppaintcore.c
@@ -325,10 +325,7 @@ gimp_paint_core_paint (GimpPaintCore    *core,
           core->last_paint.y = core->cur_coords.y;
         }
 
-      if (gimp_image_get_selected_symmetry (image))
-        sym = g_object_ref (gimp_image_get_selected_symmetry (image));
-      else
-        sym = g_object_ref (gimp_image_symmetry_get_id (image));
+      sym = g_object_ref (gimp_image_symmetry_selected (image));
       gimp_symmetry_set_origin (sym, drawable, &core->cur_coords);
 
       core_class->paint (core, drawable,
diff --git a/app/paint/gimppaintoptions.c b/app/paint/gimppaintoptions.c
index 43836df..2920872 100644
--- a/app/paint/gimppaintoptions.c
+++ b/app/paint/gimppaintoptions.c
@@ -586,16 +586,11 @@ gimp_paint_options_set_property (GObject      *object,
       options->symmetry = g_value_get_int (value);
       if (context && context->image)
         {
-          if (! gimp_image_select_symmetry (context->image,
+          if (! gimp_image_symmetry_select (context->image,
                                             options->symmetry))
             {
-              GimpSymmetry *mstroke;
-
-              mstroke  = gimp_image_symmetry_new (context->image,
-                                                  options->symmetry);
-              gimp_image_add_symmetry (context->image,
-                                       GIMP_SYMMETRY (mstroke));
-              g_object_unref (mstroke);
+              gimp_image_symmetry_add (context->image,
+                                       options->symmetry);
             }
         }
       else
@@ -1173,7 +1168,7 @@ gimp_paint_options_set_mstroke_props (GimpPaintOptions *src,
     {
       GimpSymmetry  *mstroke;
 
-      mstroke = gimp_image_get_selected_symmetry (image);
+      mstroke = gimp_image_symmetry_selected (image);
 
       g_object_set (dest,
                     "symmetry",
diff --git a/app/tools/gimppaintoptions-gui.c b/app/tools/gimppaintoptions-gui.c
index 071a6ac..56bd43c 100644
--- a/app/tools/gimppaintoptions-gui.c
+++ b/app/tools/gimppaintoptions-gui.c
@@ -643,7 +643,7 @@ gimp_paint_options_symmetry_update_cb (GimpSymmetry *sym,
 
   context = gimp_get_user_context (sym->image->gimp);
   if (image != context->image ||
-      sym != gimp_image_get_selected_symmetry (image))
+      sym != gimp_image_symmetry_selected (image))
     {
       g_signal_handlers_disconnect_by_func (G_OBJECT (sym),
                                             gimp_paint_options_symmetry_update_cb,
@@ -669,7 +669,7 @@ gimp_paint_options_symmetry_callback (GimpPaintOptions *options,
   image   = context->image;
 
   if (image &&
-      (sym = gimp_image_get_selected_symmetry (image)))
+      (sym = gimp_image_symmetry_selected (image)))
     {
       g_signal_connect (sym, "update-ui",
                         G_CALLBACK (gimp_paint_options_symmetry_update_cb),
diff --git a/app/xcf/xcf-load.c b/app/xcf/xcf-load.c
index 372a4a8..b03bb56 100644
--- a/app/xcf/xcf-load.c
+++ b/app/xcf/xcf-load.c
@@ -769,9 +769,7 @@ xcf_load_image_props (XcfInfo   *info,
                       g_free (name);
                       return FALSE;
                     }
-                  sym = gimp_image_symmetry_new (image, type);
-                  gimp_image_add_symmetry (image, sym);
-                  g_object_unref (sym);
+                  sym = gimp_image_symmetry_add (image, type);
 
                   settings = gimp_symmetry_get_xcf_settings (sym,
                                                              &nsettings);
@@ -861,7 +859,7 @@ xcf_load_image_props (XcfInfo   *info,
                   if (active == i)
                     active_sym = sym;
                 }
-              gimp_image_select_symmetry (image, active_sym->type);
+              gimp_image_symmetry_select (image, active_sym->type);
               g_free (name);
             }
           break;
diff --git a/app/xcf/xcf-save.c b/app/xcf/xcf-save.c
index 444a82d..eccb95c 100644
--- a/app/xcf/xcf-save.c
+++ b/app/xcf/xcf-save.c
@@ -364,9 +364,9 @@ xcf_save_image_props (XcfInfo    *info,
     xcf_check_error (xcf_save_prop (info, image, PROP_GUIDES, error,
                                     gimp_image_get_guides (image)));
 
-  if (gimp_image_get_symmetrys (image))
+  if (g_list_length (gimp_image_symmetry_get (image)))
     xcf_check_error (xcf_save_prop (info, image, PROP_SYMMETRY, error,
-                                    gimp_image_get_symmetrys (image)));
+                                    gimp_image_symmetry_get (image)));
 
   if (gimp_image_get_sample_points (image))
     xcf_check_error (xcf_save_prop (info, image, PROP_SAMPLE_POINTS, error,
@@ -952,12 +952,12 @@ xcf_save_prop (XcfInfo    *info,
 
         /* Index of active symmetry starting at 1
          * (because 0 means none active) */
-        if (gimp_image_get_selected_symmetry (image))
+        if (gimp_image_symmetry_selected (image))
           {
             for (i = 1, iter = syms; iter; iter = g_list_next (iter), i++)
               {
                 sym = GIMP_SYMMETRY (iter->data);
-                if (sym == gimp_image_get_selected_symmetry (image))
+                if (sym == gimp_image_symmetry_selected (image))
                   break;
               }
           }


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