[gimp] app: move gimp_image_pick_layer() to its own file



commit 6650693d295b211c92a67d80b9fe2bedeb669965
Author: Michael Natterer <mitch gimp org>
Date:   Sun Mar 7 01:55:31 2010 +0100

    app: move gimp_image_pick_layer() to its own file
    
    and add a (still unused) text layer picking function.

 app/core/Makefile.am            |    2 +
 app/core/gimpimage-pick-layer.c |  109 +++++++++++++++++++++++++++++++++++++++
 app/core/gimpimage-pick-layer.h |   30 +++++++++++
 app/core/gimpimage.c            |   33 ------------
 app/core/gimpimage.h            |    3 -
 app/pdb/image-cmds.c            |    1 +
 app/tools/gimpmovetool.c        |    1 +
 app/tools/gimpselectiontool.c   |    1 +
 tools/pdbgen/pdb/image.pdb      |    1 +
 9 files changed, 145 insertions(+), 36 deletions(-)
---
diff --git a/app/core/Makefile.am b/app/core/Makefile.am
index 86fea69..f3def87 100644
--- a/app/core/Makefile.am
+++ b/app/core/Makefile.am
@@ -231,6 +231,8 @@ libappcore_a_sources = \
 	gimpimage-new.h				\
 	gimpimage-pick-color.c			\
 	gimpimage-pick-color.h			\
+	gimpimage-pick-layer.c			\
+	gimpimage-pick-layer.h			\
 	gimpimage-preview.c			\
 	gimpimage-preview.h			\
 	gimpimage-private.h			\
diff --git a/app/core/gimpimage-pick-layer.c b/app/core/gimpimage-pick-layer.c
new file mode 100644
index 0000000..0a78fba
--- /dev/null
+++ b/app/core/gimpimage-pick-layer.c
@@ -0,0 +1,109 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <gegl.h>
+
+#include "core-types.h"
+
+#include "gimpgrouplayer.h"
+#include "gimpimage.h"
+#include "gimpimage-pick-layer.h"
+#include "gimppickable.h"
+
+#include "text/gimptextlayer.h"
+
+
+GimpLayer *
+gimp_image_pick_layer (const GimpImage *image,
+                       gint             x,
+                       gint             y)
+{
+  GList *all_layers;
+  GList *list;
+
+  g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
+
+  all_layers = gimp_image_get_layer_list (image);
+
+  for (list = all_layers; list; list = g_list_next (list))
+    {
+      GimpLayer *layer = list->data;
+      gint       off_x, off_y;
+
+      gimp_item_get_offset (GIMP_ITEM (layer), &off_x, &off_y);
+
+      if (gimp_pickable_get_opacity_at (GIMP_PICKABLE (layer),
+                                        x - off_x, y - off_y) > 63)
+        {
+          g_list_free (all_layers);
+
+          return layer;
+        }
+    }
+
+  g_list_free (all_layers);
+
+  return NULL;
+}
+
+GimpTextLayer *
+gimp_image_pick_text_layer (const GimpImage *image,
+                            gint             x,
+                            gint             y)
+{
+  GList *all_layers;
+  GList *list;
+
+  g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
+
+  all_layers = gimp_image_get_layer_list (image);
+
+  for (list = all_layers; list; list = g_list_next (list))
+    {
+      GimpLayer *layer = list->data;
+      gint       off_x, off_y;
+
+      gimp_item_get_offset (GIMP_ITEM (layer), &off_x, &off_y);
+
+      if (GIMP_IS_TEXT_LAYER (layer) &&
+          x >= off_x &&
+          y >= off_y &&
+          x <  off_x + gimp_item_get_width  (GIMP_ITEM (layer)) &&
+          y <  off_y + gimp_item_get_height (GIMP_ITEM (layer)))
+        {
+          g_list_free (all_layers);
+
+          return GIMP_TEXT_LAYER (layer);
+        }
+      else if (! GIMP_IS_GROUP_LAYER (layer) &&
+               gimp_pickable_get_opacity_at (GIMP_PICKABLE (layer),
+                                             x - off_x, y - off_y) > 63)
+        {
+          /*  a normal layer covers any possible text layers below,
+           *  bail out
+           */
+
+          break;
+        }
+    }
+
+  g_list_free (all_layers);
+
+  return NULL;
+}
diff --git a/app/core/gimpimage-pick-layer.h b/app/core/gimpimage-pick-layer.h
new file mode 100644
index 0000000..bc1374f
--- /dev/null
+++ b/app/core/gimpimage-pick-layer.h
@@ -0,0 +1,30 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattisbvf
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GIMP_IMAGE_PICK_LAYER_H__
+#define __GIMP_IMAGE_PICK_LAYER_H__
+
+
+GimpLayer     * gimp_image_pick_layer      (const GimpImage *image,
+                                            gint             x,
+                                            gint             y);
+GimpTextLayer * gimp_image_pick_text_layer (const GimpImage *image,
+                                            gint             x,
+                                            gint             y);
+
+
+#endif /* __GIMP_IMAGE_PICK_LAYER_H__ */
diff --git a/app/core/gimpimage.c b/app/core/gimpimage.c
index 1f5668d..1517b2f 100644
--- a/app/core/gimpimage.c
+++ b/app/core/gimpimage.c
@@ -3961,39 +3961,6 @@ gimp_image_reorder_vectors (GimpImage   *image,
                                       push_undo, undo_desc);
 }
 
