1
1
mirror of https://gitlab.gnome.org/GNOME/gimp.git synced 2025-10-05 21:02:42 +02:00

app, pdb: fix #13480 inconsistent use of maximum radius...

for generated brushes.
The maximum radius we allowed for generated brushes was not used
consistently everywhere.
In the API call we clamped it to 0.0-32767.0, while the param_spec
set min and max to 0.1 and 4000.0, and the brush editor used a
maximum of 1000.0.
Using a large value (probably anything larger than 4000) would
sooner or later lead to a crash.

Instead of manual changes everywhere, let's define a maximum and
minimum in one place and use that wherever we need the min/max values.
Use the values as set in the param_spec for the defines.
The only place we can't easily do that is in brush.pdb, so we add
a comment above our defines that the values need updating there too.

Actually we should probably use more defines for other values too,
that way there is less chance of min/max values getting out of synch
throughout our code.
This commit is contained in:
Jacob Boerema
2025-03-31 15:54:44 -04:00
parent e67a99b275
commit 5273f26ef0
7 changed files with 17 additions and 8 deletions

View File

@@ -719,7 +719,7 @@ context_brush_radius_cmd_callback (GimpAction *action,
radius = action_select_value (select_type,
radius,
min_radius, 4000.0, min_radius,
min_radius, GIMP_BRUSH_GENERATED_MAX_RADIUS, min_radius,
0.1, 1.0, 10.0, 0.05, FALSE);
gimp_brush_generated_set_radius (generated, radius);

View File

@@ -141,7 +141,9 @@ gimp_brush_generated_class_init (GimpBrushGeneratedClass *klass)
g_object_class_install_property (object_class, PROP_RADIUS,
g_param_spec_double ("radius", NULL,
_("Brush Radius"),
0.1, 4000.0, 5.0,
GIMP_BRUSH_GENERATED_MIN_RADIUS,
GIMP_BRUSH_GENERATED_MAX_RADIUS,
5.0,
GIMP_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
@@ -733,7 +735,7 @@ gimp_brush_generated_set_radius (GimpBrushGenerated *brush,
{
g_return_val_if_fail (GIMP_IS_BRUSH_GENERATED (brush), -1.0);
radius = CLAMP (radius, 0.0, 32767.0);
radius = CLAMP (radius, GIMP_BRUSH_GENERATED_MIN_RADIUS, GIMP_BRUSH_GENERATED_MAX_RADIUS);
if (brush->radius != radius)
{

View File

@@ -32,6 +32,10 @@
#define GIMP_BRUSH_GENERATED_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_BRUSH_GENERATED, GimpBrushGeneratedClass))
/* When changing these values, also update it in pdb/groups/brush.pdb */
#define GIMP_BRUSH_GENERATED_MIN_RADIUS 0.1
#define GIMP_BRUSH_GENERATED_MAX_RADIUS 4000.0
typedef struct _GimpBrushGeneratedClass GimpBrushGeneratedClass;
struct _GimpBrushGenerated

View File

@@ -1144,7 +1144,7 @@ register_brush_procs (GimpPDB *pdb)
"gimp-brush-set-radius");
gimp_procedure_set_static_help (procedure,
"Sets the radius of a generated brush.",
"Sets the radius for a generated brush. Clamps radius to [0.0, 32767.0]. Returns the clamped value. Returns an error when brush is non-parametric or not editable.",
"Sets the radius for a generated brush. Clamps radius to [0.1, 4000.0]. Returns the clamped value. Returns an error when brush is non-parametric or not editable.",
NULL);
gimp_procedure_set_static_attribution (procedure,
"Bill Skaggs <weskaggs@primate.ucdavis.edu>",

View File

@@ -150,7 +150,10 @@ gimp_brush_editor_init (GimpBrushEditor *editor)
gtk_widget_show (box);
/* brush radius scale */
editor->radius_data = gtk_adjustment_new (0.0, 0.1, 1000.0, 1.0, 10.0, 0.0);
editor->radius_data = gtk_adjustment_new (0.0,
GIMP_BRUSH_GENERATED_MIN_RADIUS,
GIMP_BRUSH_GENERATED_MAX_RADIUS,
1.0, 10.0, 0.0);
scale = gimp_spin_scale_new (editor->radius_data, _("Radius"), 1);
gtk_box_pack_start (GTK_BOX (editor->options_box), scale, FALSE, FALSE, 0);
gtk_widget_show (scale);

View File

@@ -494,8 +494,8 @@ gimp_brush_get_radius (GimpBrush *brush,
*
* Sets the radius of a generated brush.
*
* Sets the radius for a generated brush. Clamps radius to [0.0,
* 32767.0]. Returns the clamped value. Returns an error when brush is
* Sets the radius for a generated brush. Clamps radius to [0.1,
* 4000.0]. Returns the clamped value. Returns an error when brush is
* non-parametric or not editable.
*
* Returns: TRUE on success.

View File

@@ -542,7 +542,7 @@ sub brush_set_radius {
$help = <<'HELP';
Sets the radius for a generated brush.
Clamps radius to [0.0, 32767.0].
Clamps radius to [0.1, 4000.0].
Returns the clamped value.
Returns an error when brush is non-parametric or not editable.
HELP