gimp/app/tools/gimppaintoptions-gui.c
Michael Natterer eeec3cedb8 Added object properties for almost all tool_options values and registered
2003-02-07  Michael Natterer  <mitch@gimp.org>

	Added object properties for almost all tool_options values
	and registered lots of enums with the type system:

	Part I (enum and type cleanup):

	* app/core/core-enums.[ch]
	* app/core/core-types.h: removed InternalOrientaionType and
	register GimpOrientationType. Register GimpChannelOps.
	Removed GimpToolOptionsGUIFunc.

	* app/xcf/xcf-private.h: added XcfOrientationType with the
	same values as the old InternalOrientationType

	* app/xcf/xcf-load.c
	* app/xcf/xcf-save.c: translate between GimpOrientationType and
	XcfOrientationType.

	* app/core/gimpdrawable-transform-utils.[ch]
	* app/core/gimpdrawable-transform.[ch]
	* app/core/gimpimage-crop.c
	* app/core/gimpimage-duplicate.c
	* app/core/gimpimage-guides.c
	* app/core/gimpimage-resize.c
	* app/core/gimpimage-scale.c
	* app/core/gimpimage.h
	* app/display/gimpdisplayshell.c
	* tools/pdbgen/stddefs.pdb
	* tools/pdbgen/pdb/transform_tools.pdb: changed accordingly.

	* app/pdb/guides_cmds.c
	* app/pdb/transform_tools_cmds.c
	* libgimp/gimpenums.h
	* libgimpproxy/gimpproxytypes.h
	* plug-ins/script-fu/script-fu-constants.c
	* tools/pdbgen/enums.pl: regenerated.

	* libgimptool/gimptoolenums.[ch]: added GimpTransformGridType.

	* libgimptool/gimptooltypes.h: removed GimpToolOptionsResetFunc,
	added GimpToolOptionsGUIFunc.

	Part II (tool options changes):

	* app/config/gimpconfig-utils.c (gimp_config_reset_properties):
	don't reset object properties because they have NULL as default
	value.

	* app/widgets/gimppropwidgets.[ch]: added
	gimp_prop_[enum|boolean]_radio_frame_new(),
	gimp_prop_paint_mode_menu_new() and gimp_prop_scale_entry_new(),
	which are all needed by the new tool options GUI code.

	* app/tools/tool_options.[ch]: removed the "reset_func" since
	the virtual reset() method is used now.

	* app/paint/gimpairbrushoptions.[ch]
	* app/paint/gimpcloneoptions.[ch]
	* app/paint/gimpconvolveoptions.[ch]
	* app/paint/gimpdodgeburnoptions.[ch]
	* app/paint/gimperaseroptions.[ch]
	* app/paint/gimppaintoptions.[ch]
	* app/paint/gimpsmudgeoptions.[ch]: added properties all over the
	place and removed the widget and default_value members from
	the structs. Renamed some values (e.g. s/type/clone_type/).
	Don't #include <gtk/gtk.h>.

	* app/paint/gimpairbrush.c
	* app/paint/gimpclone.c
	* app/paint/gimpconvolve.c
	* app/paint/gimpdodgeburn.c
	* app/paint/gimperaser.c
	* app/paint/gimppaintbrush.c
	* app/paint/gimppaintcore-stroke.c
	* app/paint/gimppaintcore.c
	* app/paint/gimppencil.c
	* app/paint/gimpsmudge.c
	* app/paint/paint-types.h
	* app/paint/paint.c: changed accordingly. Don't #include <gtk/gtk.h>.

	* tools/pdbgen/pdb/paint_tools.pdb: changed accordingly.

	* app/pdb/paint_tools_cmds.c: regenerated.

	* app/tools/gimpblendoptions.[ch]
	* app/tools/gimpbucketfilloptions.[ch]
	* app/tools/gimpcolorpickeroptions.[ch]
	* app/tools/gimpcropoptions.[ch]
	* app/tools/gimpflipoptions.[ch]
	* app/tools/gimpinkoptions.c
	* app/tools/gimpmagnifyoptions.[ch]
	* app/tools/gimpmeasureoptions.[ch]
	* app/tools/gimpmoveoptions.[ch]
	* app/tools/gimptextoptions.c
	* app/tools/paint_options.[ch]
	* app/tools/selection_options.[ch]
	* app/tools/transform_options.[ch]: ditto: added properties and
	removed widget and default_value stuff. Removed most reset functions.
	Use gimp_prop widgets all over the place, renamed some values
	as above.

	* app/tools/Makefile.am
	* app/tools/gimpairbrushtool.c
	* app/tools/gimpblendtool.c
	* app/tools/gimpbucketfilltool.c
	* app/tools/gimpbycolorselecttool.c
	* app/tools/gimpclonetool.c
	* app/tools/gimpconvolvetool.c
	* app/tools/gimpcroptool.c
	* app/tools/gimpdodgeburntool.c
	* app/tools/gimperasertool.c
	* app/tools/gimpfliptool.c
	* app/tools/gimpfuzzyselecttool.c
	* app/tools/gimpmagnifytool.c
	* app/tools/gimpmovetool.c
	* app/tools/gimpselectiontool.c
	* app/tools/gimpsheartool.c
	* app/tools/gimpsmudgetool.c
	* app/tools/gimptransformtool.c
	* app/tools/gimpvectoroptions.c: changed accordingly. Ported
	the paint_options GUI constructors to gimp_prop widgets.

	* app/widgets/gimpselectioneditor.c
	* app/gui/tool-options-dialog.c: changed accordingly.
