From 984eef250079c2a95f3e93a4cb89a99aace83a70 Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Thu, 15 May 2003 14:31:22 +0000 Subject: [PATCH] added new function vectors_selection_to_vectors() which invokes the 2003-05-15 Michael Natterer * app/gui/vectors-commands.[ch]: added new function vectors_selection_to_vectors() which invokes the sel2path Plug-In. * app/gui/dialogs-constructors.c: make the new function known to GimpVectorTreeView. * app/widgets/gimpvectorstreeview.[ch]: Added a "Selection to Path" button anc call the new function. --- ChangeLog | 11 +++++++ app/actions/vectors-commands.c | 48 ++++++++++++++++++++++++++++++ app/actions/vectors-commands.h | 2 ++ app/dialogs/dialogs-constructors.c | 3 +- app/gui/dialogs-constructors.c | 3 +- app/gui/vectors-commands.c | 48 ++++++++++++++++++++++++++++++ app/gui/vectors-commands.h | 2 ++ app/widgets/gimpvectorstreeview.c | 46 +++++++++++++++++++++++++--- app/widgets/gimpvectorstreeview.h | 14 +++++---- 9 files changed, 166 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 946d1b5c4f..28b604d195 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2003-05-15 Michael Natterer + + * app/gui/vectors-commands.[ch]: added new function + vectors_selection_to_vectors() which invokes the sel2path Plug-In. + + * app/gui/dialogs-constructors.c: make the new function known to + GimpVectorTreeView. + + * app/widgets/gimpvectorstreeview.[ch]: Added a "Selection to Path" + button anc call the new function. + 2003-05-15 Michael Natterer * plug-ins/sel2path/sel2path.c: don't clear the selection after diff --git a/app/actions/vectors-commands.c b/app/actions/vectors-commands.c index 05d1384164..079bb8c866 100644 --- a/app/actions/vectors-commands.c +++ b/app/actions/vectors-commands.c @@ -40,6 +40,10 @@ #include "paint/gimppaintcore-stroke.h" #include "paint/gimppaintoptions.h" +#include "pdb/procedural_db.h" + +#include "plug-in/plug-in-run.h" + #include "vectors/gimpvectors.h" #include "widgets/gimpitemtreeview.h" @@ -328,6 +332,50 @@ vectors_stroke_vectors (GimpVectors *vectors) } } +void +vectors_selection_to_vectors (GimpImage *gimage, + gboolean advanced) +{ + ProcRecord *proc_rec; + Argument *args; + GimpDrawable *drawable; + GimpDisplay *gdisp; + + g_return_if_fail (GIMP_IS_IMAGE (gimage)); + + drawable = gimp_image_active_drawable (gimage); + gdisp = gimp_context_get_display (gimp_get_user_context (gimage->gimp)); + + if (advanced) + proc_rec = procedural_db_lookup (gimage->gimp, + "plug_in_sel2path_advanced"); + else + proc_rec = procedural_db_lookup (gimage->gimp, + "plug_in_sel2path"); + + if (! proc_rec) + { + g_message (_("Selection to path procedure lookup failed.")); + return; + } + + /* plug-in arguments as if called by /Filters/... */ + args = g_new (Argument, 3); + + args[0].arg_type = GIMP_PDB_INT32; + args[0].value.pdb_int = GIMP_RUN_INTERACTIVE; + args[1].arg_type = GIMP_PDB_IMAGE; + args[1].value.pdb_int = (gint32) gimp_image_get_ID (gimage); + args[2].arg_type = GIMP_PDB_DRAWABLE; + args[2].value.pdb_int = (gint32) gimp_item_get_ID (GIMP_ITEM (drawable)); + + plug_in_run (gimage->gimp, + proc_rec, args, 3, FALSE, TRUE, + gdisp ? gdisp->ID : 0); + + g_free (args); +} + void vectors_vectors_tool (GimpVectors *vectors) { diff --git a/app/actions/vectors-commands.h b/app/actions/vectors-commands.h index 603318250b..e34042a5e2 100644 --- a/app/actions/vectors-commands.h +++ b/app/actions/vectors-commands.h @@ -56,6 +56,8 @@ void vectors_edit_vectors_attributes_cmd_callback (GtkWidget *widget, gpointer data); void vectors_stroke_vectors (GimpVectors *vectors); +void vectors_selection_to_vectors (GimpImage *gimage, + gboolean advanced); void vectors_vectors_tool (GimpVectors *vectors); void vectors_new_vectors_query (GimpImage *gimage, GimpVectors *template, diff --git a/app/dialogs/dialogs-constructors.c b/app/dialogs/dialogs-constructors.c index f1656dd8be..50a794aa54 100644 --- a/app/dialogs/dialogs-constructors.c +++ b/app/dialogs/dialogs-constructors.c @@ -727,7 +727,8 @@ dialogs_vectors_list_view_new (GimpDialogFactory *factory, vectors_view = GIMP_VECTORS_TREE_VIEW (view); - vectors_view->stroke_item_func = vectors_stroke_vectors; + vectors_view->stroke_item_func = vectors_stroke_vectors; + vectors_view->selection_to_vectors_func = vectors_selection_to_vectors; dockable = dialogs_dockable_new (view, _("Paths List"), _("Paths"), NULL, diff --git a/app/gui/dialogs-constructors.c b/app/gui/dialogs-constructors.c index f1656dd8be..50a794aa54 100644 --- a/app/gui/dialogs-constructors.c +++ b/app/gui/dialogs-constructors.c @@ -727,7 +727,8 @@ dialogs_vectors_list_view_new (GimpDialogFactory *factory, vectors_view = GIMP_VECTORS_TREE_VIEW (view); - vectors_view->stroke_item_func = vectors_stroke_vectors; + vectors_view->stroke_item_func = vectors_stroke_vectors; + vectors_view->selection_to_vectors_func = vectors_selection_to_vectors; dockable = dialogs_dockable_new (view, _("Paths List"), _("Paths"), NULL, diff --git a/app/gui/vectors-commands.c b/app/gui/vectors-commands.c index 05d1384164..079bb8c866 100644 --- a/app/gui/vectors-commands.c +++ b/app/gui/vectors-commands.c @@ -40,6 +40,10 @@ #include "paint/gimppaintcore-stroke.h" #include "paint/gimppaintoptions.h" +#include "pdb/procedural_db.h" + +#include "plug-in/plug-in-run.h" + #include "vectors/gimpvectors.h" #include "widgets/gimpitemtreeview.h" @@ -328,6 +332,50 @@ vectors_stroke_vectors (GimpVectors *vectors) } } +void +vectors_selection_to_vectors (GimpImage *gimage, + gboolean advanced) +{ + ProcRecord *proc_rec; + Argument *args; + GimpDrawable *drawable; + GimpDisplay *gdisp; + + g_return_if_fail (GIMP_IS_IMAGE (gimage)); + + drawable = gimp_image_active_drawable (gimage); + gdisp = gimp_context_get_display (gimp_get_user_context (gimage->gimp)); + + if (advanced) + proc_rec = procedural_db_lookup (gimage->gimp, + "plug_in_sel2path_advanced"); + else + proc_rec = procedural_db_lookup (gimage->gimp, + "plug_in_sel2path"); + + if (! proc_rec) + { + g_message (_("Selection to path procedure lookup failed.")); + return; + } + + /* plug-in arguments as if called by /Filters/... */ + args = g_new (Argument, 3); + + args[0].arg_type = GIMP_PDB_INT32; + args[0].value.pdb_int = GIMP_RUN_INTERACTIVE; + args[1].arg_type = GIMP_PDB_IMAGE; + args[1].value.pdb_int = (gint32) gimp_image_get_ID (gimage); + args[2].arg_type = GIMP_PDB_DRAWABLE; + args[2].value.pdb_int = (gint32) gimp_item_get_ID (GIMP_ITEM (drawable)); + + plug_in_run (gimage->gimp, + proc_rec, args, 3, FALSE, TRUE, + gdisp ? gdisp->ID : 0); + + g_free (args); +} + void vectors_vectors_tool (GimpVectors *vectors) { diff --git a/app/gui/vectors-commands.h b/app/gui/vectors-commands.h index 603318250b..e34042a5e2 100644 --- a/app/gui/vectors-commands.h +++ b/app/gui/vectors-commands.h @@ -56,6 +56,8 @@ void vectors_edit_vectors_attributes_cmd_callback (GtkWidget *widget, gpointer data); void vectors_stroke_vectors (GimpVectors *vectors); +void vectors_selection_to_vectors (GimpImage *gimage, + gboolean advanced); void vectors_vectors_tool (GimpVectors *vectors); void vectors_new_vectors_query (GimpImage *gimage, GimpVectors *template, diff --git a/app/widgets/gimpvectorstreeview.c b/app/widgets/gimpvectorstreeview.c index 1ecfa52022..3566e606f1 100644 --- a/app/widgets/gimpvectorstreeview.c +++ b/app/widgets/gimpvectorstreeview.c @@ -56,6 +56,14 @@ static void gimp_vectors_tree_view_toselection_extended_clicked guint state, GimpVectorsTreeView *view); +static void gimp_vectors_tree_view_tovectors_clicked + (GtkWidget *widget, + GimpVectorsTreeView *view); +static void gimp_vectors_tree_view_tovectors_extended_clicked + (GtkWidget *widget, + guint state, + GimpVectorsTreeView *view); + static void gimp_vectors_tree_view_stroke_clicked (GtkWidget *widget, GimpVectorsTreeView *view); @@ -149,6 +157,19 @@ gimp_vectors_tree_view_init (GimpVectorsTreeView *view) g_free (str); + str = g_strdup_printf (_("Selection to Path\n" + "%s Advanced Options"), + gimp_get_mod_name_shift ()); + + view->tovectors_button = + gimp_editor_add_button (editor, + GIMP_STOCK_SELECTION_TO_PATH, str, NULL, + G_CALLBACK (gimp_vectors_tree_view_tovectors_clicked), + G_CALLBACK (gimp_vectors_tree_view_tovectors_extended_clicked), + view); + + g_free (str); + view->stroke_button = gimp_editor_add_button (editor, GIMP_STOCK_PATH_STROKE, _("Stroke Path"), NULL, @@ -159,7 +180,9 @@ gimp_vectors_tree_view_init (GimpVectorsTreeView *view) gtk_box_reorder_child (GTK_BOX (editor->button_box), view->toselection_button, 5); gtk_box_reorder_child (GTK_BOX (editor->button_box), - view->stroke_button, 6); + view->tovectors_button, 6); + gtk_box_reorder_child (GTK_BOX (editor->button_box), + view->stroke_button, 7); gimp_container_view_enable_dnd (GIMP_CONTAINER_VIEW (editor), GTK_BUTTON (view->toselection_button), @@ -234,6 +257,23 @@ gimp_vectors_tree_view_toselection_extended_clicked (GtkWidget *widget } } +static void +gimp_vectors_tree_view_tovectors_clicked (GtkWidget *widget, + GimpVectorsTreeView *view) +{ + gimp_vectors_tree_view_tovectors_extended_clicked (widget, 0, view); +} + +static void +gimp_vectors_tree_view_tovectors_extended_clicked (GtkWidget *widget, + guint state, + GimpVectorsTreeView *view) +{ + if (view->selection_to_vectors_func) + view->selection_to_vectors_func (GIMP_ITEM_TREE_VIEW (view)->gimage, + (state & GDK_SHIFT_MASK) != 0); +} + static void gimp_vectors_tree_view_stroke_clicked (GtkWidget *widget, GimpVectorsTreeView *view) @@ -246,7 +286,5 @@ gimp_vectors_tree_view_stroke_clicked (GtkWidget *widget, item = GIMP_ITEM_TREE_VIEW_GET_CLASS (view)->get_active_item (gimage); if (item && view->stroke_item_func) - { - view->stroke_item_func (GIMP_VECTORS (item)); - } + view->stroke_item_func (GIMP_VECTORS (item)); } diff --git a/app/widgets/gimpvectorstreeview.h b/app/widgets/gimpvectorstreeview.h index 3198f292a6..6c80c8da00 100644 --- a/app/widgets/gimpvectorstreeview.h +++ b/app/widgets/gimpvectorstreeview.h @@ -26,7 +26,9 @@ #include "gimpitemtreeview.h" -typedef void (* GimpStrokeItemFunc) (GimpVectors *vectors); +typedef void (* GimpStrokeItemFunc) (GimpVectors *vectors); +typedef void (* GimpSelectionToVectorsFunc) (GimpImage *gimage, + gboolean advanced); #define GIMP_TYPE_VECTORS_TREE_VIEW (gimp_vectors_tree_view_get_type ()) @@ -41,12 +43,14 @@ typedef struct _GimpVectorsTreeViewClass GimpVectorsTreeViewClass; struct _GimpVectorsTreeView { - GimpItemTreeView parent_instance; + GimpItemTreeView parent_instance; - GimpStrokeItemFunc stroke_item_func; + GimpStrokeItemFunc stroke_item_func; + GimpSelectionToVectorsFunc selection_to_vectors_func; - GtkWidget *toselection_button; - GtkWidget *stroke_button; + GtkWidget *toselection_button; + GtkWidget *tovectors_button; + GtkWidget *stroke_button; }; struct _GimpVectorsTreeViewClass