Commit 7ee99ea3 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer
Browse files

Transform tool cleanup:

2002-11-14  Michael Natterer  <mitch@gimp.org>

	Transform tool cleanup:

	* libgimptool/gimptoolenums.[ch]: removed the TransformState enum.

	* app/tools/gimptransformtool.[ch]: don't dispatch everything
	through the transform() virtual function. Added new vitrual
	functions dialog(), prepare(), motion() and recalc(). Do only the
	actual transform in transform(). Moved lots of logic which was
	duplicated in each subclass' transform() here. Cleanup.

	* app/tools/gimpfliptool.c
	* app/tools/gimpperspectivetool.c
	* app/tools/gimprotatetool.c
	* app/tools/gimpscaletool.c
	* app/tools/gimpsheartool.c: changed accordingly: moved code from
	transform() to the other method imlementations. Removed duplicated
	logic which is now done by our parent class. Makes everything
	smaller and more readable.

	InfoDialog cleanup:

	* app/gui/info-dialog.c: removed the "delete_event" callback so
	InfoDialog users can decide themselves what to do.

	* app/gui/info-window.c
	* app/tools/gimpmeasuretool.c: changed accordingly.

	* app/tools/gimpcolorpickertool.c: ditto. Moved info_dialog
	creation to a utility function to improve code readbility.

	* app/tools/gimpcroptool.c: ditto. Added a "Cancel" button which
	really cancels the tool instead of just hiding the dialog.

	* app/tools/gimptransformtool.c: added a "Cancel" button here too.
parent 1f3bd288
2002-11-14 Michael Natterer <mitch@gimp.org>
Transform tool cleanup:
* libgimptool/gimptoolenums.[ch]: removed the TransformState enum.
* app/tools/gimptransformtool.[ch]: don't dispatch everything
through the transform() virtual function. Added new vitrual
functions dialog(), prepare(), motion() and recalc(). Do only the
actual transform in transform(). Moved lots of logic which was
duplicated in each subclass' transform() here. Cleanup.
* app/tools/gimpfliptool.c
* app/tools/gimpperspectivetool.c
* app/tools/gimprotatetool.c
* app/tools/gimpscaletool.c
* app/tools/gimpsheartool.c: changed accordingly: moved code from
transform() to the other method imlementations. Removed duplicated
logic which is now done by our parent class. Makes everything
smaller and more readable.
InfoDialog cleanup:
* app/gui/info-dialog.c: removed the "delete_event" callback so
InfoDialog users can decide themselves what to do.
* app/gui/info-window.c
* app/tools/gimpmeasuretool.c: changed accordingly.
* app/tools/gimpcolorpickertool.c: ditto. Moved info_dialog
creation to a utility function to improve code readbility.
* app/tools/gimpcroptool.c: ditto. Added a "Cancel" button which
really cancels the tool instead of just hiding the dialog.
* app/tools/gimptransformtool.c: added a "Cancel" button here too.
2002-11-14 Michael Natterer <mitch@gimp.org>
 
