Commit c42641fe authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

Fixed & cleaned up paint function registration to work without GUI.

2003-08-30  Michael Natterer  <mitch@gimp.org>

	Fixed & cleaned up paint function registration to work without
	GUI. Finishes core/GUI separation for the paint tools:

	* app/core/gimppaintinfo.[ch]: removed "gchar *pdb_string" all over
	the place since we don't stroke using the PDB any more.
	(gimp_paint_info_new): create paint_info->paint_options here so
	the paint system is fully initialized when there is no GUI.

	* app/paint/paint.c: removed pdb_string stuff here, too.

	* app/core/gimptoolinfo.[ch]: create tool_info->tool_options
	only if tool_info->tool_options_type is not the same type
	as paint_info->paint_options_type (if we are no paint tool).

	* app/core/gimptooloptions.c: removed G_PARAM_CONSTRUCT_ONLY from
	the "tool-info" property. Instead, changed
	gimp_tool_options_set_property to ensure that it is only set once.

	* app/core/gimp.c (gimp_initialize): moved paint_init() after
	data_factory creation (was in gimp_init()), since GimpPaintInfo
	now creates the GimpPaintOptions, which are GimpContexts, which
	need gimp->*_factory to be constructed.

	* app/tools/tool_manager.c: don't create tool_info->tool_options
	here (it's not the job of the tool_manager to set up the core
	paint system correctly, it must be already initialized before any
	tool_manager function is called).

	Made "Stroke Selection" and "Stroke Path" work the same way:

	* app/paint/gimppaintcore-stroke.[ch]: added new function
	gimp_paint_core_stroke_boundary() which strokes without using
	the PDB.

	* app/core/gimpimage-mask.c (gimp_image_mask_stroke): use it
	instead of using the PDB. Enables all available paint options for
	stroke operations. Fixes bug #119411.

	* app/gui/vectors-commands.c (vectors_stroke_vectors)
	* app/core/gimpimage-mask.c (gimp_image_mask_stroke): removed all
	code which tries to figure how to stroke and simply look at the
	active tool's tool_info->paint_info, since it is always set up
	correctly now.
