app: locking brush size to zoom

This commit is contained in:
Alexia Death 2014-11-13 20:32:59 +02:00
parent e78540e581
commit 9a953a9239
11 changed files with 103 additions and 10 deletions

View File

@ -64,13 +64,18 @@
#define GIMP_COORDS_DEFAULT_DIRECTION 0.0
#define GIMP_COORDS_DEFAULT_XSCALE 1.0
#define GIMP_COORDS_DEFAULT_YSCALE 1.0
#define GIMP_COORDS_DEFAULT_VALUES { 0.0, 0.0, \
GIMP_COORDS_DEFAULT_PRESSURE, \
GIMP_COORDS_DEFAULT_TILT, \
GIMP_COORDS_DEFAULT_TILT, \
GIMP_COORDS_DEFAULT_WHEEL, \
GIMP_COORDS_DEFAULT_VELOCITY, \
GIMP_COORDS_DEFAULT_DIRECTION }
GIMP_COORDS_DEFAULT_DIRECTION,\
GIMP_COORDS_DEFAULT_XSCALE, \
GIMP_COORDS_DEFAULT_YSCALE }
/* base classes */
@ -249,6 +254,8 @@ struct _GimpCoords
gdouble wheel;
gdouble velocity;
gdouble direction;
gdouble xscale; /*some tools my care about the shell they passed through*/
gdouble yscale;
};
/* temp hack as replacement for GdkSegment */

View File

@ -590,7 +590,7 @@ gimp_brush_transform_size (GimpBrush *brush,
((angle == 0.0) || (angle == 0.5) || (angle == 1.0)))
{
*width = gimp_temp_buf_get_width (brush->priv->mask);
*height = gimp_temp_buf_get_height (brush->priv->mask);;
*height = gimp_temp_buf_get_height (brush->priv->mask);
return;
}

View File

@ -21,6 +21,7 @@
#include "gimpdata.h"
#define GIMP_BRUSH_MAX_SIZE 10000.0 /*Max size in either dimension in px*/
#define GIMP_TYPE_BRUSH (gimp_brush_get_type ())
#define GIMP_BRUSH(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_BRUSH, GimpBrush))

View File

