transformtool: Add the bunch of 8 separate options for 3 things

This commit is contained in:
Mikael Magnusson 2012-08-11 14:42:39 +02:00
parent 03117bdf40
commit f84987de73
6 changed files with 164 additions and 84 deletions

View File

@ -342,7 +342,7 @@ gimp_rotate_tool_motion (GimpTransformTool *tr_tool)
}
/* constrain the angle to 15-degree multiples if ctrl is held down */
if (options->constrain)
if (options->constrain_rotate)
{
tr_tool->trans_info[ANGLE] =
FIFTEEN_DEG * (gint) ((tr_tool->trans_info[REAL_ANGLE] +

View File

@ -139,7 +139,7 @@ gimp_scale_tool_dialog_update (GimpTransformTool *tr_tool)
g_object_set (GIMP_SCALE_TOOL (tr_tool)->box,
"width", width,
"height", height,
"keep-aspect", options->constrain,
"keep-aspect", options->constrain_scale,
NULL);
}
@ -175,7 +175,7 @@ gimp_scale_tool_prepare (GimpTransformTool *tr_tool)
g_object_new (GIMP_TYPE_SIZE_BOX,
"width", tr_tool->x2 - tr_tool->x1,
"height", tr_tool->y2 - tr_tool->y1,
"keep-aspect", options->constrain,
"keep-aspect", options->constrain_scale,
"unit", gimp_display_get_shell (display)->unit,
"xresolution", xres,
"yresolution", yres,
@ -267,7 +267,7 @@ gimp_scale_tool_motion (GimpTransformTool *tr_tool)
*y1 += diff_y;
/* if control is being held, constrain the aspect ratio */
if (options->constrain)
if (options->constrain_scale)
{
/* FIXME: improve this */
gdouble h = tr_tool->trans_info[Y1] - tr_tool->trans_info[Y0];
@ -384,7 +384,7 @@ gimp_scale_tool_size_notify (GtkWidget *box,
"keep-aspect", &constrain,
NULL);
if (constrain != options->constrain)
if (constrain != options->constrain_scale)
{
gint width;
gint height;
@ -400,7 +400,7 @@ gimp_scale_tool_size_notify (GtkWidget *box,
tr_tool->aspect = (gdouble) width / (gdouble) height;
g_object_set (options,
"constrain", constrain,
"constrain-scale", constrain,
NULL);
}
}

View File

@ -53,10 +53,14 @@ enum
PROP_PREVIEW_OPACITY,
PROP_GRID_TYPE,
PROP_GRID_SIZE,
PROP_CONSTRAIN,
PROP_KEEPASPECT,
PROP_FROMPIVOT,
PROP_FREESHEAR,
PROP_CONSTRAIN_MOVE,
PROP_CONSTRAIN_SCALE,
PROP_CONSTRAIN_ROTATE,
PROP_CONSTRAIN_SHEAR,
PROP_CONSTRAIN_PERSPECTIVE,
PROP_FROMPIVOT_SCALE,
PROP_FROMPIVOT_SHEAR,
PROP_FROMPIVOT_PERSPECTIVE,
PROP_CORNERSNAP,
PROP_FIXEDPIVOT,
};
@ -140,23 +144,43 @@ gimp_transform_options_class_init (GimpTransformOptionsClass *klass)
N_("Size of a grid cell for variable number of composition guides"),
1, 128, 15,
GIMP_PARAM_STATIC_STRINGS);
GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_CONSTRAIN,
"constrain",
GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_CONSTRAIN_MOVE,
"constrain-move",
NULL,
FALSE,
GIMP_PARAM_STATIC_STRINGS);
GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_KEEPASPECT,
"keepaspect",
GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_CONSTRAIN_SCALE,
"constrain-scale",
NULL,
FALSE,
GIMP_PARAM_STATIC_STRINGS);
GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_FROMPIVOT,
"frompivot",
GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_CONSTRAIN_ROTATE,
"constrain-rotate",
NULL,
FALSE,
GIMP_PARAM_STATIC_STRINGS);
GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_FREESHEAR,
"freeshear",
GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_CONSTRAIN_SHEAR,
"constrain-shear",
NULL,
TRUE,
GIMP_PARAM_STATIC_STRINGS);
GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_CONSTRAIN_PERSPECTIVE,
"constrain-perspective",
NULL,
FALSE,
GIMP_PARAM_STATIC_STRINGS);
GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_FROMPIVOT_SCALE,
"frompivot-scale",
NULL,
FALSE,
GIMP_PARAM_STATIC_STRINGS);
GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_FROMPIVOT_SHEAR,
"frompivot-shear",
NULL,
FALSE,
GIMP_PARAM_STATIC_STRINGS);
GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_FROMPIVOT_PERSPECTIVE,
"frompivot-perspective",
NULL,
FALSE,
GIMP_PARAM_STATIC_STRINGS);
@ -212,17 +236,29 @@ gimp_transform_options_set_property (GObject *object,
case PROP_GRID_SIZE:
options->grid_size = g_value_get_int (value);
break;
case PROP_CONSTRAIN:
options->constrain = g_value_get_boolean (value);
case PROP_CONSTRAIN_MOVE:
options->constrain_move = g_value_get_boolean (value);
break;
case PROP_KEEPASPECT:
options->keepaspect = g_value_get_boolean (value);
case PROP_CONSTRAIN_SCALE:
options->constrain_scale = g_value_get_boolean (value);
break;
case PROP_FROMPIVOT:
options->frompivot = g_value_get_boolean (value);
case PROP_CONSTRAIN_ROTATE:
options->constrain_rotate = g_value_get_boolean (value);
break;
case PROP_FREESHEAR:
options->freeshear = g_value_get_boolean (value);
case PROP_CONSTRAIN_SHEAR:
options->constrain_shear = g_value_get_boolean (value);
break;
case PROP_CONSTRAIN_PERSPECTIVE:
options->constrain_perspective = g_value_get_boolean (value);
break;
case PROP_FROMPIVOT_SCALE:
options->frompivot_scale = g_value_get_boolean (value);
break;
case PROP_FROMPIVOT_SHEAR:
options->frompivot_shear = g_value_get_boolean (value);
break;
case PROP_FROMPIVOT_PERSPECTIVE:
options->frompivot_perspective = g_value_get_boolean (value);
break;
case PROP_CORNERSNAP:
options->cornersnap = g_value_get_boolean (value);
@ -270,17 +306,29 @@ gimp_transform_options_get_property (GObject *object,
case PROP_GRID_SIZE:
g_value_set_int (value, options->grid_size);
break;
case PROP_CONSTRAIN:
g_value_set_boolean (value, options->constrain);
case PROP_CONSTRAIN_MOVE:
g_value_set_boolean (value, options->constrain_move);
break;
case PROP_KEEPASPECT:
g_value_set_boolean (value, options->keepaspect);
case PROP_CONSTRAIN_SCALE:
g_value_set_boolean (value, options->constrain_scale);
break;
case PROP_FROMPIVOT:
g_value_set_boolean (value, options->frompivot);
case PROP_CONSTRAIN_ROTATE:
g_value_set_boolean (value, options->constrain_rotate);
break;
case PROP_FREESHEAR:
g_value_set_boolean (value, options->freeshear);
case PROP_CONSTRAIN_SHEAR:
g_value_set_boolean (value, options->constrain_shear);
break;
case PROP_CONSTRAIN_PERSPECTIVE:
g_value_set_boolean (value, options->constrain_perspective);
break;
case PROP_FROMPIVOT_SCALE:
g_value_set_boolean (value, options->frompivot_scale);
break;
case PROP_FROMPIVOT_SHEAR:
g_value_set_boolean (value, options->frompivot_shear);
break;
case PROP_FROMPIVOT_PERSPECTIVE:
g_value_set_boolean (value, options->frompivot_perspective);
break;
case PROP_CORNERSNAP:
g_value_set_boolean (value, options->cornersnap);
@ -329,6 +377,7 @@ gimp_transform_options_gui (GimpToolOptions *tool_options)
GtkWidget *combo;
GtkWidget *scale;
GtkWidget *grid_box;
const gchar *constrain_name = NULL;
const gchar *constrain_label = NULL;
const gchar *constrain_tip = NULL;
@ -405,26 +454,17 @@ gimp_transform_options_gui (GimpToolOptions *tool_options)
if (tool_options->tool_info->tool_type == GIMP_TYPE_ROTATE_TOOL)
{
constrain_name = "constrain-rotate";
constrain_label = _("15 degrees (%s)");
constrain_tip = _("Limit rotation steps to 15 degrees");
}
else if (tool_options->tool_info->tool_type == GIMP_TYPE_SCALE_TOOL)
{
constrain_name = "constrain-scale";
constrain_label = _("Keep aspect (%s)");
constrain_tip = _("Keep the original aspect ratio");
}
/* The constrain behaviour is not what is in the spec, it would make the help labels essays */
/* spec:
* constrain move,rotate,perspective = ctrl
* from centre scale,shear = ctrl
* centre/corner rotate = ctrl
* keep aspect scale = shift
* free shear = shift
* real life:
* constrain move,rotate,perspective,scale(aspect),shear,rotation axis = ctrl
* from centre scale, shear = shift
*/
//TODO: check that the selection tools use the gimp_get_*_mask() functions for constrain/etc or change to what they use
else if (tool_options->tool_info->tool_type == GIMP_TYPE_UNIFIED_TRANSFORM_TOOL)
{
@ -434,27 +474,52 @@ gimp_transform_options_gui (GimpToolOptions *tool_options)
GdkModifierType mod;
gchar *name;
gchar *desc;
gchar *tip;
} opt_list[] = {
{ shift, "constrain", "Constrain movement (%s)" },
{ shift, "keepaspect", "Keep aspect (%s)" },
{ ctrl, "frompivot", "Scale from pivot / Symmetric shearing (%s)" },
{ shift, "freeshear", "Move edge freely in shearing (%s)" },
{ shift, "cornersnap", "Snap pivot point to corners/center (%s)" },
{ 0, "fixedpivot", "Lock pivot to canvas" },
{ shift, NULL, "Constrain (%s)" },
{ shift, "constrain-move", "Move", "Constrain movement to 45 degree angles from center (%s)" },
{ shift, "constrain-scale", "Scale", "Maintain aspect ratio when scaling (%s)" },
{ shift, "constrain-rotate", "Rotate", "Constrain rotation to 15 degree increments (%s)" },
{ shift, "constrain-shear", "Shear", "Shear along edge direction only (%s)" },
{ shift, "constrain-perspective", "Perspective", "Constrain perspective handles to move along edges and diagonal (%s)" },
{ ctrl, NULL, "From pivot (%s)" },
{ ctrl, "frompivot-scale", "Scale", "Scale from pivot point (%s)" },
{ ctrl, "frompivot-shear", "Shear", "Shear opposite edge by same amount (%s)" },
{ ctrl, "frompivot-perspective", "Perspective", "Maintain position of pivot while changing perspective (%s)" },
{ 0, NULL, "Pivot" },
{ shift, "cornersnap", "Snap (%s)", "Snap pivot to corners and center (%s)" },
{ 0, "fixedpivot", "Lock", "Lock pivot position to canvas" },
};
GtkWidget *button;
gchar *label;
gint i;
for (i = 0; i < 6; i++)
for (i = 0; i < 13; i++)
{
label = g_strdup_printf (opt_list[i].desc,
gimp_get_mod_string (opt_list[i].mod));
button = gimp_prop_check_button_new (config, opt_list[i].name, label);
gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
gtk_widget_show (button);
if (opt_list[i].name)
{
button = gimp_prop_check_button_new (config, opt_list[i].name, label);
gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
gtk_widget_show (button);
g_free (label);
label = g_strdup_printf (opt_list[i].tip,
gimp_get_mod_string (opt_list[i].mod));
gimp_help_set_help_data (button, label, NULL);
}
else
{
button = gtk_label_new (label);
gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
gtk_widget_show (button);
}
g_free (label);
}
@ -466,12 +531,12 @@ gimp_transform_options_gui (GimpToolOptions *tool_options)
gchar *label;
GdkModifierType constrain_mask;
constrain_mask = gimp_get_constrain_behavior_mask ();
constrain_mask = gimp_get_extend_selection_mask ();
label = g_strdup_printf (constrain_label,
gimp_get_mod_string (constrain_mask));
button = gimp_prop_check_button_new (config, "constrain", label);
button = gimp_prop_check_button_new (config, constrain_name, label);
gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
gtk_widget_show (button);

View File

@ -46,10 +46,14 @@ struct _GimpTransformOptions
gdouble preview_opacity;
GimpGuidesType grid_type;
gint grid_size;
gboolean constrain;
gboolean keepaspect;
gboolean frompivot;
gboolean freeshear;
gboolean constrain_move;
gboolean constrain_scale;
gboolean constrain_rotate;
gboolean constrain_shear;
gboolean constrain_perspective;
gboolean frompivot_scale;
gboolean frompivot_shear;
gboolean frompivot_perspective;
gboolean cornersnap;
gboolean fixedpivot;
};

View File

@ -492,7 +492,13 @@ gimp_transform_tool_modifier_key (GimpTool *tool,
if (key == gimp_get_constrain_behavior_mask ())
{
g_object_set (options,
"frompivot", ! options->frompivot,
"frompivot-scale", ! options->frompivot_scale,
NULL);
g_object_set (options,
"frompivot-shear", ! options->frompivot_shear,
NULL);
g_object_set (options,
"frompivot-perspective", ! options->frompivot_perspective,
NULL);
}
@ -501,14 +507,21 @@ gimp_transform_tool_modifier_key (GimpTool *tool,
g_object_set (options,
"cornersnap", ! options->cornersnap,
NULL);
g_object_set (options,
"constrain", ! options->constrain,
"constrain-move", ! options->constrain_move,
NULL);
g_object_set (options,
"keepaspect", ! options->keepaspect,
"constrain-scale", ! options->constrain_scale,
NULL);
g_object_set (options,
"freeshear", ! options->freeshear,
"constrain-rotate", ! options->constrain_rotate,
NULL);
g_object_set (options,
"constrain-shear", ! options->constrain_shear,
NULL);
g_object_set (options,
"constrain-perspective", ! options->constrain_perspective,
NULL);
}
}
@ -742,7 +755,10 @@ gimp_transform_tool_options_notify (GimpTool *tool,
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tr_tool));
}
if (! strcmp (pspec->name, "constrain") || ! strcmp (pspec->name, "alternate"))
if (g_str_has_prefix (pspec->name, "constrain-") ||
g_str_has_prefix (pspec->name, "frompivot-") ||
! strcmp (pspec->name, "fixedpivot") ||
! strcmp (pspec->name, "cornersnap"))
{
gimp_transform_tool_dialog_update (tr_tool);
}