* app/gui/tools-commands.c (tools_select_cmd_callback): removed
......
......@@ -46,9 +46,6 @@ static InfoDialog * info_dialog_new_extended (GimpViewable *viewable,
GimpHelpFunc help_func,
gpointer help_data,
gboolean in_notebook);
static gboolean info_dialog_delete_callback (GtkWidget *widget,
GdkEvent *event,
gpointer data);
static void info_dialog_field_new (InfoDialog *idialog,
InfoFieldType field_type,
gchar *title,
......@@ -337,10 +334,6 @@ info_dialog_new_extended (GimpViewable *viewable,
help_func, help_data,
NULL);
g_signal_connect (G_OBJECT (shell), "delete_event",
G_CALLBACK (info_dialog_delete_callback),
idialog);
vbox = gtk_vbox_new (FALSE, 4);
gtk_container_set_border_width (GTK_CONTAINER (vbox), 4);
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (shell)->vbox), vbox);
......@@ -376,16 +369,6 @@ info_dialog_new_extended (GimpViewable *viewable,
return idialog;
}
static gboolean
info_dialog_delete_callback (GtkWidget *widget,
GdkEvent *event,
gpointer data)
{
info_dialog_popdown ((InfoDialog *) data);
return TRUE;
}
static void
info_dialog_field_new (InfoDialog *idialog,
InfoFieldType field_type,
......
......@@ -332,11 +332,10 @@ info_window_create (GimpDisplay *gdisp)
gimp_standard_help_func,
"dialogs/info_window.html");
/* create the action area */
gimp_dialog_create_action_area (GIMP_DIALOG (info_win->shell),
GTK_STOCK_CLOSE, info_window_close_callback,
info_win, NULL, NULL, TRUE, FALSE,
info_win, NULL, NULL, TRUE, TRUE,
NULL);
......
......@@ -46,9 +46,6 @@ static InfoDialog * info_dialog_new_extended (GimpViewable *viewable,
GimpHelpFunc help_func,
gpointer help_data,
gboolean in_notebook);
static gboolean info_dialog_delete_callback (GtkWidget *widget,
GdkEvent *event,
gpointer data);
static void info_dialog_field_new (InfoDialog *idialog,
InfoFieldType field_type,
gchar *title,
......@@ -337,10 +334,6 @@ info_dialog_new_extended (GimpViewable *viewable,
help_func, help_data,
NULL);
g_signal_connect (G_OBJECT (shell), "delete_event",
G_CALLBACK (info_dialog_delete_callback),
idialog);
vbox = gtk_vbox_new (FALSE, 4);
gtk_container_set_border_width (GTK_CONTAINER (vbox), 4);
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (shell)->vbox), vbox);
......@@ -376,16 +369,6 @@ info_dialog_new_extended (GimpViewable *viewable,
return idialog;
}
static gboolean
info_dialog_delete_callback (GtkWidget *widget,
GdkEvent *event,
gpointer data)
{
info_dialog_popdown ((InfoDialog *) data);
return TRUE;
}
static void
info_dialog_field_new (InfoDialog *idialog,
InfoFieldType field_type,
......
......@@ -332,11 +332,10 @@ info_window_create (GimpDisplay *gdisp)
gimp_standard_help_func,
"dialogs/info_window.html");
/* create the action area */
gimp_dialog_create_action_area (GIMP_DIALOG (info_win->shell),
GTK_STOCK_CLOSE, info_window_close_callback,
info_win, NULL, NULL, TRUE, FALSE,
info_win, NULL, NULL, TRUE, TRUE,
NULL);
......
......@@ -104,10 +104,11 @@ static gboolean gimp_color_picker_tool_pick_color (GimpImage *g
static GimpToolOptions * gimp_color_picker_tool_options_new (GimpToolInfo *tool_info);
static void gimp_color_picker_tool_options_reset (GimpToolOptions *tool_options);
static void gimp_color_picker_tool_info_window_close_callback (GtkWidget *widget,
gpointer data);
static void gimp_color_picker_tool_info_update (GimpTool *tool,
gboolean valid);
static InfoDialog * gimp_color_picker_tool_info_create (GimpDrawable *drawable);
static void gimp_color_picker_tool_info_close (GtkWidget *widget,
gpointer data);
static void gimp_color_picker_tool_info_update (GimpTool *tool,
gboolean valid);
static gint col_value[5] = { 0, 0, 0, 0, 0 };
......@@ -263,105 +264,14 @@ gimp_color_picker_tool_button_press (GimpTool *tool,
tool->drawable = gimp_image_active_drawable (gdisp->gimage);
gimp_tool_control_activate (tool->control);
/* create the info dialog if it doesn't exist */
if (! gimp_color_picker_tool_info)
{
GtkWidget *hbox;
GtkWidget *frame;
GimpRGB color;
gimp_color_picker_tool_info =
info_dialog_new (NULL,
_("Color Picker"), "color_picker",
GIMP_STOCK_TOOL_COLOR_PICKER,
_("Color Picker Information"),
tool_manager_help_func, NULL);
/* if the gdisplay is for a color image, the dialog must have RGB */
switch (GIMP_IMAGE_TYPE_BASE_TYPE (gimp_drawable_type (tool->drawable)))
{
case GIMP_RGB:
info_dialog_add_label (gimp_color_picker_tool_info,
_("Red:"), red_buf);
info_dialog_add_label (gimp_color_picker_tool_info,
_("Green:"), green_buf);
info_dialog_add_label (gimp_color_picker_tool_info,
_("Blue:"), blue_buf);
info_dialog_add_label (gimp_color_picker_tool_info,
_("Alpha:"), alpha_buf);
info_dialog_add_label (gimp_color_picker_tool_info,
_("Hex Triplet:"), hex_buf);
break;
case GIMP_GRAY:
info_dialog_add_label (gimp_color_picker_tool_info,
_("Intensity:"), gray_buf);
info_dialog_add_label (gimp_color_picker_tool_info,
_("Alpha:"), alpha_buf);
info_dialog_add_label (gimp_color_picker_tool_info,
_("Hex Triplet:"), hex_buf);
break;
case GIMP_INDEXED:
info_dialog_add_label (gimp_color_picker_tool_info,
_("Index:"), index_buf);
info_dialog_add_label (gimp_color_picker_tool_info,
_("Red:"), red_buf);
info_dialog_add_label (gimp_color_picker_tool_info,
_("Green:"), green_buf);
info_dialog_add_label (gimp_color_picker_tool_info,
_("Blue:"), blue_buf);
info_dialog_add_label (gimp_color_picker_tool_info,
_("Alpha:"), alpha_buf);
info_dialog_add_label (gimp_color_picker_tool_info,
_("Hex Triplet"), hex_buf);
break;
default:
g_assert_not_reached ();
break;
}
hbox = gtk_hbox_new (FALSE, 4);
gtk_box_pack_start (GTK_BOX (gimp_color_picker_tool_info->vbox), hbox,
FALSE, FALSE, 0);
gtk_widget_show (hbox);
gtk_widget_reparent (gimp_color_picker_tool_info->info_table, hbox);
frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
gtk_box_pack_start (GTK_BOX (hbox), frame, FALSE, FALSE, 0);
gimp_rgba_set (&color, 0.0, 0.0, 0.0, 0.0);
color_area =
gimp_color_area_new (&color,
gimp_drawable_has_alpha (tool->drawable) ?
GIMP_COLOR_AREA_LARGE_CHECKS :
GIMP_COLOR_AREA_FLAT,
GDK_BUTTON1_MASK | GDK_BUTTON2_MASK);
gtk_widget_set_size_request (color_area, 48, 64);
gtk_drag_dest_unset (color_area);
gtk_container_add (GTK_CONTAINER (frame), color_area);
gtk_widget_show (color_area);
gtk_widget_show (frame);
/* create the action area */
gimp_dialog_create_action_area
(GIMP_DIALOG (gimp_color_picker_tool_info->shell),
GTK_STOCK_CLOSE, gimp_color_picker_tool_info_window_close_callback,
gimp_color_picker_tool_info, NULL, NULL, TRUE, FALSE,
NULL);
}
gimp_color_picker_tool_info = gimp_color_picker_tool_info_create (tool->drawable);
gimp_viewable_dialog_set_viewable (GIMP_VIEWABLE_DIALOG (gimp_color_picker_tool_info->shell),
GIMP_VIEWABLE (gimp_image_active_drawable (gdisp->gimage)));
GIMP_VIEWABLE (tool->drawable));
/* Keep the coordinates of the target */
gimp_drawable_offsets (gimp_image_active_drawable (gdisp->gimage),
&off_x, &off_y);
gimp_drawable_offsets (tool->drawable, &off_x, &off_y);
cp_tool->centerx = coords->x - off_x;
cp_tool->centery = coords->y - off_y;
......@@ -402,7 +312,6 @@ gimp_color_picker_tool_button_press (GimpTool *tool,
update_type = GIMP_UPDATE_COLOR_STATE_UPDATE;
}
/* Start drawing the colorpicker tool */
gimp_draw_tool_start (GIMP_DRAW_TOOL (tool), gdisp);
}
......@@ -583,9 +492,94 @@ gimp_color_picker_tool_pick_color (GimpImage *gimage,
return success;
}
static InfoDialog *
gimp_color_picker_tool_info_create (GimpDrawable *drawable)
{
InfoDialog *info_dialog;
GtkWidget *hbox;
GtkWidget *frame;
GimpRGB color;
info_dialog = info_dialog_new (NULL,
_("Color Picker"), "color_picker",
GIMP_STOCK_TOOL_COLOR_PICKER,
_("Color Picker Information"),
tool_manager_help_func, NULL);
gimp_dialog_create_action_area (GIMP_DIALOG (info_dialog->shell),
GTK_STOCK_CLOSE,
gimp_color_picker_tool_info_close,
info_dialog, NULL, NULL, TRUE, TRUE,
NULL);
/* if the gdisplay is for a color image, the dialog must have RGB */
switch (GIMP_IMAGE_TYPE_BASE_TYPE (gimp_drawable_type (drawable)))
{
case GIMP_RGB:
info_dialog_add_label (info_dialog, _("Red:"), red_buf);
info_dialog_add_label (info_dialog, _("Green:"), green_buf);
info_dialog_add_label (info_dialog, _("Blue:"), blue_buf);
info_dialog_add_label (info_dialog, _("Alpha:"), alpha_buf);
info_dialog_add_label (info_dialog, _("Hex Triplet:"), hex_buf);
break;
case GIMP_GRAY:
info_dialog_add_label (info_dialog, _("Intensity:"), gray_buf);
info_dialog_add_label (info_dialog, _("Alpha:"), alpha_buf);
info_dialog_add_label (info_dialog, _("Hex Triplet:"), hex_buf);
break;
case GIMP_INDEXED:
info_dialog_add_label (info_dialog, _("Index:"), index_buf);
info_dialog_add_label (info_dialog, _("Red:"), red_buf);
info_dialog_add_label (info_dialog, _("Green:"), green_buf);
info_dialog_add_label (info_dialog, _("Blue:"), blue_buf);
info_dialog_add_label (info_dialog, _("Alpha:"), alpha_buf);
info_dialog_add_label (info_dialog, _("Hex Triplet"), hex_buf);
break;
default:
g_assert_not_reached ();
break;
}
hbox = gtk_hbox_new (FALSE, 4);
gtk_box_pack_start (GTK_BOX (info_dialog->vbox), hbox, FALSE, FALSE, 0);
gtk_widget_show (hbox);
gtk_widget_reparent (info_dialog->info_table, hbox);
frame = gtk_frame_new (NULL);
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
gtk_box_pack_start (GTK_BOX (hbox), frame, FALSE, FALSE, 0);
gimp_rgba_set (&color, 0.0, 0.0, 0.0, 0.0);
color_area = gimp_color_area_new (&color,
gimp_drawable_has_alpha (drawable) ?
GIMP_COLOR_AREA_LARGE_CHECKS :
GIMP_COLOR_AREA_FLAT,
GDK_BUTTON1_MASK | GDK_BUTTON2_MASK);
gtk_widget_set_size_request (color_area, 48, 64);
gtk_drag_dest_unset (color_area);
gtk_container_add (GTK_CONTAINER (frame), color_area);
gtk_widget_show (color_area);
gtk_widget_show (frame);
return info_dialog;
}
static void
gimp_color_picker_tool_info_close (GtkWidget *widget,
gpointer client_data)
{
info_dialog_popdown ((InfoDialog *) client_data);
}
static void
gimp_color_picker_tool_info_update (GimpTool *tool,
gboolean valid)
gboolean valid)
{
if (!valid)
{
......@@ -683,13 +677,6 @@ gimp_color_picker_tool_info_update (GimpTool *tool,
info_dialog_popup (gimp_color_picker_tool_info);
}
static void
gimp_color_picker_tool_info_window_close_callback (GtkWidget *widget,
gpointer client_data)
{
info_dialog_popdown ((InfoDialog *) client_data);
}
/* tool options stuff */
......
......@@ -143,7 +143,7 @@ static void crop_crop_callback (GtkWidget *widget,
GimpCropTool *crop);
static void crop_resize_callback (GtkWidget *widget,
GimpCropTool *crop);
static void crop_close_callback (GtkWidget *widget,
static void crop_cancel_callback (GtkWidget *widget,
GimpCropTool *crop);
static void crop_selection_callback (GtkWidget *widget,
......@@ -281,7 +281,7 @@ gimp_crop_tool_control (GimpTool *tool,
break;
case HALT:
crop_close_callback (NULL, crop);
crop_cancel_callback (NULL, crop);
break;
default:
......@@ -424,7 +424,7 @@ gimp_crop_tool_button_release (GimpTool *tool,
FALSE);
/* Finish the tool */
crop_close_callback (NULL, crop);
crop_cancel_callback (NULL, crop);
}
else
{
......@@ -971,7 +971,6 @@ crop_info_create (GimpCropTool *crop)
gdisp = tool->gdisp;
shell = GIMP_DISPLAY_SHELL (gdisp->shell);
/* create the info dialog */
crop->crop_info = info_dialog_new (NULL,
tool->tool_info->blurb,
GIMP_OBJECT (tool->tool_info)->name,
......@@ -979,11 +978,10 @@ crop_info_create (GimpCropTool *crop)
_("Crop & Resize Information"),
tool_manager_help_func, NULL);
/* create the action area */
gimp_dialog_create_action_area (GIMP_DIALOG (crop->crop_info->shell),
GTK_STOCK_CLOSE, crop_close_callback,
crop, NULL, NULL, FALSE, FALSE,
GTK_STOCK_CANCEL, crop_cancel_callback,
crop, NULL, NULL, FALSE, TRUE,
GIMP_STOCK_RESIZE, crop_resize_callback,
crop, NULL, NULL, FALSE, FALSE,
......@@ -1086,7 +1084,7 @@ crop_crop_callback (GtkWidget *widget,
options->layer_only,
TRUE);
crop_close_callback (NULL, crop);
crop_cancel_callback (NULL, crop);
}
static void
......@@ -1106,12 +1104,12 @@ crop_resize_callback (GtkWidget *widget,
options->layer_only,
FALSE);
crop_close_callback (NULL, crop);
crop_cancel_callback (NULL, crop);
}
static void
crop_close_callback (GtkWidget *widget,
GimpCropTool *crop)
crop_cancel_callback (GtkWidget *widget,
GimpCropTool *crop)
{
if (gimp_tool_control_is_active (GIMP_TOOL (crop)->control))
gimp_draw_tool_stop (GIMP_DRAW_TOOL (crop));
......
......@@ -71,8 +71,7 @@ static void gimp_flip_tool_cursor_update (GimpTool *tool,
GimpDisplay *gdisp);
static TileManager * gimp_flip_tool_transform (GimpTransformTool *tool,
GimpDisplay *gdisp,
TransformState state);
GimpDisplay *gdisp);
static GimpToolOptions * flip_options_new (GimpToolInfo *tool_info);
static void flip_options_reset (GimpToolOptions *tool_options);
......@@ -249,32 +248,18 @@ gimp_flip_tool_cursor_update (GimpTool *tool,
static TileManager *
gimp_flip_tool_transform (GimpTransformTool *trans_tool,
GimpDisplay *gdisp,
TransformState state)
GimpDisplay *gdisp)
{
FlipOptions *options;
FlipOptions *options;
GimpDrawable *drawable;
options = (FlipOptions *) GIMP_TOOL (trans_tool)->tool_info->tool_options;
switch (state)
{
case TRANSFORM_INIT:
break;
case TRANSFORM_MOTION:
break;
case TRANSFORM_RECALC:
break;
case TRANSFORM_FINISH:
return gimp_drawable_transform_tiles_flip (gimp_image_active_drawable (gdisp->gimage),
trans_tool->original,
options->type);
break;
}
drawable = gimp_image_active_drawable (gdisp->gimage);
return NULL;
return gimp_drawable_transform_tiles_flip (drawable,
trans_tool->original,
options->type);
}
......
......@@ -403,7 +403,7 @@ gimp_measure_tool_button_press (GimpTool *tool,
GTK_STOCK_CLOSE,
measure_tool_info_window_close_callback,
measure_tool_info, NULL, NULL, TRUE, FALSE,
measure_tool_info, NULL, NULL, TRUE, TRUE,
NULL);
}
......
......@@ -35,8 +35,6 @@
#include "core/gimpdrawable-transform-utils.h"
#include "core/gimptoolinfo.h"
#include "widgets/gimpviewabledialog.h"
#include "display/gimpdisplay.h"
#include "gui/info-dialog.h"
......@@ -49,18 +47,20 @@
/* local function prototypes */
static void gimp_perspective_tool_class_init (GimpPerspectiveToolClass *klass);
static void gimp_perspective_tool_init (GimpPerspectiveTool *perspective_tool);
static void gimp_perspective_tool_class_init (GimpPerspectiveToolClass *klass);
static void gimp_perspective_tool_init (GimpPerspectiveTool *tool);
static TileManager * gimp_perspective_tool_transform (GimpTransformTool *transform_tool,
GimpDisplay *gdisp,
TransformState state);
static void gimp_perspective_tool_dialog (GimpTransformTool *tr_tool);
static void gimp_perspective_tool_prepare (GimpTransformTool *tr_tool,
GimpDisplay *gdisp);
static void gimp_perspective_tool_motion (GimpTransformTool *tr_tool,
GimpDisplay *gdisp);
static void gimp_perspective_tool_recalc (GimpTransformTool *tr_tool,
GimpDisplay *gdisp);
static TileManager * gimp_perspective_tool_transform (GimpTransformTool *tr_tool,
GimpDisplay *gdisp);
static void perspective_tool_recalc (GimpTransformTool *tr_tool,
GimpDisplay *gdisp);
static void perspective_tool_motion (GimpTransformTool *tr_tool,
GimpDisplay *gdisp);
static void perspective_info_update (GimpTransformTool *tr_tool);
static void perspective_info_update (GimpTransformTool *tr_tool);
/* storage for information dialog fields */
......@@ -124,107 +124,56 @@ gimp_perspective_tool_class_init (GimpPerspectiveToolClass *klass)
parent_class = g_type_class_peek_parent (klass);
trans_class->dialog = gimp_perspective_tool_dialog;
trans_class->prepare = gimp_perspective_tool_prepare;
trans_class->motion = gimp_perspective_tool_motion;
trans_class->recalc = gimp_perspective_tool_recalc;
trans_class->transform = gimp_perspective_tool_transform;
}
static void
gimp_perspective_tool_init (GimpPerspectiveTool *perspective_tool)
{
GimpTool *tool;
GimpTool *tool;
GimpTransformTool *tr_tool;
tool = GIMP_TOOL (perspective_tool);
tool = GIMP_TOOL (perspective_tool);
tr_tool = GIMP_TRANSFORM_TOOL (perspective_tool);
gimp_tool_control_set_tool_cursor (tool->control,
GIMP_PERSPECTIVE_TOOL_CURSOR);
tr_tool->shell_desc = _("Perspective Transform Information");
}
static TileManager *
gimp_perspective_tool_transform (GimpTransformTool *transform_tool,
GimpDisplay *gdisp,
TransformState state)
static void
gimp_perspective_tool_dialog (GimpTransformTool *tr_tool)
{
switch (state)
{
case TRANSFORM_INIT:
if (! transform_tool->info_dialog)
{
transform_tool->info_dialog =
info_dialog_new (NULL,
_("Perspective Transform"), "perspective",
GIMP_STOCK_TOOL_PERSPECTIVE,
_("Perspective Transform Information"),
gimp_standard_help_func,
"tools/transform_perspective.html");
gimp_transform_tool_info_dialog_connect (transform_tool,
GIMP_STOCK_TOOL_PERSPECTIVE);
info_dialog_add_label (transform_tool->info_dialog, _("Matrix:"),