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>
* 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_unit (GIMP_RULER (shell->hrule), shell->unit);
/* 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_unit (GIMP_RULER (shell->vrule), shell->unit);
#if 0
g_printerr ("offset_x: %d\n"

View File

@ -30,15 +30,14 @@
#include "gimphruler.h"
#define RULER_HEIGHT 13
#define MINIMUM_INCR 5
#define MAXIMUM_SUBDIVIDE 5
#define RULER_HEIGHT 13
#define MINIMUM_INCR 5
static const struct
{
gdouble ruler_scale[16];
gint subdivide[5]; /* five possible modes of subdivision */
gint subdivide[5];
} ruler_metric =
{
{ 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);
gdouble lower;
gdouble upper;
gdouble position;
gint x;
gdk_event_request_motions (event);
@ -138,6 +136,7 @@ gimp_hruler_draw_ticks (GimpRuler *ruler)
gint text_width;
gint pos;
gdouble max_size;
GimpUnit unit;
PangoLayout *layout;
PangoRectangle logical_rect, ink_rect;
@ -196,16 +195,28 @@ gimp_hruler_draw_ticks (GimpRuler *ruler)
if (scale == G_N_ELEMENTS (ruler_metric.ruler_scale))
scale = G_N_ELEMENTS (ruler_metric.ruler_scale) - 1;
unit = gimp_ruler_get_unit (ruler);
/* drawing starts here */
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) ruler_metric.subdivide[i]);
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]);
if (subd_incr * fabs (increment) <= MINIMUM_INCR)
continue;
/* don't subdivide pixels */
if (unit == GIMP_UNIT_PIXEL && subd_incr < 1.0)
continue;
/* Calculate the length of the tickmarks. Make sure that
* this length increases for each set of ticks
*/

View File

@ -30,14 +30,13 @@
#include "gimpvruler.h"
#define RULER_WIDTH 13
#define MINIMUM_INCR 5
#define MAXIMUM_SUBDIVIDE 5
#define RULER_WIDTH 13
#define MINIMUM_INCR 5
static const struct
{
gdouble ruler_scale[16];
gint subdivide[5]; /* five possible modes of subdivision */
gint subdivide[5];
} ruler_metric =
{
{ 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 pos;
gdouble max_size;
GimpUnit unit;
PangoLayout *layout;
PangoRectangle logical_rect, ink_rect;
@ -196,16 +196,28 @@ gimp_vruler_draw_ticks (GimpRuler *ruler)
if (scale == G_N_ELEMENTS (ruler_metric.ruler_scale))
scale = G_N_ELEMENTS (ruler_metric.ruler_scale) - 1;
unit = gimp_ruler_get_unit (ruler);
/* drawing starts here */
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) ruler_metric.subdivide[i]);
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]);
if (subd_incr * fabs (increment) <= MINIMUM_INCR)
continue;
/* don't subdivide pixels */
if (unit == GIMP_UNIT_PIXEL && subd_incr < 1)
continue;
/* Calculate the length of the tickmarks. Make sure that
* this length increases for each set of ticks
*/