mirror of https://github.com/GNOME/gimp.git
app: constrain line angles in display space, not image space
Add an offset_angle parameter to gimp_constrain_line(), which offsets the radial lines by a given angle. Add gimpdisplayshell-utils.[ch], with two new functions: - gimp_display_shell_get_constrained_line_offset_angle(): Returns the offset angle to be passed to gimp_constrain_line(), in order to constrain line angles in display space, according to the shell's rotation angle and flip mode. - gimp_display_shell_constrain_line(): A convenience function which calls gimp_constrain_line() with the said offset angle. Use the new functions in all instances where we constrain line angles, so that angles are constrained in display space, rather than image space. The only exception is GimpEditSelectionTool, which keeps constraining angles in image space, since it's not entirely obvious that we want to constrain angles of dragged layers/selections in display space.
This commit is contained in:
parent
59fd0315c2
commit
984ed6cefd
|
@ -610,6 +610,7 @@ gimp_utils_point_to_line_distance (const GimpVector2 *point,
|
|||
* @end_x:
|
||||
* @end_y:
|
||||
* @n_snap_lines: Number evenly disributed lines to snap to.
|
||||
* @offset_angle: The angle by which to offset the lines, in degrees.
|
||||
*
|
||||
* Projects a line onto the specified subset of evenly radially
|
||||
* distributed lines. @n_lines of 2 makes the line snap horizontally
|
||||
|
@ -621,7 +622,8 @@ gimp_constrain_line (gdouble start_x,
|
|||
gdouble start_y,
|
||||
gdouble *end_x,
|
||||
gdouble *end_y,
|
||||
gint n_snap_lines)
|
||||
gint n_snap_lines,
|
||||
gdouble offset_angle)
|
||||
{
|
||||
GimpVector2 line_point = { start_x, start_y };
|
||||
GimpVector2 point = { *end_x, *end_y };
|
||||
|
@ -634,7 +636,8 @@ gimp_constrain_line (gdouble start_x,
|
|||
|
||||
for (i = 0; i < n_snap_lines; i++)
|
||||
{
|
||||
angle = i * G_PI / n_snap_lines;
|
||||
angle = i * G_PI / n_snap_lines;
|
||||
angle += offset_angle * G_PI / 180.0;
|
||||
|
||||
gimp_vector2_set (&line_dir,
|
||||
cos (angle),
|
||||
|
|
|
@ -71,7 +71,8 @@ void gimp_constrain_line (gdouble start_x,
|
|||
gdouble start_y,
|
||||
gdouble *end_x,
|
||||
gdouble *end_y,
|
||||
gint n_snap_lines);
|
||||
gint n_snap_lines,
|
||||
gdouble offset_angle);
|
||||
|
||||
gint gimp_file_compare (GFile *file1,
|
||||
GFile *file2);
|
||||
|
|
|
@ -144,6 +144,8 @@ libappdisplay_a_sources = \
|
|||
gimpdisplayshell-tool-events.h \
|
||||
gimpdisplayshell-transform.c \
|
||||
gimpdisplayshell-transform.h \
|
||||
gimpdisplayshell-utils.c \
|
||||
gimpdisplayshell-utils.h \
|
||||
gimpdisplayxfer.c \
|
||||
gimpdisplayxfer.h \
|
||||
gimpimagewindow.c \
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
#include "gimpdisplay.h"
|
||||
#include "gimpdisplayshell.h"
|
||||
#include "gimpdisplayshell-appearance.h"
|
||||
#include "gimpdisplayshell-utils.h"
|
||||
#include "gimptoolcompass.h"
|
||||
|
||||
#include "gimp-intl.h"
|
||||
|
@ -736,9 +737,10 @@ gimp_tool_compass_motion (GimpToolWidget *widget,
|
|||
gdouble x = new_x[private->point];
|
||||
gdouble y = new_y[private->point];
|
||||
|
||||
gimp_constrain_line (new_x[0], new_y[0],
|
||||
&x, &y,
|
||||
GIMP_CONSTRAIN_LINE_15_DEGREES);
|
||||
gimp_display_shell_constrain_line (gimp_tool_widget_get_shell (widget),
|
||||
new_x[0], new_y[0],
|
||||
&x, &y,
|
||||
GIMP_CONSTRAIN_LINE_15_DEGREES);
|
||||
|
||||
new_x[private->point] = ROUND (x);
|
||||
new_y[private->point] = ROUND (y);
|
||||
|
@ -909,9 +911,12 @@ gimp_tool_compass_motion_modifier (GimpToolWidget *widget,
|
|||
new_y[2] = private->y[2];
|
||||
|
||||
if (press)
|
||||
gimp_constrain_line (private->x[0], private->y[0],
|
||||
&x, &y,
|
||||
GIMP_CONSTRAIN_LINE_15_DEGREES);
|
||||
{
|
||||
gimp_display_shell_constrain_line (gimp_tool_widget_get_shell (widget),
|
||||
private->x[0], private->y[0],
|
||||
&x, &y,
|
||||
GIMP_CONSTRAIN_LINE_15_DEGREES);
|
||||
}
|
||||
|
||||
new_x[private->point] = ROUND (x);
|
||||
new_y[private->point] = ROUND (y);
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
#include "gimpcanvasline.h"
|
||||
#include "gimpdisplayshell.h"
|
||||
#include "gimpdisplayshell-cursor.h"
|
||||
#include "gimpdisplayshell-utils.h"
|
||||
#include "gimptoolline.h"
|
||||
|
||||
#include "gimp-intl.h"
|
||||
|
@ -1201,9 +1202,13 @@ gimp_tool_line_selection_motion (GimpToolLine *line,
|
|||
|
||||
case GIMP_TOOL_LINE_HANDLE_START:
|
||||
if (constrain)
|
||||
gimp_constrain_line (private->x2, private->y2,
|
||||
&x, &y,
|
||||
GIMP_CONSTRAIN_LINE_15_DEGREES);
|
||||
{
|
||||
gimp_display_shell_constrain_line (
|
||||
gimp_tool_widget_get_shell (GIMP_TOOL_WIDGET (line)),
|
||||
private->x2, private->y2,
|
||||
&x, &y,
|
||||
GIMP_CONSTRAIN_LINE_15_DEGREES);
|
||||
}
|
||||
|
||||
g_object_set (line,
|
||||
"x1", x,
|
||||
|
@ -1213,9 +1218,13 @@ gimp_tool_line_selection_motion (GimpToolLine *line,
|
|||
|
||||
case GIMP_TOOL_LINE_HANDLE_END:
|
||||
if (constrain)
|
||||
gimp_constrain_line (private->x1, private->y1,
|
||||
&x, &y,
|
||||
GIMP_CONSTRAIN_LINE_15_DEGREES);
|
||||
{
|
||||
gimp_display_shell_constrain_line (
|
||||
gimp_tool_widget_get_shell (GIMP_TOOL_WIDGET (line)),
|
||||
private->x1, private->y1,
|
||||
&x, &y,
|
||||
GIMP_CONSTRAIN_LINE_15_DEGREES);
|
||||
}
|
||||
|
||||
g_object_set (line,
|
||||
"x2", x,
|
||||
|
|
|
@ -44,6 +44,7 @@
|
|||
#include "gimpcanvasline.h"
|
||||
#include "gimpcanvaspolygon.h"
|
||||
#include "gimpdisplayshell.h"
|
||||
#include "gimpdisplayshell-utils.h"
|
||||
#include "gimptoolpolygon.h"
|
||||
|
||||
#include "gimp-intl.h"
|
||||
|
@ -812,11 +813,13 @@ gimp_tool_polygon_update_motion (GimpToolPolygon *polygon,
|
|||
&start_point_y,
|
||||
segment_index);
|
||||
|
||||
gimp_constrain_line (start_point_x,
|
||||
start_point_y,
|
||||
&new_x,
|
||||
&new_y,
|
||||
GIMP_CONSTRAIN_LINE_15_DEGREES);
|
||||
gimp_display_shell_constrain_line (
|
||||
gimp_tool_widget_get_shell (GIMP_TOOL_WIDGET (polygon)),
|
||||
start_point_x,
|
||||
start_point_y,
|
||||
&new_x,
|
||||
&new_y,
|
||||
GIMP_CONSTRAIN_LINE_15_DEGREES);
|
||||
}
|
||||
|
||||
gimp_tool_polygon_move_segment_vertex_to (polygon,
|
||||
|
@ -1262,10 +1265,12 @@ gimp_tool_polygon_hover (GimpToolWidget *widget,
|
|||
&start_point_y,
|
||||
priv->n_segment_indices - 1);
|
||||
|
||||
gimp_constrain_line (start_point_x, start_point_y,
|
||||
&priv->pending_point.x,
|
||||
&priv->pending_point.y,
|
||||
GIMP_CONSTRAIN_LINE_15_DEGREES);
|
||||
gimp_display_shell_constrain_line (
|
||||
gimp_tool_widget_get_shell (widget),
|
||||
start_point_x, start_point_y,
|
||||
&priv->pending_point.x,
|
||||
&priv->pending_point.y,
|
||||
GIMP_CONSTRAIN_LINE_15_DEGREES);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -687,7 +687,8 @@ gimp_paint_core_get_last_coords (GimpPaintCore *core,
|
|||
void
|
||||
gimp_paint_core_round_line (GimpPaintCore *core,
|
||||
GimpPaintOptions *paint_options,
|
||||
gboolean constrain_15_degrees)
|
||||
gboolean constrain_15_degrees,
|
||||
gdouble constrain_offset_angle)
|
||||
{
|
||||
g_return_if_fail (GIMP_IS_PAINT_CORE (core));
|
||||
g_return_if_fail (GIMP_IS_PAINT_OPTIONS (paint_options));
|
||||
|
@ -703,7 +704,8 @@ gimp_paint_core_round_line (GimpPaintCore *core,
|
|||
if (constrain_15_degrees)
|
||||
gimp_constrain_line (core->last_coords.x, core->last_coords.y,
|
||||
&core->cur_coords.x, &core->cur_coords.y,
|
||||
GIMP_CONSTRAIN_LINE_15_DEGREES);
|
||||
GIMP_CONSTRAIN_LINE_15_DEGREES,
|
||||
constrain_offset_angle);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -159,7 +159,8 @@ void gimp_paint_core_get_last_coords (GimpPaintCore *core,
|
|||
|
||||
void gimp_paint_core_round_line (GimpPaintCore *core,
|
||||
GimpPaintOptions *options,
|
||||
gboolean constrain_15_degrees);
|
||||
gboolean constrain_15_degrees,
|
||||
gdouble constrain_offset_angle);
|
||||
|
||||
|
||||
/* protected functions */
|
||||
|
|
|
@ -521,7 +521,7 @@ gimp_edit_selection_tool_update_motion (GimpEditSelectionTool *edit_select,
|
|||
{
|
||||
gimp_constrain_line (edit_select->start_x, edit_select->start_y,
|
||||
&new_x, &new_y,
|
||||
GIMP_CONSTRAIN_LINE_45_DEGREES);
|
||||
GIMP_CONSTRAIN_LINE_45_DEGREES, 0.0);
|
||||
}
|
||||
|
||||
gimp_edit_selection_tool_calc_coords (edit_select, image,
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
#include "display/gimpdisplay.h"
|
||||
#include "display/gimpdisplayshell.h"
|
||||
#include "display/gimpdisplayshell-selection.h"
|
||||
#include "display/gimpdisplayshell-utils.h"
|
||||
|
||||
#include "gimpcoloroptions.h"
|
||||
#include "gimppainttool.h"
|
||||
|
@ -337,7 +338,10 @@ gimp_paint_tool_button_press (GimpTool *tool,
|
|||
/* If shift is down and this is not the first paint
|
||||
* stroke, then draw a line from the last coords to the pointer
|
||||
*/
|
||||
gimp_paint_core_round_line (core, paint_options, constrain);
|
||||
gimp_paint_core_round_line (
|
||||
core, paint_options,
|
||||
constrain,
|
||||
gimp_display_shell_get_constrained_line_offset_angle (shell));
|
||||
}
|
||||
|
||||
tool->display = display;
|
||||
|
@ -646,8 +650,10 @@ gimp_paint_tool_oper_update (GimpTool *tool,
|
|||
gdouble yres;
|
||||
gdouble angle;
|
||||
|
||||
gimp_paint_core_round_line (core, paint_options,
|
||||
(state & constrain_mask) != 0);
|
||||
gimp_paint_core_round_line (
|
||||
core, paint_options,
|
||||
(state & constrain_mask) != 0,
|
||||
gimp_display_shell_get_constrained_line_offset_angle (shell));
|
||||
|
||||
dx = core->cur_coords.x - core->last_coords.x;
|
||||
dy = core->cur_coords.y - core->last_coords.y;
|
||||
|
|
Loading…
Reference in New Issue