app: make GimpToolTransformGrid handle modifiers itself

and update the grid as soon as a constraint is changed, not only on
the next motion. Change GimpTransformTool to forward the events to the
widget if it exists, but still handle them if it doesn't (yes this
code duplication is ugly, but the widget can hardly handle events if
it doesn't exist...).
This commit is contained in:
Michael Natterer 2017-07-15 19:34:08 +02:00
parent 0a5251c97a
commit 4208aceafe
2 changed files with 115 additions and 6 deletions

View File

@ -34,6 +34,8 @@
#include "core/gimp-transform-utils.h"
#include "core/gimp-utils.h"
#include "widgets/gimpwidgets-utils.h"
#include "gimpcanvashandle.h"
#include "gimpcanvastransformguides.h"
#include "gimpdisplayshell.h"
@ -170,6 +172,14 @@ static void gimp_tool_transform_grid_hover (GimpToolWidget *
const GimpCoords *coords,
GdkModifierType state,
gboolean proximity);
static void gimp_tool_transform_grid_motion_modifier(GimpToolWidget *widget,
GdkModifierType key,
gboolean press,
GdkModifierType state);
static void gimp_tool_transform_grid_hover_modifier (GimpToolWidget *widget,
GdkModifierType key,
gboolean press,
GdkModifierType state);
static gboolean gimp_tool_transform_grid_get_cursor (GimpToolWidget *widget,
const GimpCoords *coords,
GdkModifierType state,
@ -206,6 +216,8 @@ gimp_tool_transform_grid_class_init (GimpToolTransformGridClass *klass)
widget_class->button_release = gimp_tool_transform_grid_button_release;
widget_class->motion = gimp_tool_transform_grid_motion;
widget_class->hover = gimp_tool_transform_grid_hover;
widget_class->motion_modifier = gimp_tool_transform_grid_motion_modifier;
widget_class->hover_modifier = gimp_tool_transform_grid_hover_modifier;
widget_class->get_cursor = gimp_tool_transform_grid_get_cursor;
g_object_class_install_property (object_class, PROP_TRANSFORM,
@ -1904,6 +1916,61 @@ gimp_tool_transform_grid_hover (GimpToolWidget *widget,
gimp_tool_transform_grid_update_hilight (grid);
}
static void
gimp_tool_transform_grid_modifier (GimpToolWidget *widget,
GdkModifierType key)
{
GimpToolTransformGrid *grid = GIMP_TOOL_TRANSFORM_GRID (widget);
GimpToolTransformGridPrivate *private = grid->private;
if (key == gimp_get_constrain_behavior_mask ())
{
g_object_set (widget,
"frompivot-scale", ! private->frompivot_scale,
"frompivot-shear", ! private->frompivot_shear,
"frompivot-perspective", ! private->frompivot_perspective,
NULL);
}
else if (key == gimp_get_extend_selection_mask ())
{
g_object_set (widget,
"cornersnap", ! private->cornersnap,
"constrain-move", ! private->constrain_move,
"constrain-scale", ! private->constrain_scale,
"constrain-rotate", ! private->constrain_rotate,
"constrain-shear", ! private->constrain_shear,
"constrain-perspective", ! private->constrain_perspective,
NULL);
}
}
static void
gimp_tool_transform_grid_motion_modifier (GimpToolWidget *widget,
GdkModifierType key,
gboolean press,
GdkModifierType state)
{
GimpToolTransformGrid *grid = GIMP_TOOL_TRANSFORM_GRID (widget);
GimpToolTransformGridPrivate *private = grid->private;
GimpCoords coords = { 0.0, };
gimp_tool_transform_grid_modifier (widget, key);
/* send a non-motion to update the grid with the new constraints */
coords.x = private->curx;
coords.y = private->cury;
gimp_tool_transform_grid_motion (widget, &coords, 0, state);
}
static void
gimp_tool_transform_grid_hover_modifier (GimpToolWidget *widget,
GdkModifierType key,
gboolean press,
GdkModifierType state)
{
gimp_tool_transform_grid_modifier (widget, key);
}
static gboolean
gimp_tool_transform_grid_get_cursor (GimpToolWidget *widget,
const GimpCoords *coords,

View File

@ -91,6 +91,11 @@ static void gimp_transform_tool_modifier_key (GimpTool
gboolean press,
GdkModifierType state,
GimpDisplay *display);
static void gimp_transform_tool_active_modifier_key (GimpTool *tool,
GdkModifierType key,
gboolean press,
GdkModifierType state,
GimpDisplay *display);
static void gimp_transform_tool_cursor_update (GimpTool *tool,
const GimpCoords *coords,
GdkModifierType state,
@ -176,7 +181,7 @@ gimp_transform_tool_class_init (GimpTransformToolClass *klass)
tool_class->button_release = gimp_transform_tool_button_release;
tool_class->motion = gimp_transform_tool_motion;
tool_class->modifier_key = gimp_transform_tool_modifier_key;
tool_class->active_modifier_key = gimp_transform_tool_modifier_key;
tool_class->active_modifier_key = gimp_transform_tool_active_modifier_key;
tool_class->cursor_update = gimp_transform_tool_cursor_update;
tool_class->can_undo = gimp_transform_tool_can_undo;
tool_class->can_redo = gimp_transform_tool_can_redo;
@ -440,11 +445,8 @@ gimp_transform_tool_motion (GimpTool *tool,
}
static void
gimp_transform_tool_modifier_key (GimpTool *tool,
GdkModifierType key,
gboolean press,
GdkModifierType state,
GimpDisplay *display)
gimp_transform_tool_modifier (GimpTool *tool,
GdkModifierType key)
{
GimpTransformOptions *options = GIMP_TRANSFORM_TOOL_GET_OPTIONS (tool);
@ -469,6 +471,46 @@ gimp_transform_tool_modifier_key (GimpTool *tool,
}
}
static void
gimp_transform_tool_modifier_key (GimpTool *tool,
GdkModifierType key,
gboolean press,
GdkModifierType state,
GimpDisplay *display)
{
GimpTransformTool *tr_tool = GIMP_TRANSFORM_TOOL (tool);
if (tr_tool->widget)
{
GIMP_TOOL_CLASS (parent_class)->modifier_key (tool, key, press,
state, display);
}
else
{
gimp_transform_tool_modifier (tool, key);
}
}
static void
gimp_transform_tool_active_modifier_key (GimpTool *tool,
GdkModifierType key,
gboolean press,
GdkModifierType state,
GimpDisplay *display)
{
GimpTransformTool *tr_tool = GIMP_TRANSFORM_TOOL (tool);
if (tr_tool->widget)
{
GIMP_TOOL_CLASS (parent_class)->active_modifier_key (tool, key, press,
state, display);
}
else
{
gimp_transform_tool_modifier (tool, key);
}
}
static void
gimp_transform_tool_cursor_update (GimpTool *tool,
const GimpCoords *coords,