[gimp] app: use gimp_unit_get_accurate_digits() in a few places.
- From: Jehan Pagès <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: use gimp_unit_get_accurate_digits() in a few places.
- Date: Mon, 23 Jan 2017 20:05:50 +0000 (UTC)
commit 2762662ca93b38749bdba133d87375b96bb426ad
Author: Jehan <jehan girinstud io>
Date: Mon Jan 23 20:52:32 2017 +0100
app: use gimp_unit_get_accurate_digits() in a few places.
app/display/gimpstatusbar.c | 23 +++++------------------
app/tools/gimpmeasuretool.c | 25 ++++++++++---------------
app/tools/gimppainttool.c | 21 +++++++++------------
3 files changed, 24 insertions(+), 45 deletions(-)
---
diff --git a/app/display/gimpstatusbar.c b/app/display/gimpstatusbar.c
index 690bbd3..df247e4 100644
--- a/app/display/gimpstatusbar.c
+++ b/app/display/gimpstatusbar.c
@@ -1345,24 +1345,11 @@ gimp_statusbar_shell_scaled (GimpDisplayShell *shell,
}
else /* show real world units */
{
- gint w_digits = 0;
- gint h_digits = 0;
- gint length_digits;
+ gint w_digits;
+ gint h_digits;
- if (image)
- {
- w_digits = ceil (log10 (image_width /
- gimp_pixels_to_units (image_width,
- shell->unit,
- image_xres)));
- h_digits = ceil (log10 (image_width /
- gimp_pixels_to_units (image_height,
- shell->unit,
- image_yres)));
- }
- w_digits = MAX (w_digits, gimp_unit_get_digits (shell->unit));
- h_digits = MAX (h_digits, gimp_unit_get_digits (shell->unit));
- length_digits = MAX (w_digits, h_digits);
+ w_digits = gimp_unit_get_scaled_digits (shell->unit, image_xres);
+ h_digits = gimp_unit_get_scaled_digits (shell->unit, image_yres);
g_snprintf (statusbar->cursor_format_str,
sizeof (statusbar->cursor_format_str),
@@ -1371,7 +1358,7 @@ gimp_statusbar_shell_scaled (GimpDisplayShell *shell,
strcpy (statusbar->cursor_format_str_f, statusbar->cursor_format_str);
g_snprintf (statusbar->length_format_str,
sizeof (statusbar->length_format_str),
- "%%s%%.%df%%s", length_digits);
+ "%%s%%.%df%%s", MAX (w_digits, h_digits));
}
gimp_statusbar_update_cursor (statusbar, GIMP_CURSOR_PRECISION_SUBPIXEL,
diff --git a/app/tools/gimpmeasuretool.c b/app/tools/gimpmeasuretool.c
index 4678488..f6cc417 100644
--- a/app/tools/gimpmeasuretool.c
+++ b/app/tools/gimpmeasuretool.c
@@ -881,13 +881,14 @@ gimp_measure_tool_dialog_update (GimpMeasureTool *measure,
gdouble unit_height;
gdouble pixel_distance;
gdouble unit_distance;
+ gdouble inch_distance;
gdouble theta1, theta2;
gdouble pixel_angle;
gdouble unit_angle;
gdouble xres;
gdouble yres;
gchar format[128];
- gint unit_distance_digits;
+ gint unit_distance_digits = 0;
gint unit_width_digits;
gint unit_height_digits;
@@ -915,9 +916,9 @@ gimp_measure_tool_dialog_update (GimpMeasureTool *measure,
unit_height = gimp_pixels_to_units (pixel_height, shell->unit, yres);
pixel_distance = sqrt (SQR (ax - bx) + SQR (ay - by));
- unit_distance = (gimp_unit_get_factor (shell->unit) *
- sqrt (SQR ((gdouble) (ax - bx) / xres) +
- SQR ((gdouble) (ay - by) / yres)));
+ inch_distance = sqrt (SQR ((gdouble) (ax - bx) / xres) +
+ SQR ((gdouble) (ay - by) / yres));
+ unit_distance = gimp_unit_get_factor (shell->unit) * inch_distance;
if (measure->num_points != 3)
bx = ax > 0 ? 1 : -1;
@@ -941,17 +942,11 @@ gimp_measure_tool_dialog_update (GimpMeasureTool *measure,
/* Compute minimum digits to display accurate values, so that
every pixel shows a different value in unit. */
- unit_distance_digits = ceil (log10 (pixel_distance / unit_distance));
- unit_distance_digits = MAX (gimp_unit_get_digits (shell->unit),
- unit_distance_digits);
-
- unit_width_digits = ceil (log10 (pixel_width / unit_width));
- unit_width_digits = MAX (gimp_unit_get_digits (shell->unit),
- unit_width_digits);
-
- unit_height_digits = ceil (log10 (pixel_height / unit_height));
- unit_height_digits = MAX (gimp_unit_get_digits (shell->unit),
- unit_height_digits);
+ if (inch_distance)
+ unit_distance_digits = gimp_unit_get_scaled_digits (shell->unit,
+ pixel_distance / inch_distance);
+ unit_width_digits = gimp_unit_get_scaled_digits (shell->unit, xres);
+ unit_height_digits = gimp_unit_get_scaled_digits (shell->unit, yres);
if (shell->unit == GIMP_UNIT_PIXEL)
{
diff --git a/app/tools/gimppainttool.c b/app/tools/gimppainttool.c
index 5434668..ab35f1b 100644
--- a/app/tools/gimppainttool.c
+++ b/app/tools/gimppainttool.c
@@ -668,29 +668,26 @@ gimp_paint_tool_oper_update (GimpTool *tool,
{
gdouble xres;
gdouble yres;
- gdouble dist;
- gint digits;
+ gdouble inch_dist;
+ gdouble unit_dist;
+ gint digits = 0;
gchar format_str[64];
/* The distance in unit. */
gimp_image_get_resolution (image, &xres, &yres);
- dist = (gimp_unit_get_factor (shell->unit) *
- sqrt (SQR (dx / xres) +
- SQR (dy / yres)));
+ 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. */
- digits = gimp_unit_get_digits (shell->unit);
- if (dist > 0.0)
- {
- digits = MAX (ceil (log10 (pixel_dist / dist)),
- digits);
- }
+ if (inch_dist)
+ digits = gimp_unit_get_scaled_digits (shell->unit,
+ pixel_dist / inch_dist);
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);
+ unit_dist, status_help);
}
g_free (status_help);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]