set the display unit on the ruler.

2008-05-28  Sven Neumann  <sven@gimp.org>

	* app/display/gimpdisplayshell-scale.c
	(gimp_display_shell_scale_setup): set the display unit on the ruler.

	* libgimpwidgets/gimphruler.c (gimp_hruler_draw_ticks)
	* libgimpwidgets/gimpvruler.c (gimp_vruler_draw_ticks): hack around
	to get nicer subdivisions for rulers showing pixels.

svn path=/trunk/; revision=25839
This commit is contained in:
Sven Neumann 2008-05-28 14:33:46 +00:00 committed by Sven Neumann
parent fcc0dc50a0
commit 5d0c84696c
4 changed files with 49 additions and 16 deletions

View File

@ -1,3 +1,12 @@
2008-05-28 Sven Neumann <sven@gimp.org>
* app/display/gimpdisplayshell-scale.c
(gimp_display_shell_scale_setup): set the display unit on the ruler.
* libgimpwidgets/gimphruler.c (gimp_hruler_draw_ticks)
* libgimpwidgets/gimpvruler.c (gimp_vruler_draw_ticks): hack around
to get nicer subdivisions for rulers showing pixels.
2008-05-28 Sven Neumann <sven@gimp.org> 2008-05-28 Sven Neumann <sven@gimp.org>
* libgimpwidgets/gimpruler.[ch] * libgimpwidgets/gimpruler.[ch]

View File

@ -174,6 +174,7 @@ gimp_display_shell_scale_setup (GimpDisplayShell *shell)
} }
gimp_ruler_set_range (GIMP_RULER (shell->hrule), lower, upper, max_size); gimp_ruler_set_range (GIMP_RULER (shell->hrule), lower, upper, max_size);
gimp_ruler_set_unit (GIMP_RULER (shell->hrule), shell->unit);
/* vertical ruler */ /* vertical ruler */
@ -214,7 +215,7 @@ gimp_display_shell_scale_setup (GimpDisplayShell *shell)
} }
gimp_ruler_set_range (GIMP_RULER (shell->vrule), lower, upper, max_size); gimp_ruler_set_range (GIMP_RULER (shell->vrule), lower, upper, max_size);
gimp_ruler_set_unit (GIMP_RULER (shell->vrule), shell->unit);
#if 0 #if 0
g_printerr ("offset_x: %d\n" g_printerr ("offset_x: %d\n"

View File

@ -32,13 +32,12 @@
#define RULER_HEIGHT 13 #define RULER_HEIGHT 13
#define MINIMUM_INCR 5 #define MINIMUM_INCR 5
#define MAXIMUM_SUBDIVIDE 5
static const struct static const struct
{ {
gdouble ruler_scale[16]; gdouble ruler_scale[16];
gint subdivide[5]; /* five possible modes of subdivision */ gint subdivide[5];
} ruler_metric = } ruler_metric =
{ {
{ 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000, 10000, 25000, 50000, 100000 }, { 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000, 10000, 25000, 50000, 100000 },
@ -102,7 +101,6 @@ gimp_hruler_motion_notify (GtkWidget *widget,
GimpRuler *ruler = GIMP_RULER (widget); GimpRuler *ruler = GIMP_RULER (widget);
gdouble lower; gdouble lower;
gdouble upper; gdouble upper;
gdouble position;
gint x; gint x;
gdk_event_request_motions (event); gdk_event_request_motions (event);
@ -138,6 +136,7 @@ gimp_hruler_draw_ticks (GimpRuler *ruler)
gint text_width; gint text_width;
gint pos; gint pos;
gdouble max_size; gdouble max_size;
GimpUnit unit;
PangoLayout *layout; PangoLayout *layout;
PangoRectangle logical_rect, ink_rect; PangoRectangle logical_rect, ink_rect;
@ -196,16 +195,28 @@ gimp_hruler_draw_ticks (GimpRuler *ruler)
if (scale == G_N_ELEMENTS (ruler_metric.ruler_scale)) if (scale == G_N_ELEMENTS (ruler_metric.ruler_scale))
scale = G_N_ELEMENTS (ruler_metric.ruler_scale) - 1; scale = G_N_ELEMENTS (ruler_metric.ruler_scale) - 1;
unit = gimp_ruler_get_unit (ruler);
/* drawing starts here */ /* drawing starts here */
length = 0; length = 0;
for (i = MAXIMUM_SUBDIVIDE - 1; i >= 0; i--) for (i = G_N_ELEMENTS (ruler_metric.subdivide) - 1; i >= 0; i--)
{ {
gdouble subd_incr = ((gdouble) ruler_metric.ruler_scale[scale] / gdouble subd_incr;
/* hack to get proper subdivisions at full pixels */
if (unit == GIMP_UNIT_PIXEL && scale == 1 && i == 1)
subd_incr = 1.0;
else
subd_incr = ((gdouble) ruler_metric.ruler_scale[scale] /
(gdouble) ruler_metric.subdivide[i]); (gdouble) ruler_metric.subdivide[i]);
if (subd_incr * fabs (increment) <= MINIMUM_INCR) if (subd_incr * fabs (increment) <= MINIMUM_INCR)
continue; continue;
/* don't subdivide pixels */
if (unit == GIMP_UNIT_PIXEL && subd_incr < 1.0)
continue;
/* Calculate the length of the tickmarks. Make sure that /* Calculate the length of the tickmarks. Make sure that
* this length increases for each set of ticks * this length increases for each set of ticks
*/ */

View File

@ -32,12 +32,11 @@
#define RULER_WIDTH 13 #define RULER_WIDTH 13
#define MINIMUM_INCR 5 #define MINIMUM_INCR 5
#define MAXIMUM_SUBDIVIDE 5
static const struct static const struct
{ {
gdouble ruler_scale[16]; gdouble ruler_scale[16];
gint subdivide[5]; /* five possible modes of subdivision */ gint subdivide[5];
} ruler_metric = } ruler_metric =
{ {
{ 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000, 10000, 25000, 50000, 100000 }, { 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000, 10000, 25000, 50000, 100000 },
@ -137,6 +136,7 @@ gimp_vruler_draw_ticks (GimpRuler *ruler)
gint text_height; gint text_height;
gint pos; gint pos;
gdouble max_size; gdouble max_size;
GimpUnit unit;
PangoLayout *layout; PangoLayout *layout;
PangoRectangle logical_rect, ink_rect; PangoRectangle logical_rect, ink_rect;
@ -196,16 +196,28 @@ gimp_vruler_draw_ticks (GimpRuler *ruler)
if (scale == G_N_ELEMENTS (ruler_metric.ruler_scale)) if (scale == G_N_ELEMENTS (ruler_metric.ruler_scale))
scale = G_N_ELEMENTS (ruler_metric.ruler_scale) - 1; scale = G_N_ELEMENTS (ruler_metric.ruler_scale) - 1;
unit = gimp_ruler_get_unit (ruler);
/* drawing starts here */ /* drawing starts here */
length = 0; length = 0;
for (i = MAXIMUM_SUBDIVIDE - 1; i >= 0; i--) for (i = G_N_ELEMENTS (ruler_metric.subdivide) - 1; i >= 0; i--)
{ {
gdouble subd_incr = ((gdouble) ruler_metric.ruler_scale[scale] / gdouble subd_incr;
/* hack to get proper subdivisions at full pixels */
if (unit == GIMP_UNIT_PIXEL && scale == 1 && i == 1)
subd_incr = 1.0;
else
subd_incr = ((gdouble) ruler_metric.ruler_scale[scale] /
(gdouble) ruler_metric.subdivide[i]); (gdouble) ruler_metric.subdivide[i]);
if (subd_incr * fabs (increment) <= MINIMUM_INCR) if (subd_incr * fabs (increment) <= MINIMUM_INCR)
continue; continue;
/* don't subdivide pixels */
if (unit == GIMP_UNIT_PIXEL && subd_incr < 1)
continue;
/* Calculate the length of the tickmarks. Make sure that /* Calculate the length of the tickmarks. Make sure that
* this length increases for each set of ticks * this length increases for each set of ticks
*/ */