[gimp] app: improve precision of paint tools' straight line distance...
- From: Jehan Pagès <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: improve precision of paint tools' straight line distance...
- Date: Thu, 19 Jan 2017 23:47:08 +0000 (UTC)
commit 1835b2ae61d69abc32fa61f54d73b5ca79f0aca6
Author: Jehan <jehan girinstud io>
Date: Thu Jan 19 17:29:59 2017 +0100
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.
app/tools/gimppainttool.c | 27 ++++++++++++++++++---------
1 files changed, 18 insertions(+), 9 deletions(-)
---
diff --git a/app/tools/gimppainttool.c b/app/tools/gimppainttool.c
index d1341dc..5434668 100644
--- a/app/tools/gimppainttool.c
+++ b/app/tools/gimppainttool.c
@@ -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);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]