[gimp/soc-2013-combined-selection-tool: 181/230] Added files; .c & .h for the new tools



commit cc1f9943da20757dfc22010543c478275c231ac5
Author: Ajay Ramanathan <ajay 010293 gmail com>
Date:   Sun Jun 23 14:50:32 2013 +0530

    Added files; .c & .h for the new tools

 app/tools/gimpselectbycolortool.c   |  151 +++++++++++++++++++++++++++++++++++
 app/tools/gimpselectbycolortool.h   |   55 +++++++++++++
 app/tools/gimpselectbycontenttool.c |   26 ++++++
 app/tools/gimpselectbycontenttool.h |   61 ++++++++++++++
 app/tools/gimpselectbyshapetool.c   |  150 ++++++++++++++++++++++++++++++++++
 app/tools/gimpselectbyshapetool.h   |   53 ++++++++++++
 6 files changed, 496 insertions(+), 0 deletions(-)
---
diff --git a/app/tools/gimpselectbycolortool.c b/app/tools/gimpselectbycolortool.c
new file mode 100644
index 0000000..04df638
--- /dev/null
+++ b/app/tools/gimpselectbycolortool.c
@@ -0,0 +1,151 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimpselectbycolortool.c
+ *
+ * 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 <string.h>
+
+#include <gegl.h>
+#include <gtk/gtk.h>
+
+#include "libgimpcolor/gimpcolor.h"
+#include "libgimpwidgets/gimpwidgets.h"
+
+#include "tools-types.h"
+
+#include "core/gimpimage.h"
+#include "core/gimpimage-contiguous-region.h"
+#include "core/gimpitem.h"
+#include "core/gimppickable.h"
+
+#include "widgets/gimphelp-ids.h"
+
+#include "display/gimpdisplay.h"
+
+#include "gimpselectbycolortool.h"
+#include "gimpregionselectoptions.h"
+#include "gimptoolcontrol.h"
+
+#include "gimp-intl.h"
+
+
+static GeglBuffer * gimp_select_by_color_tool_get_mask (GimpRegionSelectTool *region_select,
+                                                        GimpDisplay          *display);
+
+
+G_DEFINE_TYPE (GimpSelectByColorTool, gimp_select_by_color_tool,
+               GIMP_TYPE_REGION_SELECT_TOOL)
+
+#define parent_class gimp_select_by_color_tool_parent_class
+
+
+void
+gimp_select_by_color_tool_register (GimpToolRegisterCallback  callback,
+                                    gpointer                  data)
+{
+  (* callback) (GIMP_TYPE_SELECT_BY_COLOR_TOOL,
+                GIMP_TYPE_REGION_SELECT_OPTIONS,
+                gimp_region_select_options_gui,
+                0,
+                "gimp-select_by_color-tool",
+                _("Select by Color"),
+                _("Select by Color Tool: Select regions with similar colors; Both Over Continous and Closed 
Place"),
+                N_("_Select By Color"), "<shift>X",
+                NULL, GIMP_HELP_TOOL_SELECT_BY_COLOR,
+                GIMP_STOCK_TOOL_SELECT_BY_COLOR,
+                data);
+}
+
+static void
+gimp_select_by_color_tool_class_init (GimpSelectByColorToolClass *klass)
+{
+  GimpRegionSelectToolClass *region_class;
+
+  region_class = GIMP_REGION_SELECT_TOOL_CLASS (klass);
+
+  region_class->undo_desc = C_("command", "Select by Color");
+  region_class->get_mask  = gimp_select_by_color_tool_get_mask;
+}
+
+static void
+gimp_select_by_color_tool_init (GimpSelectByColorTool *select_by_color)
+{
+  GimpTool *tool = GIMP_TOOL (select_by_color);
+
+  gimp_tool_control_set_tool_cursor (tool->control, GIMP_TOOL_CURSOR_HAND);
+}
+
+static GeglBuffer *
+gimp_select_by_color_tool_get_mask (GimpRegionSelectTool *region_select,
+                                    GimpDisplay          *display)
+{
+  GimpTool                *tool        = GIMP_TOOL (region_select);
+  GimpSelectionOptions    *sel_options = GIMP_SELECTION_TOOL_GET_OPTIONS (tool);
+  GimpRegionSelectOptions *options     = GIMP_REGION_SELECT_TOOL_GET_OPTIONS (tool);
+  GimpImage               *image       = gimp_display_get_image (display);
+  GimpDrawable            *drawable    = gimp_image_get_active_drawable (image);
+  GimpPickable            *pickable;
+  GimpRGB                  color;
+  gint                     x, y;
+
+  x = region_select->x;
+  y = region_select->y;
+
+  if (! options->sample_merged)
+    {
+      gint off_x, off_y;
+
+      gimp_item_get_offset (GIMP_ITEM (drawable), &off_x, &off_y);
+
+      x -= off_x;
+      y -= off_y;
+
+      pickable = GIMP_PICKABLE (drawable);
+    }
+  else
+    {
+      pickable = GIMP_PICKABLE (gimp_image_get_projection (image));
+    }
+
+  gimp_pickable_flush (pickable);
+  
+  if(! options->continuous)
+    {
+           return gimp_image_contiguous_region_by_seed (image, drawable,
+                                               options->sample_merged,
+                                               sel_options->antialias,
+                                               options->threshold / 255.0,
+                                               options->select_transparent,
+                                               options->select_criterion,
+                                               x, y);
+    }
+  else
+    {
+           if (gimp_pickable_get_color_at (pickable, x, y, &color))
+            return gimp_image_contiguous_region_by_color (image, drawable,
+                                                    options->sample_merged,
+                                                    sel_options->antialias,
+                                                    options->threshold / 255.0,
+                                                    options->select_transparent,
+                                                    options->select_criterion,
+                                                    &color);
+
+        return NULL;
+    }
+}      
diff --git a/app/tools/gimpselectbycolortool.h b/app/tools/gimpselectbycolortool.h
new file mode 100644
index 0000000..c59f732
--- /dev/null
+++ b/app/tools/gimpselectbycolortool.h
@@ -0,0 +1,55 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimpselectbycolortool.h
+ *
+ * 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_SELECT_BY_COLOR_TOOL_H__
+#define __GIMP_SELECT_BY_COLOR_TOOL_H__
+
+
+#include "gimpregionselecttool.h"
+
+
+#define GIMP_TYPE_SELECT_BY_COLOR_TOOL            (gimp_select_by_color_tool_get_type ())
+#define GIMP_SELECT_BY_COLOR_TOOL(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GIMP_TYPE_SELECT_BY_COLOR_TOOL, GimpSelectByColorTool))
+#define GIMP_SELECT_BY_COLOR_TOOL_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), 
GIMP_TYPE_SELECT_BY_COLOR_TOOL, GimpSelectByColorToolClass))
+#define GIMP_IS_SELECT_BY_COLOR_TOOL(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
GIMP_TYPE_SELECT_BY_COLOR_TOOL))
+#define GIMP_IS_SELECT_BY_COLOR_TOOL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), 
GIMP_TYPE_SELECT_BY_COLOR_TOOL))
+#define GIMP_SELECT_BY_COLOR_TOOL_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), 
GIMP_TYPE_SELECT_BY_COLOR_TOOL, GimpSelectByColorToolClass))
+
+
+typedef struct _GimpSelectByColorTool      GimpSelectByColorTool;
+typedef struct _GimpSelectByColorToolClass GimpSelectByColorToolClass;
+
+struct _GimpSelectByColorTool
+{
+  GimpRegionSelectTool  parent_instance;
+};
+
+struct _GimpSelectByColorToolClass
+{
+  GimpRegionSelectToolClass  parent_class;
+};
+
+
+void    gimp_select_by_color_tool_register (GimpToolRegisterCallback  callback,
+                                            gpointer                  data);
+
+GType   gimp_select_by_color_tool_get_type (void) G_GNUC_CONST;
+
+
+#endif  /*  __GIMP_SELECT_BY_COLOR_TOOL_H__  */
diff --git a/app/tools/gimpselectbycontenttool.c b/app/tools/gimpselectbycontenttool.c
new file mode 100644
index 0000000..af3eac7
--- /dev/null
+++ b/app/tools/gimpselectbycontenttool.c
@@ -0,0 +1,26 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimpselectbycolortool.c
+ *
+ * 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/>.
+ */
+
+/* Need to add content; just made it so that it would be easier later*/
+
+
+
+#if 0
+
+#endif
\ No newline at end of file
diff --git a/app/tools/gimpselectbycontenttool.h b/app/tools/gimpselectbycontenttool.h
new file mode 100644
index 0000000..e305b19
--- /dev/null
+++ b/app/tools/gimpselectbycontenttool.h
@@ -0,0 +1,61 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * gimpselectbycolortool.h
+ *
+ * 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/>.
+ */
+
+//Just for ease of purpose
+
+#if 0
+
+#ifndef __GIMP_SELECT_BY_COLOR_TOOL_H__
+#define __GIMP_SELECT_BY_COLOR_TOOL_H__
+
+
+#include "gimpregionselecttool.h"
+
+
+#define GIMP_TYPE_SELECT_BY_COLOR_TOOL            (gimp_select_by_color_tool_get_type ())
+#define GIMP_SELECT_BY_COLOR_TOOL(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GIMP_TYPE_SELECT_BY_COLOR_TOOL, GimpSelectByColorTool))
+#define GIMP_SELECT_BY_COLOR_TOOL_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), 
GIMP_TYPE_SELECT_BY_COLOR_TOOL, GimpSelectByColorToolClass))
+#define GIMP_IS_SELECT_BY_COLOR_TOOL(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
GIMP_TYPE_SELECT_BY_COLOR_TOOL))
+#define GIMP_IS_SELECT_BY_COLOR_TOOL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), 
GIMP_TYPE_SELECT_BY_COLOR_TOOL))
+#define GIMP_SELECT_BY_COLOR_TOOL_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), 
GIMP_TYPE_SELECT_BY_COLOR_TOOL, GimpSelectByColorToolClass))
+
+
+typedef struct _GimpSelectByColorTool      GimpSelectByColorTool;
+typedef struct _GimpSelectByColorToolClass GimpSelectByColorToolClass;
+
+struct _GimpSelectByColorTool
+{
+  GimpRegionSelectTool  parent_instance;
+};
+
+struct _GimpSelectByColorToolClass
+{
+  GimpRegionSelectToolClass  parent_class;
+};
+
+
+void    gimp_select_by_color_tool_register (GimpToolRegisterCallback  callback,
+                                            gpointer                  data);
+
+GType   gimp_select_by_color_tool_get_type (void) G_GNUC_CONST;
+
+
+#endif  /*  __GIMP_SELECT_BY_COLOR_TOOL_H__  */
+
+#endif
diff --git a/app/tools/gimpselectbyshapetool.c b/app/tools/gimpselectbyshapetool.c
new file mode 100644
index 0000000..cea2a4b
--- /dev/null
+++ b/app/tools/gimpselectbyshapetool.c
@@ -0,0 +1,150 @@
+/* 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 <gtk/gtk.h>
+
+#include "libgimpwidgets/gimpwidgets.h"
+
+#include "tools-types.h"
+
+#include "core/gimpchannel-select.h"
+#include "core/gimpimage.h"
+
+#include "widgets/gimphelp-ids.h"
+
+#include "display/gimpdisplay.h"
+
+#include "gimpselectbyshapetool.h"
+#include "gimprectangleselectoptions.h"
+#include "gimptoolcontrol.h"
+
+#include "gimp-intl.h"
+
+
+static void   gimp_select_by_shape_tool_draw   (GimpDrawTool            *draw_tool);
+
+static void   gimp_select_by_shape_tool_select (GimpRectangleSelectTool *rect_tool,
+                                               GimpChannelOps           operation,
+                                               gint                     x,
+                                               gint                     y,
+                                               gint                     w,
+                                               gint                     h);
+
+
+G_DEFINE_TYPE (GimpSelectByShapeTool, gimp_select_by_shape_tool,
+               GIMP_TYPE_RECTANGLE_SELECT_TOOL)
+
+#define parent_class gimp_select_by_shape_tool_parent_class
+
+
+void
+gimp_select_by_shape_tool_register (GimpToolRegisterCallback  callback,
+                                   gpointer                  data)
+{
+  (* callback) (GIMP_TYPE_SELECT_BY_SHAPE_TOOL,
+                GIMP_TYPE_RECTANGLE_SELECT_OPTIONS,
+                gimp_rectangle_select_options_gui,
+                0,
+                "gimp-select-by-shape-tool",
+                _("Select by Shape"),
+                _("Select by Shape Tool: Selects a predefined shape"),
+                N_("_Select By Shape"), "<shift>S",
+                NULL, GIMP_HELP_TOOL_SELECT_BY_SHAPE,
+                GIMP_STOCK_TOOL_SELECT_BY_SHAPE,
+                data);
+}
+
+static void
+gimp_select_by_shape_tool_class_init (GimpSelectByShapeToolClass *klass)
+{
+  GimpDrawToolClass            *draw_tool_class = GIMP_DRAW_TOOL_CLASS (klass);
+  GimpRectangleSelectToolClass *rect_tool_class = GIMP_RECTANGLE_SELECT_TOOL_CLASS (klass);
+
+  draw_tool_class->draw   = gimp_select_by_shape_tool_draw;
+
+  rect_tool_class->select = gimp_select_by_shape_tool_select;
+}
+
+static void
+gimp_select_by_shape_tool_init (GimpSelectByShapeTool *select_by_shape)
+{
+  GimpTool *tool = GIMP_TOOL (select_by_shape);
+
+  gimp_tool_control_set_tool_cursor (tool->control,
+                                     GIMP_TOOL_CURSOR_ELLIPSE_SELECT);
+  //Need to add new Cursors :'(
+}
+
+static void
+gimp_select_by_shape_tool_draw (GimpDrawTool *draw_tool)
+{
+  gint x1, y1, x2, y2;
+
+  GIMP_DRAW_TOOL_CLASS (parent_class)->draw (draw_tool);
+
+  g_object_get (draw_tool,
+                "x1", &x1,
+                "y1", &y1,
+                "x2", &x2,
+                "y2", &y2,
+                NULL);
+
+  gimp_draw_tool_add_arc (draw_tool,
+                          FALSE,
+                          x1, y1,
+                          x2 - x1, y2 - y1,
+                          0.0, 2 * G_PI);
+}
+
+static void
+gimp_select_by_shape_tool_select (GimpRectangleSelectTool *rect_tool,
+                                 GimpChannelOps           operation,
+                                 gint                     x,
+                                 gint                     y,
+                                 gint                     w,
+                                 gint                     h)
+{
+  GimpTool                   *tool    = GIMP_TOOL (rect_tool);
+  GimpSelectionOptions       *options = GIMP_SELECTION_TOOL_GET_OPTIONS (rect_tool);
+  GimpImage                  *image   = gimp_display_get_image (tool->display);
+  GimpRectangleSelectOptions *sel_options     = GIMP_RECTANGLE_SELECT_TOOL_GET_OPTIONS (tool);
+
+  if(! sel_options->shape_options)
+   {
+     gimp_channel_select_ellipse (gimp_image_get_mask (image),
+                               x, y, w, h,
+                               operation,
+                               options->antialias,
+                               options->feather,
+                               options->feather_radius,
+                               options->feather_radius,
+                               TRUE);
+   }
+   else 
+   {   
+     gimp_channel_select_rectangle (gimp_image_get_mask (image),
+                                     x, y, w, h,
+                                     operation,
+                                     options->feather,
+                                     options->feather_radius,
+                                     options->feather_radius,
+                                     TRUE);
+   }  
+}
diff --git a/app/tools/gimpselectbyshapetool.h b/app/tools/gimpselectbyshapetool.h
new file mode 100644
index 0000000..cf18501
--- /dev/null
+++ b/app/tools/gimpselectbyshapetool.h
@@ -0,0 +1,53 @@
+/* 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/>.
+ */
+
+#ifndef __GIMP_SELECT_BY_SHAPE_TOOL_H__
+#define __GIMP_SELECT_BY_SHAPE_TOOL_H__
+
+
+#include "gimprectangleselecttool.h"
+
+
+#define GIMP_TYPE_SELECT_BY_SHAPE_TOOL            (gimp_select_by_shape_tool_get_type ())
+#define GIMP_SELECT_BY_SHAPE_TOOL(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GIMP_TYPE_SELECT_BY_SHAPE_TOOL, GimpSelectByShapeTool))
+#define GIMP_SELECT_BY_SHAPE_TOOL_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), 
GIMP_TYPE_SELECT_BY_SHAPE_TOOL, GimpSelectByShapeToolClass))
+#define GIMP_IS_SELECT_BY_SHAPE_TOOL(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
GIMP_TYPE_SELECT_BY_SHAPE_TOOL))
+#define GIMP_IS_SELECT_BY_SHAPE_TOOL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), 
GIMP_TYPE_SELECT_BY_SHAPE_TOOL))
+#define GIMP_SELECT_BY_SHAPE_TOOL_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), 
GIMP_TYPE_SELECT_BY_SHAPE_TOOL, GimpSelectByShapeToolClass))
+
+
+typedef struct _GimpSelectByShapeTool      GimpSelectByShapeTool;
+typedef struct _GimpSelectByShapeToolClass GimpSelectByShapeToolClass;
+
+struct _GimpSelectByShapeTool
+{
+  GimpRectangleSelectTool  parent_instance;
+};
+
+struct _GimpSelectByShapeToolClass
+{
+  GimpRectangleSelectToolClass  parent_class;
+};
+
+
+void    gimp_select_by_shape_tool_register (GimpToolRegisterCallback  callback,
+                                           gpointer                  data);
+
+GType   gimp_select_by_shape_tool_get_type (void) G_GNUC_CONST;
+
+
+#endif  /*  __GIMP_SELECT_BY_SHAPE_TOOL_H__  */


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