Commit 9bb4c3d4 authored by Michael Natterer's avatar Michael Natterer 😴

app: pull some GEGL operation logic from subclasses into GimpImageMapTool

- connect to the config object's notify generically and update the preview
- allow to properly exchange the operation at runtime to remove major
  uglyness from GimpOperationTool
- return undo_desc from GimpImageMapTool::get_operation() so we have
  proper strings in the undo history, not always "GEGL operation"
- simplify all get_operation() implementations
parent 9994a4d5
......@@ -72,7 +72,8 @@ static void gimp_brightness_contrast_tool_motion (GimpTool
static GeglNode *
gimp_brightness_contrast_tool_get_operation (GimpImageMapTool *image_map_tool,
GObject **config);
GObject **config,
gchar **undo_desc);
static void gimp_brightness_contrast_tool_dialog (GimpImageMapTool *image_map_tool);
static void brightness_contrast_config_notify (GObject *object,
......@@ -154,28 +155,23 @@ gimp_brightness_contrast_tool_initialize (GimpTool *tool,
static GeglNode *
gimp_brightness_contrast_tool_get_operation (GimpImageMapTool *im_tool,
GObject **config)
GObject **config,
gchar **undo_desc)
{
GimpBrightnessContrastTool *bc_tool = GIMP_BRIGHTNESS_CONTRAST_TOOL (im_tool);
GeglNode *node;
node = g_object_new (GEGL_TYPE_NODE,
"operation", "gimp:brightness-contrast",
NULL);
bc_tool->config = g_object_new (GIMP_TYPE_BRIGHTNESS_CONTRAST_CONFIG, NULL);
*config = G_OBJECT (bc_tool->config);
g_signal_connect_object (bc_tool->config, "notify",
G_CALLBACK (brightness_contrast_config_notify),
G_OBJECT (bc_tool), 0);
gegl_node_set (node,
"config", bc_tool->config,
NULL);
*config = G_OBJECT (bc_tool->config);
return node;
return gegl_node_new_child (NULL,
"operation", "gimp:brightness-contrast",
"config", bc_tool->config,
NULL);
}
static void
......@@ -322,8 +318,6 @@ brightness_contrast_config_notify (GObject *object,
gtk_adjustment_set_value (bc_tool->contrast_data,
config->contrast * 127.0);
}
gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (bc_tool));
}
static void
......
......@@ -50,7 +50,8 @@ static gboolean gimp_color_balance_tool_initialize (GimpTool *tool,
GError **error);
static GeglNode * gimp_color_balance_tool_get_operation (GimpImageMapTool *im_tool,
GObject **config);
GObject **config,
gchar **undo_desc);
static void gimp_color_balance_tool_dialog (GimpImageMapTool *im_tool);
static void gimp_color_balance_tool_reset (GimpImageMapTool *im_tool);
......@@ -143,28 +144,23 @@ gimp_color_balance_tool_initialize (GimpTool *tool,
static GeglNode *
gimp_color_balance_tool_get_operation (GimpImageMapTool *im_tool,
GObject **config)
GObject **config,
gchar **undo_desc)
{
GimpColorBalanceTool *cb_tool = GIMP_COLOR_BALANCE_TOOL (im_tool);
GeglNode *node;
node = g_object_new (GEGL_TYPE_NODE,
"operation", "gimp:color-balance",
NULL);
cb_tool->config = g_object_new (GIMP_TYPE_COLOR_BALANCE_CONFIG, NULL);
*config = G_OBJECT (cb_tool->config);
g_signal_connect_object (cb_tool->config, "notify",
G_CALLBACK (color_balance_config_notify),
G_OBJECT (cb_tool), 0);
gegl_node_set (node,
"config", cb_tool->config,
NULL);
*config = G_OBJECT (cb_tool->config);
return node;
return gegl_node_new_child (NULL,
"operation", "gimp:color-balance",
"config", cb_tool->config,
NULL);
}
......@@ -365,8 +361,6 @@ color_balance_config_notify (GObject *object,
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (cb_tool->preserve_toggle),
config->preserve_luminosity);
}
gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (cb_tool));
}
static void
......
......@@ -55,7 +55,8 @@ static gboolean gimp_colorize_tool_initialize (GimpTool *tool,
GError **error);
static GeglNode * gimp_colorize_tool_get_operation (GimpImageMapTool *im_tool,
GObject **config);
GObject **config,
gchar **undo_desc);
static void gimp_colorize_tool_dialog (GimpImageMapTool *im_tool);
static void gimp_colorize_tool_color_picked (GimpImageMapTool *im_tool,
gpointer identifier,
......@@ -154,28 +155,23 @@ gimp_colorize_tool_initialize (GimpTool *tool,
static GeglNode *
gimp_colorize_tool_get_operation (GimpImageMapTool *im_tool,
GObject **config)
GObject **config,
gchar **undo_desc)
{
GimpColorizeTool *col_tool = GIMP_COLORIZE_TOOL (im_tool);
GeglNode *node;
node = g_object_new (GEGL_TYPE_NODE,
"operation", "gimp:colorize",
NULL);
col_tool->config = g_object_new (GIMP_TYPE_COLORIZE_CONFIG, NULL);
*config = G_OBJECT (col_tool->config);
g_signal_connect_object (col_tool->config, "notify",
G_CALLBACK (gimp_colorize_tool_config_notify),
G_OBJECT (col_tool), 0);
gegl_node_set (node,
"config", col_tool->config,
NULL);
*config = G_OBJECT (col_tool->config);
return node;
return gegl_node_new_child (NULL,
"operation", "gimp:colorize",
"config", col_tool->config,
NULL);
}
......@@ -323,8 +319,6 @@ gimp_colorize_tool_config_notify (GObject *object,
gimp_colorize_config_get_color (col_tool->config, &color);
gimp_color_button_set_color (GIMP_COLOR_BUTTON (col_tool->color_button),
&color);
gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (col_tool));
}
static void
......
......@@ -86,7 +86,8 @@ static void gimp_curves_tool_color_picked (GimpColorTool *color_t
const GimpRGB *color,
gint color_index);
static GeglNode * gimp_curves_tool_get_operation (GimpImageMapTool *image_map_tool,
GObject **config);
GObject **config,
gchar **undo_desc);
static void gimp_curves_tool_dialog (GimpImageMapTool *image_map_tool);
static void gimp_curves_tool_reset (GimpImageMapTool *image_map_tool);
static gboolean gimp_curves_tool_settings_import(GimpImageMapTool *image_map_tool,
......@@ -351,28 +352,23 @@ gimp_curves_tool_color_picked (GimpColorTool *color_tool,
static GeglNode *
gimp_curves_tool_get_operation (GimpImageMapTool *image_map_tool,
GObject **config)
GObject **config,
gchar **undo_desc)
{
GimpCurvesTool *tool = GIMP_CURVES_TOOL (image_map_tool);
GeglNode *node;
node = g_object_new (GEGL_TYPE_NODE,
"operation", "gimp:curves",
NULL);
tool->config = g_object_new (GIMP_TYPE_CURVES_CONFIG, NULL);
*config = G_OBJECT (tool->config);
g_signal_connect_object (tool->config, "notify",
G_CALLBACK (gimp_curves_tool_config_notify),
tool, 0);
gegl_node_set (node,
"config", tool->config,
NULL);
*config = G_OBJECT (tool->config);
return node;
return gegl_node_new_child (NULL,
"operation", "gimp:curves",
"config", tool->config,
NULL);
}
......@@ -773,8 +769,6 @@ gimp_curves_tool_config_notify (GObject *object,
gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (tool->curve_type),
curve->curve_type);
}
gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (tool));
}
static void
......
......@@ -47,7 +47,8 @@ static gboolean gimp_desaturate_tool_initialize (GimpTool *tool,
GError **error);
static GeglNode * gimp_desaturate_tool_get_operation (GimpImageMapTool *im_tool,
GObject **config);
GObject **config,
gchar **undo_desc);
static void gimp_desaturate_tool_dialog (GimpImageMapTool *im_tool);
static void gimp_desaturate_tool_config_notify (GObject *object,
......@@ -134,28 +135,23 @@ gimp_desaturate_tool_initialize (GimpTool *tool,
static GeglNode *
gimp_desaturate_tool_get_operation (GimpImageMapTool *image_map_tool,
GObject **config)
GObject **config,
gchar **undo_desc)
{
GimpDesaturateTool *desaturate_tool = GIMP_DESATURATE_TOOL (image_map_tool);
GeglNode *node;
node = g_object_new (GEGL_TYPE_NODE,
"operation", "gimp:desaturate",
NULL);
desaturate_tool->config = g_object_new (GIMP_TYPE_DESATURATE_CONFIG, NULL);
*config = G_OBJECT (desaturate_tool->config);
g_signal_connect_object (desaturate_tool->config, "notify",
G_CALLBACK (gimp_desaturate_tool_config_notify),
G_OBJECT (desaturate_tool), 0);
gegl_node_set (node,
"config", desaturate_tool->config,
NULL);
*config = G_OBJECT (desaturate_tool->config);
return node;
return gegl_node_new_child (NULL,
"operation", "gimp:desaturate",
"config", desaturate_tool->config,
NULL);
}
......@@ -195,8 +191,6 @@ gimp_desaturate_tool_config_notify (GObject *object,
gimp_int_radio_group_set_active (GTK_RADIO_BUTTON (desaturate_tool->button),
config->mode);
gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (desaturate_tool));
}
static void
......
......@@ -56,7 +56,8 @@ static gboolean gimp_hue_saturation_tool_initialize (GimpTool *tool
GError **error);
static GeglNode * gimp_hue_saturation_tool_get_operation (GimpImageMapTool *im_tool,
GObject **config);
GObject **config,
gchar **undo_desc);
static void gimp_hue_saturation_tool_dialog (GimpImageMapTool *im_tool);
static void gimp_hue_saturation_tool_reset (GimpImageMapTool *im_tool);
......@@ -151,28 +152,23 @@ gimp_hue_saturation_tool_initialize (GimpTool *tool,
static GeglNode *
gimp_hue_saturation_tool_get_operation (GimpImageMapTool *im_tool,
GObject **config)
GObject **config,
gchar **undo_desc)
{
GimpHueSaturationTool *hs_tool = GIMP_HUE_SATURATION_TOOL (im_tool);
GeglNode *node;
node = g_object_new (GEGL_TYPE_NODE,
"operation", "gimp:hue-saturation",
NULL);
hs_tool->config = g_object_new (GIMP_TYPE_HUE_SATURATION_CONFIG, NULL);
*config = G_OBJECT (hs_tool->config);
g_signal_connect_object (hs_tool->config, "notify",
G_CALLBACK (hue_saturation_config_notify),
G_OBJECT (hs_tool), 0);
gegl_node_set (node,
"config", hs_tool->config,
NULL);
*config = G_OBJECT (hs_tool->config);
return node;
return gegl_node_new_child (NULL,
"operation", "gimp:hue-saturation",
"config", hs_tool->config,
NULL);
}
......@@ -470,8 +466,6 @@ hue_saturation_config_notify (GObject *object,
}
hue_saturation_update_color_areas (hs_tool);
gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (hs_tool));
}
static void
......
......@@ -111,9 +111,13 @@ static void gimp_image_map_tool_dialog (GimpImageMapTool *im_tool);
static void gimp_image_map_tool_dialog_unmap (GtkWidget *dialog,
GimpImageMapTool *im_tool);
static void gimp_image_map_tool_reset (GimpImageMapTool *im_tool);
static void gimp_image_map_tool_create_map (GimpImageMapTool *im_tool);
static void gimp_image_map_tool_flush (GimpImageMap *image_map,
GimpImageMapTool *im_tool);
static void gimp_image_map_tool_config_notify (GObject *object,
const GParamSpec *pspec,
GimpImageMapTool *im_tool);
static void gimp_image_map_tool_response (GtkWidget *widget,
gint response_id,
......@@ -210,32 +214,16 @@ gimp_image_map_tool_init (GimpImageMapTool *image_map_tool)
GIMP_DIRTY_DRAWABLE |
GIMP_DIRTY_SELECTION |
GIMP_DIRTY_ACTIVE_DRAWABLE);
image_map_tool->drawable = NULL;
image_map_tool->operation = NULL;
image_map_tool->config = NULL;
image_map_tool->default_config = NULL;
image_map_tool->image_map = NULL;
image_map_tool->dialog = NULL;
image_map_tool->main_vbox = NULL;
image_map_tool->settings_box = NULL;
image_map_tool->label_group = NULL;
}
static void
gimp_image_map_tool_constructed (GObject *object)
{
GimpImageMapTool *image_map_tool = GIMP_IMAGE_MAP_TOOL (object);
GimpImageMapToolClass *klass;
GimpImageMapTool *image_map_tool = GIMP_IMAGE_MAP_TOOL (object);
G_OBJECT_CLASS (parent_class)->constructed (object);
klass = GIMP_IMAGE_MAP_TOOL_GET_CLASS (image_map_tool);
if (klass->get_operation)
image_map_tool->operation = klass->get_operation (image_map_tool,
&image_map_tool->config);
gimp_image_map_tool_get_operation (image_map_tool);
}
static void
......@@ -261,6 +249,12 @@ gimp_image_map_tool_finalize (GObject *object)
image_map_tool->default_config = NULL;
}
if (image_map_tool->undo_desc)
{
g_free (image_map_tool->undo_desc);
image_map_tool->undo_desc = NULL;
}
if (image_map_tool->dialog)
gimp_image_map_tool_dialog_destroy (image_map_tool);
......@@ -429,7 +423,7 @@ gimp_image_map_tool_initialize (GimpTool *tool,
image_map_tool->drawable = drawable;
gimp_image_map_tool_create_map (image_map_tool, NULL);
gimp_image_map_tool_create_map (image_map_tool);
return TRUE;
}
......@@ -651,9 +645,8 @@ gimp_image_map_tool_reset (GimpImageMapTool *tool)
}
}
void
gimp_image_map_tool_create_map (GimpImageMapTool *tool,
const gchar *undo_desc)
static void
gimp_image_map_tool_create_map (GimpImageMapTool *tool)
{
GimpToolInfo *tool_info;
......@@ -669,11 +662,8 @@ gimp_image_map_tool_create_map (GimpImageMapTool *tool,
tool_info = GIMP_TOOL (tool)->tool_info;
if (! undo_desc)
undo_desc = tool_info->blurb;
tool->image_map = gimp_image_map_new (tool->drawable,
undo_desc,
tool->undo_desc,
tool->operation,
gimp_viewable_get_stock_id (GIMP_VIEWABLE (tool_info)));
......@@ -692,6 +682,14 @@ gimp_image_map_tool_flush (GimpImageMap *image_map,
gimp_projection_flush (gimp_image_get_projection (image));
}
static void
gimp_image_map_tool_config_notify (GObject *object,
const GParamSpec *pspec,
GimpImageMapTool *image_map_tool)
{
gimp_image_map_tool_preview (image_map_tool);
}
static void
gimp_image_map_tool_response (GtkWidget *widget,
gint response_id,
......@@ -779,6 +777,61 @@ gimp_image_map_tool_dialog_destroy (GimpImageMapTool *image_map_tool)
image_map_tool->settings_box = NULL;
}
void
gimp_image_map_tool_get_operation (GimpImageMapTool *image_map_tool)
{
GimpImageMapToolClass *klass;
g_return_if_fail (GIMP_IS_IMAGE_MAP_TOOL (image_map_tool));
klass = GIMP_IMAGE_MAP_TOOL_GET_CLASS (image_map_tool);
if (image_map_tool->image_map)
{
gimp_image_map_abort (image_map_tool->image_map);
g_object_unref (image_map_tool->image_map);
image_map_tool->image_map = NULL;
}
if (image_map_tool->operation)
{
g_object_unref (image_map_tool->operation);
image_map_tool->operation = NULL;
}
if (image_map_tool->config)
{
g_signal_handlers_disconnect_by_func (image_map_tool->config,
gimp_image_map_tool_config_notify,
image_map_tool);
g_object_unref (image_map_tool->config);
image_map_tool->config = NULL;
}
if (image_map_tool->undo_desc)
{
g_free (image_map_tool->undo_desc);
image_map_tool->undo_desc = NULL;
}
image_map_tool->operation = klass->get_operation (image_map_tool,
&image_map_tool->config,
&image_map_tool->undo_desc);
if (! image_map_tool->undo_desc)
image_map_tool->undo_desc =
g_strdup (GIMP_TOOL (image_map_tool)->tool_info->blurb);
if (image_map_tool->config)
g_signal_connect_object (image_map_tool->config, "notify",
G_CALLBACK (gimp_image_map_tool_config_notify),
G_OBJECT (image_map_tool), 0);
if (GIMP_TOOL (image_map_tool)->drawable)
gimp_image_map_tool_create_map (image_map_tool);
}
void
gimp_image_map_tool_preview (GimpImageMapTool *image_map_tool)
{
......
......@@ -43,6 +43,7 @@ struct _GimpImageMapTool
GeglNode *operation;
GObject *config;
GObject *default_config;
gchar *undo_desc;
GimpImageMap *image_map;
......@@ -68,7 +69,8 @@ struct _GimpImageMapToolClass
/* virtual functions */
GeglNode * (* get_operation) (GimpImageMapTool *image_map_tool,
GObject **config);
GObject **config,
gchar **undo_desc);
void (* map) (GimpImageMapTool *image_map_tool);
void (* dialog) (GimpImageMapTool *image_map_tool);
void (* reset) (GimpImageMapTool *image_map_tool);
......@@ -96,17 +98,15 @@ struct _GimpImageMapToolClass
};
GType gimp_image_map_tool_get_type (void) G_GNUC_CONST;
GType gimp_image_map_tool_get_type (void) G_GNUC_CONST;
void gimp_image_map_tool_preview (GimpImageMapTool *image_map_tool);
void gimp_image_map_tool_preview (GimpImageMapTool *image_map_tool);
/* temp hack for the gegl tool */
void gimp_image_map_tool_create_map (GimpImageMapTool *image_map_tool,
const gchar *undo_desc);
void gimp_image_map_tool_get_operation (GimpImageMapTool *image_map_tool);
void gimp_image_map_tool_edit_as (GimpImageMapTool *image_map_tool,
const gchar *new_tool_id,
GimpConfig *config);
void gimp_image_map_tool_edit_as (GimpImageMapTool *image_map_tool,
const gchar *new_tool_id,
GimpConfig *config);
/* accessors for derived classes */
GtkWidget * gimp_image_map_tool_dialog_get_vbox (GimpImageMapTool *tool);
......
......@@ -74,7 +74,8 @@ static gboolean gimp_levels_tool_initialize (GimpTool *tool,
GError **error);
static GeglNode * gimp_levels_tool_get_operation (GimpImageMapTool *im_tool,
GObject **config);
GObject **config,
gchar **undo_desc);
static void gimp_levels_tool_dialog (GimpImageMapTool *im_tool);
static void gimp_levels_tool_reset (GimpImageMapTool *im_tool);
static gboolean gimp_levels_tool_settings_import(GimpImageMapTool *im_tool,
......@@ -282,28 +283,23 @@ gimp_levels_tool_initialize (GimpTool *tool,
static GeglNode *
gimp_levels_tool_get_operation (GimpImageMapTool *im_tool,
GObject **config)
GObject **config,
gchar **undo_desc)
{
GimpLevelsTool *tool = GIMP_LEVELS_TOOL (im_tool);
GeglNode *node;
node = g_object_new (GEGL_TYPE_NODE,
"operation", "gimp:levels",
NULL);
tool->config = g_object_new (GIMP_TYPE_LEVELS_CONFIG, NULL);
*config = G_OBJECT (tool->config);
g_signal_connect_object (tool->config, "notify",
G_CALLBACK (gimp_levels_tool_config_notify),
G_OBJECT (tool), 0);
gegl_node_set (node,
"config", tool->config,
NULL);
*config = G_OBJECT (tool->config);
return node;
return gegl_node_new_child (NULL,
"operation", "gimp:levels",
"config", tool->config,
NULL);
}
......@@ -896,8 +892,6 @@ gimp_levels_tool_config_notify (GObject *object,
config->high_output[config->channel] *
scale_factor);
}
gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (tool));
}
static void
......
......@@ -60,7 +60,8 @@ static gboolean gimp_operation_tool_initialize (GimpTool *tool,
GError **error);
static GeglNode * gimp_operation_tool_get_operation (GimpImageMapTool *im_tool,
GObject **config);
GObject **config,
gchar **undo_desc);
static void gimp_operation_tool_map (GimpImageMapTool *im_tool);
static void gimp_operation_tool_dialog (GimpImageMapTool *im_tool);
static void gimp_operation_tool_reset (GimpImageMapTool *im_tool);
......@@ -77,10 +78,6 @@ static void gimp_operation_tool_color_picked (GimpImageMapTool *im_to
const Babl *sample_format,
const GimpRGB *color);
static void gimp_operation_tool_config_notify (GObject *object,
GParamSpec *pspec,
GimpOperationTool *tool);
G_DEFINE_TYPE (GimpOperationTool, gimp_operation_tool,
GIMP_TYPE_IMAGE_MAP_TOOL)
......@@ -185,8 +182,22 @@ gimp_operation_tool_initialize (GimpTool *tool,
static GeglNode *
gimp_operation_tool_get_operation (GimpImageMapTool *im_tool,
GObject **config)
GObject **config,
gchar **undo_desc)
{
GimpOperationTool *tool = GIMP_OPERATION_TOOL (im_tool);
if (tool->config)
*config = g_object_ref (tool->config);
if (tool->undo_desc)
*undo_desc = g_strdup (tool->undo_desc);
if (tool->operation)
return gegl_node_new_child (NULL,
"operation", tool->operation,
NULL);
return g_object_new (GEGL_TYPE_NODE, NULL);
}
......@@ -295,14 +306,6 @@ gimp_operation_tool_color_picked (GimpImageMapTool *im_tool,
NULL);
}
static void
gimp_operation_tool_config_notify (GObject *object,
GParamSpec *pspec,
GimpOperationTool *tool)
{
gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (tool));
}