added Store/Recall buttons for one-click saving and loading of curves.

2004-06-22  Bill Skaggs  <weskaggs@primate.ucdavis.edu>

	* app/tools/gimpcurvestool.c: added Store/Recall buttons for
	one-click saving and loading of curves.  Should create stock
	labels for them.  Hopefully resolves bug #75558.
This commit is contained in:
Bill Skaggs 2004-06-22 17:17:16 +00:00 committed by William Skaggs
parent 9fe8e84963
commit 848307668e
2 changed files with 265 additions and 167 deletions

View File

@ -1,3 +1,9 @@
2004-06-22 Bill Skaggs <weskaggs@primate.ucdavis.edu>
* app/tools/gimpcurvestool.c: added Store/Recall buttons for
one-click saving and loading of curves. Should create stock
labels for them. Hopefully resolves bug #75558.
2004-06-22 Michael Natterer <mitch@gimp.org>
* app/actions/view-actions.c

View File

@ -26,6 +26,7 @@
#include "libgimpcolor/gimpcolor.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "libgimpbase/gimpenv.h"
#include "tools-types.h"
@ -123,7 +124,10 @@ static gboolean curves_graph_events (GtkWidget *widget,
static gboolean curves_graph_expose (GtkWidget *widget,
GdkEventExpose *eevent,
GimpCurvesTool *tool);
static void gimp_curves_tool_store_settings (GtkWidget *widget,
gpointer data);
static void gimp_curves_tool_recall_settings (GtkWidget *widget,
gpointer data);
static GimpImageMapToolClass *parent_class = NULL;
@ -157,18 +161,18 @@ gimp_curves_tool_get_type (void)
static const GTypeInfo tool_info =
{
sizeof (GimpCurvesToolClass),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_curves_tool_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpCurvesTool),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_curves_tool_init,
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gimp_curves_tool_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GimpCurvesTool),
0, /* n_preallocs */
(GInstanceInitFunc) gimp_curves_tool_init,
};
tool_type = g_type_register_static (GIMP_TYPE_IMAGE_MAP_TOOL,
"GimpCurvesTool",
"GimpCurvesTool",
&tool_info, 0);
}
@ -267,7 +271,7 @@ gimp_curves_tool_finalize (GObject *object)
static gboolean
gimp_curves_tool_initialize (GimpTool *tool,
GimpDisplay *gdisp)
GimpDisplay *gdisp)
{
GimpCurvesTool *c_tool = GIMP_CURVES_TOOL (tool);
GimpDrawable *drawable;
@ -301,6 +305,12 @@ gimp_curves_tool_initialize (GimpTool *tool,
GIMP_TOOL_CLASS (parent_class)->initialize (tool, gdisp);
GIMP_IMAGE_MAP_OPTIONS (tool->tool_info->tool_options)->settings
= g_build_filename (gimp_directory (),
GIMP_IMAGE_MAP_TOOL_GET_CLASS (tool)->settings_name,
G_DIR_SEPARATOR_S,
NULL);
/* always pick colors */
gimp_color_tool_enable (GIMP_COLOR_TOOL (tool),
GIMP_COLOR_OPTIONS (tool->tool_info->tool_options));
@ -327,8 +337,8 @@ static void
gimp_curves_tool_button_release (GimpTool *tool,
GimpCoords *coords,
guint32 time,
GdkModifierType state,
GimpDisplay *gdisp)
GdkModifierType state,
GimpDisplay *gdisp)
{
GimpCurvesTool *c_tool = GIMP_CURVES_TOOL (tool);
GimpDrawable *drawable;
@ -358,9 +368,9 @@ gimp_curves_tool_button_release (GimpTool *tool,
static void
gimp_curves_tool_color_picked (GimpColorTool *color_tool,
GimpImageType sample_type,
GimpRGB *color,
gint color_index)
GimpImageType sample_type,
GimpRGB *color,
gint color_index)
{
GimpCurvesTool *tool;
GimpDrawable *drawable;
@ -388,9 +398,9 @@ gimp_curves_tool_color_picked (GimpColorTool *color_tool,
static void
curves_add_point (GimpCurvesTool *tool,
gint x,
gint y,
gint cchan)
gint x,
gint y,
gint cchan)
{
/* Add point onto the curve */
gint closest_point = 0;
@ -405,17 +415,17 @@ curves_add_point (GimpCurvesTool *tool,
distance = G_MAXINT;
for (i = 0; i < 17; i++)
{
if (tool->curves->points[cchan][i][0] != -1)
if (abs (curvex - tool->curves->points[cchan][i][0]) < distance)
{
distance = abs (curvex - tool->curves->points[cchan][i][0]);
closest_point = i;
}
}
{
if (tool->curves->points[cchan][i][0] != -1)
if (abs (curvex - tool->curves->points[cchan][i][0]) < distance)
{
distance = abs (curvex - tool->curves->points[cchan][i][0]);
closest_point = i;
}
}
if (distance > MIN_DISTANCE)
closest_point = (curvex + 8) / 16;
closest_point = (curvex + 8) / 16;
tool->curves->points[cchan][closest_point][0] = curvex;
tool->curves->points[cchan][closest_point][1] = tool->curves->curve[cchan][curvex];
@ -433,9 +443,9 @@ gimp_curves_tool_map (GimpImageMapTool *image_map_tool)
GimpCurvesTool *tool = GIMP_CURVES_TOOL (image_map_tool);
gimp_lut_setup (tool->lut,
(GimpLutFunc) curves_lut_func,
(GimpLutFunc) curves_lut_func,
tool->curves,
gimp_drawable_bytes (image_map_tool->drawable));
gimp_drawable_bytes (image_map_tool->drawable));
gimp_image_map_apply (image_map_tool->image_map,
(GimpImageMapApplyFunc) gimp_lut_process_2,
@ -512,7 +522,7 @@ gimp_curves_tool_dialog (GimpImageMapTool *image_map_tool)
/* The left color bar */
vbox2 = gtk_vbox_new (FALSE, 0);
gtk_table_attach (GTK_TABLE (table), vbox2, 0, 1, 0, 1,
GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
gtk_widget_show (vbox2);
frame = gtk_frame_new (NULL);
@ -529,7 +539,7 @@ gimp_curves_tool_dialog (GimpImageMapTool *image_map_tool)
frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
gtk_table_attach (GTK_TABLE (table), frame, 1, 2, 0, 1,
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
gtk_widget_show (frame);
tool->graph = gimp_histogram_view_new (FALSE);
@ -549,8 +559,8 @@ gimp_curves_tool_dialog (GimpImageMapTool *image_map_tool)
gtk_widget_show (tool->graph);
g_signal_connect (tool->graph, "event",
G_CALLBACK (curves_graph_events),
tool);
G_CALLBACK (curves_graph_events),
tool);
g_signal_connect_after (tool->graph, "expose_event",
G_CALLBACK (curves_graph_expose),
tool);
@ -562,7 +572,7 @@ gimp_curves_tool_dialog (GimpImageMapTool *image_map_tool)
/* The bottom color bar */
hbox2 = gtk_hbox_new (FALSE, 0);
gtk_table_attach (GTK_TABLE (table), hbox2, 1, 2, 1, 2,
GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);
gtk_widget_show (hbox2);
frame = gtk_frame_new (NULL);
@ -595,11 +605,15 @@ gimp_curves_tool_dialog (GimpImageMapTool *image_map_tool)
gtk_box_pack_start (GTK_BOX (hbox), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
vbox = gtk_vbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (frame), vbox);
gtk_widget_show (vbox);
bbox = gtk_hbutton_box_new ();
gtk_container_set_border_width (GTK_CONTAINER (bbox), 2);
gtk_box_set_spacing (GTK_BOX (bbox), 4);
gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_SPREAD);
gtk_container_add (GTK_CONTAINER (frame), bbox);
gtk_box_pack_start (GTK_BOX (vbox), bbox, FALSE, FALSE, 0);
gtk_widget_show (bbox);
gtk_box_pack_start (GTK_BOX (bbox), image_map_tool->load_button,
@ -614,16 +628,41 @@ gimp_curves_tool_dialog (GimpImageMapTool *image_map_tool)
_("Save curves settings to file"), NULL);
gtk_widget_show (image_map_tool->save_button);
bbox = gtk_hbutton_box_new ();
gtk_container_set_border_width (GTK_CONTAINER (bbox), 2);
gtk_box_set_spacing (GTK_BOX (bbox), 4);
gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_SPREAD);
gtk_box_pack_start (GTK_BOX (vbox), bbox, FALSE, FALSE, 0);
gtk_widget_show (bbox);
button = gtk_button_new_with_mnemonic (_("S_tore"));
gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0);
g_signal_connect (button, "clicked",
G_CALLBACK (gimp_curves_tool_store_settings),
tool);
gimp_help_set_help_data (button,
_("Remember curve temporarily"), NULL);
gtk_widget_show (button);
button = gtk_button_new_with_mnemonic (_("_Recall"));
gtk_box_pack_start (GTK_BOX (bbox), button, FALSE, FALSE, 0);
g_signal_connect (button, "clicked",
G_CALLBACK (gimp_curves_tool_recall_settings),
tool);
gimp_help_set_help_data (button,
_("Recall most recently stored curve"), NULL);
gtk_widget_show (button);
/* The radio box for selecting the curve type */
frame = gimp_frame_new (_("Curve Type"));
gtk_box_pack_end (GTK_BOX (hbox), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
hbox = gimp_enum_stock_box_new (GIMP_TYPE_CURVE_TYPE,
"gimp-curve", GTK_ICON_SIZE_MENU,
G_CALLBACK (curves_curve_type_callback),
tool,
&tool->curve_type);
"gimp-curve", GTK_ICON_SIZE_MENU,
G_CALLBACK (curves_curve_type_callback),
tool,
&tool->curve_type);
gtk_widget_style_get (bbox, "child_internal_pad_x", &padding, NULL);
@ -673,15 +712,15 @@ gimp_curves_tool_settings_load (GimpImageMapTool *image_map_tool,
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)
{
{
fields = fscanf (file, "%d %d ", &index[i][j], &value[i][j]);
if (fields != 2)
{
/* FIXME: should have a helpful error message here */
g_printerr ("fields != 2");
return FALSE;
}
}
g_printerr ("fields != 2");
return FALSE;
}
}
}
for (i = 0; i < 5; i++)
@ -689,10 +728,10 @@ gimp_curves_tool_settings_load (GimpImageMapTool *image_map_tool,
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];
}
{
tool->curves->points[i][j][0] = index[i][j];
tool->curves->points[i][j][1] = value[i][j];
}
}
for (i = 0; i < 5; i++)
@ -701,7 +740,7 @@ gimp_curves_tool_settings_load (GimpImageMapTool *image_map_tool,
curves_update (tool, ALL);
gimp_int_radio_group_set_active (GTK_RADIO_BUTTON (tool->curve_type),
GIMP_CURVE_SMOOTH);
GIMP_CURVE_SMOOTH);
return TRUE;
}
@ -718,14 +757,14 @@ gimp_curves_tool_settings_save (GimpImageMapTool *image_map_tool,
for (i = 0; i < 5; i++)
if (tool->curves->curve_type[i] == GIMP_CURVE_FREE)
{
/* pick representative points from the curve
/* 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];
}
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");
@ -733,7 +772,7 @@ gimp_curves_tool_settings_save (GimpImageMapTool *image_map_tool,
for (i = 0; i < 5; i++)
{
for (j = 0; j < 17; j++)
fprintf (file, "%d %d ",
fprintf (file, "%d %d ",
tool->curves->points[i][j][0],
tool->curves->points[i][j][1]);
@ -743,10 +782,63 @@ gimp_curves_tool_settings_save (GimpImageMapTool *image_map_tool,
return TRUE;
}
static void
gimp_curves_tool_store_settings (GtkWidget *widget,
gpointer data)
{
GimpImageMapTool *tool = (GimpImageMapTool *)data;
gchar *tmp;
FILE *fp;
tmp = g_build_filename (gimp_directory (),
GIMP_IMAGE_MAP_TOOL_GET_CLASS (tool)->settings_name,
G_DIR_SEPARATOR_S,
".stored-curve",
NULL);
fp = fopen (tmp, "w");
if (!fp)
{
g_message ("Unable to open file for curves store.");
return;
}
gimp_curves_tool_settings_save (tool, (gpointer)fp);
fclose (fp);
g_free (tmp);
}
static void
gimp_curves_tool_recall_settings (GtkWidget *widget,
gpointer data)
{
GimpImageMapTool *tool = (GimpImageMapTool *)data;
gchar *tmp;
FILE *fp;
tmp = g_build_filename (gimp_directory (),
GIMP_IMAGE_MAP_TOOL_GET_CLASS (tool)->settings_name,
G_DIR_SEPARATOR_S,
".stored-curve",
NULL);
fp = fopen (tmp, "r");
if (!fp)
{
g_message ("Unable to open file for curves recall.");
return;
}
gimp_curves_tool_settings_load (tool, (gpointer)fp);
fclose (fp);
g_free (tmp);
}
/* TODO: preview alpha channel stuff correctly. -- austin, 20/May/99 */
static void
curves_update (GimpCurvesTool *tool,
gint update)
gint update)
{
GimpHistogramChannel channel;
@ -768,24 +860,24 @@ curves_update (GimpCurvesTool *tool,
if (update & XRANGE)
{
switch (channel)
{
case GIMP_HISTOGRAM_VALUE:
case GIMP_HISTOGRAM_ALPHA:
{
case GIMP_HISTOGRAM_VALUE:
case GIMP_HISTOGRAM_ALPHA:
gimp_color_bar_set_buffers (GIMP_COLOR_BAR (tool->xrange),
tool->curves->curve[channel],
tool->curves->curve[channel],
tool->curves->curve[channel]);
break;
break;
case GIMP_HISTOGRAM_RED:
case GIMP_HISTOGRAM_GREEN:
case GIMP_HISTOGRAM_BLUE:
case GIMP_HISTOGRAM_RED:
case GIMP_HISTOGRAM_GREEN:
case GIMP_HISTOGRAM_BLUE:
gimp_color_bar_set_buffers (GIMP_COLOR_BAR (tool->xrange),
tool->curves->curve[GIMP_HISTOGRAM_RED],
tool->curves->curve[GIMP_HISTOGRAM_GREEN],
tool->curves->curve[GIMP_HISTOGRAM_BLUE]);
break;
}
break;
}
}
if (update & YRANGE)
@ -796,7 +888,7 @@ curves_update (GimpCurvesTool *tool,
static void
curves_channel_callback (GtkWidget *widget,
GimpCurvesTool *tool)
GimpCurvesTool *tool)
{
gimp_int_combo_box_get_active (GIMP_INT_COMBO_BOX (widget),
(gint *) &tool->channel);
@ -857,7 +949,7 @@ curves_menu_visible_func (GtkTreeModel *model,
static void
curves_curve_type_callback (GtkWidget *widget,
GimpCurvesTool *tool)
GimpCurvesTool *tool)
{
GimpCurveType curve_type;
@ -893,8 +985,8 @@ curves_curve_type_callback (GtkWidget *widget,
static gboolean
curves_graph_events (GtkWidget *widget,
GdkEvent *event,
GimpCurvesTool *tool)
GdkEvent *event,
GimpCurvesTool *tool)
{
static GimpCursorType cursor_type = GDK_TOP_LEFT_ARROW;
@ -925,11 +1017,11 @@ curves_graph_events (GtkWidget *widget,
for (i = 0, closest_point = 0; i < 17; i++)
{
if (tool->curves->points[tool->channel][i][0] != -1)
if (abs (x - tool->curves->points[tool->channel][i][0]) < distance)
{
distance = abs (x - tool->curves->points[tool->channel][i][0]);
closest_point = i;
}
if (abs (x - tool->curves->points[tool->channel][i][0]) < distance)
{
distance = abs (x - tool->curves->points[tool->channel][i][0]);
closest_point = i;
}
}
if (distance > MIN_DISTANCE)
@ -946,35 +1038,35 @@ curves_graph_events (GtkWidget *widget,
new_cursor = GDK_TCROSS;
switch (tool->curves->curve_type[tool->channel])
{
case GIMP_CURVE_SMOOTH:
/* determine the leftmost and rightmost points */
tool->leftmost = -1;
for (i = closest_point - 1; i >= 0; i--)
if (tool->curves->points[tool->channel][i][0] != -1)
{
tool->leftmost = tool->curves->points[tool->channel][i][0];
break;
}
tool->rightmost = 256;
for (i = closest_point + 1; i < 17; i++)
if (tool->curves->points[tool->channel][i][0] != -1)
{
tool->rightmost = tool->curves->points[tool->channel][i][0];
break;
}
{
case GIMP_CURVE_SMOOTH:
/* determine the leftmost and rightmost points */
tool->leftmost = -1;
for (i = closest_point - 1; i >= 0; i--)
if (tool->curves->points[tool->channel][i][0] != -1)
{
tool->leftmost = tool->curves->points[tool->channel][i][0];
break;
}
tool->rightmost = 256;
for (i = closest_point + 1; i < 17; i++)
if (tool->curves->points[tool->channel][i][0] != -1)
{
tool->rightmost = tool->curves->points[tool->channel][i][0];
break;
}
tool->grab_point = closest_point;
tool->curves->points[tool->channel][tool->grab_point][0] = x;
tool->curves->points[tool->channel][tool->grab_point][1] = 255 - y;
break;
tool->grab_point = closest_point;
tool->curves->points[tool->channel][tool->grab_point][0] = x;
tool->curves->points[tool->channel][tool->grab_point][1] = 255 - y;
break;
case GIMP_CURVE_FREE:
tool->curves->curve[tool->channel][x] = 255 - y;
tool->grab_point = x;
tool->last = y;
break;
}
case GIMP_CURVE_FREE:
tool->curves->curve[tool->channel][x] = 255 - y;
tool->grab_point = x;
tool->last = y;
break;
}
curves_calculate_curve (tool->curves, tool->channel);
@ -998,83 +1090,83 @@ curves_graph_events (GtkWidget *widget,
mevent = (GdkEventMotion *) event;
switch (tool->curves->curve_type[tool->channel])
{
case GIMP_CURVE_SMOOTH:
/* If no point is grabbed... */
if (tool->grab_point == -1)
{
if (tool->curves->points[tool->channel][closest_point][0] != -1)
new_cursor = GDK_FLEUR;
else
new_cursor = GDK_TCROSS;
}
/* Else, drag the grabbed point */
else
{
new_cursor = GDK_TCROSS;
{
case GIMP_CURVE_SMOOTH:
/* If no point is grabbed... */
if (tool->grab_point == -1)
{
if (tool->curves->points[tool->channel][closest_point][0] != -1)
new_cursor = GDK_FLEUR;
else
new_cursor = GDK_TCROSS;
}
/* Else, drag the grabbed point */
else
{
new_cursor = GDK_TCROSS;
tool->curves->points[tool->channel][tool->grab_point][0] = -1;
tool->curves->points[tool->channel][tool->grab_point][0] = -1;
if (x > tool->leftmost && x < tool->rightmost)
{
closest_point = (x + 8) / 16;
if (tool->curves->points[tool->channel][closest_point][0] == -1)
tool->grab_point = closest_point;
if (x > tool->leftmost && x < tool->rightmost)
{
closest_point = (x + 8) / 16;
if (tool->curves->points[tool->channel][closest_point][0] == -1)
tool->grab_point = closest_point;
tool->curves->points[tool->channel][tool->grab_point][0] = x;
tool->curves->points[tool->channel][tool->grab_point][1] = 255 - y;
}
tool->curves->points[tool->channel][tool->grab_point][0] = x;
tool->curves->points[tool->channel][tool->grab_point][1] = 255 - y;
}
curves_calculate_curve (tool->curves, tool->channel);
}
break;
curves_calculate_curve (tool->curves, tool->channel);
}
break;
case GIMP_CURVE_FREE:
if (tool->grab_point != -1)
{
if (tool->grab_point > x)
{
x1 = x;
x2 = tool->grab_point;
y1 = y;
y2 = tool->last;
}
else
{
x1 = tool->grab_point;
x2 = x;
y1 = tool->last;
y2 = y;
}
case GIMP_CURVE_FREE:
if (tool->grab_point != -1)
{
if (tool->grab_point > x)
{
x1 = x;
x2 = tool->grab_point;
y1 = y;
y2 = tool->last;
}
else
{
x1 = tool->grab_point;
x2 = x;
y1 = tool->last;
y2 = y;
}
if (x2 != x1)
for (i = x1; i <= x2; i++)
tool->curves->curve[tool->channel][i] = 255 - (y1 + ((y2 - y1) * (i - x1)) / (x2 - x1));
else
tool->curves->curve[tool->channel][x] = 255 - y;
if (x2 != x1)
for (i = x1; i <= x2; i++)
tool->curves->curve[tool->channel][i] = 255 - (y1 + ((y2 - y1) * (i - x1)) / (x2 - x1));
else
tool->curves->curve[tool->channel][x] = 255 - y;
tool->grab_point = x;
tool->last = y;
}
tool->grab_point = x;
tool->last = y;
}
if (mevent->state & GDK_BUTTON1_MASK)
new_cursor = GDK_TCROSS;
else
new_cursor = GDK_PENCIL;
if (mevent->state & GDK_BUTTON1_MASK)
new_cursor = GDK_TCROSS;
else
new_cursor = GDK_PENCIL;
break;
}
break;
}
if (new_cursor != cursor_type)
{
cursor_type = new_cursor;
{
cursor_type = new_cursor;
gimp_cursor_set (tool->graph,
GIMP_GUI_CONFIG (GIMP_TOOL (tool)->tool_info->gimp->config)->cursor_format,
cursor_type,
GIMP_TOOL_CURSOR_NONE,
GIMP_CURSOR_MODIFIER_NONE);
}
}
tool->cursor_x = x;
tool->cursor_y = y;