gimp/app/tools/gimppaintoptions-gui.c

677 lines
23 KiB
C

/* GIMP - The GNU 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 "libgimpwidgets/gimpwidgets.h"
#include "tools-types.h"
#include "core/gimptoolinfo.h"
#include "paint/gimppaintoptions.h"
#include "widgets/gimppropwidgets.h"
#include "widgets/gimpviewablebox.h"
#include "widgets/gimpwidgets-utils.h"
#include "gimpairbrushtool.h"
#include "gimpclonetool.h"
#include "gimpconvolvetool.h"
#include "gimpdodgeburntool.h"
#include "gimperasertool.h"
#include "gimphealtool.h"
#include "gimpinktool.h"
#include "gimppaintoptions-gui.h"
#include "gimppenciltool.h"
#include "gimpperspectiveclonetool.h"
#include "gimpsmudgetool.h"
#include "gimptooloptions-gui.h"
#include "gimp-intl.h"
static gboolean tool_has_opacity_dynamics (GType tool_type);
static gboolean tool_has_hardness_dynamics (GType tool_type);
static gboolean tool_has_rate_dynamics (GType tool_type);
static gboolean tool_has_size_dynamics (GType tool_type);
static gboolean tool_has_color_dynamics (GType tool_type);
static void pressure_options_gui (GimpPaintOptions *paint_options,
GType tool_type,
GtkTable *table,
gint row,
GtkWidget *labels[]);
static void velocity_options_gui (GimpPaintOptions *paint_options,
GType tool_type,
GtkTable *table,
gint row);
static void random_options_gui (GimpPaintOptions *paint_options,
GType tool_type,
GtkTable *table,
gint row);
static GtkWidget * fade_options_gui (GimpPaintOptions *paint_options,
GType tool_type);
static GtkWidget * gradient_options_gui (GimpPaintOptions *paint_options,
GType tool_type,
GtkWidget *incremental_toggle);
static GtkWidget * jitter_options_gui (GimpPaintOptions *paint_options,
GType tool_type);
/* public functions */
GtkWidget *
gimp_paint_options_gui (GimpToolOptions *tool_options)
{
GObject *config = G_OBJECT (tool_options);
GimpPaintOptions *options = GIMP_PAINT_OPTIONS (tool_options);
GtkWidget *vbox = gimp_tool_options_gui (tool_options);
GtkWidget *frame;
GtkWidget *table;
GtkWidget *menu;
GtkWidget *label;
GtkWidget *button;
GtkWidget *incremental_toggle = NULL;
gint table_row = 0;
gint n_dynamics = 0;
GtkWidget *dynamics_labels[5];
GType tool_type;
tool_type = tool_options->tool_info->tool_type;
/* 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);
g_object_set_data (G_OBJECT (vbox), GIMP_PAINT_OPTIONS_TABLE_KEY, table);
/* the paint mode menu */
menu = gimp_prop_paint_mode_menu_new (config, "paint-mode", TRUE, FALSE);
label = gimp_table_attach_aligned (GTK_TABLE (table), 0, table_row++,
_("Mode:"), 0.0, 0.5,
menu, 2, FALSE);
if (tool_type == GIMP_TYPE_ERASER_TOOL ||
tool_type == GIMP_TYPE_CONVOLVE_TOOL ||
tool_type == GIMP_TYPE_DODGE_BURN_TOOL ||
tool_type == GIMP_TYPE_SMUDGE_TOOL)
{
gtk_widget_set_sensitive (menu, FALSE);
gtk_widget_set_sensitive (label, FALSE);
}
/* the opacity scale */
gimp_prop_opacity_entry_new (config, "opacity",
GTK_TABLE (table), 0, table_row++,
_("Opacity:"));
/* the brush */
if (g_type_is_a (tool_type, GIMP_TYPE_BRUSH_TOOL))
{
GtkObject *adj;
button = gimp_prop_brush_box_new (NULL, GIMP_CONTEXT (tool_options), 2,
"brush-view-type", "brush-view-size");
gimp_table_attach_aligned (GTK_TABLE (table), 0, table_row++,
_("Brush:"), 0.0, 0.5,
button, 2, FALSE);
adj = gimp_prop_scale_entry_new (config, "brush-scale",
GTK_TABLE (table), 0, table_row++,
_("Scale:"),
0.01, 0.1, 2,
FALSE, 0.0, 0.0);
gimp_scale_entry_set_logarithmic (adj, TRUE);
}
if (tool_has_opacity_dynamics (tool_type))
{
dynamics_labels[n_dynamics] = gtk_label_new (_("Opacity"));
n_dynamics++;
}
if (tool_has_hardness_dynamics (tool_type))
{
dynamics_labels[n_dynamics] = gtk_label_new (_("Hardness"));
n_dynamics++;
}
if (tool_has_rate_dynamics (tool_type))
{
dynamics_labels[n_dynamics] = gtk_label_new (_("Rate"));
n_dynamics++;
}
if (tool_has_size_dynamics (tool_type))
{
dynamics_labels[n_dynamics] = gtk_label_new (_("Size"));
n_dynamics++;
}
if (tool_has_color_dynamics (tool_type))
{
dynamics_labels[n_dynamics] = gtk_label_new (_("Color"));
n_dynamics++;
}
if (n_dynamics > 0)
{
GtkWidget *inner_frame;
GtkWidget *fixed;
gint i;
gboolean rtl = gtk_widget_get_direction (vbox) == GTK_TEXT_DIR_RTL;
frame = gimp_prop_expander_new (config, "dynamics-expanded",
_("Brush Dynamics"));
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
inner_frame = gimp_frame_new ("<expander>");
gtk_container_add (GTK_CONTAINER (frame), inner_frame);
gtk_widget_show (inner_frame);
table = gtk_table_new (4, n_dynamics + 2, FALSE);
gtk_container_add (GTK_CONTAINER (inner_frame), table);
gtk_widget_show (table);
label = gtk_label_new (_("Pressure:"));
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2,
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
gtk_widget_show (label);
label = gtk_label_new (_("Velocity:"));
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_table_attach (GTK_TABLE (table), label, 0, 1, 2, 3,
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
gtk_widget_show (label);
label = gtk_label_new (_("Random:"));
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_table_attach (GTK_TABLE (table), label, 0, 1, 3, 4,
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
gtk_widget_show (label);
pressure_options_gui (options, tool_type,
GTK_TABLE (table), 1,
dynamics_labels);
velocity_options_gui (options, tool_type,
GTK_TABLE (table), 2);
random_options_gui (options, tool_type,
GTK_TABLE (table), 3);
/* EEK: pack the fixed *after* the buttons so the table calls
* size-allocates on it *before* it places the toggles. Fixes
* label positions in RTL mode.
*/
fixed = gtk_fixed_new ();
gtk_table_attach (GTK_TABLE (table), fixed, 0, n_dynamics + 2, 0, 1,
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
gtk_widget_show (fixed);
for (i = 0; i < n_dynamics; i++)
{
gtk_label_set_angle (GTK_LABEL (dynamics_labels[i]),
rtl ? 315 : 45);
gtk_misc_set_alignment (GTK_MISC (dynamics_labels[i]), 1.0, 1.0);
gtk_fixed_put (GTK_FIXED (fixed), dynamics_labels[i], 0, 0);
gtk_widget_show (dynamics_labels[i]);
}
}
if (g_type_is_a (tool_type, GIMP_TYPE_BRUSH_TOOL))
{
frame = fade_options_gui (options, tool_type);
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
frame = jitter_options_gui (options, tool_type);
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
}
/* the "incremental" toggle */
if (tool_type == GIMP_TYPE_PENCIL_TOOL ||
tool_type == GIMP_TYPE_PAINTBRUSH_TOOL ||
tool_type == GIMP_TYPE_ERASER_TOOL)
{
incremental_toggle =
gimp_prop_enum_check_button_new (config,
"application-mode",
_("Incremental"),
GIMP_PAINT_CONSTANT,
GIMP_PAINT_INCREMENTAL);
gtk_box_pack_start (GTK_BOX (vbox), incremental_toggle, FALSE, FALSE, 0);
gtk_widget_show (incremental_toggle);
}
/* the "hard edge" toggle */
if (tool_type == GIMP_TYPE_ERASER_TOOL ||
tool_type == GIMP_TYPE_CLONE_TOOL ||
tool_type == GIMP_TYPE_HEAL_TOOL ||
tool_type == GIMP_TYPE_PERSPECTIVE_CLONE_TOOL ||
tool_type == GIMP_TYPE_CONVOLVE_TOOL ||
tool_type == GIMP_TYPE_DODGE_BURN_TOOL ||
tool_type == GIMP_TYPE_SMUDGE_TOOL)
{
button = gimp_prop_check_button_new (config, "hard", _("Hard edge"));
gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
gtk_widget_show (button);
}
if (g_type_is_a (tool_type, GIMP_TYPE_PAINTBRUSH_TOOL))
{
frame = gradient_options_gui (options, tool_type, incremental_toggle);
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
}
return vbox;
}
/* private functions */
static gboolean
tool_has_opacity_dynamics (GType tool_type)
{
return (g_type_is_a (tool_type, GIMP_TYPE_PAINTBRUSH_TOOL) ||
tool_type == GIMP_TYPE_CLONE_TOOL ||
tool_type == GIMP_TYPE_HEAL_TOOL ||
tool_type == GIMP_TYPE_PERSPECTIVE_CLONE_TOOL ||
tool_type == GIMP_TYPE_DODGE_BURN_TOOL ||
tool_type == GIMP_TYPE_ERASER_TOOL);
}
static gboolean
tool_has_hardness_dynamics (GType tool_type)
{
return (tool_type == GIMP_TYPE_AIRBRUSH_TOOL ||
tool_type == GIMP_TYPE_CLONE_TOOL ||
tool_type == GIMP_TYPE_HEAL_TOOL ||
tool_type == GIMP_TYPE_PERSPECTIVE_CLONE_TOOL ||
tool_type == GIMP_TYPE_CONVOLVE_TOOL ||
tool_type == GIMP_TYPE_ERASER_TOOL ||
tool_type == GIMP_TYPE_DODGE_BURN_TOOL ||
tool_type == GIMP_TYPE_PAINTBRUSH_TOOL ||
tool_type == GIMP_TYPE_SMUDGE_TOOL);
}
static gboolean
tool_has_rate_dynamics (GType tool_type)
{
return (tool_type == GIMP_TYPE_AIRBRUSH_TOOL ||
tool_type == GIMP_TYPE_CONVOLVE_TOOL ||
tool_type == GIMP_TYPE_SMUDGE_TOOL);
}
static gboolean
tool_has_size_dynamics (GType tool_type)
{
return (g_type_is_a (tool_type, GIMP_TYPE_PAINTBRUSH_TOOL) ||
tool_type == GIMP_TYPE_CLONE_TOOL ||
tool_type == GIMP_TYPE_HEAL_TOOL ||
tool_type == GIMP_TYPE_PERSPECTIVE_CLONE_TOOL ||
tool_type == GIMP_TYPE_CONVOLVE_TOOL ||
tool_type == GIMP_TYPE_DODGE_BURN_TOOL ||
tool_type == GIMP_TYPE_ERASER_TOOL);
}
static gboolean
tool_has_color_dynamics (GType tool_type)
{
return (g_type_is_a (tool_type, GIMP_TYPE_PAINTBRUSH_TOOL));
}
static GtkWidget *
dynamics_check_button_new (GObject *config,
const gchar *property_name,
GtkTable *table,
gint column,
gint row)
{
GtkWidget *button;
button = gimp_prop_check_button_new (config, property_name, NULL);
gtk_table_attach (table, button, column, column + 1, row, row + 1,
GTK_SHRINK, GTK_SHRINK, 0, 0);
gtk_widget_show (button);
return button;
}
static void
dynamics_check_button_size_allocate (GtkWidget *toggle,
GtkAllocation *allocation,
GtkWidget *label)
{
GtkWidget *fixed = label->parent;
gint x, y;
if (gtk_widget_get_direction (label) == GTK_TEXT_DIR_LTR)
x = allocation->x;
else
x = allocation->x + allocation->width - label->allocation.width;
x -= fixed->allocation.x;
y = fixed->allocation.height - label->allocation.height;
gtk_fixed_move (GTK_FIXED (fixed), label, x, y);
}
static void
pressure_options_gui (GimpPaintOptions *paint_options,
GType tool_type,
GtkTable *table,
gint row,
GtkWidget *labels[])
{
GObject *config = G_OBJECT (paint_options);
GtkWidget *button;
gint column = 1;
GtkWidget *scalebutton;
if (tool_has_opacity_dynamics (tool_type))
{
button = dynamics_check_button_new (config, "pressure-opacity",
table, column, row);
g_signal_connect (button, "size-allocate",
G_CALLBACK (dynamics_check_button_size_allocate),
labels[column - 1]);
column++;
}
if (tool_has_hardness_dynamics (tool_type))
{
button = dynamics_check_button_new (config, "pressure-hardness",
table, column, row);
g_signal_connect (button, "size-allocate",
G_CALLBACK (dynamics_check_button_size_allocate),
labels[column - 1]);
column++;
}
if (tool_has_rate_dynamics (tool_type))
{
button = dynamics_check_button_new (config, "pressure-rate",
table, column, row);
g_signal_connect (button, "size-allocate",
G_CALLBACK (dynamics_check_button_size_allocate),
labels[column - 1]);
column++;
}
if (tool_has_size_dynamics (tool_type))
{
if (tool_type != GIMP_TYPE_AIRBRUSH_TOOL)
button = dynamics_check_button_new (config, "pressure-size",
table, column, row);
else
button = dynamics_check_button_new (config, "pressure-inverse-size",
table, column, row);
g_signal_connect (button, "size-allocate",
G_CALLBACK (dynamics_check_button_size_allocate),
labels[column - 1]);
column++;
}
if (tool_has_color_dynamics (tool_type))
{
button = dynamics_check_button_new (config, "pressure-color",
table, column, row);
g_signal_connect (button, "size-allocate",
G_CALLBACK (dynamics_check_button_size_allocate),
labels[column - 1]);
column++;
}
scalebutton = gimp_prop_scale_button_new (config, "pressure-prescale");
gtk_table_attach (table, scalebutton, column, column + 1, row, row + 1,
GTK_SHRINK, GTK_SHRINK, 0, 0);
gtk_widget_show (scalebutton);
}
static void
velocity_options_gui (GimpPaintOptions *paint_options,
GType tool_type,
GtkTable *table,
gint row)
{
GObject *config = G_OBJECT (paint_options);
gint column = 1;
GtkWidget *scalebutton;
if (tool_has_opacity_dynamics (tool_type))
{
dynamics_check_button_new (config, "velocity-opacity",
table, column++, row);
}
if (tool_has_hardness_dynamics (tool_type))
{
dynamics_check_button_new (config, "velocity-hardness",
table, column++, row);
}
if (tool_has_rate_dynamics (tool_type))
{
dynamics_check_button_new (config, "velocity-rate",
table, column++, row);
}
if (tool_has_size_dynamics (tool_type))
{
dynamics_check_button_new (config, "velocity-size",
table, column++, row);
}
if (tool_has_color_dynamics (tool_type))
{
dynamics_check_button_new (config, "velocity-color",
table, column++, row);
}
scalebutton = gimp_prop_scale_button_new (config, "velocity-prescale");
gtk_table_attach (table, scalebutton, column, column + 1, row, row + 1,
GTK_SHRINK, GTK_SHRINK, 0, 0);
gtk_widget_show (scalebutton);
}
static void
random_options_gui (GimpPaintOptions *paint_options,
GType tool_type,
GtkTable *table,
gint row)
{
GObject *config = G_OBJECT (paint_options);
gint column = 1;
GtkWidget *scalebutton;
if (tool_has_opacity_dynamics (tool_type))
{
dynamics_check_button_new (config, "random-opacity",
table, column++, row);
}
if (tool_has_hardness_dynamics (tool_type))
{
dynamics_check_button_new (config, "random-hardness",
table, column++, row);
}
if (tool_has_rate_dynamics (tool_type))
{
dynamics_check_button_new (config, "random-rate",
table, column++, row);
}
if (tool_has_size_dynamics (tool_type))
{
dynamics_check_button_new (config, "random-size",
table, column++, row);
}
if (tool_has_color_dynamics (tool_type))
{
dynamics_check_button_new (config, "random-color",
table, column++, row);
}
scalebutton = gimp_prop_scale_button_new (config, "random-prescale");
gtk_table_attach (table, scalebutton, column, column + 1, row, row + 1,
GTK_SHRINK, GTK_SHRINK, 0, 0);
gtk_widget_show (scalebutton);
}
static GtkWidget *
fade_options_gui (GimpPaintOptions *paint_options,
GType tool_type)
{
GObject *config = G_OBJECT (paint_options);
GtkWidget *frame;
GtkWidget *table;
GtkWidget *spinbutton;
GtkWidget *menu;
table = gtk_table_new (1, 3, FALSE);
gtk_table_set_col_spacings (GTK_TABLE (table), 2);
frame = gimp_prop_expanding_frame_new (config, "use-fade",
_("Fade out"),
table, NULL);
/* 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:"), 0.0, 0.5,
spinbutton, 1, FALSE);
/* the fade-out unitmenu */
menu = gimp_prop_unit_menu_new (config, "fade-unit", "%a");
gtk_table_attach (GTK_TABLE (table), menu, 2, 3, 0, 1,
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
gtk_widget_show (menu);
g_object_set_data (G_OBJECT (menu), "set_digits", spinbutton);
gimp_unit_menu_set_pixel_digits (GIMP_UNIT_MENU (menu), 0);
return frame;
}
static GtkWidget *
jitter_options_gui (GimpPaintOptions *paint_options,
GType tool_type)
{
GObject *config = G_OBJECT (paint_options);
GtkWidget *frame;
GtkWidget *table;
table = gtk_table_new (1, 3, FALSE);
gtk_table_set_col_spacings (GTK_TABLE (table), 2);
frame = gimp_prop_expanding_frame_new (config, "use-jitter",
_("Apply Jitter"),
table, NULL);
gimp_prop_scale_entry_new (config, "jitter-amount",
GTK_TABLE (table), 0, 0,
_("Amount:"),
0.01, 0.1, 2,
TRUE, 0.0, 5.0);
return frame;
}
static GtkWidget *
gradient_options_gui (GimpPaintOptions *paint_options,
GType tool_type,
GtkWidget *incremental_toggle)
{
GObject *config = G_OBJECT (paint_options);
GtkWidget *frame;
GtkWidget *table;
GtkWidget *spinbutton;
GtkWidget *button;
GtkWidget *menu;
GtkWidget *combo;
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);
frame = gimp_prop_expanding_frame_new (config, "use-gradient",
_("Use color from gradient"),
table, &button);
if (incremental_toggle)
{
gtk_widget_set_sensitive (incremental_toggle,
! paint_options->gradient_options->use_gradient);
g_object_set_data (G_OBJECT (button), "inverse_sensitive",
incremental_toggle);
}
/* the gradient view */
button = gimp_prop_gradient_box_new (NULL, GIMP_CONTEXT (config), 2,
"gradient-view-type",
"gradient-view-size",
"gradient-reverse");
gimp_table_attach_aligned (GTK_TABLE (table), 0, 0,
_("Gradient:"), 0.0, 0.5,
button, 2, TRUE);
/* 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, 1,
_("Length:"), 0.0, 0.5,
spinbutton, 1, FALSE);
/* the gradient unitmenu */
menu = gimp_prop_unit_menu_new (config, "gradient-unit", "%a");
gtk_table_attach (GTK_TABLE (table), menu, 2, 3, 1, 2,
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
gtk_widget_show (menu);
g_object_set_data (G_OBJECT (menu), "set_digits", spinbutton);
gimp_unit_menu_set_pixel_digits (GIMP_UNIT_MENU (menu), 0);
/* the repeat type */
combo = gimp_prop_enum_combo_box_new (config, "gradient-repeat", 0, 0);
gimp_table_attach_aligned (GTK_TABLE (table), 0, 2,
_("Repeat:"), 0.0, 0.5,
combo, 2, FALSE);
return frame;
}