app: use the new gimp_display_shell_get_line_status() for measure...

... and paint tools (shift-click mode). The feature was already there
but reimplemented twice. Just replace the code to use the same function.
This commit is contained in:
Jehan 2017-12-22 22:26:13 +01:00
parent 0116d7316a
commit 2069496af3
2 changed files with 20 additions and 85 deletions

View File

@ -40,6 +40,7 @@
#include "display/gimpdisplay.h" #include "display/gimpdisplay.h"
#include "display/gimpdisplayshell.h" #include "display/gimpdisplayshell.h"
#include "display/gimpdisplayshell-appearance.h" #include "display/gimpdisplayshell-appearance.h"
#include "display/gimpdisplayshell-utils.h"
#include "display/gimptoolcompass.h" #include "display/gimptoolcompass.h"
#include "display/gimptoolgui.h" #include "display/gimptoolgui.h"
@ -447,6 +448,7 @@ gimp_measure_tool_dialog_update (GimpMeasureTool *measure,
{ {
GimpDisplayShell *shell = gimp_display_get_shell (display); GimpDisplayShell *shell = gimp_display_get_shell (display);
GimpImage *image = gimp_display_get_image (display); GimpImage *image = gimp_display_get_image (display);
gchar *status;
gint ax, ay; gint ax, ay;
gint bx, by; gint bx, by;
gint pixel_width; gint pixel_width;
@ -521,26 +523,23 @@ gimp_measure_tool_dialog_update (GimpMeasureTool *measure,
unit_width_digits = gimp_unit_get_scaled_digits (shell->unit, xres); unit_width_digits = gimp_unit_get_scaled_digits (shell->unit, xres);
unit_height_digits = gimp_unit_get_scaled_digits (shell->unit, yres); unit_height_digits = gimp_unit_get_scaled_digits (shell->unit, yres);
status = gimp_display_shell_get_line_status (shell, "", "",
ax, ay, bx, by);
if (shell->unit == GIMP_UNIT_PIXEL) if (shell->unit == GIMP_UNIT_PIXEL)
{ {
gimp_tool_replace_status (GIMP_TOOL (measure), display, gimp_tool_replace_status (GIMP_TOOL (measure), display,
"%.1f %s, %.2f\302\260 (%d × %d)", "%s (%d × %d)",
pixel_distance, _("pixels"), pixel_angle, status, pixel_width, pixel_height);
pixel_width, pixel_height);
} }
else else
{ {
g_snprintf (format, sizeof (format), g_snprintf (format, sizeof (format), "%s (%%.%df × %%.%df)",
"%%.%df %s, %%.2f\302\260 (%%.%df × %%.%df)", status, unit_width_digits, unit_height_digits);
unit_distance_digits,
gimp_unit_get_plural (shell->unit),
unit_width_digits,
unit_height_digits);
gimp_tool_replace_status (GIMP_TOOL (measure), display, format, gimp_tool_replace_status (GIMP_TOOL (measure), display, format,
unit_distance, unit_angle,
unit_width, unit_height); unit_width, unit_height);
} }
g_free (status);
if (measure->gui) if (measure->gui)
{ {

View File

@ -628,6 +628,7 @@ gimp_paint_tool_oper_update (GimpTool *tool,
if (drawable && proximity) if (drawable && proximity)
{ {
gchar *status;
gboolean constrain_mask = gimp_get_constrain_behavior_mask (); gboolean constrain_mask = gimp_get_constrain_behavior_mask ();
gint off_x, off_y; gint off_x, off_y;
@ -643,94 +644,30 @@ gimp_paint_tool_oper_update (GimpTool *tool,
/* If shift is down and this is not the first paint stroke, /* If shift is down and this is not the first paint stroke,
* draw a line. * draw a line.
*/ */
gchar *status_help; gchar *status_help;
gdouble dx, dy, pixel_dist;
gdouble xres;
gdouble yres;
gdouble angle;
gimp_paint_core_round_line ( gimp_paint_core_round_line (
core, paint_options, core, paint_options,
(state & constrain_mask) != 0, (state & constrain_mask) != 0,
gimp_display_shell_get_constrained_line_offset_angle (shell)); 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;
status_help = gimp_suggest_modifiers (paint_tool->status_line, status_help = gimp_suggest_modifiers (paint_tool->status_line,
constrain_mask & ~state, constrain_mask & ~state,
NULL, NULL,
_("%s for constrained angles"), _("%s for constrained angles"),
NULL); NULL);
pixel_dist = sqrt (SQR (dx) + SQR (dy)); status = gimp_display_shell_get_line_status (shell, status_help,
". ",
if (shell->unit == GIMP_UNIT_PIXEL) core->cur_coords.x,
xres = yres = 1.0; core->cur_coords.y,
else core->last_coords.x,
gimp_image_get_resolution (image, &xres, &yres); core->last_coords.y);
if (dx)
{
angle = gimp_rad_to_deg (atan ((dy/yres) / (dx/xres)));
if (dx > 0)
{
if (dy > 0)
angle = 360.0 - angle;
else if (dy < 0)
angle = -angle;
}
else
{
angle = 180.0 - angle;
}
}
else if (dy)
{
angle = dy > 0 ? 270.0 : 90.0;
}
else
{
angle = 0.0;
}
/* show distance and angle in statusbar */
if (shell->unit == GIMP_UNIT_PIXEL)
{
gimp_tool_push_status (tool, display, "%.1f %s, %.2f\302\260. %s",
pixel_dist, _("pixels"), angle, status_help);
}
else
{
gdouble inch_dist;
gdouble unit_dist;
gint digits = 0;
gchar format_str[64];
/* The distance in unit. */
inch_dist = sqrt (SQR (dx / xres) + SQR (dy / yres));
unit_dist = gimp_unit_get_factor (shell->unit) * inch_dist;
/* The ideal digit precision for unit in current resolution. */
if (inch_dist)
digits = gimp_unit_get_scaled_digits (shell->unit,
pixel_dist / inch_dist);
g_snprintf (format_str, sizeof (format_str), "%%.%df %s, %%.2f\302\260. %%s",
digits, gimp_unit_get_symbol (shell->unit));
gimp_tool_push_status (tool, display, format_str,
unit_dist, angle, status_help);
}
g_free (status_help); g_free (status_help);
paint_tool->draw_line = TRUE; paint_tool->draw_line = TRUE;
} }
else else
{ {
gchar *status;
GdkModifierType modifiers = 0; GdkModifierType modifiers = 0;
/* HACK: A paint tool may set status_ctrl to NULL to indicate that /* HACK: A paint tool may set status_ctrl to NULL to indicate that
@ -751,11 +688,10 @@ gimp_paint_tool_oper_update (GimpTool *tool,
_("%s for a straight line"), _("%s for a straight line"),
paint_tool->status_ctrl, paint_tool->status_ctrl,
NULL); NULL);
gimp_tool_push_status (tool, display, "%s", status);
g_free (status);
paint_tool->draw_line = FALSE; paint_tool->draw_line = FALSE;
} }
gimp_tool_push_status (tool, display, "%s", status);
g_free (status);
if (! gimp_draw_tool_is_active (draw_tool)) if (! gimp_draw_tool_is_active (draw_tool))
gimp_draw_tool_start (draw_tool, display); gimp_draw_tool_start (draw_tool, display);