-GimpLayer *
-gimp_image_pick_layer (const GimpImage *image,
-                       gint             x,
-                       gint             y)
-{
-  GList *all_layers;
-  GList *list;
-
-  g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
-
-  all_layers = gimp_image_get_layer_list (image);
-
-  for (list = all_layers; list; list = g_list_next (list))
-    {
-      GimpLayer *layer = list->data;
-      gint       off_x, off_y;
-
-      gimp_item_get_offset (GIMP_ITEM (layer), &off_x, &off_y);
-
-      if (gimp_pickable_get_opacity_at (GIMP_PICKABLE (layer),
-                                        x - off_x, y - off_y) > 63)
-        {
-          g_list_free (all_layers);
-
-          return layer;
-        }
-    }
-
-  g_list_free (all_layers);
-
-  return NULL;
-}
-
 gboolean
 gimp_image_coords_in_active_pickable (GimpImage        *image,
                                       const GimpCoords *coords,
diff --git a/app/core/gimpimage.h b/app/core/gimpimage.h
index b4ef022..a904659 100644
--- a/app/core/gimpimage.h
+++ b/app/core/gimpimage.h
@@ -492,9 +492,6 @@ gboolean        gimp_image_reorder_vectors       (GimpImage          *image,
                                                   gboolean            push_undo,
                                                   const gchar        *undo_desc);
 
-GimpLayer     * gimp_image_pick_layer            (const GimpImage    *image,
-                                                  gint                x,
-                                                  gint                y);
 gboolean    gimp_image_coords_in_active_pickable (GimpImage          *image,
                                                   const GimpCoords   *coords,
                                                   gboolean            sample_merged,
diff --git a/app/pdb/image-cmds.c b/app/pdb/image-cmds.c
index fddacfd..3f743fb 100644
--- a/app/pdb/image-cmds.c
+++ b/app/pdb/image-cmds.c
@@ -39,6 +39,7 @@
 #include "core/gimpimage-flip.h"
 #include "core/gimpimage-merge.h"
 #include "core/gimpimage-pick-color.h"
+#include "core/gimpimage-pick-layer.h"
 #include "core/gimpimage-resize.h"
 #include "core/gimpimage-rotate.h"
 #include "core/gimpimage-scale.h"
diff --git a/app/tools/gimpmovetool.c b/app/tools/gimpmovetool.c
index 75d2ddf..29bf724 100644
--- a/app/tools/gimpmovetool.c
+++ b/app/tools/gimpmovetool.c
@@ -35,6 +35,7 @@
 #include "core/gimpguide.h"
 #include "core/gimpimage.h"
 #include "core/gimpimage-guides.h"
+#include "core/gimpimage-pick-layer.h"
 #include "core/gimplayer.h"
 #include "core/gimpimage-undo.h"
 #include "core/gimplayermask.h"
diff --git a/app/tools/gimpselectiontool.c b/app/tools/gimpselectiontool.c
index 7ac8ea7..45593d9 100644
--- a/app/tools/gimpselectiontool.c
+++ b/app/tools/gimpselectiontool.c
@@ -27,6 +27,7 @@
 
 #include "core/gimpchannel.h"
 #include "core/gimpimage.h"
+#include "core/gimpimage-pick-layer.h"
 #include "core/gimppickable.h"
 
 #include "display/gimpdisplay.h"
diff --git a/tools/pdbgen/pdb/image.pdb b/tools/pdbgen/pdb/image.pdb
index 8ea8bc9..dc968c4 100644
--- a/tools/pdbgen/pdb/image.pdb
+++ b/tools/pdbgen/pdb/image.pdb
@@ -713,6 +713,7 @@ HELP
     );
 
     %invoke = (
+	headers => [ qw("core/gimpimage-pick-layer.h") ],
 	code => <<'CODE'
 {
   layer = gimp_image_pick_layer (image, x, y);



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