parent d401ae3b
2003-08-30 Michael Natterer <mitch@gimp.org>
Fixed & cleaned up paint function registration to work without
GUI. Finishes core/GUI separation for the paint tools:
* app/core/gimppaintinfo.[ch]: removed "gchar *pdb_string" all over
the place since we don't stroke using the PDB any more.
(gimp_paint_info_new): create paint_info->paint_options here so
the paint system is fully initialized when there is no GUI.
* app/paint/paint.c: removed pdb_string stuff here, too.
* app/core/gimptoolinfo.[ch]: create tool_info->tool_options
only if tool_info->tool_options_type is not the same type
as paint_info->paint_options_type (if we are no paint tool).
* app/core/gimptooloptions.c: removed G_PARAM_CONSTRUCT_ONLY from
the "tool-info" property. Instead, changed
gimp_tool_options_set_property to ensure that it is only set once.
* app/core/gimp.c (gimp_initialize): moved paint_init() after
data_factory creation (was in gimp_init()), since GimpPaintInfo
now creates the GimpPaintOptions, which are GimpContexts, which
need gimp->*_factory to be constructed.
* app/tools/tool_manager.c: don't create tool_info->tool_options
here (it's not the job of the tool_manager to set up the core
paint system correctly, it must be already initialized before any
tool_manager function is called).
Made "Stroke Selection" and "Stroke Path" work the same way:
* app/paint/gimppaintcore-stroke.[ch]: added new function
gimp_paint_core_stroke_boundary() which strokes without using
the PDB.
* app/core/gimpimage-mask.c (gimp_image_mask_stroke): use it
instead of using the PDB. Enables all available paint options for
stroke operations. Fixes bug #119411.
* app/gui/vectors-commands.c (vectors_stroke_vectors)
* app/core/gimpimage-mask.c (gimp_image_mask_stroke): removed all
code which tries to figure how to stroke and simply look at the
active tool's tool_info->paint_info, since it is always set up
correctly now.
2003-08-30 Simon Budig <simon@gimp.org>
* app/tools/gimpvectortool.[ch]: fixed stupid int vs. float
......@@ -278,26 +278,17 @@ vectors_stroke_vectors (GimpVectors *vectors)
if (vectors && vectors->strokes)
{
GimpToolInfo *tool_info;
GimpPaintOptions *paint_options;
GimpPaintCore *core;
GimpToolInfo *tool_info;
GimpPaintInfo *paint_info;
GimpPaintCore *core;
tool_info = gimp_context_get_tool (gimp_get_user_context (gimage->gimp));
tool_info = gimp_context_get_tool (gimp_get_user_context (gimage->gimp));
paint_info = tool_info->paint_info;
if (! (tool_info && GIMP_IS_PAINT_OPTIONS (tool_info->tool_options)))
{
tool_info = (GimpToolInfo *)
gimp_container_get_child_by_name (gimage->gimp->tool_info_list,
"gimp-paintbrush-tool");
}
paint_options = GIMP_PAINT_OPTIONS (tool_info->tool_options);
core = g_object_new (tool_info->paint_info->paint_type, NULL);
core = g_object_new (paint_info->paint_type, NULL);
gimp_paint_core_stroke_vectors (core,
active_drawable,
paint_options,
gimp_paint_core_stroke_vectors (core, active_drawable,
paint_info->paint_options,
vectors);
g_object_unref (core);
......
......@@ -200,8 +200,6 @@ gimp_init (Gimp *gimp)
gimp->parasites = gimp_parasite_list_new ();
paint_init (gimp);
gimp_modules_init (gimp);
gimp->environ_table = gimp_environ_table_new ();
......@@ -726,6 +724,8 @@ gimp_initialize (Gimp *gimp,
gimp_palette_get_standard);
gimp_object_set_name (GIMP_OBJECT (gimp->palette_factory), "palette factory");
paint_init (gimp);
/* Set the last values used to default values. */
gimp->image_new_last_template = gimp_template_new ("last values");
......
......@@ -28,9 +28,13 @@
#include "paint-funcs/paint-funcs.h"
#include "pdb/procedural_db.h"
#include "paint/gimppaintcore.h"
#include "paint/gimppaintcore-stroke.h"
#include "paint/gimppaintoptions.h"
#include "gimp.h"
#include "gimpchannel.h"
#include "gimpcontainer.h"
#include "gimpcontext.h"
#include "gimpimage.h"
#include "gimpimage-mask.h"
......@@ -619,20 +623,14 @@ gimp_image_mask_stroke (GimpImage *gimage,
GimpDrawable *drawable,
GimpContext *context)
{
BoundSeg *bs_in;
BoundSeg *bs_out;
gint num_segs_in;
gint num_segs_out;
BoundSeg *stroke_segs;
gint num_strokes;
gint seg;
gint offx, offy;
gint i;
gdouble *stroke_points;
gint cpnt;
Argument *return_vals;
gint nreturn_vals;
const gchar *pdb_string;
BoundSeg *bs_in;
BoundSeg *bs_out;
gint num_segs_in;
gint num_segs_out;
GimpToolInfo *tool_info;
GimpPaintInfo *paint_info;
GimpPaintCore *core;
gboolean retval;
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), FALSE);
......@@ -645,74 +643,26 @@ gimp_image_mask_stroke (GimpImage *gimage,
return FALSE;
}
stroke_segs = sort_boundary (bs_in, num_segs_in, &num_strokes);
if (num_strokes == 0)
return TRUE;
pdb_string = gimp_context_get_tool (context)->paint_info->pdb_string;
/* find the drawable offsets */
gimp_item_offsets (GIMP_ITEM (drawable), &offx, &offy);
gimp_image_mask_stroking = TRUE;
/* Start an undo group */
gimp_image_undo_group_start (gimage, GIMP_UNDO_GROUP_PAINT,
_("Stroke Selection"));
seg = 0;
cpnt = 0;
/* Largest array required (may be used in segments!) */
stroke_points = g_malloc (sizeof (gdouble) * 2 * (num_segs_in + 4));
tool_info = gimp_context_get_tool (context);
paint_info = tool_info->paint_info;
/* we offset all coordinates by 0.5 to align the brush with the path */
core = g_object_new (paint_info->paint_type, NULL);
stroke_points[cpnt++] = (gdouble)(stroke_segs[0].x1 - offx + 0.5);
stroke_points[cpnt++] = (gdouble)(stroke_segs[0].y1 - offy + 0.5);
retval = gimp_paint_core_stroke_boundary (core, drawable,
paint_info->paint_options,
bs_in, num_segs_in,
0, 0);
for (i = 0; i < num_strokes; i++)
{
while ((stroke_segs[seg].x1 != -1 ||
stroke_segs[seg].x2 != -1 ||
stroke_segs[seg].y1 != -1 ||
stroke_segs[seg].y2 != -1))
{
stroke_points[cpnt++] = (gdouble)(stroke_segs[seg].x2 - offx + 0.5);
stroke_points[cpnt++] = (gdouble)(stroke_segs[seg].y2 - offy + 0.5);
seg ++;
}
g_object_unref (core);
/* Close the stroke points up */
stroke_points[cpnt++] = stroke_points[0];
stroke_points[cpnt++] = stroke_points[1];
/* Stroke with the correct tool */
return_vals =
procedural_db_run_proc (gimage->gimp,
pdb_string,
&nreturn_vals,
GIMP_PDB_DRAWABLE, gimp_item_get_ID (GIMP_ITEM (drawable)),
GIMP_PDB_INT32, (gint32) cpnt,
GIMP_PDB_FLOATARRAY, stroke_points,
GIMP_PDB_END);
if (return_vals && return_vals[0].value.pdb_int != GIMP_PDB_SUCCESS)
g_message (_("Paint operation failed."));
procedural_db_destroy_args (return_vals, nreturn_vals);
cpnt = 0;
seg ++;
stroke_points[cpnt++] = (gdouble)(stroke_segs[seg].x1 - offx + 0.5);
stroke_points[cpnt++] = (gdouble)(stroke_segs[seg].y1 - offy + 0.5);
}
gimp_image_undo_group_end (gimage);
/* cleanup */
gimp_image_mask_stroking = FALSE;
g_free (stroke_points);
g_free (stroke_segs);
/* End an undo group */
gimp_image_undo_group_end (gimage);
return TRUE;
return retval;
}
......@@ -43,21 +43,21 @@ gimp_paint_info_get_type (void)
if (! paint_info_type)
{
static const GTypeInfo paint_info_info =
{
sizeof (GimpPaintInfoClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_paint_info_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpPaintInfo),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_paint_info_init,
};
{
sizeof (GimpPaintInfoClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_paint_info_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpPaintInfo),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_paint_info_init,
};
paint_info_type = g_type_register_static (GIMP_TYPE_OBJECT,
"GimpPaintInfo",
&paint_info_info, 0);
"GimpPaintInfo",
&paint_info_info, 0);
}
return paint_info_type;
......@@ -81,7 +81,6 @@ gimp_paint_info_init (GimpPaintInfo *paint_info)
paint_info->gimp = NULL;
paint_info->paint_type = G_TYPE_NONE;
paint_info->blurb = NULL;
paint_info->pdb_string = NULL;
paint_info->paint_options = NULL;
}
......@@ -98,10 +97,10 @@ gimp_paint_info_finalize (GObject *object)
paint_info->blurb = NULL;
}
if (paint_info->pdb_string)
if (paint_info->paint_options)
{
g_free (paint_info->pdb_string);
paint_info->pdb_string = NULL;
g_object_unref (paint_info->paint_options);
paint_info->paint_options = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
......@@ -111,14 +110,12 @@ GimpPaintInfo *
gimp_paint_info_new (Gimp *gimp,
GType paint_type,
GType paint_options_type,
const gchar *blurb,
const gchar *pdb_string)
const gchar *blurb)
{
GimpPaintInfo *paint_info;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
g_return_val_if_fail (blurb != NULL, NULL);
g_return_val_if_fail (pdb_string != NULL, NULL);
paint_info = g_object_new (GIMP_TYPE_PAINT_INFO,
"name", g_type_name (paint_type),
......@@ -128,7 +125,10 @@ gimp_paint_info_new (Gimp *gimp,
paint_info->paint_type = paint_type;
paint_info->paint_options_type = paint_options_type;
paint_info->blurb = g_strdup (blurb);
paint_info->pdb_string = g_strdup (pdb_string);
paint_info->paint_options = g_object_new (paint_info->paint_options_type,
"gimp", gimp,
NULL);
return paint_info;
}
......@@ -43,7 +43,6 @@ struct _GimpPaintInfo
GType paint_options_type;
gchar *blurb;
gchar *pdb_string;
GimpPaintOptions *paint_options;
};
......@@ -59,8 +58,7 @@ GType gimp_paint_info_get_type (void) G_GNUC_CONST;
GimpPaintInfo * gimp_paint_info_new (Gimp *gimp,
GType paint_type,
GType paint_options_type,
const gchar *blurb,
const gchar *pdb_string);
const gchar *blurb);
#endif /* __GIMP_PAINT_INFO_H__ */
......@@ -191,13 +191,13 @@ gimp_tool_info_new (Gimp *gimp,
{
GimpPaintInfo *paint_info;
GimpToolInfo *tool_info;
GimpViewable *viewable;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
g_return_val_if_fail (identifier != NULL, NULL);
g_return_val_if_fail (blurb != NULL, NULL);
g_return_val_if_fail (help != NULL, NULL);
g_return_val_if_fail (menu_path != NULL, NULL);
g_return_val_if_fail (help_id != NULL, NULL);
g_return_val_if_fail (paint_core_name != NULL, NULL);
g_return_val_if_fail (stock_id != NULL, NULL);
......@@ -207,14 +207,10 @@ gimp_tool_info_new (Gimp *gimp,
g_return_val_if_fail (GIMP_IS_PAINT_INFO (paint_info), NULL);
tool_info = g_object_new (GIMP_TYPE_TOOL_INFO,
"name", identifier,
"name", identifier,
"stock-id", stock_id,
NULL);
viewable = GIMP_VIEWABLE (tool_info);
tool_info->tool_options = NULL;
tool_info->paint_info = paint_info;
tool_info->gimp = gimp;
tool_info->tool_type = tool_type;
tool_info->tool_options_type = tool_options_type;
......@@ -229,7 +225,20 @@ gimp_tool_info_new (Gimp *gimp,
tool_info->help_domain = g_strdup (help_domain);
tool_info->help_id = g_strdup (help_id);
gimp_viewable_set_stock_id (viewable, stock_id);
tool_info->paint_info = paint_info;
if (tool_info->tool_options_type == paint_info->paint_options_type)
{
tool_info->tool_options = g_object_ref (paint_info->paint_options);
}
else
{
tool_info->tool_options = g_object_new (tool_info->tool_options_type,
"gimp", gimp,
NULL);
}
g_object_set (tool_info->tool_options, "tool-info", tool_info, NULL);
return tool_info;
}
......@@ -241,13 +250,16 @@ gimp_tool_info_set_standard (Gimp *gimp,
g_return_if_fail (GIMP_IS_GIMP (gimp));
g_return_if_fail (! tool_info || GIMP_IS_TOOL_INFO (tool_info));
if (gimp->standard_tool_info)
g_object_unref (gimp->standard_tool_info);
if (tool_info != gimp->standard_tool_info)
{
if (gimp->standard_tool_info)
g_object_unref (gimp->standard_tool_info);
gimp->standard_tool_info = tool_info;
gimp->standard_tool_info = tool_info;
if (gimp->standard_tool_info)
g_object_ref (gimp->standard_tool_info);
if (gimp->standard_tool_info)
g_object_ref (gimp->standard_tool_info);
}
}
GimpToolInfo *
......
......@@ -46,8 +46,8 @@ struct _GimpToolInfo
gchar *blurb;
gchar *help;
gchar *menu_path;
gchar *menu_accel;
gchar *menu_path;
gchar *menu_accel;
gchar *help_domain;
gchar *help_id;
......
......@@ -83,7 +83,7 @@ gimp_tool_options_get_type (void)
return type;
}
static void
static void
gimp_tool_options_class_init (GimpToolOptionsClass *klass)
{
GObjectClass *object_class;
......@@ -101,8 +101,7 @@ gimp_tool_options_class_init (GimpToolOptionsClass *klass)
g_param_spec_object ("tool-info",
NULL, NULL,
GIMP_TYPE_TOOL_INFO,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY));
G_PARAM_READWRITE));
}
......@@ -125,7 +124,8 @@ gimp_tool_options_set_property (GObject *object,
switch (property_id)
{
case PROP_TOOL_INFO:
options->tool_info = g_value_get_object (value);
g_return_if_fail (options->tool_info == NULL);
options->tool_info = GIMP_TOOL_INFO (g_value_dup_object (value));
break;
default:
......@@ -193,7 +193,7 @@ gimp_tool_options_build_filename (GimpToolOptions *tool_options,
filename = g_build_filename (gimp_directory (),
"tool-options",
GIMP_OBJECT (tool_options->tool_info)->name,
NULL);
NULL);
}
return filename;
......
......@@ -278,26 +278,17 @@ vectors_stroke_vectors (GimpVectors *vectors)
if (vectors && vectors->strokes)
{
GimpToolInfo *tool_info;
GimpPaintOptions *paint_options;
GimpPaintCore *core;
GimpToolInfo *tool_info;
GimpPaintInfo *paint_info;
GimpPaintCore *core;
tool_info = gimp_context_get_tool (gimp_get_user_context (gimage->gimp));
tool_info = gimp_context_get_tool (gimp_get_user_context (gimage->gimp));
paint_info = tool_info->paint_info;
if (! (tool_info && GIMP_IS_PAINT_OPTIONS (tool_info->tool_options)))
{
tool_info = (GimpToolInfo *)
gimp_container_get_child_by_name (gimage->gimp->tool_info_list,
"gimp-paintbrush-tool");
}
paint_options = GIMP_PAINT_OPTIONS (tool_info->tool_options);
core = g_object_new (tool_info->paint_info->paint_type, NULL);
core = g_object_new (paint_info->paint_type, NULL);
gimp_paint_core_stroke_vectors (core,
active_drawable,
paint_options,
gimp_paint_core_stroke_vectors (core, active_drawable,
paint_info->paint_options,
vectors);
g_object_unref (core);
......
......@@ -22,6 +22,8 @@
#include "paint-types.h"
#include "base/boundary.h"
#include "core/gimpdrawable.h"
#include "vectors/gimpstroke.h"
......@@ -78,6 +80,105 @@ gimp_paint_core_stroke (GimpPaintCore *core,
return FALSE;
}
gboolean
gimp_paint_core_stroke_boundary (GimpPaintCore *core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options,
const BoundSeg *bound_segs,
gint n_bound_segs,
gint offset_x,
gint offset_y)
{
GimpImage *gimage;
BoundSeg *stroke_segs;
gint n_stroke_segs;
gint off_x;
gint off_y;
GimpCoords *coords;
gint n_coords;
gint seg;
gint i;
g_return_val_if_fail (GIMP_IS_PAINT_CORE (core), FALSE);
g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), FALSE);
g_return_val_if_fail (GIMP_IS_PAINT_OPTIONS (paint_options), FALSE);
g_return_val_if_fail (bound_segs != NULL && n_bound_segs > 0, FALSE);
gimage = gimp_item_get_image (GIMP_ITEM (drawable));
stroke_segs = sort_boundary (bound_segs, n_bound_segs, &n_stroke_segs);
if (n_stroke_segs == 0)
return TRUE;
gimp_item_offsets (GIMP_ITEM (drawable), &off_x, &off_y);
off_x -= offset_x;
off_y -= offset_y;
coords = g_new0 (GimpCoords, n_bound_segs + 4);
seg = 0;
n_coords = 0;
/* we offset all coordinates by 0.5 to align the brush with the path */
coords[n_coords].x = (gdouble) (stroke_segs[0].x1 - off_x + 0.5);
coords[n_coords].y = (gdouble) (stroke_segs[0].y1 - off_y + 0.5);
coords[n_coords].pressure = 1.0;
coords[n_coords].xtilt = 0.5;
coords[n_coords].ytilt = 0.5;
coords[n_coords].wheel = 0.5;
n_coords++;
for (i = 0; i < n_stroke_segs; i++)
{
while (stroke_segs[seg].x1 != -1 ||
stroke_segs[seg].x2 != -1 ||
stroke_segs[seg].y1 != -1 ||
stroke_segs[seg].y2 != -1)
{
coords[n_coords].x = (gdouble) (stroke_segs[seg].x1 -
off_x + 0.5);
coords[n_coords].y = (gdouble) (stroke_segs[seg].y1 -
off_y + 0.5);
coords[n_coords].pressure = 1.0;
coords[n_coords].xtilt = 0.5;
coords[n_coords].ytilt = 0.5;
coords[n_coords].wheel = 0.5;
n_coords++;
seg++;
}
/* Close the stroke points up */
coords[n_coords] = coords[0];
n_coords++;
gimp_paint_core_stroke (core, drawable, paint_options,
coords, n_coords);
n_coords = 0;
seg++;
coords[n_coords].x = (gdouble) (stroke_segs[seg].x1 - off_x + 0.5);
coords[n_coords].y = (gdouble) (stroke_segs[seg].y1 - off_y + 0.5);
coords[n_coords].pressure = 1.0;
coords[n_coords].xtilt = 0.5;
coords[n_coords].ytilt = 0.5;
coords[n_coords].wheel = 0.5;
n_coords++;
}
g_free (coords);
g_free (stroke_segs);
return TRUE;
}
gboolean
gimp_paint_core_stroke_vectors (GimpPaintCore *core,
GimpDrawable *drawable,
......
......@@ -20,15 +20,22 @@
#define __GIMP_PAINT_CORE_STROKE_H__
gboolean gimp_paint_core_stroke (GimpPaintCore *core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options,
GimpCoords *strokes,
gint n_strokes);
gboolean gimp_paint_core_stroke_vectors (GimpPaintCore *core,
GimpDrawable *drawable,
GimpPaintOptions *paint_options,