Commit 0d3e3625 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer

moved "shell_desc" from GimpImageMapTool to GimpImageMapToolClass and

2004-02-25  Michael Natterer  <mitch@gimp.org>

	* app/tools/gimpimagemaptool.[ch]: moved "shell_desc" from
	GimpImageMapTool to GimpImageMapToolClass and added
	"load_dialog_title" and "save_dialog_title". Create the
	load/save buttons in gimp_image_map_tool_initialize() and
	remember them in the GimpImageMapTool struct. Moved the
	whole load/save button/dialog logic into private functions.

	* app/tools/gimpcurvestool.c
	* app/tools/gimplevelstool.c: changed accordingly, removed
	load/save callbacks, inlined the load/save functions into
	GimpImageMapTool's virtual function implementations.

	* app/tools/gimpbrightnesscontrasttool.c
	* app/tools/gimpcolorbalancetool.c
	* app/tools/gimpcolorizetool.c
	* app/tools/gimphuesaturationtool.c
	* app/tools/gimpposterizetool.c
	* app/tools/gimpthresholdtool.c: changed accordingly.
parent dc25eebf
2004-02-25 Michael Natterer <mitch@gimp.org>
* app/tools/gimpimagemaptool.[ch]: moved "shell_desc" from
GimpImageMapTool to GimpImageMapToolClass and added
"load_dialog_title" and "save_dialog_title". Create the
load/save buttons in gimp_image_map_tool_initialize() and
remember them in the GimpImageMapTool struct. Moved the
whole load/save button/dialog logic into private functions.
* app/tools/gimpcurvestool.c
* app/tools/gimplevelstool.c: changed accordingly, removed
load/save callbacks, inlined the load/save functions into
GimpImageMapTool's virtual function implementations.
* app/tools/gimpbrightnesscontrasttool.c
* app/tools/gimpcolorbalancetool.c
* app/tools/gimpcolorizetool.c
* app/tools/gimphuesaturationtool.c
* app/tools/gimpposterizetool.c
* app/tools/gimpthresholdtool.c: changed accordingly.
2004-02-25 Sven Neumann <sven@gimp.org>
* app/tools/gimpcurvestool.[ch]
......@@ -135,6 +135,8 @@ gimp_brightness_contrast_tool_class_init (GimpBrightnessContrastToolClass *klass
tool_class->initialize = gimp_brightness_contrast_tool_initialize;
image_map_tool_class->shell_desc = _("Adjust Brightness and Contrast");
image_map_tool_class->map = gimp_brightness_contrast_tool_map;
image_map_tool_class->dialog = gimp_brightness_contrast_tool_dialog;
image_map_tool_class->reset = gimp_brightness_contrast_tool_reset;
......@@ -143,10 +145,6 @@ gimp_brightness_contrast_tool_class_init (GimpBrightnessContrastToolClass *klass
static void
gimp_brightness_contrast_tool_init (GimpBrightnessContrastTool *bc_tool)
{
GimpImageMapTool *image_map_tool = GIMP_IMAGE_MAP_TOOL (bc_tool);
image_map_tool->shell_desc = _("Adjust Brightness and Contrast");
bc_tool->brightness = 0.0;
bc_tool->contrast = 0.0;
bc_tool->lut = gimp_lut_new ();
......
......@@ -146,6 +146,8 @@ gimp_color_balance_tool_class_init (GimpColorBalanceToolClass *klass)
tool_class->initialize = gimp_color_balance_tool_initialize;
image_map_tool_class->shell_desc = _("Adjust Color Balance");
image_map_tool_class->map = gimp_color_balance_tool_map;
image_map_tool_class->dialog = gimp_color_balance_tool_dialog;
image_map_tool_class->reset = gimp_color_balance_tool_reset;
......@@ -154,10 +156,6 @@ gimp_color_balance_tool_class_init (GimpColorBalanceToolClass *klass)
static void
gimp_color_balance_tool_init (GimpColorBalanceTool *cb_tool)
{
GimpImageMapTool *image_map_tool = GIMP_IMAGE_MAP_TOOL (cb_tool);
image_map_tool->shell_desc = _("Adjust Color Balance");
cb_tool->color_balance = g_new0 (ColorBalance, 1);
cb_tool->transfer_mode = GIMP_MIDTONES;
......
......@@ -149,6 +149,8 @@ gimp_colorize_tool_class_init (GimpColorizeToolClass *klass)
tool_class->initialize = gimp_colorize_tool_initialize;
image_map_tool_class->shell_desc = _("Colorize the Image");
image_map_tool_class->map = gimp_colorize_tool_map;
image_map_tool_class->dialog = gimp_colorize_tool_dialog;
image_map_tool_class->reset = gimp_colorize_tool_reset;
......@@ -157,10 +159,6 @@ gimp_colorize_tool_class_init (GimpColorizeToolClass *klass)
static void
gimp_colorize_tool_init (GimpColorizeTool *col_tool)
{
GimpImageMapTool *image_map_tool = GIMP_IMAGE_MAP_TOOL (col_tool);
image_map_tool->shell_desc = _("Colorize the Image");
col_tool->colorize = g_new0 (Colorize, 1);
colorize_init (col_tool->colorize);
......
......@@ -90,10 +90,10 @@ static void gimp_curves_tool_color_picked (GimpColorTool *color_tool,
static void gimp_curves_tool_map (GimpImageMapTool *image_map_tool);
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_load (GimpImageMapTool *tool,
gpointer file);
static gboolean gimp_curves_tool_settings_save (GimpImageMapTool *tool,
gpointer file);
static gboolean gimp_curves_tool_settings_load (GimpImageMapTool *image_map_tool,
gpointer fp);
static gboolean gimp_curves_tool_settings_save (GimpImageMapTool *image_map_tool,
gpointer fp);
static void curves_add_point (GimpCurvesTool *tool,
gint x,
......@@ -112,10 +112,6 @@ static gboolean curves_set_sensitive_callback (GimpHistogramChannel channel,
GimpCurvesTool *tool);
static void curves_curve_type_callback (GtkWidget *widget,
GimpCurvesTool *tool);
static void curves_load_callback (GtkWidget *widget,
GimpCurvesTool *tool);
static void curves_save_callback (GtkWidget *widget,
GimpCurvesTool *tool);
static gboolean curves_graph_events (GtkWidget *widget,
GdkEvent *event,
GimpCurvesTool *tool);
......@@ -123,11 +119,6 @@ static gboolean curves_graph_expose (GtkWidget *widget,
GdkEventExpose *eevent,
GimpCurvesTool *tool);
static gboolean curves_read_from_file (GimpCurvesTool *tool,
FILE *file);
static gboolean curves_write_to_file (GimpCurvesTool *tool,
FILE *file);
static GimpImageMapToolClass *parent_class = NULL;
......@@ -204,23 +195,23 @@ gimp_curves_tool_class_init (GimpCurvesToolClass *klass)
color_tool_class->picked = gimp_curves_tool_color_picked;
image_map_tool_class->settings_name = "curves";
image_map_tool_class->shell_desc = _("Adjust Color Curves");
image_map_tool_class->settings_name = "curves";
image_map_tool_class->load_dialog_title = _("Load Curves");
image_map_tool_class->save_dialog_title = _("Save Curves");
image_map_tool_class->map = gimp_curves_tool_map;
image_map_tool_class->dialog = gimp_curves_tool_dialog;
image_map_tool_class->reset = gimp_curves_tool_reset;
image_map_tool_class->map = gimp_curves_tool_map;
image_map_tool_class->dialog = gimp_curves_tool_dialog;
image_map_tool_class->reset = gimp_curves_tool_reset;
image_map_tool_class->settings_load = gimp_curves_tool_settings_load;
image_map_tool_class->settings_save = gimp_curves_tool_settings_save;
image_map_tool_class->settings_load = gimp_curves_tool_settings_load;
image_map_tool_class->settings_save = gimp_curves_tool_settings_save;
}
static void
gimp_curves_tool_init (GimpCurvesTool *tool)
{
GimpImageMapTool *image_map_tool = GIMP_IMAGE_MAP_TOOL (tool);
gint i;
image_map_tool->shell_desc = _("Adjust Color Curves");
gint i;
tool->curves = g_new0 (Curves, 1);
tool->lut = gimp_lut_new ();
......@@ -602,25 +593,17 @@ gimp_curves_tool_dialog (GimpImageMapTool *image_map_tool)
gtk_container_add (GTK_CONTAINER (frame), bbox);
gtk_widget_show (bbox);
button = gtk_button_new_from_stock (GTK_STOCK_OPEN);
GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0);
gimp_help_set_help_data (button, _("Read curves settings from file"), NULL);
gtk_widget_show (button);
gtk_box_pack_start (GTK_BOX (bbox), image_map_tool->load_button,
FALSE, FALSE, 0);
gimp_help_set_help_data (image_map_tool->load_button,
_("Read curves settings from file"), NULL);
gtk_widget_show (image_map_tool->load_button);
g_signal_connect (button, "clicked",
G_CALLBACK (curves_load_callback),
tool);
button = gtk_button_new_from_stock (GTK_STOCK_SAVE);
GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0);
gimp_help_set_help_data (button, _("Save curves settings to file"), NULL);
gtk_widget_show (button);
g_signal_connect (button, "clicked",
G_CALLBACK (curves_save_callback),
tool);
gtk_box_pack_start (GTK_BOX (bbox), image_map_tool->save_button,
FALSE, FALSE, 0);
gimp_help_set_help_data (image_map_tool->save_button,
_("Save curves settings to file"), NULL);
gtk_widget_show (image_map_tool->save_button);
/* The radio box for selecting the curve type */
frame = gtk_frame_new (_("Curve Type"));
......@@ -661,17 +644,93 @@ gimp_curves_tool_reset (GimpImageMapTool *image_map_tool)
}
static gboolean
gimp_curves_tool_settings_load (GimpImageMapTool *tool,
gpointer file)
gimp_curves_tool_settings_load (GimpImageMapTool *image_map_tool,
gpointer fp)
{
return curves_read_from_file (GIMP_CURVES_TOOL (tool), (FILE *) file);
GimpCurvesTool *tool = GIMP_CURVES_TOOL (image_map_tool);
FILE *file = fp;
gint i, j;
gint fields;
gchar buf[50];
gint index[5][17];
gint value[5][17];
if (! fgets (buf, sizeof (buf), file))
return FALSE;
if (strcmp (buf, "# GIMP Curves File\n") != 0)
return FALSE;
for (i = 0; i < 5; i++)
{
for (j = 0; j < 17; j++)
{
fields = fscanf (file, "%d %d ", &index[i][j], &value[i][j]);
if (fields != 2)
{
g_print ("fields != 2");
return FALSE;
}
}
}
for (i = 0; i < 5; i++)
{
tool->curves->curve_type[i] = GIMP_CURVE_SMOOTH;
for (j = 0; j < 17; j++)
{
tool->curves->points[i][j][0] = index[i][j];
tool->curves->points[i][j][1] = value[i][j];
}
}
for (i = 0; i < 5; i++)
curves_calculate_curve (tool->curves, i);
curves_update (tool, ALL);
gimp_int_radio_group_set_active (GTK_RADIO_BUTTON (tool->curve_type),
GIMP_CURVE_SMOOTH);
return TRUE;
}
static gboolean
gimp_curves_tool_settings_save (GimpImageMapTool *tool,
gpointer file)
gimp_curves_tool_settings_save (GimpImageMapTool *image_map_tool,
gpointer fp)
{
return curves_write_to_file (GIMP_CURVES_TOOL (tool), (FILE *) file);
GimpCurvesTool *tool = GIMP_CURVES_TOOL (image_map_tool);
FILE *file = fp;
gint i, j;
gint32 index;
for (i = 0; i < 5; i++)
if (tool->curves->curve_type[i] == GIMP_CURVE_FREE)
{
/* pick representative points from the curve
and make them control points */
for (j = 0; j <= 8; j++)
{
index = CLAMP0255 (j * 32);
tool->curves->points[i][j * 2][0] = index;
tool->curves->points[i][j * 2][1] = tool->curves->curve[i][index];
}
}
fprintf (file, "# GIMP Curves File\n");
for (i = 0; i < 5; i++)
{
for (j = 0; j < 17; j++)
fprintf (file, "%d %d ",
tool->curves->points[i][j][0],
tool->curves->points[i][j][1]);
fprintf (file, "\n");
}
return TRUE;
}
/* TODO: preview alpha channel stuff correctly. -- austin, 20/May/99 */
......@@ -1181,107 +1240,3 @@ curves_graph_expose (GtkWidget *widget,
return FALSE;
}
static void
curves_load_callback (GtkWidget *widget,
GimpCurvesTool *tool)
{
gimp_image_map_tool_settings_dialog (GIMP_IMAGE_MAP_TOOL (tool),
_("Load Curves"), FALSE);
}
static void
curves_save_callback (GtkWidget *widget,
GimpCurvesTool *tool)
{
gimp_image_map_tool_settings_dialog (GIMP_IMAGE_MAP_TOOL (tool),
_("Save Curves"), TRUE);
}
static gboolean
curves_read_from_file (GimpCurvesTool *tool,
FILE *file)
{
gint i, j;
gint fields;
gchar buf[50];
gint index[5][17];
gint value[5][17];
if (! fgets (buf, sizeof (buf), file))
return FALSE;
if (strcmp (buf, "# GIMP Curves File\n") != 0)
return FALSE;
for (i = 0; i < 5; i++)
{
for (j = 0; j < 17; j++)
{
fields = fscanf (file, "%d %d ", &index[i][j], &value[i][j]);
if (fields != 2)
{
g_print ("fields != 2");
return FALSE;
}
}
}
for (i = 0; i < 5; i++)
{
tool->curves->curve_type[i] = GIMP_CURVE_SMOOTH;
for (j = 0; j < 17; j++)
{
tool->curves->points[i][j][0] = index[i][j];
tool->curves->points[i][j][1] = value[i][j];
}
}
for (i = 0; i < 5; i++)
curves_calculate_curve (tool->curves, i);
curves_update (tool, ALL);
gimp_int_radio_group_set_active (GTK_RADIO_BUTTON (tool->curve_type),
GIMP_CURVE_SMOOTH);
gimp_image_map_tool_preview (GIMP_IMAGE_MAP_TOOL (tool));
return TRUE;
}
static gboolean
curves_write_to_file (GimpCurvesTool *tool,
FILE *file)
{
gint i, j;
gint32 index;
for (i = 0; i < 5; i++)
if (tool->curves->curve_type[i] == GIMP_CURVE_FREE)
{
/* pick representative points from the curve
and make them control points */
for (j = 0; j <= 8; j++)
{
index = CLAMP0255 (j * 32);
tool->curves->points[i][j * 2][0] = index;
tool->curves->points[i][j * 2][1] = tool->curves->curve[i][index];
}
}
fprintf (file, "# GIMP Curves File\n");
for (i = 0; i < 5; i++)
{
for (j = 0; j < 17; j++)
fprintf (file, "%d %d ",
tool->curves->points[i][j][0],
tool->curves->points[i][j][1]);
fprintf (file, "\n");
}
return TRUE;
}
......@@ -163,6 +163,8 @@ gimp_hue_saturation_tool_class_init (GimpHueSaturationToolClass *klass)
tool_class->initialize = gimp_hue_saturation_tool_initialize;
image_map_tool_class->shell_desc = _("Adjust Hue / Lightness / Saturation");
image_map_tool_class->map = gimp_hue_saturation_tool_map;
image_map_tool_class->dialog = gimp_hue_saturation_tool_dialog;
image_map_tool_class->reset = gimp_hue_saturation_tool_reset;
......@@ -171,10 +173,6 @@ gimp_hue_saturation_tool_class_init (GimpHueSaturationToolClass *klass)
static void
gimp_hue_saturation_tool_init (GimpHueSaturationTool *hs_tool)
{
GimpImageMapTool *image_map_tool = GIMP_IMAGE_MAP_TOOL (hs_tool);
image_map_tool->shell_desc = _("Adjust Hue / Lightness / Saturation");
hs_tool->hue_saturation = g_new0 (HueSaturation, 1);
hs_tool->hue_partition = GIMP_ALL_HUES;
......
......@@ -81,6 +81,14 @@ static void gimp_image_map_tool_response (GtkWidget *widget,
gint response_id,
GimpImageMapTool *image_map_tool);
static void gimp_image_map_tool_load_clicked (GtkWidget *widget,
GimpImageMapTool *image_map_tool);
static void gimp_image_map_tool_save_clicked (GtkWidget *widget,
GimpImageMapTool *image_map_tool);
static void gimp_image_map_tool_settings_dialog (GimpImageMapTool *image_map_tool,
const gchar *title,
gboolean save);
static void gimp_image_map_tool_notify_preview (GObject *config,
GParamSpec *pspec,
GimpImageMapTool *image_map_tool);
......@@ -137,7 +145,10 @@ gimp_image_map_tool_class_init (GimpImageMapToolClass *klass)
color_tool_class->pick = gimp_image_map_tool_pick_color;
klass->settings_name = NULL;
klass->shell_desc = NULL;
klass->settings_name = NULL;
klass->load_dialog_title = NULL;
klass->save_dialog_title = NULL;
klass->map = NULL;
klass->dialog = NULL;
......@@ -154,12 +165,13 @@ gimp_image_map_tool_init (GimpImageMapTool *image_map_tool)
gimp_tool_control_set_scroll_lock (tool->control, TRUE);
gimp_tool_control_set_preserve (tool->control, FALSE);
image_map_tool->drawable = NULL;
image_map_tool->image_map = NULL;
image_map_tool->drawable = NULL;
image_map_tool->image_map = NULL;
image_map_tool->shell_desc = NULL;
image_map_tool->shell = NULL;
image_map_tool->main_vbox = NULL;
image_map_tool->shell = NULL;
image_map_tool->main_vbox = NULL;
image_map_tool->load_button = NULL;
image_map_tool->save_button = NULL;
}
static void
......@@ -170,8 +182,10 @@ gimp_image_map_tool_finalize (GObject *object)
if (image_map_tool->shell)
{
gtk_widget_destroy (image_map_tool->shell);
image_map_tool->shell = NULL;
image_map_tool->main_vbox = NULL;
image_map_tool->shell = NULL;
image_map_tool->main_vbox = NULL;
image_map_tool->load_button = NULL;
image_map_tool->save_button = NULL;
}
G_OBJECT_CLASS (parent_class)->finalize (object);
......@@ -194,17 +208,19 @@ gimp_image_map_tool_initialize (GimpTool *tool,
if (! image_map_tool->shell)
{
GtkWidget *shell;
GtkWidget *vbox;
GtkWidget *toggle;
const gchar *stock_id;
GimpImageMapToolClass *klass;
GtkWidget *shell;
GtkWidget *vbox;
GtkWidget *toggle;
const gchar *stock_id;
klass = GIMP_IMAGE_MAP_TOOL_GET_CLASS (image_map_tool);
stock_id = gimp_viewable_get_stock_id (GIMP_VIEWABLE (tool_info));
image_map_tool->shell = shell =
gimp_tool_dialog_new (tool_info,
gdisp->shell,
image_map_tool->shell_desc,
gimp_tool_dialog_new (tool_info, gdisp->shell,
klass->shell_desc,
GIMP_STOCK_RESET, RESPONSE_RESET,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
......@@ -233,6 +249,26 @@ gimp_image_map_tool_initialize (GimpTool *tool,
G_CALLBACK (gimp_image_map_tool_notify_preview),
image_map_tool);
if (klass->load_dialog_title)
{
image_map_tool->load_button =
gtk_button_new_from_stock (GTK_STOCK_OPEN);
g_signal_connect (image_map_tool->load_button, "clicked",
G_CALLBACK (gimp_image_map_tool_load_clicked),
image_map_tool);
}
if (klass->save_dialog_title)
{
image_map_tool->save_button =
gtk_button_new_from_stock (GTK_STOCK_SAVE);
g_signal_connect (image_map_tool->save_button, "clicked",
G_CALLBACK (gimp_image_map_tool_save_clicked),
image_map_tool);
}
/* Fill in subclass widgets */
gimp_image_map_tool_dialog (image_map_tool);
......@@ -333,7 +369,13 @@ gimp_image_tool_settings_load (GimpImageMapTool *tool,
g_return_val_if_fail (tool_class->settings_load != NULL, FALSE);
return tool_class->settings_load (tool, file);
if (tool_class->settings_load (tool, file))
{
gimp_image_map_tool_preview (tool);
return TRUE;
}
return FALSE;
}
static gboolean
......@@ -530,10 +572,35 @@ settings_dialog_response (GtkWidget *dialog,
fclose (file);
}
if (save)
gtk_widget_set_sensitive (tool->load_button, TRUE);
else
gtk_widget_set_sensitive (tool->save_button, TRUE);
gtk_widget_destroy (dialog);
}
void
static void
gimp_image_map_tool_load_clicked (GtkWidget *widget,
GimpImageMapTool *image_map_tool)
{
GimpImageMapToolClass *klass = GIMP_IMAGE_MAP_TOOL_GET_CLASS (image_map_tool);
gimp_image_map_tool_settings_dialog (image_map_tool,
klass->load_dialog_title, FALSE);
}
static void
gimp_image_map_tool_save_clicked (GtkWidget *widget,
GimpImageMapTool *image_map_tool)
{
GimpImageMapToolClass *klass = GIMP_IMAGE_MAP_TOOL_GET_CLASS (image_map_tool);
gimp_image_map_tool_settings_dialog (image_map_tool,
klass->save_dialog_title, TRUE);
}
static void
gimp_image_map_tool_settings_dialog (GimpImageMapTool *tool,
const gchar *title,
gboolean save)
......@@ -549,6 +616,11 @@ gimp_image_map_tool_settings_dialog (GimpImageMapTool *tool,
return;
}
if (save)
gtk_widget_set_sensitive (tool->load_button, FALSE);
else
gtk_widget_set_sensitive (tool->save_button, FALSE);
tool->settings_dialog = gtk_file_selection_new (title);
dialog = GTK_FILE_SELECTION (tool->settings_dialog);
......
......@@ -41,9 +41,10 @@ struct _GimpImageMapTool
GimpImageMap *image_map;
/* dialog */
const gchar *shell_desc;
GtkWidget *shell;
GtkWidget *main_vbox;
GtkWidget *load_button;
GtkWidget *save_button;
/* settings file dialog */
GtkWidget *settings_dialog;
......@@ -53,7 +54,10 @@ struct _GimpImageMapToolClass
{
GimpColorToolClass parent_class;
const gchar *shell_desc;
const gchar *settings_name;
const gchar *load_dialog_title;
const gchar *save_dialog_title;
/* virtual functions */
void (* map) (GimpImageMapTool *image_map_tool);
......@@ -67,13 +71,9 @@ 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_settings_dialog (GimpImageMapTool *image_map_tool,
const gchar *title,
gboolean save);
void gimp_image_map_tool_preview (GimpImageMapTool *image_map_tool);
#endif /* __GIMP_IMAGE_MAP_TOOL_H__ */
......@@ -95,10 +95,10 @@ static void gimp_levels_tool_color_picked (GimpColorTool *color_tool,
static void gimp_levels_tool_map (GimpImageMapTool *image_map_tool);
static void gimp_levels_tool_dialog (GimpImageMapTool *image_map_tool);
static void gimp_levels_tool_reset (GimpImageMapTool *image_map_tool);
static gboolean gimp_levels_tool_settings_load (GimpImageMapTool *tool,
gpointer file);
static gboolean gimp_levels_tool_settings_save (GimpImageMapTool *tool,
gpointer file);
static gboolean gimp_levels_tool_settings_load (GimpImageMapTool *image_mao_tool,