2003-02-07 17:12:21 +00:00

439 lines
15 KiB
C

/* The GIMP -- an image manipulation program
* Copyright (C) 1995-1999 Spencer Kimball and Peter Mattis
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include <gtk/gtk.h>
#include "libgimpbase/gimpbase.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "tools-types.h"
#include "config/gimpconfig.h"
#include "core/gimp.h"
#include "core/gimptoolinfo.h"
#include "paint/gimppaintoptions.h"
#include "widgets/gimpdialogfactory.h"
#include "widgets/gimpdock.h"
#include "widgets/gimpenummenu.h"
#include "widgets/gimppreview.h"
#include "widgets/gimppropwidgets.h"
#include "widgets/gimpwidgets-constructors.h"
#include "widgets/gtkhwrapbox.h"
#include "paint_options.h"
#include "tool_manager.h"
#include "gimpairbrushtool.h"
#include "gimpblendtool.h"
#include "gimpbucketfilltool.h"
#include "gimpdodgeburntool.h"
#include "gimperasertool.h"
#include "gimpinktool.h"
#include "gimppaintbrushtool.h"
#include "gimppenciltool.h"
#include "gimpdodgeburntool.h"
#include "gimpsmudgetool.h"
#include "gimpclonetool.h"
#include "gimpconvolvetool.h"
#include "libgimp/gimpintl.h"
static GtkWidget * pressure_options_gui (GimpPressureOptions *pressure,
GimpPaintOptions *paint_options,
GType tool_type);
static GtkWidget * fade_options_gui (GimpGradientOptions *gradient,
GimpPaintOptions *paint_options,
GType tool_type);
static GtkWidget * gradient_options_gui (GimpGradientOptions *gradient,
GimpPaintOptions *paint_options,
GType tool_type,
GtkWidget *incremental_toggle);
static void paint_options_brush_clicked (GtkWidget *widget,
gpointer data);
void
gimp_paint_options_gui (GimpToolOptions *tool_options)
{
GimpPaintOptions *options;
GimpContext *context;
GObject *config;
GtkWidget *vbox;
GtkWidget *frame;
GtkWidget *table;
GtkWidget *optionmenu;
GtkWidget *mode_label;
GtkWidget *incremental_toggle = NULL;
options = GIMP_PAINT_OPTIONS (tool_options);
context = GIMP_CONTEXT (tool_options);
config = G_OBJECT (tool_options);
vbox = tool_options->main_vbox;
/* the main table */
table = gtk_table_new (3, 3, FALSE);
gtk_table_set_col_spacings (GTK_TABLE (table), 2);
gtk_table_set_row_spacings (GTK_TABLE (table), 2);
gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
gtk_widget_show (table);
/* the opacity scale */
gimp_prop_scale_entry_new (config, "opacity",
GTK_TABLE (table), 0, 0,
_("Opacity:"),
1.0, 10.0, 1,
FALSE, 0.0, 0.0);
/* the paint mode menu */
optionmenu = gimp_prop_paint_mode_menu_new (config, "paint-mode", TRUE);
mode_label = gimp_table_attach_aligned (GTK_TABLE (table), 0, 1,
_("Mode:"), 1.0, 0.5,
optionmenu, 2, TRUE);
if (tool_options->tool_info->tool_type == GIMP_TYPE_ERASER_TOOL ||
tool_options->tool_info->tool_type == GIMP_TYPE_CONVOLVE_TOOL ||
tool_options->tool_info->tool_type == GIMP_TYPE_DODGEBURN_TOOL ||
tool_options->tool_info->tool_type == GIMP_TYPE_SMUDGE_TOOL)
{
gtk_widget_set_sensitive (optionmenu, FALSE);
gtk_widget_set_sensitive (mode_label, FALSE);
}
/* the brush preview */
if (tool_options->tool_info->tool_type != GIMP_TYPE_BUCKET_FILL_TOOL &&
tool_options->tool_info->tool_type != GIMP_TYPE_BLEND_TOOL &&
tool_options->tool_info->tool_type != GIMP_TYPE_INK_TOOL)
{
GimpBrush *brush;
GtkWidget *button;
GtkWidget *preview;
brush = gimp_context_get_brush (context);
button = gtk_button_new ();
preview = gimp_preview_new_full (GIMP_VIEWABLE (brush),
24, 24, 0,
FALSE, TRUE, TRUE);
gtk_container_add (GTK_CONTAINER (button), preview);
gtk_widget_show (preview);
gimp_table_attach_aligned (GTK_TABLE (table), 0, 2,
_("Brush:"), 1.0, 0.5,
button, 2, TRUE);
g_signal_connect_object (options, "brush_changed",
G_CALLBACK (gimp_preview_set_viewable),
preview,
G_CONNECT_SWAPPED);
g_signal_connect (button, "clicked",
G_CALLBACK (paint_options_brush_clicked),
NULL);
}
/* a separator after the common paint options */
if (tool_options->tool_info->tool_type == GIMP_TYPE_BLEND_TOOL)
{
GtkWidget *separator;
separator = gtk_hseparator_new ();
gtk_box_pack_start (GTK_BOX (vbox), separator, FALSE, FALSE, 0);
gtk_widget_show (separator);
}
/* the "incremental" toggle */
if (tool_options->tool_info->tool_type == GIMP_TYPE_AIRBRUSH_TOOL ||
tool_options->tool_info->tool_type == GIMP_TYPE_ERASER_TOOL ||
tool_options->tool_info->tool_type == GIMP_TYPE_PAINTBRUSH_TOOL ||
tool_options->tool_info->tool_type == GIMP_TYPE_PENCIL_TOOL)
{
incremental_toggle = gimp_prop_check_button_new (config,
"incremental",
_("Incremental"));
gtk_box_pack_start (GTK_BOX (vbox), incremental_toggle, FALSE, FALSE, 0);
gtk_widget_show (incremental_toggle);
}
frame = pressure_options_gui (options->pressure_options,
options,
tool_options->tool_info->tool_type);
if (frame)
{
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
}
frame = fade_options_gui (options->gradient_options,
options,
tool_options->tool_info->tool_type);
if (frame)
{
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
}
frame = gradient_options_gui (options->gradient_options,
options,
tool_options->tool_info->tool_type,
incremental_toggle);
if (frame)
{
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
}
}
/* private functions */
static GtkWidget *
pressure_options_gui (GimpPressureOptions *pressure,
GimpPaintOptions *paint_options,
GType tool_type)
{
GObject *config;
GtkWidget *frame = NULL;
GtkWidget *wbox = NULL;
GtkWidget *button;
config = G_OBJECT (paint_options);
if (tool_type == GIMP_TYPE_AIRBRUSH_TOOL ||
tool_type == GIMP_TYPE_CLONE_TOOL ||
tool_type == GIMP_TYPE_CONVOLVE_TOOL ||
tool_type == GIMP_TYPE_DODGEBURN_TOOL ||
tool_type == GIMP_TYPE_ERASER_TOOL ||
tool_type == GIMP_TYPE_PAINTBRUSH_TOOL ||
tool_type == GIMP_TYPE_PENCIL_TOOL ||
tool_type == GIMP_TYPE_SMUDGE_TOOL)
{
frame = gtk_frame_new (_("Pressure Sensitivity"));
wbox = gtk_hwrap_box_new (FALSE);
gtk_wrap_box_set_aspect_ratio (GTK_WRAP_BOX (wbox), 6);
gtk_container_add (GTK_CONTAINER (frame), wbox);
gtk_widget_show (wbox);
}
/* the opacity toggle */
if (tool_type == GIMP_TYPE_CLONE_TOOL ||
tool_type == GIMP_TYPE_DODGEBURN_TOOL ||
tool_type == GIMP_TYPE_ERASER_TOOL ||
tool_type == GIMP_TYPE_PAINTBRUSH_TOOL ||
tool_type == GIMP_TYPE_PENCIL_TOOL)
{
button = gimp_prop_check_button_new (config, "pressure-opacity",
_("Opacity"));;
gtk_container_add (GTK_CONTAINER (wbox), button);
gtk_widget_show (button);
}
/* the pressure toggle */
if (tool_type == GIMP_TYPE_AIRBRUSH_TOOL ||
tool_type == GIMP_TYPE_CLONE_TOOL ||
tool_type == GIMP_TYPE_CONVOLVE_TOOL ||
tool_type == GIMP_TYPE_DODGEBURN_TOOL ||
tool_type == GIMP_TYPE_PAINTBRUSH_TOOL ||
tool_type == GIMP_TYPE_SMUDGE_TOOL)
{
button = gimp_prop_check_button_new (config, "pressure-pressure",
_("Hardness"));;
gtk_container_add (GTK_CONTAINER (wbox), button);
gtk_widget_show (button);
}
/* the rate toggle */
if (tool_type == GIMP_TYPE_AIRBRUSH_TOOL ||
tool_type == GIMP_TYPE_CONVOLVE_TOOL ||
tool_type == GIMP_TYPE_SMUDGE_TOOL)
{
button = gimp_prop_check_button_new (config, "pressure-rate",
_("Rate"));;
gtk_container_add (GTK_CONTAINER (wbox), button);
gtk_widget_show (button);
}
/* the size toggle */
if (tool_type == GIMP_TYPE_AIRBRUSH_TOOL ||
tool_type == GIMP_TYPE_CLONE_TOOL ||
tool_type == GIMP_TYPE_CONVOLVE_TOOL ||
tool_type == GIMP_TYPE_DODGEBURN_TOOL ||
tool_type == GIMP_TYPE_ERASER_TOOL ||
tool_type == GIMP_TYPE_PAINTBRUSH_TOOL ||
tool_type == GIMP_TYPE_PENCIL_TOOL)
{
button = gimp_prop_check_button_new (config, "pressure-size",
_("Size"));;
gtk_container_add (GTK_CONTAINER (wbox), button);
gtk_widget_show (button);
}
/* the color toggle */
if (tool_type == GIMP_TYPE_AIRBRUSH_TOOL ||
tool_type == GIMP_TYPE_PAINTBRUSH_TOOL ||
tool_type == GIMP_TYPE_PENCIL_TOOL)
{
button = gimp_prop_check_button_new (config, "pressure-color",
_("Size"));;
gtk_container_add (GTK_CONTAINER (wbox), button);
gtk_widget_show (button);
}
return frame;
}
static GtkWidget *
fade_options_gui (GimpGradientOptions *gradient,
GimpPaintOptions *paint_options,
GType tool_type)
{
GObject *config;
GtkWidget *frame = NULL;
GtkWidget *table;
GtkWidget *spinbutton;
GtkWidget *button;
GtkWidget *unitmenu;
config = G_OBJECT (paint_options);
if (tool_type == GIMP_TYPE_PAINTBRUSH_TOOL)
{
frame = gtk_frame_new (NULL);
table = gtk_table_new (1, 3, FALSE);
gtk_container_set_border_width (GTK_CONTAINER (table), 2);
gtk_table_set_col_spacings (GTK_TABLE (table), 2);
gtk_container_add (GTK_CONTAINER (frame), table);
gtk_widget_show (table);
button = gimp_prop_check_button_new (config, "use-fade",
_("Fade Out"));
gtk_frame_set_label_widget (GTK_FRAME (frame), button);
gtk_widget_show (button);
gtk_widget_set_sensitive (table, gradient->use_fade);
g_object_set_data (G_OBJECT (button), "set_sensitive", table);
/* the fade-out sizeentry */
spinbutton = gimp_prop_spin_button_new (config, "fade-length",
1.0, 50.0, 0);
gtk_entry_set_width_chars (GTK_ENTRY (spinbutton), 6);
gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
_("Length:"), 1.0, 0.5,
spinbutton, 1, FALSE);
/* the fade-out unitmenu */
unitmenu = gimp_prop_unit_menu_new (config, "fade-unit", "%a");
gtk_table_attach (GTK_TABLE (table), unitmenu, 2, 3, 0, 1,
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
gtk_widget_show (unitmenu);
g_object_set_data (G_OBJECT (unitmenu), "set_digits", spinbutton);
}
return frame;
}
static GtkWidget *
gradient_options_gui (GimpGradientOptions *gradient,
GimpPaintOptions *paint_options,
GType tool_type,
GtkWidget *incremental_toggle)
{
GObject *config;
GtkWidget *frame = NULL;
GtkWidget *table;
GtkWidget *spinbutton;
GtkWidget *button;
GtkWidget *unitmenu;
GtkWidget *enummenu;
config = G_OBJECT (paint_options);
if (tool_type == GIMP_TYPE_PAINTBRUSH_TOOL)
{
frame = gtk_frame_new (NULL);
table = gtk_table_new (2, 3, FALSE);
gtk_container_set_border_width (GTK_CONTAINER (table), 2);
gtk_table_set_col_spacings (GTK_TABLE (table), 2);
gtk_table_set_row_spacings (GTK_TABLE (table), 2);
gtk_container_add (GTK_CONTAINER (frame), table);
gtk_widget_show (table);
button = gimp_prop_check_button_new (config, "use-gradient",
_("Use Color from Gradient"));
gtk_frame_set_label_widget (GTK_FRAME (frame), button);
gtk_widget_show (button);
gtk_widget_set_sensitive (table, gradient->use_gradient);
g_object_set_data (G_OBJECT (button), "set_sensitive", table);
g_object_set_data (G_OBJECT (button), "inverse_sensitive",
incremental_toggle);
/* the gradient length scale */
spinbutton = gimp_prop_spin_button_new (config, "gradient-length",
1.0, 50.0, 0);
gtk_entry_set_width_chars (GTK_ENTRY (spinbutton), 6);
gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
_("Length:"), 1.0, 0.5,
spinbutton, 1, FALSE);
/* the gradient unitmenu */
unitmenu = gimp_prop_unit_menu_new (config, "gradient-unit", "%a");
gtk_table_attach (GTK_TABLE (table), unitmenu, 2, 3, 0, 1,
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
gtk_widget_show (unitmenu);
g_object_set_data (G_OBJECT (unitmenu), "set_digits", spinbutton);
/* the gradient type */
enummenu = gimp_prop_enum_option_menu_new (config, "gradient-type",
0, 0);
gimp_table_attach_aligned (GTK_TABLE (table), 0, 1,
_("Type:"), 1.0, 0.5,
enummenu, 2, TRUE);
gtk_widget_show (table);
}
return frame;
}
static void
paint_options_brush_clicked (GtkWidget *widget,
gpointer data)
{
GtkWidget *toplevel;
toplevel = gtk_widget_get_toplevel (widget);
if (GIMP_IS_DOCK (toplevel))
gimp_dialog_factory_dialog_raise (GIMP_DOCK (toplevel)->dialog_factory,
"gimp-brush-grid", -1);
}