app: properly "auto straighten" in measure tool.

In particular, this tool should not make huge rotation where the top
ends up in the bottom and it should not depend on whether we started the
measure tool from the left, right, bottom or top. This is fixed by using
atan() instead of atan2().

Also make a proper tooltip text. Help id is unneeded most likely though.
Finally do some cleaning and alignment.
This commit is contained in:
Jehan 2018-06-05 16:00:43 +02:00
parent 9baf2b62cd
commit ba1d937dfb
2 changed files with 13 additions and 10 deletions

View File

@ -130,7 +130,9 @@ gimp_measure_options_gui (GimpToolOptions *tool_options)
button = gtk_button_new_with_label (_("Auto straighten"));
gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
gtk_widget_set_sensitive (button, FALSE);
// gimp_help_set_help_data (button, NULL, GIMP_HELP_PATH_STROKE);
gimp_help_set_help_data (button,
_("Rotate the active layer using the measurement line as horizon"),
NULL);
gtk_widget_show (button);
GIMP_MEASURE_OPTIONS (tool_options)->auto_straighten = button;

View File

@ -110,7 +110,7 @@ static GimpToolGui * gimp_measure_tool_dialog_new (GimpMeasureTool *measur
static void gimp_measure_tool_dialog_update (GimpMeasureTool *measure,
GimpDisplay *display);
static void rotate_active_layer (GtkWidget *button,
static void gimp_measure_tool_rotate_active_layer (GtkWidget *button,
GimpMeasureTool *measure);
G_DEFINE_TYPE (GimpMeasureTool, gimp_measure_tool, GIMP_TYPE_DRAW_TOOL)
@ -281,6 +281,7 @@ gimp_measure_tool_compass_changed (GimpToolWidget *widget,
GimpMeasureTool *measure)
{
GimpMeasureOptions *options = GIMP_MEASURE_TOOL_GET_OPTIONS (measure);
g_object_get (widget,
"n-points", &measure->n_points,
"x1", &measure->x[0],
@ -362,8 +363,8 @@ gimp_measure_tool_start (GimpMeasureTool *measure,
GimpDisplay *display,
const GimpCoords *coords)
{
GimpTool *tool = GIMP_TOOL (measure);
GimpDisplayShell *shell = gimp_display_get_shell (display);
GimpTool *tool = GIMP_TOOL (measure);
GimpDisplayShell *shell = gimp_display_get_shell (display);
GimpMeasureOptions *options = GIMP_MEASURE_TOOL_GET_OPTIONS (tool);
measure->n_points = 1;
@ -398,7 +399,7 @@ gimp_measure_tool_start (GimpMeasureTool *measure,
G_CALLBACK (gimp_measure_tool_compass_create_guides),
measure);
g_signal_connect (options->auto_straighten, "clicked",
G_CALLBACK (rotate_active_layer),
G_CALLBACK (gimp_measure_tool_rotate_active_layer),
measure);
tool->display = display;
@ -410,7 +411,7 @@ static void
gimp_measure_tool_halt (GimpMeasureTool *measure)
{
GimpMeasureOptions *options = GIMP_MEASURE_TOOL_GET_OPTIONS (measure);
GimpTool *tool = GIMP_TOOL (measure);
GimpTool *tool = GIMP_TOOL (measure);
gtk_widget_set_sensitive (options->auto_straighten, FALSE);
@ -421,7 +422,7 @@ gimp_measure_tool_halt (GimpMeasureTool *measure)
gimp_draw_tool_stop (GIMP_DRAW_TOOL (measure));
g_signal_handlers_disconnect_by_func (options->auto_straighten,
G_CALLBACK (rotate_active_layer),
G_CALLBACK (gimp_measure_tool_rotate_active_layer),
measure);
gimp_draw_tool_set_widget (GIMP_DRAW_TOOL (tool), NULL);
@ -803,8 +804,8 @@ gimp_measure_tool_dialog_new (GimpMeasureTool *measure)
}
static void
rotate_active_layer (GtkWidget *button,
GimpMeasureTool *measure)
gimp_measure_tool_rotate_active_layer (GtkWidget *button,
GimpMeasureTool *measure)
{
GimpMeasureOptions *options = GIMP_MEASURE_TOOL_GET_OPTIONS (measure);
GimpDisplay *display = GIMP_TOOL (measure)->display;
@ -813,7 +814,7 @@ rotate_active_layer (GtkWidget *button,
gdouble ax = measure->x[1] - measure->x[0];
gdouble ay = measure->y[1] - measure->y[0];
GimpLayer *item = gimp_image_get_active_layer (image);
gdouble angle = atan2 (ay, ax);
gdouble angle = atan (ay / ax);
GimpMatrix3 matrix;