app: implement readjust() in various transform tools
Implement GimpTransformGridTool::radjust(), added in the previous
commit, in various transform tools:
The unified-transform, scale, and perspective tools readjust the
transformation such that the grid is centered relative to the view,
and its handles are fully within view under arbitrary rotation.
The rotate tool readjusts the transformation such that the pivot is
centered, and the grid is unrotated, relative to the view.
(cherry picked from commit 5e5118c1db
)
This commit is contained in:
@ -28,6 +28,8 @@
|
||||
#include "widgets/gimphelp-ids.h"
|
||||
|
||||
#include "display/gimpdisplay.h"
|
||||
#include "display/gimpdisplayshell.h"
|
||||
#include "display/gimpdisplayshell-transform.h"
|
||||
#include "display/gimptoolgui.h"
|
||||
#include "display/gimptooltransformgrid.h"
|
||||
|
||||
@ -57,6 +59,7 @@ enum
|
||||
static void gimp_perspective_tool_matrix_to_info (GimpTransformGridTool *tg_tool,
|
||||
const GimpMatrix3 *transform);
|
||||
static void gimp_perspective_tool_prepare (GimpTransformGridTool *tg_tool);
|
||||
static void gimp_perspective_tool_readjust (GimpTransformGridTool *tg_tool);
|
||||
static GimpToolWidget * gimp_perspective_tool_get_widget (GimpTransformGridTool *tg_tool);
|
||||
static void gimp_perspective_tool_update_widget (GimpTransformGridTool *tg_tool);
|
||||
static void gimp_perspective_tool_widget_changed (GimpTransformGridTool *tg_tool);
|
||||
@ -97,6 +100,7 @@ gimp_perspective_tool_class_init (GimpPerspectiveToolClass *klass)
|
||||
|
||||
tg_class->matrix_to_info = gimp_perspective_tool_matrix_to_info;
|
||||
tg_class->prepare = gimp_perspective_tool_prepare;
|
||||
tg_class->readjust = gimp_perspective_tool_readjust;
|
||||
tg_class->get_widget = gimp_perspective_tool_get_widget;
|
||||
tg_class->update_widget = gimp_perspective_tool_update_widget;
|
||||
tg_class->widget_changed = gimp_perspective_tool_widget_changed;
|
||||
@ -161,6 +165,37 @@ gimp_perspective_tool_prepare (GimpTransformGridTool *tg_tool)
|
||||
tg_tool->trans_info[Y3] = (gdouble) tr_tool->y2;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_perspective_tool_readjust (GimpTransformGridTool *tg_tool)
|
||||
{
|
||||
GimpTool *tool = GIMP_TOOL (tg_tool);
|
||||
GimpDisplayShell *shell = gimp_display_get_shell (tool->display);
|
||||
gdouble x;
|
||||
gdouble y;
|
||||
gdouble r;
|
||||
|
||||
x = shell->disp_width / 2.0;
|
||||
y = shell->disp_height / 2.0;
|
||||
r = MIN (x, y) / G_SQRT2;
|
||||
|
||||
gimp_display_shell_untransform_xy_f (shell,
|
||||
x - r, y - r,
|
||||
&tg_tool->trans_info[X0],
|
||||
&tg_tool->trans_info[Y0]);
|
||||
gimp_display_shell_untransform_xy_f (shell,
|
||||
x + r, y - r,
|
||||
&tg_tool->trans_info[X1],
|
||||
&tg_tool->trans_info[Y1]);
|
||||
gimp_display_shell_untransform_xy_f (shell,
|
||||
x - r, y + r,
|
||||
&tg_tool->trans_info[X2],
|
||||
&tg_tool->trans_info[Y2]);
|
||||
gimp_display_shell_untransform_xy_f (shell,
|
||||
x + r, y + r,
|
||||
&tg_tool->trans_info[X3],
|
||||
&tg_tool->trans_info[Y3]);
|
||||
}
|
||||
|
||||
static GimpToolWidget *
|
||||
gimp_perspective_tool_get_widget (GimpTransformGridTool *tg_tool)
|
||||
{
|
||||
|
@ -33,6 +33,7 @@
|
||||
|
||||
#include "display/gimpdisplay.h"
|
||||
#include "display/gimpdisplayshell.h"
|
||||
#include "display/gimpdisplayshell-transform.h"
|
||||
#include "display/gimptoolgui.h"
|
||||
#include "display/gimptoolrotategrid.h"
|
||||
|
||||
@ -70,6 +71,7 @@ static gchar * gimp_rotate_tool_get_undo_desc (GimpTransformGridTool *
|
||||
static void gimp_rotate_tool_dialog (GimpTransformGridTool *tg_tool);
|
||||
static void gimp_rotate_tool_dialog_update (GimpTransformGridTool *tg_tool);
|
||||
static void gimp_rotate_tool_prepare (GimpTransformGridTool *tg_tool);
|
||||
static void gimp_rotate_tool_readjust (GimpTransformGridTool *tg_tool);
|
||||
static GimpToolWidget * gimp_rotate_tool_get_widget (GimpTransformGridTool *tg_tool);
|
||||
static void gimp_rotate_tool_update_widget (GimpTransformGridTool *tg_tool);
|
||||
static void gimp_rotate_tool_widget_changed (GimpTransformGridTool *tg_tool);
|
||||
@ -117,6 +119,7 @@ gimp_rotate_tool_class_init (GimpRotateToolClass *klass)
|
||||
tg_class->dialog = gimp_rotate_tool_dialog;
|
||||
tg_class->dialog_update = gimp_rotate_tool_dialog_update;
|
||||
tg_class->prepare = gimp_rotate_tool_prepare;
|
||||
tg_class->readjust = gimp_rotate_tool_readjust;
|
||||
tg_class->get_widget = gimp_rotate_tool_get_widget;
|
||||
tg_class->update_widget = gimp_rotate_tool_update_widget;
|
||||
tg_class->widget_changed = gimp_rotate_tool_widget_changed;
|
||||
@ -379,6 +382,24 @@ gimp_rotate_tool_prepare (GimpTransformGridTool *tg_tool)
|
||||
tg_tool);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_rotate_tool_readjust (GimpTransformGridTool *tg_tool)
|
||||
{
|
||||
GimpTool *tool = GIMP_TOOL (tg_tool);
|
||||
GimpDisplayShell *shell = gimp_display_get_shell (tool->display);
|
||||
|
||||
tg_tool->trans_info[ANGLE] = -gimp_deg_to_rad (shell->rotate_angle);
|
||||
|
||||
if (tg_tool->trans_info[ANGLE] <= -G_PI)
|
||||
tg_tool->trans_info[ANGLE] += 2.0 * G_PI;
|
||||
|
||||
gimp_display_shell_untransform_xy_f (shell,
|
||||
shell->disp_width / 2.0,
|
||||
shell->disp_height / 2.0,
|
||||
&tg_tool->trans_info[PIVOT_X],
|
||||
&tg_tool->trans_info[PIVOT_Y]);
|
||||
}
|
||||
|
||||
static GimpToolWidget *
|
||||
gimp_rotate_tool_get_widget (GimpTransformGridTool *tg_tool)
|
||||
{
|
||||
|
@ -35,6 +35,7 @@
|
||||
|
||||
#include "display/gimpdisplay.h"
|
||||
#include "display/gimpdisplayshell.h"
|
||||
#include "display/gimpdisplayshell-transform.h"
|
||||
#include "display/gimptoolgui.h"
|
||||
#include "display/gimptooltransformgrid.h"
|
||||
|
||||
@ -68,6 +69,7 @@ static gchar * gimp_scale_tool_get_undo_desc (GimpTransformGridTool *t
|
||||
static void gimp_scale_tool_dialog (GimpTransformGridTool *tg_tool);
|
||||
static void gimp_scale_tool_dialog_update (GimpTransformGridTool *tg_tool);
|
||||
static void gimp_scale_tool_prepare (GimpTransformGridTool *tg_tool);
|
||||
static void gimp_scale_tool_readjust (GimpTransformGridTool *tg_tool);
|
||||
static GimpToolWidget * gimp_scale_tool_get_widget (GimpTransformGridTool *tg_tool);
|
||||
static void gimp_scale_tool_update_widget (GimpTransformGridTool *tg_tool);
|
||||
static void gimp_scale_tool_widget_changed (GimpTransformGridTool *tg_tool);
|
||||
@ -111,6 +113,7 @@ gimp_scale_tool_class_init (GimpScaleToolClass *klass)
|
||||
tg_class->dialog = gimp_scale_tool_dialog;
|
||||
tg_class->dialog_update = gimp_scale_tool_dialog_update;
|
||||
tg_class->prepare = gimp_scale_tool_prepare;
|
||||
tg_class->readjust = gimp_scale_tool_readjust;
|
||||
tg_class->get_widget = gimp_scale_tool_get_widget;
|
||||
tg_class->update_widget = gimp_scale_tool_update_widget;
|
||||
tg_class->widget_changed = gimp_scale_tool_widget_changed;
|
||||
@ -254,6 +257,29 @@ gimp_scale_tool_prepare (GimpTransformGridTool *tg_tool)
|
||||
tg_tool);
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_scale_tool_readjust (GimpTransformGridTool *tg_tool)
|
||||
{
|
||||
GimpTool *tool = GIMP_TOOL (tg_tool);
|
||||
GimpDisplayShell *shell = gimp_display_get_shell (tool->display);
|
||||
gdouble x;
|
||||
gdouble y;
|
||||
gdouble r;
|
||||
|
||||
x = shell->disp_width / 2.0;
|
||||
y = shell->disp_height / 2.0;
|
||||
r = MIN (x, y) / G_SQRT2;
|
||||
|
||||
gimp_display_shell_untransform_xy_f (shell,
|
||||
x, y,
|
||||
&x, &y);
|
||||
|
||||
tg_tool->trans_info[X0] = RINT (x - FUNSCALEX (shell, r));
|
||||
tg_tool->trans_info[Y0] = RINT (y - FUNSCALEY (shell, r));
|
||||
tg_tool->trans_info[X1] = RINT (x + FUNSCALEX (shell, r));
|
||||
tg_tool->trans_info[Y1] = RINT (y + FUNSCALEY (shell, r));
|
||||
}
|
||||
|
||||
static GimpToolWidget *
|
||||
gimp_scale_tool_get_widget (GimpTransformGridTool *tg_tool)
|
||||
{
|
||||
|
@ -28,6 +28,8 @@
|
||||
#include "widgets/gimphelp-ids.h"
|
||||
|
||||
#include "display/gimpdisplay.h"
|
||||
#include "display/gimpdisplayshell.h"
|
||||
#include "display/gimpdisplayshell-transform.h"
|
||||
#include "display/gimptoolgui.h"
|
||||
#include "display/gimptooltransformgrid.h"
|
||||
|
||||
@ -59,6 +61,7 @@ enum
|
||||
static void gimp_unified_transform_tool_matrix_to_info (GimpTransformGridTool *tg_tool,
|
||||
const GimpMatrix3 *transform);
|
||||
static void gimp_unified_transform_tool_prepare (GimpTransformGridTool *tg_tool);
|
||||
static void gimp_unified_transform_tool_readjust (GimpTransformGridTool *tg_tool);
|
||||
static GimpToolWidget * gimp_unified_transform_tool_get_widget (GimpTransformGridTool *tg_tool);
|
||||
static void gimp_unified_transform_tool_update_widget (GimpTransformGridTool *tg_tool);
|
||||
static void gimp_unified_transform_tool_widget_changed (GimpTransformGridTool *tg_tool);
|
||||
@ -99,6 +102,7 @@ gimp_unified_transform_tool_class_init (GimpUnifiedTransformToolClass *klass)
|
||||
|
||||
tg_class->matrix_to_info = gimp_unified_transform_tool_matrix_to_info;
|
||||
tg_class->prepare = gimp_unified_transform_tool_prepare;
|
||||
tg_class->readjust = gimp_unified_transform_tool_readjust;
|
||||
tg_class->get_widget = gimp_unified_transform_tool_get_widget;
|
||||
tg_class->update_widget = gimp_unified_transform_tool_update_widget;
|
||||
tg_class->widget_changed = gimp_unified_transform_tool_widget_changed;
|
||||
@ -173,6 +177,42 @@ gimp_unified_transform_tool_prepare (GimpTransformGridTool *tg_tool)
|
||||
tg_tool->trans_info[Y3] = (gdouble) tr_tool->y2;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_unified_transform_tool_readjust (GimpTransformGridTool *tg_tool)
|
||||
{
|
||||
GimpTool *tool = GIMP_TOOL (tg_tool);
|
||||
GimpDisplayShell *shell = gimp_display_get_shell (tool->display);
|
||||
gdouble x;
|
||||
gdouble y;
|
||||
gdouble r;
|
||||
|
||||
x = shell->disp_width / 2.0;
|
||||
y = shell->disp_height / 2.0;
|
||||
r = MIN (x, y) / G_SQRT2;
|
||||
|
||||
gimp_display_shell_untransform_xy_f (shell,
|
||||
x, y,
|
||||
&tg_tool->trans_info[PIVOT_X],
|
||||
&tg_tool->trans_info[PIVOT_Y]);
|
||||
|
||||
gimp_display_shell_untransform_xy_f (shell,
|
||||
x - r, y - r,
|
||||
&tg_tool->trans_info[X0],
|
||||
&tg_tool->trans_info[Y0]);
|
||||
gimp_display_shell_untransform_xy_f (shell,
|
||||
x + r, y - r,
|
||||
&tg_tool->trans_info[X1],
|
||||
&tg_tool->trans_info[Y1]);
|
||||
gimp_display_shell_untransform_xy_f (shell,
|
||||
x - r, y + r,
|
||||
&tg_tool->trans_info[X2],
|
||||
&tg_tool->trans_info[Y2]);
|
||||
gimp_display_shell_untransform_xy_f (shell,
|
||||
x + r, y + r,
|
||||
&tg_tool->trans_info[X3],
|
||||
&tg_tool->trans_info[Y3]);
|
||||
}
|
||||
|
||||
static GimpToolWidget *
|
||||
gimp_unified_transform_tool_get_widget (GimpTransformGridTool *tg_tool)
|
||||
{
|
||||
|
Reference in New Issue
Block a user