View File

@ -585,11 +585,6 @@ gimp_unified_transform_tool_motion (GimpTransformTool *transform_tool)
GimpTransformOptions *options = GIMP_TRANSFORM_TOOL_GET_OPTIONS (transform_tool);
gboolean constrain = options->constrain;
gboolean keepaspect = options->keepaspect;
gboolean frompivot = options->frompivot;
gboolean freeshear = options->freeshear;
gboolean cornersnap = options->cornersnap;
gboolean fixedpivot = options->fixedpivot;
TransformAction function = transform_tool->function;
@ -617,7 +612,7 @@ gimp_unified_transform_tool_motion (GimpTransformTool *transform_tool)
/* move */
if (function == TRANSFORM_HANDLE_CENTER)
{
if (constrain)
if (options->constrain_move)
{
/* snap to 45 degree vectors from starting point */
gdouble angle = 16. * calcangle ((GimpVector2){1., 0.}, d) / (2.*G_PI);
@ -653,7 +648,7 @@ gimp_unified_transform_tool_motion (GimpTransformTool *transform_tool)
if (function == TRANSFORM_HANDLE_ROTATION)
{
gdouble angle = calcangle (vectorsubtract (cur, pivot), vectorsubtract (mouse, pivot));
if (constrain)
if (options->constrain_rotate)
{
/* round to 15 degree multiple */
angle /= 2*G_PI/24.;
@ -671,7 +666,7 @@ gimp_unified_transform_tool_motion (GimpTransformTool *transform_tool)
{
gint screenx, screeny;
if (cornersnap)
if (options->cornersnap)
{
/* snap to corner points and center */
gint closest = 0;
@ -723,7 +718,7 @@ gimp_unified_transform_tool_motion (GimpTransformTool *transform_tool)
/* when the keep aspect transformation constraint is enabled, the
* translation shall only be along the diagonal that runs trough
* this corner point. */
if (keepaspect)
if (options->constrain_scale)
{
/* restrict to movement along the diagonal */
GimpVector2 diag = vectorsubtract (oldpos[this], oldpos[opposite]);
@ -776,7 +771,7 @@ gimp_unified_transform_tool_motion (GimpTransformTool *transform_tool)
*
*/
if (frompivot && transform_is_convex (newpos))
if (options->frompivot_scale && transform_is_convex (newpos))
{
/* transform the pivot point before the interaction and after, and move everything by
* this difference */
@ -818,12 +813,12 @@ gimp_unified_transform_tool_motion (GimpTransformTool *transform_tool)
/* restrict to movement along the midline */
d = vectorproject (d, midline);
if (keepaspect)
if (options->constrain_scale)
{
GimpVector2 before, after, effective_pivot = pivot;
gdouble distance;
if (!frompivot)
if (!options->frompivot_scale)
{
/* center of the opposite side is pivot */
effective_pivot = scalemult (vectoradd (oldpos[opp_l], oldpos[opp_r]), 0.5);
@ -848,7 +843,7 @@ gimp_unified_transform_tool_motion (GimpTransformTool *transform_tool)
newpos[this_r] = vectoradd (oldpos[this_r], d);
}
if (!keepaspect && frompivot && transform_is_convex (newpos))
if (!options->constrain_scale && options->frompivot_scale && transform_is_convex (newpos))
{
GimpVector2 delta = getpivotdelta (transform_tool, oldpos, newpos, pivot);
for (i = 0; i < 4; i++)
@ -881,12 +876,12 @@ gimp_unified_transform_tool_motion (GimpTransformTool *transform_tool)
opp_l = 3 - this_l;
opp_r = 3 - this_r;
if (frompivot)
if (options->frompivot_shear)
po = vectorsubtract (zero, d);
else
po = zero;
if (!freeshear)
if (options->constrain_shear)
{
/* restrict to movement along the side */
GimpVector2 side = vectorsubtract (oldpos[this_r], oldpos[this_l]);
@ -894,7 +889,7 @@ gimp_unified_transform_tool_motion (GimpTransformTool *transform_tool)
d = vectorproject (d, side);
}
if (!freeshear && frompivot)
if (options->constrain_shear && options->frompivot_shear)
{
/* restrict to movement along the opposite side */
GimpVector2 side = vectorsubtract (oldpos[opp_r], oldpos[opp_l]);
@ -929,7 +924,7 @@ gimp_unified_transform_tool_motion (GimpTransformTool *transform_tool)
this = 3; left = 2; right = 1; opposite = 0;
} else g_assert_not_reached ();
if (constrain)
if (options->constrain_perspective)
{ /* when the constrain transformation constraint is enabled, the
translation shall only be either along the side angles of the
two sides that run to this corner point, or along the
@ -959,7 +954,7 @@ gimp_unified_transform_tool_motion (GimpTransformTool *transform_tool)
newpos[this] = vectoradd (oldpos[this], d);
if (frompivot && transform_is_convex (newpos))
if (options->frompivot_perspective && transform_is_convex (newpos))
{
GimpVector2 delta = getpivotdelta (transform_tool, oldpos, newpos, pivot);