Issue #9270: Change GimpBrushSelect to choose only brush.

gimp_brushes_popup() was triggering a popup allowing to change not only
the brush, but also the "paint mode", the opacity and the spacing. As
far as I could see, this was used nowhere for the paint mode and
opacity.

As for the spacing, it looks like gfig was indeed getting this data,
except that the GimpBrushSelect was disabling the effect on this scale
by setting change_brush_spacing to FALSE when calling
gimp_brush_factory_view_new(), and even setting this to TRUE, it was not
working fine anyway. Rather than debugging this, let's simplify the API.
Such settings seems like additional paint settings which don't have to
be in the brush selection. If someone wants people to also select an
opacity, spacing or paint mode, it would be much more efficient to add
separate plug-in arguments for these.

Additionally, I fix GimpBrushFactoryView not to show the spacing scale
when change_brush_spacing was set to FALSE anyway. This is just a bogus
widget then, which can only confuse people.
This commit is contained in:
Jehan 2024-09-06 18:02:16 +02:00
parent 6cd39dc442
commit a92388c433
5 changed files with 2 additions and 228 deletions

View File

@ -178,7 +178,7 @@ gimp_brush_factory_view_new (GimpViewType view_type,
gtk_box_pack_end (GTK_BOX (editor->view), factory_view->spacing_scale,
FALSE, FALSE, 0);
gtk_widget_show (factory_view->spacing_scale);
gtk_widget_set_visible (factory_view->spacing_scale, change_brush_spacing);
factory_view->spacing_changed_handler_id =
gimp_container_add_handler (gimp_data_factory_get_container (factory), "spacing-changed",

View File

@ -46,38 +46,13 @@
#include "gimp-intl.h"
enum
{
PROP_0,
PROP_OPACITY,
PROP_PAINT_MODE,
PROP_SPACING
};
static void gimp_brush_select_constructed (GObject *object);
static void gimp_brush_select_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static GimpValueArray * gimp_brush_select_run_callback (GimpPdbDialog *dialog,
GimpObject *object,
gboolean closing,
GError **error);
static void gimp_brush_select_opacity_changed (GimpContext *context,
gdouble opacity,
GimpBrushSelect *select);
static void gimp_brush_select_mode_changed (GimpContext *context,
GimpLayerMode paint_mode,
GimpBrushSelect *select);
static void gimp_brush_select_opacity_update (GtkAdjustment *adj,
GimpBrushSelect *select);
static void gimp_brush_select_spacing_update (GimpBrushFactoryView *view,
GimpBrushSelect *select);
G_DEFINE_TYPE (GimpBrushSelect, gimp_brush_select, GIMP_TYPE_PDB_DIALOG)
@ -91,30 +66,8 @@ gimp_brush_select_class_init (GimpBrushSelectClass *klass)
GimpPdbDialogClass *pdb_class = GIMP_PDB_DIALOG_CLASS (klass);
object_class->constructed = gimp_brush_select_constructed;
object_class->set_property = gimp_brush_select_set_property;
pdb_class->run_callback = gimp_brush_select_run_callback;
g_object_class_install_property (object_class, PROP_OPACITY,
g_param_spec_double ("opacity", NULL, NULL,
GIMP_OPACITY_TRANSPARENT,
GIMP_OPACITY_OPAQUE,
GIMP_OPACITY_OPAQUE,
GIMP_PARAM_WRITABLE |
G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class, PROP_PAINT_MODE,
g_param_spec_enum ("paint-mode", NULL, NULL,
GIMP_TYPE_LAYER_MODE,
GIMP_LAYER_MODE_NORMAL,
GIMP_PARAM_WRITABLE |
G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class, PROP_SPACING,
g_param_spec_int ("spacing", NULL, NULL,
-G_MAXINT, 1000, -1,
GIMP_PARAM_WRITABLE |
G_PARAM_CONSTRUCT));
}
static void
@ -126,26 +79,10 @@ static void
gimp_brush_select_constructed (GObject *object)
{
GimpPdbDialog *dialog = GIMP_PDB_DIALOG (object);
GimpBrushSelect *select = GIMP_BRUSH_SELECT (object);
GtkWidget *content_area;
GtkWidget *vbox;
GtkWidget *scale;
GtkWidget *hbox;
GtkWidget *label;
GtkAdjustment *spacing_adj;
G_OBJECT_CLASS (parent_class)->constructed (object);
gimp_context_set_opacity (dialog->context, select->initial_opacity);
gimp_context_set_paint_mode (dialog->context, select->initial_mode);
g_signal_connect (dialog->context, "opacity-changed",
G_CALLBACK (gimp_brush_select_opacity_changed),
dialog);
g_signal_connect (dialog->context, "paint-mode-changed",
G_CALLBACK (gimp_brush_select_mode_changed),
dialog);
dialog->view =
gimp_brush_factory_view_new (GIMP_VIEW_TYPE_GRID,
dialog->context->gimp->brush_factory,
@ -163,93 +100,6 @@ gimp_brush_select_constructed (GObject *object)
content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
gtk_box_pack_start (GTK_BOX (content_area), dialog->view, TRUE, TRUE, 0);
gtk_widget_show (dialog->view);
vbox = GTK_WIDGET (GIMP_CONTAINER_EDITOR (dialog->view)->view);
/* Create the opacity scale widget */
select->opacity_data =
gtk_adjustment_new (gimp_context_get_opacity (dialog->context) * 100.0,
0.0, 100.0,
1.0, 10.0, 0.0);
scale = gimp_spin_scale_new (select->opacity_data,
_("Opacity"), 1);
gimp_spin_scale_set_constrain_drag (GIMP_SPIN_SCALE (scale), TRUE);
gtk_box_pack_end (GTK_BOX (vbox), scale, FALSE, FALSE, 0);
gtk_widget_show (scale);
g_signal_connect (select->opacity_data, "value-changed",
G_CALLBACK (gimp_brush_select_opacity_update),
select);
/* Create the paint mode option menu */
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
gtk_box_pack_end (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
gtk_widget_show (hbox);
label = gtk_label_new (_("Mode:"));
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
gtk_widget_show (label);
select->layer_mode_box = gimp_layer_mode_box_new (GIMP_LAYER_MODE_CONTEXT_PAINT);
gtk_box_pack_start (GTK_BOX (hbox), select->layer_mode_box, TRUE, TRUE, 0);
gtk_widget_show (select->layer_mode_box);
g_object_bind_property (G_OBJECT (dialog->context), "paint-mode",
G_OBJECT (select->layer_mode_box), "layer-mode",
G_BINDING_BIDIRECTIONAL |
G_BINDING_SYNC_CREATE);
spacing_adj = GIMP_BRUSH_FACTORY_VIEW (dialog->view)->spacing_adjustment;
/* Use passed spacing instead of brushes default */
if (select->spacing >= 0)
gtk_adjustment_set_value (spacing_adj, select->spacing);
g_signal_connect (dialog->view, "spacing-changed",
G_CALLBACK (gimp_brush_select_spacing_update),
select);
}
static void
gimp_brush_select_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GimpPdbDialog *dialog = GIMP_PDB_DIALOG (object);
GimpBrushSelect *select = GIMP_BRUSH_SELECT (object);
switch (property_id)
{
case PROP_OPACITY:
if (dialog->view)
gimp_context_set_opacity (dialog->context, g_value_get_double (value));
else
select->initial_opacity = g_value_get_double (value);
break;
case PROP_PAINT_MODE:
if (dialog->view)
gimp_context_set_paint_mode (dialog->context, g_value_get_enum (value));
else
select->initial_mode = g_value_get_enum (value);
break;
case PROP_SPACING:
if (dialog->view)
{
if (g_value_get_int (value) >= 0)
gtk_adjustment_set_value (GIMP_BRUSH_FACTORY_VIEW (dialog->view)->spacing_adjustment,
g_value_get_int (value));
}
else
{
select->spacing = g_value_get_int (value);
}
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static GimpValueArray *
@ -279,9 +129,6 @@ gimp_brush_select_run_callback (GimpPdbDialog *dialog,
NULL, error,
dialog->callback_name,
GIMP_TYPE_RESOURCE, object,
G_TYPE_DOUBLE, gimp_context_get_opacity (dialog->context) * 100.0,
G_TYPE_INT, GIMP_BRUSH_SELECT (dialog)->spacing,
GIMP_TYPE_LAYER_MODE, gimp_context_get_paint_mode (dialog->context),
G_TYPE_INT, gimp_brush_get_width (brush),
G_TYPE_INT, gimp_brush_get_height (brush),
G_TYPE_BYTES, bytes,
@ -294,51 +141,3 @@ gimp_brush_select_run_callback (GimpPdbDialog *dialog,
return return_vals;
}
static void
gimp_brush_select_opacity_changed (GimpContext *context,
gdouble opacity,
GimpBrushSelect *select)
{
g_signal_handlers_block_by_func (select->opacity_data,
gimp_brush_select_opacity_update,
select);
gtk_adjustment_set_value (select->opacity_data, opacity * 100.0);
g_signal_handlers_unblock_by_func (select->opacity_data,
gimp_brush_select_opacity_update,
select);
gimp_pdb_dialog_run_callback ((GimpPdbDialog **) &select, FALSE);
}
static void
gimp_brush_select_mode_changed (GimpContext *context,
GimpLayerMode paint_mode,
GimpBrushSelect *select)
{
gimp_pdb_dialog_run_callback ((GimpPdbDialog **) &select, FALSE);
}
static void
gimp_brush_select_opacity_update (GtkAdjustment *adjustment,
GimpBrushSelect *select)
{
gimp_context_set_opacity (GIMP_PDB_DIALOG (select)->context,
gtk_adjustment_get_value (adjustment) / 100.0);
}
static void
gimp_brush_select_spacing_update (GimpBrushFactoryView *view,
GimpBrushSelect *select)
{
gdouble value = gtk_adjustment_get_value (view->spacing_adjustment);
if (select->spacing != value)
{
select->spacing = value;
gimp_pdb_dialog_run_callback ((GimpPdbDialog **) &select, FALSE);
}
}

View File

@ -39,13 +39,6 @@ typedef struct _GimpBrushSelectClass GimpBrushSelectClass;
struct _GimpBrushSelect
{
GimpPdbDialog parent_instance;
gdouble initial_opacity;
GimpLayerMode initial_mode;
gint spacing;
GtkAdjustment *opacity_data;
GtkWidget *layer_mode_box;
};
struct _GimpBrushSelectClass

View File

@ -146,6 +146,7 @@ gimp_resource_chooser_class_init (GimpResourceChooserClass *klass)
object_class->get_property = gimp_resource_chooser_get_property;
klass->resource_set = NULL;
klass->draw_interior = NULL;
/**
* GimpResourceChooser:title:

View File

@ -139,25 +139,6 @@ create_callback_PDB_procedure_params (GimpProcedure *procedure,
}
else if (g_type_is_a (resource_type, GIMP_TYPE_BRUSH))
{
gimp_procedure_add_double_argument (procedure, "opacity",
"Opacity",
NULL,
0.0, 100.0, 100.0,
G_PARAM_READWRITE);
gimp_procedure_add_int_argument (procedure, "spacing",
"Spacing",
NULL,
-1, 1000, 20,
G_PARAM_READWRITE);
gimp_procedure_add_enum_argument (procedure, "paint-mode",
"Paint mode",
NULL,
GIMP_TYPE_LAYER_MODE,
GIMP_LAYER_MODE_NORMAL,
G_PARAM_READWRITE);
gimp_procedure_add_int_argument (procedure, "mask-width",
"Brush width",
NULL,