@ -322,6 +322,10 @@ gimp_coords_interpolate_catmull (const GimpCoords catmul_pt1,
coords.direction = start_coords.direction + dir_step * n;
coords.direction = coords.direction - floor (coords.direction);
coords.xscale = end_coords.xscale;
coords.yscale = end_coords.yscale;
g_array_append_val (*ret_coords, coords);

View File

@ -569,6 +569,8 @@ gimp_display_shell_canvas_tool_events (GtkWidget *canvas,
last_motion.xtilt = image_coords.xtilt;
last_motion.ytilt = image_coords.ytilt;
last_motion.wheel = image_coords.wheel;
last_motion.xscale = image_coords.xscale;
last_motion.yscale = image_coords.yscale;
image_coords = last_motion;

View File

@ -600,6 +600,10 @@ gimp_display_shell_untransform_coords (const GimpDisplayShell *shell,
image_coords->x /= shell->scale_x;
image_coords->y /= shell->scale_y;
image_coords->xscale = shell->scale_x;
image_coords->yscale = shell->scale_y;
}
/**

View File

@ -323,18 +323,33 @@ gimp_brush_core_pre_paint (GimpPaintCore *paint_core,
if (GIMP_BRUSH_CORE_GET_CLASS (core)->handles_dynamic_transforming_brush)
{
gdouble width;
gdouble height;
fade_point = gimp_paint_options_get_fade (paint_options, image,
paint_core->pixel_dist);
width = gimp_brush_get_width (core->main_brush);
height = gimp_brush_get_height (core->main_brush);
scale = paint_options->brush_size /
MAX (gimp_brush_get_width (core->main_brush),
gimp_brush_get_height (core->main_brush)) *
MAX (width, height) *
gimp_dynamics_get_linear_value (core->dynamics,
GIMP_DYNAMICS_OUTPUT_SIZE,
&current_coords,
paint_options,
fade_point);
if (paint_options->brush_zoom)
{
scale = scale / MAX (current_coords.xscale, current_coords.xscale);
/*Cap transform result for brushes or OOM can occur*/
if ((MAX (width, height)) > GIMP_BRUSH_MAX_SIZE)
{
scale = GIMP_BRUSH_MAX_SIZE / MAX (width, height);
}
}
if (scale < 0.0000001)
return FALSE;
}
@ -730,6 +745,8 @@ gimp_brush_core_interpolate (GimpPaintCore *paint_core,
current_coords.wheel = last_coords.wheel + p * delta_wheel;
current_coords.velocity = last_coords.velocity + p * delta_velocity;
current_coords.direction = temp_direction;
current_coords.xscale = last_coords.xscale;
current_coords.yscale = last_coords.yscale;
if (core->jitter > 0.0)
{
@ -778,6 +795,8 @@ gimp_brush_core_interpolate (GimpPaintCore *paint_core,
current_coords.ytilt = last_coords.ytilt + delta_ytilt;
current_coords.wheel = last_coords.wheel + delta_wheel;
current_coords.velocity = last_coords.velocity + delta_velocity;
current_coords.xscale = last_coords.xscale;
current_coords.yscale = last_coords.yscale;
gimp_paint_core_set_current_coords (paint_core, &current_coords);
gimp_paint_core_set_last_coords (paint_core, &current_coords);
@ -1480,9 +1499,24 @@ gimp_brush_core_eval_transform_dynamics (GimpBrushCore *core,
const GimpCoords *coords)
{
if (core->main_brush)
core->scale = paint_options->brush_size /
MAX (gimp_brush_get_width (core->main_brush),
gimp_brush_get_height (core->main_brush));
{
gdouble max_side;
max_side = MAX (gimp_brush_get_width (core->main_brush),
gimp_brush_get_height (core->main_brush));
core->scale = paint_options->brush_size / max_side;
if (paint_options->brush_zoom && MAX (coords->xscale, coords->yscale) > 0)
{
core->scale /= MAX (coords->xscale, coords->yscale);
/*Cap transform result for brushes or OOM can occur*/
if ((core->scale * max_side) > GIMP_BRUSH_MAX_SIZE)
{
core->scale = GIMP_BRUSH_MAX_SIZE / max_side;
}
}
}
else
core->scale = -1;

View File

@ -40,6 +40,8 @@
#define DEFAULT_BRUSH_SIZE 20.0
#define DEFAULT_BRUSH_ZOOM FALSE
#define DEFAULT_BRUSH_ASPECT_RATIO 0.0
#define DEFAULT_BRUSH_ANGLE 0.0
#define DEFAULT_BRUSH_SPACING 10.0
@ -78,6 +80,7 @@ enum
PROP_USE_APPLICATOR, /* temp debug */
PROP_BRUSH_SIZE,
PROP_BRUSH_ZOOM,
PROP_BRUSH_ASPECT_RATIO,
PROP_BRUSH_ANGLE,
PROP_BRUSH_SPACING,
@ -156,9 +159,15 @@ gimp_paint_options_class_init (GimpPaintOptionsClass *klass)
GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_BRUSH_SIZE,
"brush-size", _("Brush Size"),
1.0, 10000.0, DEFAULT_BRUSH_SIZE,
1.0, GIMP_BRUSH_MAX_SIZE, DEFAULT_BRUSH_SIZE,
GIMP_PARAM_STATIC_STRINGS);
GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_BRUSH_ZOOM,
"brush-zoom", _("Link brush with zoom"),
DEFAULT_BRUSH_ZOOM,
GIMP_PARAM_STATIC_STRINGS);
GIMP_CONFIG_INSTALL_PROP_DOUBLE (object_class, PROP_BRUSH_ASPECT_RATIO,
"brush-aspect-ratio", _("Brush Aspect Ratio"),
-20.0, 20.0, DEFAULT_BRUSH_ASPECT_RATIO,
@ -352,6 +361,10 @@ gimp_paint_options_set_property (GObject *object,
options->brush_size = g_value_get_double (value);
break;
case PROP_BRUSH_ZOOM:
options->brush_zoom = g_value_get_boolean (value);
break;
case PROP_BRUSH_ASPECT_RATIO:
options->brush_aspect_ratio = g_value_get_double (value);
break;
@ -480,6 +493,10 @@ gimp_paint_options_get_property (GObject *object,
g_value_set_double (value, options->brush_size);
break;
case PROP_BRUSH_ZOOM:
g_value_set_boolean (value, options->brush_zoom);
break;
case PROP_BRUSH_ASPECT_RATIO:
g_value_set_double (value, options->brush_aspect_ratio);
break;
@ -797,18 +814,21 @@ gimp_paint_options_copy_brush_props (GimpPaintOptions *src,
gdouble brush_size;
gdouble brush_angle;
gdouble brush_aspect_ratio;
gboolean brush_zoom;
g_return_if_fail (GIMP_IS_PAINT_OPTIONS (src));
g_return_if_fail (GIMP_IS_PAINT_OPTIONS (dest));
g_object_get (src,
"brush-size", &brush_size,
"brush-zoom", &brush_zoom,
"brush-angle", &brush_angle,
"brush-aspect-ratio", &brush_aspect_ratio,
NULL);
g_object_set (dest,
"brush-size", brush_size,
"brush-zoom", brush_zoom,
"brush-angle", brush_angle,
"brush-aspect-ratio", brush_aspect_ratio,
NULL);

View File

@ -83,6 +83,7 @@ struct _GimpPaintOptions
gboolean use_applicator;
gdouble brush_size;
gboolean brush_zoom;
gdouble brush_angle;
gdouble brush_aspect_ratio;
gdouble brush_spacing;

View File

@ -63,6 +63,7 @@ static void gimp_smudge_accumulator_coords (GimpPaintCore *paint_core,
gint *y);
static void gimp_smudge_accumulator_size (GimpPaintOptions *paint_options,
const GimpCoords *coords,
gint *accumulator_size);
@ -174,7 +175,7 @@ gimp_smudge_start (GimpPaintCore *paint_core,
if (! paint_buffer)
return FALSE;
gimp_smudge_accumulator_size (paint_options, &accum_size);
gimp_smudge_accumulator_size (paint_options, coords, &accum_size);
/* Allocate the accumulation buffer */
smudge->accum_buffer = gegl_buffer_new (GEGL_RECTANGLE (0, 0,
@ -344,10 +345,18 @@ gimp_smudge_accumulator_coords (GimpPaintCore *paint_core,
static void
gimp_smudge_accumulator_size (GimpPaintOptions *paint_options,
const GimpCoords *coords,
gint *accumulator_size)
{
gdouble max_view_scale = 1.0;
gdouble max_brush_size;
if (paint_options->brush_zoom)
max_view_scale = MAX (coords->xscale, coords->yscale);
max_brush_size = MIN (paint_options->brush_size / max_view_scale, GIMP_BRUSH_MAX_SIZE);
/* Note: the max brush mask size plus a border of 1 pixel and a
* little headroom
*/
*accumulator_size = ceil (sqrt (2 * SQR (paint_options->brush_size + 1)) + 2);
*accumulator_size = ceil (sqrt (2 * SQR (max_brush_size + 1)) + 2);
}

View File

@ -202,6 +202,17 @@ gimp_paint_options_gui (GimpToolOptions *tool_options)
gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
gtk_widget_show (frame);
}
/* the "Link size to zoom" toggle */
if (g_type_is_a (tool_type, GIMP_TYPE_BRUSH_TOOL))
{
GtkWidget *button;
button = gimp_prop_check_button_new (config,
"brush-zoom",
_("Lock brush size to zoom"));
gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
gtk_widget_show (button);
}
/* the "incremental" toggle */
if (tool_type == GIMP_TYPE_PENCIL_TOOL ||