Commit 80c423ae authored by Michael Natterer's avatar Michael Natterer 😴

app: move the improved paint property copying code to GimpPaintOptions

and remove the old brush, dynamics, gradient property copying
functions.
parent 5299b189
......@@ -1189,106 +1189,110 @@ gimp_paint_options_set_default_brush_hardness (GimpPaintOptions *paint_options,
}
}
void
gimp_paint_options_copy_brush_props (GimpPaintOptions *src,
GimpPaintOptions *dest)
static const gchar *brush_props[] =
{
gdouble brush_size;
gdouble brush_angle;
gdouble brush_aspect_ratio;
gdouble brush_spacing;
gdouble brush_hardness;
gdouble brush_force;
gboolean brush_link_size;
gboolean brush_link_angle;
gboolean brush_link_aspect_ratio;
gboolean brush_link_spacing;
gboolean brush_link_hardness;
"brush-size",
"brush-angle",
"brush-aspect-ratio",
"brush-spacing",
"brush-hardness",
"brush-force",
"brush-link-size",
"brush-link-angle",
"brush-link-aspect-ratio",
"brush-link-spacing",
"brush-link-hardness",
"brush-lock-to-view"
};
gboolean brush_lock_to_view;
static const gchar *dynamics_props[] =
{
"dynamics-expanded",
"fade-reverse",
"fade-length",
"fade-unit",
"fade-repeat"
};
g_return_if_fail (GIMP_IS_PAINT_OPTIONS (src));
g_return_if_fail (GIMP_IS_PAINT_OPTIONS (dest));
static const gchar *gradient_props[] =
{
"gradient-reverse",
"gradient-blend-color-space"
};
g_object_get (src,
"brush-size", &brush_size,
"brush-angle", &brush_angle,
"brush-aspect-ratio", &brush_aspect_ratio,
"brush-spacing", &brush_spacing,
"brush-hardness", &brush_hardness,
"brush-force", &brush_force,
"brush-link-size", &brush_link_size,
"brush-link-angle", &brush_link_angle,
"brush-link-aspect-ratio", &brush_link_aspect_ratio,
"brush-link-spacing", &brush_link_spacing,
"brush-link-hardness", &brush_link_hardness,
"brush-lock-to-view", &brush_lock_to_view,
NULL);
g_object_set (dest,
"brush-size", brush_size,
"brush-angle", brush_angle,
"brush-aspect-ratio", brush_aspect_ratio,
"brush-spacing", brush_spacing,
"brush-hardness", brush_hardness,
"brush-force", brush_force,
"brush-link-size", brush_link_size,
"brush-link-angle", brush_link_angle,
"brush-link-aspect-ratio", brush_link_aspect_ratio,
"brush-link-spacing", brush_link_spacing,
"brush-link-hardness", brush_link_hardness,
"brush-lock-to-view", brush_lock_to_view,
NULL);
}
static const gint max_n_props = (G_N_ELEMENTS (brush_props) +
G_N_ELEMENTS (dynamics_props) +
G_N_ELEMENTS (gradient_props));
void
gimp_paint_options_copy_dynamics_props (GimpPaintOptions *src,
GimpPaintOptions *dest)
gboolean
gimp_paint_options_is_prop (const gchar *prop_name,
GimpContextPropMask prop_mask)
{
gboolean dynamics_expanded;
gboolean fade_reverse;
gdouble fade_length;
GimpUnit fade_unit;
GimpRepeatMode fade_repeat;
gint i;
g_return_if_fail (GIMP_IS_PAINT_OPTIONS (src));
g_return_if_fail (GIMP_IS_PAINT_OPTIONS (dest));
g_return_val_if_fail (prop_name != NULL, FALSE);
g_object_get (src,
"dynamics-expanded", &dynamics_expanded,
"fade-reverse", &fade_reverse,
"fade-length", &fade_length,
"fade-unit", &fade_unit,
"fade-repeat", &fade_repeat,
NULL);
g_object_set (dest,
"dynamics-expanded", dynamics_expanded,
"fade-reverse", fade_reverse,
"fade-length", fade_length,
"fade-unit", fade_unit,
"fade-repeat", fade_repeat,
NULL);
if (prop_mask & GIMP_CONTEXT_PROP_MASK_BRUSH)
{
for (i = 0; i < G_N_ELEMENTS (brush_props); i++)
if (! strcmp (prop_name, brush_props[i]))
return TRUE;
}
if (prop_mask & GIMP_CONTEXT_PROP_MASK_DYNAMICS)
{
for (i = 0; i < G_N_ELEMENTS (dynamics_props); i++)
if (! strcmp (prop_name, dynamics_props[i]))
return TRUE;
}
if (prop_mask & GIMP_CONTEXT_PROP_MASK_GRADIENT)
{
for (i = 0; i < G_N_ELEMENTS (gradient_props); i++)
if (! strcmp (prop_name, gradient_props[i]))
return TRUE;
}
return FALSE;
}
void
gimp_paint_options_copy_gradient_props (GimpPaintOptions *src,
GimpPaintOptions *dest)
gimp_paint_options_copy_props (GimpPaintOptions *src,
GimpPaintOptions *dest,
GimpContextPropMask prop_mask)
{
gboolean gradient_reverse;
GimpGradientBlendColorSpace gradient_blend_color_space;
const gchar *names[max_n_props];
GValue values[max_n_props];
gint n_props = 0;
gint i;
g_return_if_fail (GIMP_IS_PAINT_OPTIONS (src));
g_return_if_fail (GIMP_IS_PAINT_OPTIONS (dest));
g_object_get (src,
"gradient-reverse", &gradient_reverse,
"gradient-blend-color-space", &gradient_blend_color_space,
NULL);
if (prop_mask & GIMP_CONTEXT_PROP_MASK_BRUSH)
{
for (i = 0; i < G_N_ELEMENTS (brush_props); i++)
names[n_props++] = brush_props[i];
}
g_object_set (dest,
"gradient-reverse", gradient_reverse,
"gradient-blend-color-space", gradient_blend_color_space,
NULL);
if (prop_mask & GIMP_CONTEXT_PROP_MASK_DYNAMICS)
{
for (i = 0; i < G_N_ELEMENTS (dynamics_props); i++)
names[n_props++] = dynamics_props[i];
}
if (prop_mask & GIMP_CONTEXT_PROP_MASK_GRADIENT)
{
for (i = 0; i < G_N_ELEMENTS (gradient_props); i++)
names[n_props++] = gradient_props[i];
}
if (n_props > 0)
{
g_object_getv (G_OBJECT (src), n_props, names, values);
g_object_setv (G_OBJECT (dest), n_props, names, values);
while (n_props--)
g_value_unset (&values[n_props]);
}
}
......@@ -128,49 +128,49 @@ struct _GimpPaintOptionsClass
};
GType gimp_paint_options_get_type (void) G_GNUC_CONST;
GType gimp_paint_options_get_type (void) G_GNUC_CONST;
GimpPaintOptions * gimp_paint_options_new (GimpPaintInfo *paint_info);
GimpPaintOptions *
gimp_paint_options_new (GimpPaintInfo *paint_info);
gdouble gimp_paint_options_get_fade (GimpPaintOptions *paint_options,
GimpImage *image,
gdouble pixel_dist);
gdouble gimp_paint_options_get_fade (GimpPaintOptions *options,
GimpImage *image,
gdouble pixel_dist);
gdouble gimp_paint_options_get_jitter (GimpPaintOptions *paint_options,
GimpImage *image);
gdouble gimp_paint_options_get_jitter (GimpPaintOptions *options,
GimpImage *image);
gboolean gimp_paint_options_get_gradient_color (GimpPaintOptions *paint_options,
GimpImage *image,
gdouble grad_point,
gdouble pixel_dist,
GimpRGB *color);
gboolean gimp_paint_options_get_gradient_color (GimpPaintOptions *options,
GimpImage *image,
gdouble grad_point,
gdouble pixel_dist,
GimpRGB *color);
GimpBrushApplicationMode
gimp_paint_options_get_brush_mode (GimpPaintOptions *paint_options);
void gimp_paint_options_set_default_brush_size
(GimpPaintOptions *paint_options,
GimpBrush *brush);
void gimp_paint_options_set_default_brush_angle
(GimpPaintOptions *paint_options,
GimpBrush *brush);
void gimp_paint_options_set_default_brush_aspect_ratio
(GimpPaintOptions *paint_options,
GimpBrush *brush);
void gimp_paint_options_set_default_brush_spacing
(GimpPaintOptions *paint_options,
GimpBrush *brush);
void gimp_paint_options_set_default_brush_hardness
(GimpPaintOptions *paint_options,
GimpBrush *brush);
void gimp_paint_options_copy_brush_props (GimpPaintOptions *src,
GimpPaintOptions *dest);
void gimp_paint_options_copy_dynamics_props (GimpPaintOptions *src,
GimpPaintOptions *dest);
void gimp_paint_options_copy_gradient_props (GimpPaintOptions *src,
GimpPaintOptions *dest);
gimp_paint_options_get_brush_mode (GimpPaintOptions *options);
void gimp_paint_options_set_default_brush_size
(GimpPaintOptions *options,
GimpBrush *brush);
void gimp_paint_options_set_default_brush_angle
(GimpPaintOptions *options,
GimpBrush *brush);
void gimp_paint_options_set_default_brush_aspect_ratio
(GimpPaintOptions *options,
GimpBrush *brush);
void gimp_paint_options_set_default_brush_spacing
(GimpPaintOptions *options,
GimpBrush *brush);
void gimp_paint_options_set_default_brush_hardness
(GimpPaintOptions *options,
GimpBrush *brush);
gboolean gimp_paint_options_is_prop (const gchar *prop_name,
GimpContextPropMask prop_mask);
void gimp_paint_options_copy_props (GimpPaintOptions *src,
GimpPaintOptions *dest,
GimpContextPropMask prop_mask);
#endif /* __GIMP_PAINT_OPTIONS_H__ */
......@@ -313,41 +313,6 @@ tool_options_manager_global_notify (GimpCoreConfig *config,
manager->global_props = global_props;
}
static const gchar *brush_props[] =
{
"brush-size",
"brush-angle",
"brush-aspect-ratio",
"brush-spacing",
"brush-hardness",
"brush-force",
"brush-link-size",
"brush-link-angle",
"brush-link-aspect-ratio",
"brush-link-spacing",
"brush-link-hardness",
"brush-lock-to-view"
};
static const gchar *dynamics_props[] =
{
"dynamics-expanded",
"fade-reverse",
"fade-length",
"fade-unit",
"fade-repeat"
};
static const gchar *gradient_props[] =
{
"gradient-reverse",
"gradient-blend-color-space"
};
static const gint max_n_props = (G_N_ELEMENTS (brush_props) +
G_N_ELEMENTS (dynamics_props) +
G_N_ELEMENTS (gradient_props));
static void
tool_options_manager_paint_options_notify (GimpPaintOptions *src,
const GParamSpec *pspec,
......@@ -357,9 +322,8 @@ tool_options_manager_paint_options_notify (GimpPaintOptions *src,
GimpCoreConfig *config = gimp->config;
GimpToolOptionsManager *manager;
GimpToolInfo *tool_info;
gboolean active = FALSE;
GValue value = G_VALUE_INIT;
gint i;
GimpContextPropMask prop_mask = 0;
gboolean active = FALSE;
manager = g_object_get_qdata (G_OBJECT (gimp), manager_quark);
......@@ -377,46 +341,39 @@ tool_options_manager_paint_options_notify (GimpPaintOptions *src,
if ((active || config->global_brush) &&
tool_info->context_props & GIMP_CONTEXT_PROP_MASK_BRUSH)
{
for (i = 0; i < G_N_ELEMENTS (brush_props); i++)
if (! strcmp (pspec->name, brush_props[i]))
goto copy_value;
prop_mask |= GIMP_CONTEXT_PROP_MASK_BRUSH;
}
if ((active || config->global_dynamics) &&
tool_info->context_props & GIMP_CONTEXT_PROP_MASK_DYNAMICS)
else if ((active || config->global_dynamics) &&
tool_info->context_props & GIMP_CONTEXT_PROP_MASK_DYNAMICS)
{
for (i = 0; i < G_N_ELEMENTS (dynamics_props); i++)
if (! strcmp (pspec->name, dynamics_props[i]))
goto copy_value;
prop_mask |= GIMP_CONTEXT_PROP_MASK_DYNAMICS;
}
if ((active || config->global_gradient) &&
tool_info->context_props & GIMP_CONTEXT_PROP_MASK_GRADIENT)
else if ((active || config->global_gradient) &&
tool_info->context_props & GIMP_CONTEXT_PROP_MASK_GRADIENT)
{
for (i = 0; i < G_N_ELEMENTS (gradient_props); i++)
if (! strcmp (pspec->name, gradient_props[i]))
goto copy_value;
prop_mask |= GIMP_CONTEXT_PROP_MASK_GRADIENT;
}
return;
copy_value:
if (gimp_paint_options_is_prop (pspec->name, prop_mask))
{
GValue value = G_VALUE_INIT;
g_value_init (&value, pspec->value_type);
g_value_init (&value, pspec->value_type);
g_object_get_property (G_OBJECT (src), pspec->name, &value);
g_object_get_property (G_OBJECT (src), pspec->name, &value);
g_signal_handlers_block_by_func (dest,
tool_options_manager_paint_options_notify,
src);
g_signal_handlers_block_by_func (dest,
tool_options_manager_paint_options_notify,
src);
g_object_set_property (G_OBJECT (dest), pspec->name, &value);
g_object_set_property (G_OBJECT (dest), pspec->name, &value);
g_signal_handlers_unblock_by_func (dest,
tool_options_manager_paint_options_notify,
src);
g_signal_handlers_unblock_by_func (dest,
tool_options_manager_paint_options_notify,
src);
g_value_unset (&value);
g_value_unset (&value);
}
}
static void
......@@ -424,46 +381,15 @@ tool_options_manager_copy_paint_props (GimpPaintOptions *src,
GimpPaintOptions *dest,
GimpContextPropMask prop_mask)
{
const gchar *names[max_n_props];
GValue values[max_n_props];
gint n_props = 0;
gint i;
if (prop_mask & GIMP_CONTEXT_PROP_MASK_BRUSH)
{
for (i = 0; i < G_N_ELEMENTS (brush_props); i++)
names[n_props++] = brush_props[i];
}
if (prop_mask & GIMP_CONTEXT_PROP_MASK_DYNAMICS)
{
for (i = 0; i < G_N_ELEMENTS (dynamics_props); i++)
names[n_props++] = dynamics_props[i];
}
if (prop_mask & GIMP_CONTEXT_PROP_MASK_GRADIENT)
{
for (i = 0; i < G_N_ELEMENTS (gradient_props); i++)
names[n_props++] = gradient_props[i];
}
if (n_props > 0)
{
g_object_getv (G_OBJECT (src), n_props, names, values);
g_signal_handlers_block_by_func (dest,
tool_options_manager_paint_options_notify,
src);
g_signal_handlers_block_by_func (dest,
tool_options_manager_paint_options_notify,
src);
g_object_setv (G_OBJECT (dest), n_props, names, values);
gimp_paint_options_copy_props (src, dest, prop_mask);
g_signal_handlers_unblock_by_func (dest,
tool_options_manager_paint_options_notify,
src);
while (n_props--)
g_value_unset (&values[n_props]);
}
g_signal_handlers_unblock_by_func (dest,
tool_options_manager_paint_options_notify,
src);
}
static void
......
......@@ -739,8 +739,12 @@ tool_manager_preset_changed (GimpContext *user_context,
if (GIMP_IS_PAINT_OPTIONS (preset->tool_options))
{
GimpToolOptions *src = preset->tool_options;
GimpToolOptions *dest = tool_manager->active_tool->tool_info->tool_options;
GimpToolOptions *src;
GimpToolOptions *dest;
GimpContextPropMask prop_mask = 0;
src = preset->tool_options;
dest = tool_manager->active_tool->tool_info->tool_options;
/* copy various data objects' additional tool options again
* manually, they might have been overwritten by e.g. the "link
......@@ -748,16 +752,17 @@ tool_manager_preset_changed (GimpContext *user_context,
* gimptooloptions-gui.c
*/
if (preset->use_brush)
gimp_paint_options_copy_brush_props (GIMP_PAINT_OPTIONS (src),
GIMP_PAINT_OPTIONS (dest));
prop_mask |= GIMP_CONTEXT_PROP_MASK_BRUSH;
if (preset->use_dynamics)
gimp_paint_options_copy_dynamics_props (GIMP_PAINT_OPTIONS (src),
GIMP_PAINT_OPTIONS (dest));
prop_mask |= GIMP_CONTEXT_PROP_MASK_DYNAMICS;
if (preset->use_gradient)
gimp_paint_options_copy_gradient_props (GIMP_PAINT_OPTIONS (src),
GIMP_PAINT_OPTIONS (dest));
prop_mask |= GIMP_CONTEXT_PROP_MASK_GRADIENT;
gimp_paint_options_copy_props (GIMP_PAINT_OPTIONS (src),
GIMP_PAINT_OPTIONS (dest),
prop_mask);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment