app/tools/gimpcurvestool.[ch] app/tools/gimpimagemapoptions.[ch]
2004-02-25 Sven Neumann <sven@gimp.org> * app/tools/gimpcurvestool.[ch] * app/tools/gimpimagemapoptions.[ch] * app/tools/gimpimagemaptool.[ch] * app/tools/gimplevelstool.[ch]: moved the settings file dialog that was duplicated in the curves and levels tools to the GimpImageMapTool class. Store the last used filename in the GimpImageMapOptions (proper fix for bug #135059).
This commit is contained in:

committed by
Sven Neumann

parent
c9ee3dc2a6
commit
c1de6345a7
10
ChangeLog
10
ChangeLog
@ -1,3 +1,13 @@
|
||||
2004-02-25 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* app/tools/gimpcurvestool.[ch]
|
||||
* app/tools/gimpimagemapoptions.[ch]
|
||||
* app/tools/gimpimagemaptool.[ch]
|
||||
* app/tools/gimplevelstool.[ch]: moved the settings file dialog
|
||||
that was duplicated in the curves and levels tools to the
|
||||
GimpImageMapTool class. Store the last used filename in the
|
||||
GimpImageMapOptions (proper fix for bug #135059).
|
||||
|
||||
2004-02-24 Dave Neary <bolsh@gimp.org>
|
||||
|
||||
* app/tools/gimpcurvestool.c: Revert to 1.2 behaviour of hiding
|
||||
|
@ -21,7 +21,6 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
@ -92,6 +91,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 void curves_add_point (GimpCurvesTool *tool,
|
||||
gint x,
|
||||
@ -121,14 +124,9 @@ static gboolean curves_graph_expose (GtkWidget *widget,
|
||||
GdkEventExpose *eevent,
|
||||
GimpCurvesTool *tool);
|
||||
|
||||
static void file_dialog_create (GimpCurvesTool *tool);
|
||||
static void file_dialog_response (GtkWidget *dialog,
|
||||
gint response_id,
|
||||
GimpCurvesTool *tool);
|
||||
|
||||
static gboolean curves_read_from_file (GimpCurvesTool *tool,
|
||||
FILE *file);
|
||||
static void curves_write_to_file (GimpCurvesTool *tool,
|
||||
static gboolean curves_write_to_file (GimpCurvesTool *tool,
|
||||
FILE *file);
|
||||
|
||||
|
||||
@ -200,16 +198,21 @@ gimp_curves_tool_class_init (GimpCurvesToolClass *klass)
|
||||
|
||||
parent_class = g_type_class_peek_parent (klass);
|
||||
|
||||
object_class->finalize = gimp_curves_tool_finalize;
|
||||
object_class->finalize = gimp_curves_tool_finalize;
|
||||
|
||||
tool_class->initialize = gimp_curves_tool_initialize;
|
||||
tool_class->button_release = gimp_curves_tool_button_release;
|
||||
tool_class->initialize = gimp_curves_tool_initialize;
|
||||
tool_class->button_release = gimp_curves_tool_button_release;
|
||||
|
||||
color_tool_class->picked = gimp_curves_tool_color_picked;
|
||||
color_tool_class->picked = gimp_curves_tool_color_picked;
|
||||
|
||||
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_name = "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->settings_load = gimp_curves_tool_settings_load;
|
||||
image_map_tool_class->settings_save = gimp_curves_tool_settings_save;
|
||||
}
|
||||
|
||||
static void
|
||||
@ -231,6 +234,8 @@ gimp_curves_tool_init (GimpCurvesTool *tool)
|
||||
|
||||
tool->cursor_x = -1;
|
||||
tool->cursor_y = -1;
|
||||
|
||||
tool->filename = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
@ -263,6 +268,11 @@ gimp_curves_tool_finalize (GObject *object)
|
||||
g_object_unref (tool->xpos_layout);
|
||||
tool->xpos_layout = NULL;
|
||||
}
|
||||
if (tool->filename)
|
||||
{
|
||||
g_free (tool->filename);
|
||||
tool->filename = NULL;
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
||||
}
|
||||
@ -658,6 +668,19 @@ gimp_curves_tool_reset (GimpImageMapTool *image_map_tool)
|
||||
curves_update (tool, XRANGE | GRAPH);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gimp_curves_tool_settings_load (GimpImageMapTool *tool,
|
||||
gpointer file)
|
||||
{
|
||||
return curves_read_from_file (GIMP_CURVES_TOOL (tool), (FILE *) file);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gimp_curves_tool_settings_save (GimpImageMapTool *tool,
|
||||
gpointer file)
|
||||
{
|
||||
return curves_write_to_file (GIMP_CURVES_TOOL (tool), (FILE *) file);
|
||||
}
|
||||
|
||||
/* TODO: preview alpha channel stuff correctly. -- austin, 20/May/99 */
|
||||
static void
|
||||
@ -1171,114 +1194,16 @@ static void
|
||||
curves_load_callback (GtkWidget *widget,
|
||||
GimpCurvesTool *tool)
|
||||
{
|
||||
if (! tool->file_dialog)
|
||||
file_dialog_create (tool);
|
||||
|
||||
if (GTK_WIDGET_VISIBLE (tool->file_dialog))
|
||||
{
|
||||
gtk_window_present (GTK_WINDOW (tool->file_dialog));
|
||||
return;
|
||||
}
|
||||
|
||||
tool->is_save = FALSE;
|
||||
|
||||
gtk_window_set_title (GTK_WINDOW (tool->file_dialog), _("Load Curves"));
|
||||
gtk_widget_show (tool->file_dialog);
|
||||
gimp_image_map_tool_settings_dialog (GIMP_IMAGE_MAP_TOOL (tool),
|
||||
_("Load Curves"), FALSE);
|
||||
}
|
||||
|
||||
static void
|
||||
curves_save_callback (GtkWidget *widget,
|
||||
GimpCurvesTool *tool)
|
||||
{
|
||||
if (! tool->file_dialog)
|
||||
file_dialog_create (tool);
|
||||
|
||||
if (GTK_WIDGET_VISIBLE (tool->file_dialog))
|
||||
{
|
||||
gtk_window_present (GTK_WINDOW (tool->file_dialog));
|
||||
return;
|
||||
}
|
||||
|
||||
tool->is_save = TRUE;
|
||||
|
||||
gtk_window_set_title (GTK_WINDOW (tool->file_dialog), _("Save Curves"));
|
||||
gtk_widget_show (tool->file_dialog);
|
||||
}
|
||||
|
||||
static void
|
||||
file_dialog_create (GimpCurvesTool *tool)
|
||||
{
|
||||
GtkFileSelection *file_dlg;
|
||||
gchar *temp;
|
||||
|
||||
tool->file_dialog = gtk_file_selection_new ("");
|
||||
|
||||
file_dlg = GTK_FILE_SELECTION (tool->file_dialog);
|
||||
|
||||
gtk_window_set_role (GTK_WINDOW (file_dlg), "gimp-load-save-curves");
|
||||
gtk_window_set_position (GTK_WINDOW (file_dlg), GTK_WIN_POS_MOUSE);
|
||||
|
||||
gtk_container_set_border_width (GTK_CONTAINER (file_dlg), 6);
|
||||
gtk_container_set_border_width (GTK_CONTAINER (file_dlg->button_area), 4);
|
||||
|
||||
g_object_add_weak_pointer (G_OBJECT (file_dlg),
|
||||
(gpointer) &tool->file_dialog);
|
||||
|
||||
gtk_window_set_transient_for (GTK_WINDOW (file_dlg),
|
||||
GTK_WINDOW (GIMP_IMAGE_MAP_TOOL (tool)->shell));
|
||||
gtk_window_set_destroy_with_parent (GTK_WINDOW (file_dlg), TRUE);
|
||||
|
||||
g_signal_connect (file_dlg, "response",
|
||||
G_CALLBACK (file_dialog_response),
|
||||
tool);
|
||||
|
||||
temp = g_build_filename (gimp_directory (), "curves",
|
||||
G_DIR_SEPARATOR_S, NULL);
|
||||
gtk_file_selection_set_filename (file_dlg, temp);
|
||||
g_free (temp);
|
||||
|
||||
gimp_help_connect (tool->file_dialog, gimp_standard_help_func,
|
||||
GIMP_TOOL (tool)->tool_info->help_id, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
file_dialog_response (GtkWidget *dialog,
|
||||
gint response_id,
|
||||
GimpCurvesTool *tool)
|
||||
{
|
||||
if (response_id == GTK_RESPONSE_OK)
|
||||
{
|
||||
const gchar *filename;
|
||||
FILE *file;
|
||||
|
||||
filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (dialog));
|
||||
|
||||
file = fopen (filename, tool->is_save ? "wt" : "rt");
|
||||
|
||||
if (! file)
|
||||
{
|
||||
g_message (tool->is_save ?
|
||||
_("Could not open '%s' for writing: %s") :
|
||||
_("Could not open '%s' for reading: %s"),
|
||||
gimp_filename_to_utf8 (filename),
|
||||
g_strerror (errno));
|
||||
return;
|
||||
}
|
||||
|
||||
if (tool->is_save)
|
||||
{
|
||||
curves_write_to_file (tool, file);
|
||||
}
|
||||
else if (! curves_read_from_file (tool, file))
|
||||
{
|
||||
g_message ("Error in reading file '%s'.",
|
||||
gimp_filename_to_utf8 (filename));
|
||||
}
|
||||
|
||||
fclose (file);
|
||||
}
|
||||
|
||||
gtk_widget_hide (dialog);
|
||||
gimp_image_map_tool_settings_dialog (GIMP_IMAGE_MAP_TOOL (tool),
|
||||
_("Save Curves"), TRUE);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
@ -1291,7 +1216,7 @@ curves_read_from_file (GimpCurvesTool *tool,
|
||||
gint index[5][17];
|
||||
gint value[5][17];
|
||||
|
||||
if (! fgets (buf, 50, file))
|
||||
if (! fgets (buf, sizeof (buf), file))
|
||||
return FALSE;
|
||||
|
||||
if (strcmp (buf, "# GIMP Curves File\n") != 0)
|
||||
@ -1334,7 +1259,7 @@ curves_read_from_file (GimpCurvesTool *tool,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
static gboolean
|
||||
curves_write_to_file (GimpCurvesTool *tool,
|
||||
FILE *file)
|
||||
{
|
||||
@ -1365,4 +1290,6 @@ curves_write_to_file (GimpCurvesTool *tool,
|
||||
|
||||
fprintf (file, "\n");
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -66,6 +66,7 @@ struct _GimpCurvesTool
|
||||
PangoRectangle cursor_rect;
|
||||
|
||||
GtkWidget *file_dialog;
|
||||
gchar *filename;
|
||||
gboolean is_save;
|
||||
};
|
||||
|
||||
|
@ -30,11 +30,13 @@
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_PREVIEW
|
||||
PROP_PREVIEW,
|
||||
PROP_SETTINGS
|
||||
};
|
||||
|
||||
|
||||
static void gimp_image_map_options_class_init (GimpImageMapOptionsClass *klass);
|
||||
static void gimp_image_map_options_finalize (GObject *object);
|
||||
|
||||
static void gimp_image_map_options_set_property (GObject *object,
|
||||
guint property_id,
|
||||
@ -46,6 +48,9 @@ static void gimp_image_map_options_get_property (GObject *object,
|
||||
GParamSpec *pspec);
|
||||
|
||||
|
||||
static GimpToolOptionsClass *parent_class = NULL;
|
||||
|
||||
|
||||
GType
|
||||
gimp_image_map_options_get_type (void)
|
||||
{
|
||||
@ -79,6 +84,9 @@ gimp_image_map_options_class_init (GimpImageMapOptionsClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
parent_class = g_type_class_peek_parent (klass);
|
||||
|
||||
object_class->finalize = gimp_image_map_options_finalize;
|
||||
object_class->set_property = gimp_image_map_options_set_property;
|
||||
object_class->get_property = gimp_image_map_options_get_property;
|
||||
|
||||
@ -86,8 +94,28 @@ gimp_image_map_options_class_init (GimpImageMapOptionsClass *klass)
|
||||
"preview", NULL,
|
||||
TRUE,
|
||||
0);
|
||||
g_object_class_install_property (object_class, PROP_SETTINGS,
|
||||
g_param_spec_string ("settings",
|
||||
NULL, NULL,
|
||||
NULL,
|
||||
G_PARAM_READWRITE));
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_image_map_options_finalize (GObject *object)
|
||||
{
|
||||
GimpImageMapOptions *options = GIMP_IMAGE_MAP_OPTIONS (object);
|
||||
|
||||
if (options->settings)
|
||||
{
|
||||
g_free (options->settings);
|
||||
options->settings = NULL;
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
gimp_image_map_options_set_property (GObject *object,
|
||||
guint property_id,
|
||||
@ -101,6 +129,10 @@ gimp_image_map_options_set_property (GObject *object,
|
||||
case PROP_PREVIEW:
|
||||
options->preview = g_value_get_boolean (value);
|
||||
break;
|
||||
case PROP_SETTINGS:
|
||||
g_free (options->settings);
|
||||
options->settings = g_value_dup_string (value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
@ -120,6 +152,9 @@ gimp_image_map_options_get_property (GObject *object,
|
||||
case PROP_PREVIEW:
|
||||
g_value_set_boolean (value, options->preview);
|
||||
break;
|
||||
case PROP_SETTINGS:
|
||||
g_value_set_string (value, options->settings);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
|
@ -38,6 +38,7 @@ struct _GimpImageMapOptions
|
||||
GimpToolOptions parent_instance;
|
||||
|
||||
gboolean preview;
|
||||
gchar *settings;
|
||||
};
|
||||
|
||||
|
||||
|
@ -18,8 +18,12 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "libgimpbase/gimpbase.h"
|
||||
#include "libgimpwidgets/gimpwidgets.h"
|
||||
|
||||
#include "tools-types.h"
|
||||
@ -133,9 +137,13 @@ gimp_image_map_tool_class_init (GimpImageMapToolClass *klass)
|
||||
|
||||
color_tool_class->pick = gimp_image_map_tool_pick_color;
|
||||
|
||||
klass->map = NULL;
|
||||
klass->dialog = NULL;
|
||||
klass->reset = NULL;
|
||||
klass->settings_name = NULL;
|
||||
|
||||
klass->map = NULL;
|
||||
klass->dialog = NULL;
|
||||
klass->reset = NULL;
|
||||
klass->settings_load = NULL;
|
||||
klass->settings_save = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
@ -154,28 +162,6 @@ gimp_image_map_tool_init (GimpImageMapTool *image_map_tool)
|
||||
image_map_tool->main_vbox = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
gimp_image_map_tool_preview (GimpImageMapTool *image_map_tool)
|
||||
{
|
||||
GimpTool *tool;
|
||||
GimpImageMapOptions *options;
|
||||
|
||||
g_return_if_fail (GIMP_IS_IMAGE_MAP_TOOL (image_map_tool));
|
||||
|
||||
tool = GIMP_TOOL (image_map_tool);
|
||||
|
||||
options = GIMP_IMAGE_MAP_OPTIONS (tool->tool_info->tool_options);
|
||||
|
||||
if (options->preview)
|
||||
{
|
||||
gimp_tool_control_set_preserve (tool->control, TRUE);
|
||||
|
||||
gimp_image_map_tool_map (image_map_tool);
|
||||
|
||||
gimp_tool_control_set_preserve (tool->control, FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_image_map_tool_finalize (GObject *object)
|
||||
{
|
||||
@ -320,21 +306,47 @@ gimp_image_map_tool_pick_color (GimpColorTool *color_tool,
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_image_map_tool_map (GimpImageMapTool *image_map_tool)
|
||||
gimp_image_map_tool_map (GimpImageMapTool *tool)
|
||||
{
|
||||
GIMP_IMAGE_MAP_TOOL_GET_CLASS (image_map_tool)->map (image_map_tool);
|
||||
GIMP_IMAGE_MAP_TOOL_GET_CLASS (tool)->map (tool);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_image_map_tool_dialog (GimpImageMapTool *image_map_tool)
|
||||
gimp_image_map_tool_dialog (GimpImageMapTool *tool)
|
||||
{
|
||||
GIMP_IMAGE_MAP_TOOL_GET_CLASS (image_map_tool)->dialog (image_map_tool);
|
||||
GIMP_IMAGE_MAP_TOOL_GET_CLASS (tool)->dialog (tool);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_image_map_tool_reset (GimpImageMapTool *image_map_tool)
|
||||
gimp_image_map_tool_reset (GimpImageMapTool *tool)
|
||||
{
|
||||
GIMP_IMAGE_MAP_TOOL_GET_CLASS (image_map_tool)->reset (image_map_tool);
|
||||
GIMP_IMAGE_MAP_TOOL_GET_CLASS (tool)->reset (tool);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gimp_image_tool_settings_load (GimpImageMapTool *tool,
|
||||
gpointer file)
|
||||
{
|
||||
GimpImageMapToolClass *tool_class;
|
||||
|
||||
tool_class = GIMP_IMAGE_MAP_TOOL_GET_CLASS (tool);
|
||||
|
||||
g_return_val_if_fail (tool_class->settings_load != NULL, FALSE);
|
||||
|
||||
return tool_class->settings_load (tool, file);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gimp_image_tool_settings_save (GimpImageMapTool *tool,
|
||||
gpointer file)
|
||||
{
|
||||
GimpImageMapToolClass *tool_class;
|
||||
|
||||
tool_class = GIMP_IMAGE_MAP_TOOL_GET_CLASS (tool);
|
||||
|
||||
g_return_val_if_fail (tool_class->settings_save != NULL, FALSE);
|
||||
|
||||
return tool_class->settings_save (tool, file);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -448,3 +460,139 @@ gimp_image_map_tool_notify_preview (GObject *config,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gimp_image_map_tool_preview (GimpImageMapTool *image_map_tool)
|
||||
{
|
||||
GimpTool *tool;
|
||||
GimpImageMapOptions *options;
|
||||
|
||||
g_return_if_fail (GIMP_IS_IMAGE_MAP_TOOL (image_map_tool));
|
||||
|
||||
tool = GIMP_TOOL (image_map_tool);
|
||||
|
||||
options = GIMP_IMAGE_MAP_OPTIONS (tool->tool_info->tool_options);
|
||||
|
||||
if (options->preview)
|
||||
{
|
||||
gimp_tool_control_set_preserve (tool->control, TRUE);
|
||||
|
||||
gimp_image_map_tool_map (image_map_tool);
|
||||
|
||||
gimp_tool_control_set_preserve (tool->control, FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
settings_dialog_response (GtkWidget *dialog,
|
||||
gint response_id,
|
||||
GimpImageMapTool *tool)
|
||||
{
|
||||
GimpImageMapOptions *options;
|
||||
gboolean save;
|
||||
|
||||
save = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (dialog), "save"));
|
||||
|
||||
if (response_id == GTK_RESPONSE_OK)
|
||||
{
|
||||
const gchar *filename;
|
||||
FILE *file;
|
||||
|
||||
filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (dialog));
|
||||
|
||||
file = fopen (filename, save ? "wt" : "rt");
|
||||
|
||||
if (! file)
|
||||
{
|
||||
g_message (save ?
|
||||
_("Could not open '%s' for writing: %s") :
|
||||
_("Could not open '%s' for reading: %s"),
|
||||
gimp_filename_to_utf8 (filename),
|
||||
g_strerror (errno));
|
||||
return;
|
||||
}
|
||||
|
||||
options = GIMP_IMAGE_MAP_OPTIONS (GIMP_TOOL (tool)->tool_info->tool_options);
|
||||
|
||||
g_free (options->settings);
|
||||
options->settings = g_strdup (filename);
|
||||
|
||||
if (save)
|
||||
{
|
||||
gimp_image_tool_settings_save (tool, file);
|
||||
}
|
||||
else if (! gimp_image_tool_settings_load (tool, file))
|
||||
{
|
||||
g_message ("Error in reading file '%s'.",
|
||||
gimp_filename_to_utf8 (filename));
|
||||
}
|
||||
|
||||
fclose (file);
|
||||
}
|
||||
|
||||
gtk_widget_destroy (dialog);
|
||||
}
|
||||
|
||||
void
|
||||
gimp_image_map_tool_settings_dialog (GimpImageMapTool *tool,
|
||||
const gchar *title,
|
||||
gboolean save)
|
||||
{
|
||||
GimpImageMapOptions *options;
|
||||
GtkFileSelection *dialog;
|
||||
|
||||
g_return_if_fail (GIMP_IS_IMAGE_MAP_TOOL (tool));
|
||||
|
||||
if (tool->settings_dialog)
|
||||
{
|
||||
gtk_window_present (GTK_WINDOW (tool->settings_dialog));
|
||||
return;
|
||||
}
|
||||
|
||||
tool->settings_dialog = gtk_file_selection_new (title);
|
||||
|
||||
dialog = GTK_FILE_SELECTION (tool->settings_dialog);
|
||||
|
||||
g_object_set_data (G_OBJECT (dialog), "save", GINT_TO_POINTER (save));
|
||||
|
||||
gtk_window_set_role (GTK_WINDOW (dialog), "gimp-load-save-settings");
|
||||
gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE);
|
||||
|
||||
gtk_container_set_border_width (GTK_CONTAINER (dialog), 6);
|
||||
gtk_container_set_border_width (GTK_CONTAINER (dialog->button_area), 4);
|
||||
|
||||
g_object_add_weak_pointer (G_OBJECT (dialog),
|
||||
(gpointer) &tool->settings_dialog);
|
||||
|
||||
gtk_window_set_transient_for (GTK_WINDOW (dialog),
|
||||
GTK_WINDOW (tool->shell));
|
||||
gtk_window_set_destroy_with_parent (GTK_WINDOW (dialog), TRUE);
|
||||
|
||||
g_signal_connect (dialog, "response",
|
||||
G_CALLBACK (settings_dialog_response),
|
||||
tool);
|
||||
|
||||
options = GIMP_IMAGE_MAP_OPTIONS (GIMP_TOOL (tool)->tool_info->tool_options);
|
||||
|
||||
if (options->settings)
|
||||
{
|
||||
gtk_file_selection_set_filename (dialog, options->settings);
|
||||
}
|
||||
else if (GIMP_IMAGE_MAP_TOOL_GET_CLASS (tool)->settings_name)
|
||||
{
|
||||
gchar *tmp;
|
||||
|
||||
tmp = g_build_filename (gimp_directory (),
|
||||
GIMP_IMAGE_MAP_TOOL_GET_CLASS (tool)->settings_name,
|
||||
G_DIR_SEPARATOR_S,
|
||||
NULL);
|
||||
|
||||
gtk_file_selection_set_filename (dialog, tmp);
|
||||
g_free (tmp);
|
||||
}
|
||||
|
||||
gimp_help_connect (tool->settings_dialog, gimp_standard_help_func,
|
||||
GIMP_TOOL (tool)->tool_info->help_id, NULL);
|
||||
|
||||
gtk_widget_show (tool->settings_dialog);
|
||||
}
|
||||
|
@ -40,27 +40,40 @@ struct _GimpImageMapTool
|
||||
GimpDrawable *drawable;
|
||||
GimpImageMap *image_map;
|
||||
|
||||
/* the dialog */
|
||||
/* dialog */
|
||||
const gchar *shell_desc;
|
||||
|
||||
GtkWidget *shell;
|
||||
GtkWidget *main_vbox;
|
||||
|
||||
/* settings file dialog */
|
||||
GtkWidget *settings_dialog;
|
||||
};
|
||||
|
||||
struct _GimpImageMapToolClass
|
||||
{
|
||||
GimpColorToolClass parent_class;
|
||||
|
||||
const gchar *settings_name;
|
||||
|
||||
/* virtual functions */
|
||||
void (* map) (GimpImageMapTool *image_map_tool);
|
||||
void (* dialog) (GimpImageMapTool *image_map_tool);
|
||||
void (* reset) (GimpImageMapTool *image_map_tool);
|
||||
void (* map) (GimpImageMapTool *image_map_tool);
|
||||
void (* dialog) (GimpImageMapTool *image_map_tool);
|
||||
void (* reset) (GimpImageMapTool *image_map_tool);
|
||||
|
||||
gboolean (* settings_load) (GimpImageMapTool *image_map_tool,
|
||||
gpointer file);
|
||||
gboolean (* settings_save) (GimpImageMapTool *image_map_tool,
|
||||
gpointer file);
|
||||
};
|
||||
|
||||
|
||||
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);
|
||||
|
||||
void gimp_image_map_tool_settings_dialog (GimpImageMapTool *image_map_tool,
|
||||
const gchar *title,
|
||||
gboolean save);
|
||||
|
||||
|
||||
#endif /* __GIMP_IMAGE_MAP_TOOL_H__ */
|
||||
|
@ -88,13 +88,18 @@ static void gimp_levels_tool_finalize (GObject *object);
|
||||
static gboolean gimp_levels_tool_initialize (GimpTool *tool,
|
||||
GimpDisplay *gdisp);
|
||||
|
||||
static void gimp_levels_tool_color_picked (GimpColorTool *color_tool,
|
||||
GimpImageType sample_type,
|
||||
GimpRGB *color,
|
||||
gint color_index);
|
||||
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 void gimp_levels_tool_color_picked (GimpColorTool *color_tool,
|
||||
GimpImageType sample_type,
|
||||
GimpRGB *color,
|
||||
gint color_index);
|
||||
|
||||
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 void levels_update (GimpLevelsTool *tool,
|
||||
guint update);
|
||||
@ -137,14 +142,9 @@ static gboolean levels_output_area_expose (GtkWidget *widget,
|
||||
GdkEventExpose *event,
|
||||
GimpLevelsTool *tool);
|
||||
|
||||
static void file_dialog_create (GimpLevelsTool *tool);
|
||||
static void file_dialog_response (GtkWidget *dialog,
|
||||
gint response_id,
|
||||
GimpLevelsTool *tool);
|
||||
|
||||
static gboolean levels_read_from_file (GimpLevelsTool *tool,
|
||||
FILE *f);
|
||||
static void levels_write_to_file (GimpLevelsTool *tool,
|
||||
static gboolean levels_write_to_file (GimpLevelsTool *tool,
|
||||
FILE *f);
|
||||
|
||||
|
||||
@ -216,15 +216,20 @@ gimp_levels_tool_class_init (GimpLevelsToolClass *klass)
|
||||
|
||||
parent_class = g_type_class_peek_parent (klass);
|
||||
|
||||
object_class->finalize = gimp_levels_tool_finalize;
|
||||
object_class->finalize = gimp_levels_tool_finalize;
|
||||
|
||||
tool_class->initialize = gimp_levels_tool_initialize;
|
||||
tool_class->initialize = gimp_levels_tool_initialize;
|
||||
|
||||
color_tool_class->picked = gimp_levels_tool_color_picked;
|
||||
color_tool_class->picked = gimp_levels_tool_color_picked;
|
||||
|
||||
image_map_tool_class->map = gimp_levels_tool_map;
|
||||
image_map_tool_class->dialog = gimp_levels_tool_dialog;
|
||||
image_map_tool_class->reset = gimp_levels_tool_reset;
|
||||
image_map_tool_class->settings_name = "levels";
|
||||
|
||||
image_map_tool_class->map = gimp_levels_tool_map;
|
||||
image_map_tool_class->dialog = gimp_levels_tool_dialog;
|
||||
image_map_tool_class->reset = gimp_levels_tool_reset;
|
||||
|
||||
image_map_tool_class->settings_load = gimp_levels_tool_settings_load;
|
||||
image_map_tool_class->settings_save = gimp_levels_tool_settings_save;
|
||||
}
|
||||
|
||||
static void
|
||||
@ -253,13 +258,11 @@ gimp_levels_tool_finalize (GObject *object)
|
||||
gimp_lut_free (tool->lut);
|
||||
tool->lut = NULL;
|
||||
}
|
||||
|
||||
if (tool->levels)
|
||||
{
|
||||
g_free (tool->levels);
|
||||
tool->levels = NULL;
|
||||
}
|
||||
|
||||
if (tool->hist)
|
||||
{
|
||||
gimp_histogram_free (tool->hist);
|
||||
@ -710,6 +713,20 @@ gimp_levels_tool_reset (GimpImageMapTool *image_map_tool)
|
||||
levels_update (tool, ALL);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gimp_levels_tool_settings_load (GimpImageMapTool *tool,
|
||||
gpointer file)
|
||||
{
|
||||
return levels_read_from_file (GIMP_LEVELS_TOOL (tool), (FILE *) file);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gimp_levels_tool_settings_save (GimpImageMapTool *tool,
|
||||
gpointer file)
|
||||
{
|
||||
return levels_write_to_file (GIMP_LEVELS_TOOL (tool), (FILE *) file);
|
||||
}
|
||||
|
||||
static void
|
||||
levels_draw_slider (GtkWidget *widget,
|
||||
GdkGC *border_gc,
|
||||
@ -1359,128 +1376,32 @@ static void
|
||||
levels_load_callback (GtkWidget *widget,
|
||||
GimpLevelsTool *tool)
|
||||
{
|
||||
if (! tool->file_dialog)
|
||||
file_dialog_create (tool);
|
||||
|
||||
if (GTK_WIDGET_VISIBLE (tool->file_dialog))
|
||||
{
|
||||
gtk_window_present (GTK_WINDOW (tool->file_dialog));
|
||||
return;
|
||||
}
|
||||
|
||||
tool->is_save = FALSE;
|
||||
|
||||
gtk_window_set_title (GTK_WINDOW (tool->file_dialog), _("Load Levels"));
|
||||
gtk_widget_show (tool->file_dialog);
|
||||
gimp_image_map_tool_settings_dialog (GIMP_IMAGE_MAP_TOOL (tool),
|
||||
_("Load Levels"), FALSE);
|
||||
}
|
||||
|
||||
static void
|
||||
levels_save_callback (GtkWidget *widget,
|
||||
GimpLevelsTool *tool)
|
||||
{
|
||||
if (! tool->file_dialog)
|
||||
file_dialog_create (tool);
|
||||
|
||||
if (GTK_WIDGET_VISIBLE (tool->file_dialog))
|
||||
{
|
||||
gtk_window_present (GTK_WINDOW (tool->file_dialog));
|
||||
return;
|
||||
}
|
||||
|
||||
tool->is_save = TRUE;
|
||||
|
||||
gtk_window_set_title (GTK_WINDOW (tool->file_dialog), _("Save Levels"));
|
||||
gtk_widget_show (tool->file_dialog);
|
||||
}
|
||||
|
||||
static void
|
||||
file_dialog_create (GimpLevelsTool *tool)
|
||||
{
|
||||
GtkFileSelection *file_dlg;
|
||||
gchar *temp;
|
||||
|
||||
tool->file_dialog = gtk_file_selection_new ("");
|
||||
|
||||
file_dlg = GTK_FILE_SELECTION (tool->file_dialog);
|
||||
|
||||
gtk_window_set_role (GTK_WINDOW (file_dlg), "gimp-load-save-levels");
|
||||
gtk_window_set_position (GTK_WINDOW (file_dlg), GTK_WIN_POS_MOUSE);
|
||||
|
||||
gtk_container_set_border_width (GTK_CONTAINER (file_dlg), 6);
|
||||
gtk_container_set_border_width (GTK_CONTAINER (file_dlg->button_area), 4);
|
||||
|
||||
g_object_add_weak_pointer (G_OBJECT (file_dlg),
|
||||
(gpointer) &tool->file_dialog);
|
||||
|
||||
gtk_window_set_transient_for (GTK_WINDOW (file_dlg),
|
||||
GTK_WINDOW (GIMP_IMAGE_MAP_TOOL (tool)->shell));
|
||||
gtk_window_set_destroy_with_parent (GTK_WINDOW (file_dlg), TRUE);
|
||||
|
||||
g_signal_connect (file_dlg, "response",
|
||||
G_CALLBACK (file_dialog_response),
|
||||
tool);
|
||||
|
||||
temp = g_build_filename (gimp_directory (), "levels", ".", NULL);
|
||||
gtk_file_selection_set_filename (file_dlg, temp);
|
||||
g_free (temp);
|
||||
|
||||
gimp_help_connect (tool->file_dialog, gimp_standard_help_func,
|
||||
GIMP_TOOL (tool)->tool_info->help_id, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
file_dialog_response (GtkWidget *dialog,
|
||||
gint response_id,
|
||||
GimpLevelsTool *tool)
|
||||
{
|
||||
if (response_id == GTK_RESPONSE_OK)
|
||||
{
|
||||
const gchar *filename;
|
||||
FILE *file;
|
||||
|
||||
filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (dialog));
|
||||
|
||||
file = fopen (filename, tool->is_save ? "wt" : "rt");
|
||||
|
||||
if (! file)
|
||||
{
|
||||
g_message (tool->is_save ?
|
||||
_("Could not open '%s' for writing: %s") :
|
||||
_("Could not open '%s' for reading: %s"),
|
||||
gimp_filename_to_utf8 (filename),
|
||||
g_strerror (errno));
|
||||
return;
|
||||
}
|
||||
|
||||
if (tool->is_save)
|
||||
{
|
||||
levels_write_to_file (tool, file);
|
||||
}
|
||||
else if (! levels_read_from_file (tool, file))
|
||||
{
|
||||
g_message (("Error in reading file '%s'."),
|
||||
gimp_filename_to_utf8 (filename));
|
||||
}
|
||||
|
||||
fclose (file);
|
||||
}
|
||||
|
||||
gtk_widget_destroy (dialog);
|
||||
gimp_image_map_tool_settings_dialog (GIMP_IMAGE_MAP_TOOL (tool),
|
||||
_("Save Levels"), TRUE);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
levels_read_from_file (GimpLevelsTool *tool,
|
||||
FILE *file)
|
||||
{
|
||||
gint low_input[5];
|
||||
gint high_input[5];
|
||||
gint low_output[5];
|
||||
gint high_output[5];
|
||||
gdouble gamma[5];
|
||||
gint i, fields;
|
||||
gchar buf[50], *nptr;
|
||||
gint low_input[5];
|
||||
gint high_input[5];
|
||||
gint low_output[5];
|
||||
gint high_output[5];
|
||||
gdouble gamma[5];
|
||||
gint i, fields;
|
||||
gchar buf[50];
|
||||
gchar *nptr;
|
||||
|
||||
if (! fgets (buf, 50, file))
|
||||
if (! fgets (buf, sizeof (buf), file))
|
||||
return FALSE;
|
||||
|
||||
if (strcmp (buf, "# GIMP Levels File\n") != 0)
|
||||
@ -1522,7 +1443,7 @@ levels_read_from_file (GimpLevelsTool *tool,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
static gboolean
|
||||
levels_write_to_file (GimpLevelsTool *tool,
|
||||
FILE *file)
|
||||
{
|
||||
@ -1541,4 +1462,6 @@ levels_write_to_file (GimpLevelsTool *tool,
|
||||
g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%f",
|
||||
tool->levels->gamma[i]));
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -64,6 +64,7 @@ struct _GimpLevelsTool
|
||||
GtkWidget *channel_menu;
|
||||
|
||||
GtkWidget *file_dialog;
|
||||
gchar *filename;
|
||||
gboolean is_save;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user