Commit 52d07c96 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

implemented gimp_image_mask_select_vectors() as simple wrapper around

2002-02-26  Michael Natterer  <mitch@gimp.org>

	* app/core/gimpimage-mask-select.[ch]: implemented
	gimp_image_mask_select_vectors() as simple wrapper around
	gimp_image_mask_select_polygon().

	* app/gui/vectors-commands.c: call it from the "to selection"
	callbacks.

	* app/gui/channels-commands.c: use gimp_image_mask_select_channel()
	instead of doing the same manually.

	* app/paint/gimppencil.c: register as "GimpPencil", not
	"GimpPencilCore".

	* app/widgets/Makefile.am
	* app/widgets/widgets-types.h
	* app/widgets/gimpvectorslistview.[ch]: new GimpItemListView
	subclass featuring a "To Selection" and "Stroke" button.

	* app/widgets/gimpitemlistview.c: create GimpVectorsListViews.
parent 5aa1c92f
2002-02-26 Michael Natterer <mitch@gimp.org>
* app/core/gimpimage-mask-select.[ch]: implemented
gimp_image_mask_select_vectors() as simple wrapper around
gimp_image_mask_select_polygon().
* app/gui/vectors-commands.c: call it from the "to selection"
callbacks.
* app/gui/channels-commands.c: use gimp_image_mask_select_channel()
instead of doing the same manually.
* app/paint/gimppencil.c: register as "GimpPencil", not
"GimpPencilCore".
* app/widgets/Makefile.am
* app/widgets/widgets-types.h
* app/widgets/gimpvectorslistview.[ch]: new GimpItemListView
subclass featuring a "To Selection" and "Stroke" button.
* app/widgets/gimpitemlistview.c: create GimpVectorsListViews.
2002-02-26 Michael Natterer <mitch@gimp.org>
* app/paint/gimppaintcore-stroke.[ch]: added
......
......@@ -29,6 +29,7 @@
#include "core/gimpchannel.h"
#include "core/gimpimage.h"
#include "core/gimpimage-mask.h"
#include "core/gimpimage-mask-select.h"
#include "core/gimplist.h"
#include "display/gimpdisplay-foreach.h"
......@@ -138,9 +139,9 @@ channels_delete_channel_cmd_callback (GtkWidget *widget,
}
}
void
channels_channel_to_sel_cmd_callback (GtkWidget *widget,
gpointer data)
static void
channels_channel_to_sel (GtkWidget *widget,
ChannelOps op)
{
GimpImage *gimage;
GimpChannel *active_channel;
......@@ -152,93 +153,42 @@ channels_channel_to_sel_cmd_callback (GtkWidget *widget,
if ((active_channel = gimp_image_get_active_channel (gimage)))
{
gimp_image_mask_load (gimage, active_channel);
gimp_image_mask_select_channel (gimage,
NULL, FALSE,
active_channel,
op,
FALSE, 0, 0);
gdisplays_flush ();
}
}
void
channels_channel_to_sel_cmd_callback (GtkWidget *widget,
gpointer data)
{
channels_channel_to_sel (widget, CHANNEL_OP_REPLACE);
}
void
channels_add_channel_to_sel_cmd_callback (GtkWidget *widget,
gpointer data)
{
GimpImage *gimage;
GimpChannel *active_channel;
GimpChannel *new_channel;
gimage = (GimpImage *) gimp_widget_get_callback_context (widget);
if (! gimage)
return;
if ((active_channel = gimp_image_get_active_channel (gimage)))
{
new_channel = gimp_channel_copy (gimp_image_get_mask (gimage),
G_TYPE_FROM_INSTANCE (gimp_image_get_mask (gimage)),
TRUE);
gimp_channel_combine_mask (new_channel,
active_channel,
CHANNEL_OP_ADD,
0, 0); /* off x/y */
gimp_image_mask_load (gimage, new_channel);
g_object_unref (G_OBJECT (new_channel));
gdisplays_flush ();
}
channels_channel_to_sel (widget, CHANNEL_OP_ADD);
}
void
channels_sub_channel_from_sel_cmd_callback (GtkWidget *widget,
gpointer data)
{
GimpImage *gimage;
GimpChannel *active_channel;
GimpChannel *new_channel;
gimage = (GimpImage *) gimp_widget_get_callback_context (widget);
if (! gimage)
return;
if ((active_channel = gimp_image_get_active_channel (gimage)))
{
new_channel = gimp_channel_copy (gimp_image_get_mask (gimage),
G_TYPE_FROM_INSTANCE (gimp_image_get_mask (gimage)),
TRUE);
gimp_channel_combine_mask (new_channel,
active_channel,
CHANNEL_OP_SUB,
0, 0); /* off x/y */
gimp_image_mask_load (gimage, new_channel);
g_object_unref (G_OBJECT (new_channel));
gdisplays_flush ();
}
channels_channel_to_sel (widget, CHANNEL_OP_SUB);
}
void
channels_intersect_channel_with_sel_cmd_callback (GtkWidget *widget,
gpointer data)
{
GimpImage *gimage;
GimpChannel *active_channel;
GimpChannel *new_channel;
gimage = (GimpImage *) gimp_widget_get_callback_context (widget);
if (! gimage)
return;
if ((active_channel = gimp_image_get_active_channel (gimage)))
{
new_channel = gimp_channel_copy (gimp_image_get_mask (gimage),
G_TYPE_FROM_INSTANCE (gimp_image_get_mask (gimage)),
TRUE);
gimp_channel_combine_mask (new_channel,
active_channel,
CHANNEL_OP_INTERSECT,
0, 0); /* off x/y */
gimp_image_mask_load (gimage, new_channel);
g_object_unref (G_OBJECT (new_channel));
gdisplays_flush ();
}
channels_channel_to_sel (widget, CHANNEL_OP_INTERSECT);
}
void
......
......@@ -29,6 +29,7 @@
#include "core/gimpcontext.h"
#include "core/gimpimage.h"
#include "core/gimpimage-mask.h"
#include "core/gimpimage-mask-select.h"
#include "core/gimplist.h"
#include "core/gimptoolinfo.h"
......@@ -42,6 +43,7 @@
#include "widgets/gimpitemfactory.h"
#include "widgets/gimpwidgets-utils.h"
#include "tools/gimppainttool.h"
#include "tools/gimpvectortool.h"
#include "tools/tool_manager.h"
......@@ -150,9 +152,9 @@ vectors_delete_vectors_cmd_callback (GtkWidget *widget,
}
}
void
vectors_vectors_to_sel_cmd_callback (GtkWidget *widget,
gpointer data)
static void
vectors_vectors_to_sel (GtkWidget *widget,
ChannelOps op)
{
GimpImage *gimage;
GimpVectors *active_vectors;
......@@ -166,130 +168,42 @@ vectors_vectors_to_sel_cmd_callback (GtkWidget *widget,
if (active_vectors)
{
GimpChannel *vectors_mask;
vectors_mask = NULL; /*gimp_vectors_to_channel (active_vectors);*/
gimp_image_mask_load (gimage, vectors_mask);
g_object_unref (G_OBJECT (vectors_mask));
gimp_image_mask_select_vectors (gimage,
active_vectors,
op,
TRUE,
FALSE, 0, 0);
gdisplays_flush ();
}
}
void
vectors_vectors_to_sel_cmd_callback (GtkWidget *widget,
gpointer data)
{
vectors_vectors_to_sel (widget, CHANNEL_OP_REPLACE);
}
void
vectors_add_vectors_to_sel_cmd_callback (GtkWidget *widget,
gpointer data)
{
GimpImage *gimage;
GimpVectors *active_vectors;
gimage = (GimpImage *) gimp_widget_get_callback_context (widget);
if (! gimage)
return;
active_vectors = gimp_image_get_active_vectors (gimage);
if (active_vectors)
{
GimpChannel *vectors_mask;
GimpChannel *new_mask;
vectors_mask = NULL; /*gimp_vectors_to_channel (active_vectors);*/
new_mask = gimp_channel_copy (gimp_image_get_mask (gimage),
G_TYPE_FROM_INSTANCE (gimp_image_get_mask (gimage)),
TRUE);
gimp_channel_combine_mask (new_mask,
vectors_mask,
CHANNEL_OP_ADD,
0, 0); /* off x/y */
gimp_image_mask_load (gimage, new_mask);
g_object_unref (G_OBJECT (new_mask));
gdisplays_flush ();
}
vectors_vectors_to_sel (widget, CHANNEL_OP_ADD);
}
void
vectors_sub_vectors_from_sel_cmd_callback (GtkWidget *widget,
gpointer data)
{
GimpImage *gimage;
GimpVectors *active_vectors;
gimage = (GimpImage *) gimp_widget_get_callback_context (widget);
if (! gimage)
return;
active_vectors = gimp_image_get_active_vectors (gimage);
if (active_vectors)
{
GimpChannel *vectors_mask;
GimpChannel *new_mask;
vectors_mask = NULL; /*gimp_vectors_to_channel (active_vectors);*/
new_mask = gimp_channel_copy (gimp_image_get_mask (gimage),
G_TYPE_FROM_INSTANCE (gimp_image_get_mask (gimage)),
TRUE);
gimp_channel_combine_mask (new_mask,
vectors_mask,
CHANNEL_OP_SUB,
0, 0); /* off x/y */
gimp_image_mask_load (gimage, new_mask);
g_object_unref (G_OBJECT (new_mask));
gdisplays_flush ();
}
vectors_vectors_to_sel (widget, CHANNEL_OP_SUB);
}
void
vectors_intersect_vectors_with_sel_cmd_callback (GtkWidget *widget,
gpointer data)
{
GimpImage *gimage;
GimpVectors *active_vectors;
gimage = (GimpImage *) gimp_widget_get_callback_context (widget);
if (! gimage)
return;
active_vectors = gimp_image_get_active_vectors (gimage);
if (active_vectors)
{
GimpChannel *vectors_mask;
GimpChannel *new_mask;
vectors_mask = NULL; /*gimp_vectors_to_channel (active_vectors);*/
new_mask = gimp_channel_copy (gimp_image_get_mask (gimage),
G_TYPE_FROM_INSTANCE (gimp_image_get_mask (gimage)),
TRUE);
gimp_channel_combine_mask (new_mask,
vectors_mask,
CHANNEL_OP_INTERSECT,
0, 0); /* off x/y */
gimp_image_mask_load (gimage, new_mask);
g_object_unref (G_OBJECT (new_mask));
gdisplays_flush ();
}
vectors_vectors_to_sel (widget, CHANNEL_OP_INTERSECT);
}
void
......@@ -335,18 +249,30 @@ vectors_stroke_vectors_cmd_callback (GtkWidget *widget,
if (active_vectors && active_vectors->strokes)
{
GimpTool *active_tool;
GimpPaintCore *core;
GType core_type;
GimpToolInfo *tool_info;
GimpPaintOptions *paint_options;
GimpDisplay *gdisp;
tool_info = (GimpToolInfo *)
gimp_container_get_child_by_name (gimage->gimp->tool_info_list,
"gimp:paintbrush_tool");
active_tool = tool_manager_get_active (gimage->gimp);
if (GIMP_IS_PAINT_TOOL (active_tool))
{
tool_info = active_tool->tool_info;
}
else
{
tool_info = (GimpToolInfo *)
gimp_container_get_child_by_name (gimage->gimp->tool_info_list,
"gimp:paintbrush_tool");
}
paint_options = (GimpPaintOptions *) tool_info->tool_options;
g_print ("core_name: %s\n", tool_info->paint_core_name);
core_type = g_type_from_name (tool_info->paint_core_name);
core = g_object_new (core_type, NULL);
......
......@@ -29,6 +29,9 @@
#include "gimpimage-mask-select.h"
#include "gimpscanconvert.h"
#include "vectors/gimpstroke.h"
#include "vectors/gimpvectors.h"
void
gimp_image_mask_select_rectangle (GimpImage *gimage,
......@@ -169,6 +172,63 @@ gimp_image_mask_select_polygon (GimpImage *gimage,
}
}
void
gimp_image_mask_select_vectors (GimpImage *gimage,
GimpVectors *vectors,
ChannelOps op,
gboolean antialias,
gboolean feather,
gdouble feather_radius_x,
gdouble feather_radius_y)
{
GimpStroke *stroke;
GimpCoords *coords = NULL;
gint n_coords;
gboolean closed;
g_return_if_fail (GIMP_IS_IMAGE (gimage));
/* gimp_stroke_interpolate() may return NULL, so iterate over the
* list of strokes until one returns coords
*/
for (stroke = vectors->strokes; stroke; stroke = stroke->next)
{
coords = gimp_stroke_interpolate (stroke, 1.0,
&n_coords,
&closed);
if (coords)
break;
}
if (coords)
{
GimpVector2 *points;
gint i;
points = g_new0 (GimpVector2, n_coords);
for (i = 0; i < n_coords; i++)
{
points[i].x = coords[i].x;
points[i].y = coords[i].y;
}
g_free (coords);
gimp_image_mask_select_polygon (GIMP_ITEM (vectors)->gimage,
n_coords,
points,
op,
antialias,
feather,
feather_radius_x,
feather_radius_y);
g_free (points);
}
}
void
gimp_image_mask_select_channel (GimpImage *gimage,
GimpDrawable *drawable,
......
......@@ -50,6 +50,14 @@ void gimp_image_mask_select_polygon (GimpImage *gimage,
gdouble feather_radius_x,
gdouble feather_radius_y);
void gimp_image_mask_select_vectors (GimpImage *gimage,
GimpVectors *vectors,
ChannelOps op,
gboolean antialias,
gboolean feather,
gdouble feather_radius_x,
gdouble feather_radius_y);
void gimp_image_mask_select_channel (GimpImage *gimage,
GimpDrawable *drawable,
gboolean sample_merged,
......
......@@ -29,6 +29,9 @@
#include "gimpimage-mask-select.h"
#include "gimpscanconvert.h"
#include "vectors/gimpstroke.h"
#include "vectors/gimpvectors.h"
void
gimp_image_mask_select_rectangle (GimpImage *gimage,
......@@ -169,6 +172,63 @@ gimp_image_mask_select_polygon (GimpImage *gimage,
}
}
void
gimp_image_mask_select_vectors (GimpImage *gimage,
GimpVectors *vectors,
ChannelOps op,
gboolean antialias,
gboolean feather,
gdouble feather_radius_x,
gdouble feather_radius_y)
{
GimpStroke *stroke;
GimpCoords *coords = NULL;
gint n_coords;
gboolean closed;
g_return_if_fail (GIMP_IS_IMAGE (gimage));
/* gimp_stroke_interpolate() may return NULL, so iterate over the
* list of strokes until one returns coords
*/
for (stroke = vectors->strokes; stroke; stroke = stroke->next)
{
coords = gimp_stroke_interpolate (stroke, 1.0,
&n_coords,
&closed);
if (coords)
break;
}
if (coords)
{
GimpVector2 *points;
gint i;
points = g_new0 (GimpVector2, n_coords);
for (i = 0; i < n_coords; i++)
{
points[i].x = coords[i].x;
points[i].y = coords[i].y;
}
g_free (coords);
gimp_image_mask_select_polygon (GIMP_ITEM (vectors)->gimage,
n_coords,
points,
op,
antialias,
feather,
feather_radius_x,
feather_radius_y);
g_free (points);
}
}
void
gimp_image_mask_select_channel (GimpImage *gimage,
GimpDrawable *drawable,
......
......@@ -50,6 +50,14 @@ void gimp_image_mask_select_polygon (GimpImage *gimage,
gdouble feather_radius_x,
gdouble feather_radius_y);
void gimp_image_mask_select_vectors (GimpImage *gimage,
GimpVectors *vectors,
ChannelOps op,
gboolean antialias,
gboolean feather,
gdouble feather_radius_x,
gdouble feather_radius_y);
void gimp_image_mask_select_channel (GimpImage *gimage,
GimpDrawable *drawable,
gboolean sample_merged,
......
......@@ -29,6 +29,7 @@
#include "core/gimpchannel.h"
#include "core/gimpimage.h"
#include "core/gimpimage-mask.h"
#include "core/gimpimage-mask-select.h"
#include "core/gimplist.h"
#include "display/gimpdisplay-foreach.h"
......@@ -138,9 +139,9 @@ channels_delete_channel_cmd_callback (GtkWidget *widget,
}
}
void
channels_channel_to_sel_cmd_callback (GtkWidget *widget,
gpointer data)
static void
channels_channel_to_sel (GtkWidget *widget,
ChannelOps op)
{
GimpImage *gimage;
GimpChannel *active_channel;
......@@ -152,93 +153,42 @@ channels_channel_to_sel_cmd_callback (GtkWidget *widget,
if ((active_channel = gimp_image_get_active_channel (gimage)))
{
gimp_image_mask_load (gimage, active_channel);
gimp_image_mask_select_channel (gimage,
NULL, FALSE,
active_channel,
op,
FALSE, 0, 0);
gdisplays_flush ();
}
}
void
channels_channel_to_sel_cmd_callback (GtkWidget *widget,
gpointer data)
{
channels_channel_to_sel (widget, CHANNEL_OP_REPLACE);
}
void
channels_add_channel_to_sel_cmd_callback (GtkWidget *widget,
gpointer data)
{
GimpImage *gimage;
GimpChannel *active_channel;
GimpChannel *new_channel;
gimage = (GimpImage *) gimp_widget_get_callback_context (widget);
if (! gimage)
return;
if ((active_channel = gimp_image_get_active_channel (gimage)))
{
new_channel = gimp_channel_copy (gimp_image_get_mask (gimage),
G_TYPE_FROM_INSTANCE (gimp_image_get_mask (gimage)),
TRUE);
gimp_channel_combine_mask (new_channel,
active_channel,
CHANNEL_OP_ADD,
0, 0); /* off x/y */
gimp_image_mask_load (gimage, new_channel);
g_object_unref (G_OBJECT (new_channel));
gdisplays_flush ();
}
channels_channel_to_sel (widget, CHANNEL_OP_ADD);
}
void
channels_sub_channel_from_sel_cmd_callback (GtkWidget *widget,
gpointer data)
{
GimpImage *gimage;
GimpChannel *active_channel;
GimpChannel *new_channel;
gimage = (GimpImage *) gimp_widget_get_callback_context (widget);
if (! gimage)
return;
if ((active_channel = gimp_image_get_active_channel (gimage)))
{
new_channel = gimp_channel_copy (gimp_image_get_mask (gimage),
G_TYPE_FROM_INSTANCE (gimp_image_get_mask (gimage)),
TRUE);
gimp_channel_combine_mask (new_channel,
active_channel,
CHANNEL_OP_SUB,
0, 0); /* off x/y */
gimp_image_mask_load (gimage, new_channel);
g_object_unref (G_OBJECT (new_channel));
gdisplays_flush ();
}
channels_channel_to_sel (widget, CHANNEL_OP_SUB);
}
void
channels_intersect_channel_with_sel_cmd_callback (GtkWidget *widget,
gpointer data)
{
GimpImage *gimage;
GimpChannel *active_channel;
GimpChannel *new_channel;
gimage = (GimpImage *) gimp_widget_get_callback_context (widget);
if (! gimage)
return;
if ((active_channel = gimp_image_get_active_channel (gimage)))
{
new_channel = gimp_channel_copy (gimp_image_get_mask (gimage),
G_TYPE_FROM_INSTANCE (gimp_image_get_mask (gimage)),
TRUE);
gimp_channel_combine_mask (new_channel,
active_channel,
CHANNEL_OP_INTERSECT,
0, 0); /* off x/y */
gimp_image_mask_load (gimage, new_channel);
g_object_unref (G_OBJECT (new_channel));
gdisplays_flush ();
}
channels_channel_to_sel (widget, CHANNEL_OP_INTERSECT);
}
void
......
......@@ -29,6 +29,7 @@
#include "core/gimpcontext.h"
#include "core/gimpimage.h"
#include "core/gimpimage-mask.h"
#include "core/gimpimage-mask-select.h"
#include "core/gimplist.h"
#include "core/gimptoolinfo.h"
......@@ -42,6 +43,7 @@
#include "widgets/gimpitemfactory.h"
#include "widgets/gimpwidgets-utils.h"
#include "tools/gimppainttool.h"
#include "tools/gimpvectortool.h"
#include "tools/tool_manager.h"
......@@ -150,9 +152,9 @@ vectors_delete_vectors_cmd_callback (GtkWidget *widget,
}
}
void
vectors_vectors_to_sel_cmd_callback (GtkWidget *widget,
gpointer data)
static void
vectors_vectors_to_sel (GtkWidget *widget,
ChannelOps op)
{
GimpImage *gimage;
GimpVectors *active_vectors;
......@@ -166,130 +168,42 @@ vectors_vectors_to_sel_cmd_callback (GtkWidget *widget,
if (active_vectors)
{
GimpChannel *vectors_mask;
vectors_mask = NULL; /*gimp_vectors_to_channel (active_vectors);*/
gimp_image_mask_load (gimage, vectors_mask);
g_object_unref (G_OBJECT (vectors_mask));
gimp_image_mask_select_vectors (gimage,
active_vectors,
op,
TRUE,
FALSE, 0, 0);
gdisplays_flush ();
}
}
void
vectors_vectors_to_sel_cmd_callback (GtkWidget *widget,
gpointer data)
{
vectors_vectors_to_sel (widget, CHANNEL_OP_REPLACE);
}
void
vectors_add_vectors_to_sel_cmd_callback (GtkWidget *widget,
gpointer data)
{
GimpImage *gimage;
GimpVectors *active_vectors;
gimage = (GimpImage *) gimp_widget_get_callback_context (widget);
if (! gimage)
return;
active_vectors = gimp_image_get_active_vectors (gimage);
if (active_vectors)