app: improve precision of paint tools' straight line distance...

... in status bar.
Follow-up of commits f836892 and d1c3c3d. With high resolutions, the
distance displayed in the status bar when shift-clicking in a paint tool
may lack digit precision and show the same value (in non-pixel unit) for
several consecutive pixels. Compute a more accurate precision than what
gimp_unit_get_digits() can provide in such cases.
This commit is contained in:
Jehan 2017-01-19 17:29:59 +01:00
parent d1c3c3deb0
commit 1835b2ae61
1 changed files with 18 additions and 9 deletions

View File

@ -642,7 +642,7 @@ gimp_paint_tool_oper_update (GimpTool *tool,
*/
gchar *status_help;
gdouble dx, dy, dist;
gdouble dx, dy, pixel_dist;
gimp_paint_core_round_line (core, paint_options,
(state & constrain_mask) != 0);
@ -656,30 +656,39 @@ gimp_paint_tool_oper_update (GimpTool *tool,
_("%s for constrained angles"),
NULL);
pixel_dist = sqrt (SQR (dx) + SQR (dy));
/* show distance in statusbar */
if (shell->unit == GIMP_UNIT_PIXEL)
{
dist = sqrt (SQR (dx) + SQR (dy));
gimp_tool_push_status (tool, display, "%.1f %s. %s",
dist, _("pixels"), status_help);
pixel_dist, _("pixels"), status_help);
}
else
{
gdouble xres;
gdouble yres;
gdouble dist;
gint digits;
gchar format_str[64];
/* The distance in unit. */
gimp_image_get_resolution (image, &xres, &yres);
g_snprintf (format_str, sizeof (format_str), "%%.%df %s. %%s",
gimp_unit_get_digits (shell->unit),
gimp_unit_get_symbol (shell->unit));
dist = (gimp_unit_get_factor (shell->unit) *
sqrt (SQR (dx / xres) +
SQR (dy / yres)));
/* The ideal digit precision for unit in current resolution. */
digits = gimp_unit_get_digits (shell->unit);
if (dist > 0.0)
{
digits = MAX (ceil (log10 (pixel_dist / dist)),
digits);
}
g_snprintf (format_str, sizeof (format_str), "%%.%df %s. %%s",
digits, gimp_unit_get_symbol (shell->unit));
gimp_tool_push_status (tool, display, format_str,
dist, status_help);
}