Commit a60b2c2f authored by Michael Natterer's avatar Michael Natterer Committed by Michael Natterer

the Tool structure is now allocated by a common constructor which sets

1999-07-02  Michael Natterer  <mitschel@cs.tu-berlin.de>

	* app/[all tools]: the Tool structure is now allocated by a common
	constructor which sets default values and provides default tool
	action functions. To get rid of much code duplication there should
	be a object hierarchy of tools.

	* app/context_manager.c
	* app/tools.[ch]: create and destroy private contexts for the
	paint tools on startup and exit. They are not used yet.

	* app/interface.c
	* app/menus.c
	* app/tools.h: num_tools is now exported in tools.h

	* app/commands.c
	* app/gdisplay.c
	* app/menus.c: made "Toggle Selection" a toggleable menu item.
parent 4a99a0b1
1999-07-02 Michael Natterer <mitschel@cs.tu-berlin.de>
* app/[all tools]: the Tool structure is now allocated by a common
constructor which sets default values and provides default tool
action functions. To get rid of much code duplication there should
be a object hierarchy of tools.
* app/context_manager.c
* app/tools.[ch]: create and destroy private contexts for the
paint tools on startup and exit. They are not used yet.
* app/interface.c
* app/menus.c
* app/tools.h: num_tools is now exported in tools.h
* app/commands.c
* app/gdisplay.c
* app/menus.c: made "Toggle Selection" a toggleable menu item.
Thu Jul 1 23:37:38 1999 Owen Taylor <otaylor@redhat.com>
* ifscompose_storage.c: New file implementing saving
......
......@@ -527,10 +527,18 @@ view_toggle_selection_cmd_callback (GtkWidget *widget,
gpointer client_data)
{
GDisplay * gdisp;
int new_val;
return_if_no_display (gdisp);
selection_hide (gdisp->select, (void *) gdisp);
gdisplays_flush ();
new_val = GTK_CHECK_MENU_ITEM (widget)->active;
/* hidden == TRUE corresponds to the menu toggle being FALSE */
if (new_val == gdisp->select->hidden)
{
selection_hide (gdisp->select, (void *) gdisp);
gdisplays_flush ();
}
}
void
......
......@@ -58,11 +58,7 @@ static ColorBalanceDialog *color_balance_dialog = NULL;
/* color balance action functions */
static void color_balance_button_press (Tool *, GdkEventButton *, gpointer);
static void color_balance_button_release (Tool *, GdkEventButton *, gpointer);
static void color_balance_motion (Tool *, GdkEventMotion *, gpointer);
static void color_balance_cursor_update (Tool *, GdkEventMotion *, gpointer);
static void color_balance_control (Tool *, ToolAction, gpointer);
static void color_balance_control (Tool *, ToolAction, gpointer);
static ColorBalanceDialog * color_balance_new_dialog (void);
......@@ -149,44 +145,6 @@ color_balance (PixelRegion *srcPR,
/* by_color select action functions */
static void
color_balance_button_press (Tool *tool,
GdkEventButton *bevent,
gpointer gdisp_ptr)
{
GDisplay *gdisp;
gdisp = gdisp_ptr;
tool->gdisp_ptr = gdisp;
tool->drawable = gimage_active_drawable (gdisp->gimage);
}
static void
color_balance_button_release (Tool *tool,
GdkEventButton *bevent,
gpointer gdisp_ptr)
{
}
static void
color_balance_motion (Tool *tool,
GdkEventMotion *mevent,
gpointer gdisp_ptr)
{
}
static void
color_balance_cursor_update (Tool *tool,
GdkEventMotion *mevent,
gpointer gdisp_ptr)
{
GDisplay *gdisp;
gdisp = (GDisplay *) gdisp_ptr;
gdisplay_install_tool_cursor (gdisp, GDK_TOP_LEFT_ARROW);
}
static void
color_balance_control (Tool *tool,
ToolAction action,
......@@ -227,25 +185,14 @@ tools_new_color_balance ()
tools_register (COLOR_BALANCE, color_balance_options);
}
tool = (Tool *) g_malloc (sizeof (Tool));
private = (ColorBalance *) g_malloc (sizeof (ColorBalance));
tool = tools_new_tool (COLOR_BALANCE);
private = g_new (ColorBalance, 1);
tool->type = COLOR_BALANCE;
tool->state = INACTIVE;
tool->scroll_lock = 1; /* Disallow scrolling */
tool->auto_snap_to = TRUE;
tool->private = (void *) private;
tool->scroll_lock = TRUE; /* Disallow scrolling */
tool->preserve = FALSE; /* Don't preserve on drawable change */
tool->preserve = FALSE;
tool->gdisp_ptr = NULL;
tool->drawable = NULL;
tool->private = (void *) private;
tool->button_press_func = color_balance_button_press;
tool->button_release_func = color_balance_button_release;
tool->motion_func = color_balance_motion;
tool->arrow_keys_func = standard_arrow_keys_func;
tool->modifier_key_func = standard_modifier_key_func;
tool->cursor_update_func = color_balance_cursor_update;
tool->control_func = color_balance_control;
return tool;
......
......@@ -96,7 +96,6 @@ static CRMatrix CR_basis =
static void curves_button_press (Tool *, GdkEventButton *, gpointer);
static void curves_button_release (Tool *, GdkEventButton *, gpointer);
static void curves_motion (Tool *, GdkEventMotion *, gpointer);
static void curves_cursor_update (Tool *, GdkEventMotion *, gpointer);
static void curves_control (Tool *, ToolAction, gpointer);
static CurvesDialog * curves_new_dialog (void);
......@@ -164,38 +163,6 @@ curves_lut_func (CurvesDialog *cd,
return inten;
}
/* curves action functions */
static void
curves_button_press (Tool *tool,
GdkEventButton *bevent,
gpointer gdisp_ptr)
{
GDisplay *gdisp;
GimpDrawable * drawable;
gdisp = gdisp_ptr;
drawable = gimage_active_drawable (gdisp->gimage);
tool->gdisp_ptr = gdisp;
if (drawable != tool->drawable)
{
active_tool->preserve = TRUE;
image_map_abort (curves_dialog->image_map);
active_tool->preserve = FALSE;
tool->drawable = drawable;
curves_dialog->drawable = drawable;
curves_dialog->color = drawable_color (drawable);
curves_dialog->image_map = image_map_create (gdisp, drawable);
}
if(tool)
tool->state = ACTIVE;
}
static void
curves_colour_update (Tool *tool,
GDisplay *gdisp,
......@@ -271,6 +238,43 @@ curves_add_point(GimpDrawable * drawable,gint x, gint y,gint cchan)
curves_dialog->points[cchan][closest_point][1] = curves_dialog->curve[cchan][curvex];
}
/* curves action functions */
static void
curves_button_press (Tool *tool,
GdkEventButton *bevent,
gpointer gdisp_ptr)
{
GDisplay *gdisp;
gint x, y;
GimpDrawable * drawable;
gdisp = gdisp_ptr;
drawable = gimage_active_drawable (gdisp->gimage);
tool->gdisp_ptr = gdisp;
if (drawable != tool->drawable)
{
active_tool->preserve = TRUE;
image_map_abort (curves_dialog->image_map);
active_tool->preserve = FALSE;
tool->drawable = drawable;
curves_dialog->drawable = drawable;
curves_dialog->color = drawable_color (drawable);
curves_dialog->image_map = image_map_create (gdisp, drawable);
}
tool->state = ACTIVE;
gdisplay_untransform_coords (gdisp, bevent->x, bevent->y, &x, &y,
FALSE, FALSE);
curves_colour_update (tool, gdisp, drawable, x, y);
curves_update (curves_dialog, GRAPH | DRAW);
}
static void
curves_button_release (Tool *tool,
GdkEventButton *bevent,
......@@ -329,17 +333,6 @@ curves_motion (Tool *tool,
curves_update (curves_dialog, GRAPH | DRAW);
}
static void
curves_cursor_update (Tool *tool,
GdkEventMotion *mevent,
gpointer gdisp_ptr)
{
GDisplay *gdisp;
gdisp = (GDisplay *) gdisp_ptr;
gdisplay_install_tool_cursor (gdisp, GDK_TOP_LEFT_ARROW);
}
static void
curves_control (Tool *tool,
ToolAction action,
......@@ -376,26 +369,18 @@ tools_new_curves ()
tools_register (CURVES, curves_options);
}
tool = (Tool *) g_malloc (sizeof (Tool));
private = (Curves *) g_malloc (sizeof (Curves));
tool = tools_new_tool (CURVES);
private = g_new (Curves, 1);
tool->type = CURVES;
tool->state = INACTIVE;
tool->scroll_lock = 1; /* Disallow scrolling */
tool->auto_snap_to = TRUE;
tool->private = (void *) private;
tool->scroll_lock = TRUE; /* Disallow scrolling */
tool->preserve = FALSE; /* Don't preserve on drawable change */
tool->preserve = FALSE;
tool->gdisp_ptr = NULL;
tool->drawable = NULL;
tool->private = (void *) private;
tool->button_press_func = curves_button_press;
tool->button_press_func = curves_button_press;
tool->button_release_func = curves_button_release;
tool->motion_func = curves_motion;
tool->arrow_keys_func = standard_arrow_keys_func;
tool->modifier_key_func = standard_modifier_key_func;
tool->cursor_update_func = curves_cursor_update;
tool->control_func = curves_control;
tool->motion_func = curves_motion;
tool->control_func = curves_control;
return tool;
}
......@@ -507,9 +492,9 @@ curves_free ()
}
}
/**************************/
/* Select Curves dialog */
/**************************/
/*******************/
/* Curves dialog */
/*******************/
static CurvesDialog *
curves_new_dialog ()
......
......@@ -79,13 +79,9 @@ static int default_colors[6][3] =
/* hue saturation action functions */
static void hue_saturation_button_press (Tool *, GdkEventButton *, gpointer);
static void hue_saturation_button_release (Tool *, GdkEventButton *, gpointer);
static void hue_saturation_motion (Tool *, GdkEventMotion *, gpointer);
static void hue_saturation_cursor_update (Tool *, GdkEventMotion *, gpointer);
static void hue_saturation_control (Tool *, ToolAction, gpointer);
static void hue_saturation_control (Tool *, ToolAction, gpointer);
static HueSaturationDialog * hue_saturation_new_dialog (void);
static HueSaturationDialog * hue_saturation_new_dialog (void);
static void hue_saturation_update (HueSaturationDialog *,
int);
......@@ -229,44 +225,6 @@ hue_saturation (PixelRegion *srcPR,
/* by_color select action functions */
static void
hue_saturation_button_press (Tool *tool,
GdkEventButton *bevent,
gpointer gdisp_ptr)
{
GDisplay *gdisp;
gdisp = gdisp_ptr;
tool->gdisp_ptr = gdisp;
tool->drawable = gimage_active_drawable (gdisp->gimage);
}
static void
hue_saturation_button_release (Tool *tool,
GdkEventButton *bevent,
gpointer gdisp_ptr)
{
}
static void
hue_saturation_motion (Tool *tool,
GdkEventMotion *mevent,
gpointer gdisp_ptr)
{
}
static void
hue_saturation_cursor_update (Tool *tool,
GdkEventMotion *mevent,
gpointer gdisp_ptr)
{
GDisplay *gdisp;
gdisp = (GDisplay *) gdisp_ptr;
gdisplay_install_tool_cursor (gdisp, GDK_TOP_LEFT_ARROW);
}
static void
hue_saturation_control (Tool *tool,
ToolAction action,
......@@ -303,25 +261,14 @@ tools_new_hue_saturation ()
tools_register (HUE_SATURATION, hue_saturation_options);
}
tool = (Tool *) g_malloc (sizeof (Tool));
private = (HueSaturation *) g_malloc (sizeof (HueSaturation));
tool = tools_new_tool (HUE_SATURATION);
private = g_new (HueSaturation, 1);
tool->type = HUE_SATURATION;
tool->state = INACTIVE;
tool->scroll_lock = 1; /* Disallow scrolling */
tool->auto_snap_to = TRUE;
tool->private = (void *) private;
tool->scroll_lock = TRUE; /* Disallow scrolling */
tool->preserve = FALSE; /* Don't preserve on drawable change */
tool->preserve = FALSE;
tool->gdisp_ptr = NULL;
tool->drawable = NULL;
tool->private = (void *) private;
tool->button_press_func = hue_saturation_button_press;
tool->button_release_func = hue_saturation_button_release;
tool->motion_func = hue_saturation_motion;
tool->arrow_keys_func = standard_arrow_keys_func;
tool->modifier_key_func = standard_modifier_key_func;
tool->cursor_update_func = hue_saturation_cursor_update;
tool->control_func = hue_saturation_control;
return tool;
......@@ -352,7 +299,7 @@ hue_saturation_initialize (GDisplay *gdisp)
return;
}
/* The "by color" dialog */
/* The "hue-saturation color" dialog */
if (!hue_saturation_dialog)
hue_saturation_dialog = hue_saturation_new_dialog ();
else
......
......@@ -49,11 +49,7 @@ static ThresholdDialog *threshold_dialog = NULL;
/* threshold action functions */
static void threshold_button_press (Tool *, GdkEventButton *, gpointer);
static void threshold_button_release (Tool *, GdkEventButton *, gpointer);
static void threshold_motion (Tool *, GdkEventMotion *, gpointer);
static void threshold_cursor_update (Tool *, GdkEventMotion *, gpointer);
static void threshold_control (Tool *, ToolAction, gpointer);
static void threshold_control (Tool *, ToolAction, gpointer);
static ThresholdDialog * threshold_new_dialog (void);
......@@ -158,44 +154,6 @@ threshold_histogram_range (HistogramWidget *w,
/* threshold action functions */
static void
threshold_button_press (Tool *tool,
GdkEventButton *bevent,
gpointer gdisp_ptr)
{
GDisplay *gdisp;
gdisp = gdisp_ptr;
tool->gdisp_ptr = gdisp;
tool->drawable = gimage_active_drawable (gdisp->gimage);
}
static void
threshold_button_release (Tool *tool,
GdkEventButton *bevent,
gpointer gdisp_ptr)
{
}
static void
threshold_motion (Tool *tool,
GdkEventMotion *mevent,
gpointer gdisp_ptr)
{
}
static void
threshold_cursor_update (Tool *tool,
GdkEventMotion *mevent,
gpointer gdisp_ptr)
{
GDisplay *gdisp;
gdisp = (GDisplay *) gdisp_ptr;
gdisplay_install_tool_cursor (gdisp, GDK_TOP_LEFT_ARROW);
}
static void
threshold_control (Tool *tool,
ToolAction action,
......@@ -239,25 +197,14 @@ tools_new_threshold ()
if (!GTK_WIDGET_VISIBLE (threshold_dialog->shell))
gtk_widget_show (threshold_dialog->shell);
tool = (Tool *) g_malloc (sizeof (Tool));
private = (Threshold *) g_malloc (sizeof (Threshold));
tool = tools_new_tool (THRESHOLD);
private = g_new (Threshold, 1);
tool->type = THRESHOLD;
tool->state = INACTIVE;
tool->scroll_lock = 1; /* Disallow scrolling */
tool->auto_snap_to = TRUE;
tool->private = (void *) private;
tool->scroll_lock = TRUE; /* Disallow scrolling */
tool->preserve = FALSE; /* Don't preserve on drawable change */
tool->preserve = FALSE;
tool->gdisp_ptr = NULL;
tool->drawable = NULL;
tool->private = (void *) private;
tool->button_press_func = threshold_button_press;
tool->button_release_func = threshold_button_release;
tool->motion_func = threshold_motion;
tool->arrow_keys_func = standard_arrow_keys_func;
tool->modifier_key_func = standard_modifier_key_func;
tool->cursor_update_func = threshold_cursor_update;
tool->control_func = threshold_control;
return tool;
......
......@@ -212,31 +212,25 @@ tools_new_bezier_select ()
tools_register (BEZIER_SELECT, (ToolOptions *) bezier_options);
}
tool = g_malloc (sizeof (Tool));
private = g_malloc (sizeof (BezierSelect));
tool = tools_new_tool (BEZIER_SELECT);
private = g_new (BezierSelect, 1);
private->num_points = 0;
private->mask = NULL;
private->core = draw_core_new (bezier_select_draw);
bezier_select_reset (private);
tool->type = BEZIER_SELECT;
tool->state = INACTIVE;
tool->scroll_lock = 1; /* Do not allow scrolling */
tool->auto_snap_to = TRUE;
tool->private = (void *) private;
tool->scroll_lock = TRUE; /* Disallow scrolling */
tool->preserve = FALSE; /* Don't preserve on drawable change */
tool->preserve = FALSE;
tool->gdisp_ptr = NULL;
tool->drawable = NULL;
tool->private = (void *) private;
tool->button_press_func = bezier_select_button_press;
tool->button_press_func = bezier_select_button_press;
tool->button_release_func = bezier_select_button_release;
tool->motion_func = bezier_select_motion;
tool->arrow_keys_func = standard_arrow_keys_func;
tool->modifier_key_func = standard_modifier_key_func;
tool->cursor_update_func = bezier_select_cursor_update;
tool->control_func = bezier_select_control;
tool->motion_func = bezier_select_motion;
tool->cursor_update_func = bezier_select_cursor_update;
tool->control_func = bezier_select_control;
curCore = private->core;
curSel = private;
......
......@@ -1732,28 +1732,20 @@ tools_new_blend ()
tools_register (BLEND, (ToolOptions *) blend_options);
}
tool = (Tool *) g_malloc (sizeof (Tool));
private = (BlendTool *) g_malloc (sizeof (BlendTool));
tool = tools_new_tool (BLEND);
private = g_new (BlendTool, 1);
private->core = draw_core_new (blend_draw);
tool->type = BLEND;
tool->state = INACTIVE;
tool->scroll_lock = 1; /* Disallow scrolling */
tool->auto_snap_to = TRUE;
tool->private = (void *) private;
tool->scroll_lock = TRUE; /* Disallow scrolling */
tool->preserve = TRUE;
tool->gdisp_ptr = NULL;
tool->drawable = NULL;
tool->private = (void *) private;
tool->button_press_func = blend_button_press;
tool->button_press_func = blend_button_press;
tool->button_release_func = blend_button_release;
tool->motion_func = blend_motion;
tool->arrow_keys_func = standard_arrow_keys_func;
tool->modifier_key_func = standard_modifier_key_func;
tool->cursor_update_func = blend_cursor_update;
tool->control_func = blend_control;
tool->motion_func = blend_motion;
tool->cursor_update_func = blend_cursor_update;
tool->control_func = blend_control;
return tool;
}
......
......@@ -82,13 +82,9 @@ static BrightnessContrastDialog *brightness_contrast_dialog = NULL;
/* brightness contrast action functions */
static void brightness_contrast_button_press (Tool *, GdkEventButton *, gpointer);
static void brightness_contrast_button_release (Tool *, GdkEventButton *, gpointer);
static void brightness_contrast_motion (Tool *, GdkEventMotion *, gpointer);
static void brightness_contrast_cursor_update (Tool *, GdkEventMotion *, gpointer);
static void brightness_contrast_control (Tool *, ToolAction, gpointer);
static void brightness_contrast_control (Tool *, ToolAction, gpointer);
static BrightnessContrastDialog * brightness_contrast_new_dialog (void);
static BrightnessContrastDialog * brightness_contrast_new_dialog (void);
static void brightness_contrast_update (BrightnessContrastDialog *, int);
static void brightness_contrast_preview (BrightnessContrastDialog *);
......@@ -102,45 +98,7 @@ static void brightness_contrast_brightness_text_update (GtkWidget *, gpointer
static void brightness_contrast_contrast_text_update (GtkWidget *, gpointer);
/* by_color select action functions */
static void
brightness_contrast_button_press (Tool *tool,
GdkEventButton *bevent,
gpointer gdisp_ptr)
{
GDisplay *gdisp;
gdisp = gdisp_ptr;
tool->gdisp_ptr = gdisp;
tool->drawable = gimage_active_drawable (gdisp->gimage);
}
static void
brightness_contrast_button_release (Tool *tool,
GdkEventButton *bevent,
gpointer gdisp_ptr)
{
}
static void
brightness_contrast_motion (Tool *tool,
GdkEventMotion *mevent,
gpointer gdisp_ptr)
{
}
static void