app: add gimp_transform_tool_set_type()

... which temporarily changes the transform-type of the tool,
restoring the original type once it's halted.  To be used when
activating a transform tool through an action for a specific
transform type.
This commit is contained in:
Ell 2019-08-10 23:55:56 +03:00
parent e4990bee7b
commit f651db52fb
2 changed files with 87 additions and 6 deletions

View File

@ -64,6 +64,10 @@
/* local function prototypes */
static void gimp_transform_tool_control (GimpTool *tool,
GimpToolAction action,
GimpDisplay *display);
static gchar * gimp_transform_tool_real_get_undo_desc (GimpTransformTool *tr_tool);
static GimpTransformDirection gimp_transform_tool_real_get_direction (GimpTransformTool *tr_tool);
static GeglBuffer * gimp_transform_tool_real_transform (GimpTransformTool *tr_tool,
@ -75,6 +79,8 @@ static GeglBuffer * gimp_transform_tool_real_transform (GimpTran
gint *new_offset_x,
gint *new_offset_y);
static void gimp_transform_tool_halt (GimpTransformTool *tr_tool);
static gboolean gimp_transform_tool_confirm (GimpTransformTool *tr_tool,
GimpDisplay *display);
@ -90,6 +96,10 @@ G_DEFINE_TYPE (GimpTransformTool, gimp_transform_tool, GIMP_TYPE_DRAW_TOOL)
static void
gimp_transform_tool_class_init (GimpTransformToolClass *klass)
{
GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass);
tool_class->control = gimp_transform_tool_control;
klass->recalc_matrix = NULL;
klass->get_undo_desc = gimp_transform_tool_real_get_undo_desc;
klass->get_direction = gimp_transform_tool_real_get_direction;
@ -104,6 +114,34 @@ gimp_transform_tool_init (GimpTransformTool *tr_tool)
{
gimp_matrix3_identity (&tr_tool->transform);
tr_tool->transform_valid = TRUE;
tr_tool->restore_type = FALSE;
}
static void
gimp_transform_tool_control (GimpTool *tool,
GimpToolAction action,
GimpDisplay *display)
{
GimpTransformTool *tr_tool = GIMP_TRANSFORM_TOOL (tool);
switch (action)
{
case GIMP_TOOL_ACTION_PAUSE:
break;
case GIMP_TOOL_ACTION_RESUME:
break;
case GIMP_TOOL_ACTION_HALT:
gimp_transform_tool_halt (tr_tool);
break;
case GIMP_TOOL_ACTION_COMMIT:
break;
}
GIMP_TOOL_CLASS (parent_class)->control (tool, action, display);
}
static gchar *
@ -216,6 +254,21 @@ gimp_transform_tool_real_transform (GimpTransformTool *tr_tool,
return ret;
}
static void
gimp_transform_tool_halt (GimpTransformTool *tr_tool)
{
GimpTransformOptions *options = GIMP_TRANSFORM_TOOL_GET_OPTIONS (tr_tool);
if (tr_tool->restore_type)
{
g_object_set (options,
"type", tr_tool->saved_type,
NULL);
tr_tool->restore_type = FALSE;
}
}
static gboolean
gimp_transform_tool_confirm (GimpTransformTool *tr_tool,
GimpDisplay *display)
@ -830,3 +883,25 @@ gimp_transform_tool_transform (GimpTransformTool *tr_tool,
return TRUE;
}
void
gimp_transform_tool_set_type (GimpTransformTool *tr_tool,
GimpTransformType type)
{
GimpTransformOptions *options;
g_return_if_fail (GIMP_IS_TRANSFORM_TOOL (tr_tool));
options = GIMP_TRANSFORM_TOOL_GET_OPTIONS (tr_tool);
if (! tr_tool->restore_type)
tr_tool->saved_type = options->type;
tr_tool->restore_type = FALSE;
g_object_set (options,
"type", type,
NULL);
tr_tool->restore_type = TRUE;
}

View File

@ -54,6 +54,9 @@ struct _GimpTransformTool
GimpMatrix3 transform; /* transformation matrix */
gboolean transform_valid; /* whether the matrix is valid */
gboolean restore_type;
GimpTransformType saved_type;
};
struct _GimpTransformToolClass
@ -94,5 +97,8 @@ void gimp_transform_tool_recalc_matrix (GimpTransformTool *tr_too
gboolean gimp_transform_tool_transform (GimpTransformTool *tr_tool,
GimpDisplay *display);
void gimp_transform_tool_set_type (GimpTransformTool *tr_tool,
GimpTransformType type);
#endif /* __GIMP_TRANSFORM_TOOL_H__ */