summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlex Valavanis <valavanisalex@gmail.com>2012-12-31 13:38:00 +0000
committerAlex Valavanis <valavanisalex@gmail.com>2012-12-31 13:38:00 +0000
commitcf96e2170b696c55977ed90b020813684b9d0000 (patch)
treed27de59d5ebf9eff22b3c054e8c81c96a65a114f /src
parentReplace C-style pointer casts in event contexts (diff)
downloadinkscape-cf96e2170b696c55977ed90b020813684b9d0000.tar.gz
inkscape-cf96e2170b696c55977ed90b020813684b9d0000.zip
rulers: (Merge from GIMP) Set range in ruler units, not in px
(bzr r12002)
Diffstat (limited to 'src')
-rw-r--r--src/widgets/desktop-widget.cpp16
-rw-r--r--src/widgets/ruler.cpp25
-rw-r--r--src/widgets/ruler.h12
3 files changed, 20 insertions, 33 deletions
diff --git a/src/widgets/desktop-widget.cpp b/src/widgets/desktop-widget.cpp
index 8f7b6445c..a22786b2a 100644
--- a/src/widgets/desktop-widget.cpp
+++ b/src/widgets/desktop-widget.cpp
@@ -1696,23 +1696,17 @@ SPDesktopWidget::viewSetPosition (Geom::Point p)
void
sp_desktop_widget_update_rulers (SPDesktopWidget *dtw)
{
- /* The viewbox (in integers) must exactly match the size of SPCanvasbuf's pixel buffer.
- * This is important because the former is being used for drawing the ruler, whereas
- * the latter is used for drawing e.g. the grids and guides. Only when the viewbox
- * coincides with the pixel buffer, everything will line up nicely.
- */
- Geom::IntRect viewbox = dtw->canvas->getViewboxIntegers();
+ Geom::Rect viewbox = dtw->desktop->get_display_area();
- double const scale = dtw->desktop->current_zoom();
- double lower_x = viewbox.min()[Geom::X] / scale - dtw->ruler_origin[Geom::X];
- double upper_x = viewbox.max()[Geom::X] / scale - dtw->ruler_origin[Geom::X];
+ double lower_x = dtw->dt2r * (viewbox.left() - dtw->ruler_origin[Geom::X]);
+ double upper_x = dtw->dt2r * (viewbox.right() - dtw->ruler_origin[Geom::X]);
sp_ruler_set_range(SP_RULER(dtw->hruler),
lower_x,
upper_x,
(upper_x - lower_x));
- double lower_y = viewbox.min()[Geom::Y] / -scale - dtw->ruler_origin[Geom::Y];
- double upper_y = viewbox.max()[Geom::Y] / -scale - dtw->ruler_origin[Geom::Y];
+ double lower_y = dtw->dt2r * (viewbox.bottom() - dtw->ruler_origin[Geom::Y]);
+ double upper_y = dtw->dt2r * (viewbox.top() - dtw->ruler_origin[Geom::Y]);
sp_ruler_set_range(SP_RULER(dtw->vruler),
lower_y,
upper_y,
diff --git a/src/widgets/ruler.cpp b/src/widgets/ruler.cpp
index 733de2239..34d8f1bc5 100644
--- a/src/widgets/ruler.cpp
+++ b/src/widgets/ruler.cpp
@@ -88,15 +88,15 @@ typedef struct
/// Ruler metrics.
static SPRulerMetric const sp_ruler_metrics[] = {
// NOTE: the order of records in this struct must correspond to the SPMetric enum.
- {1, { 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000 }, { 1, 5, 10, 50, 100 }}, // SP_NONE
- {PX_PER_MM, { 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000 }, { 1, 5, 10, 50, 100 }}, // SP_MM
- {PX_PER_CM, { 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000 }, { 1, 5, 10, 50, 100 }}, // SP_CM
- {PX_PER_IN, { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512 }, { 1, 2, 4, 8, 16 }}, // SP_IN
- {PX_PER_FT, { 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000 }, { 1, 5, 10, 50, 100 }}, // SP_FT
- {PX_PER_PT, { 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000 }, { 1, 5, 10, 50, 100 }}, // SP_PT
- {PX_PER_PC, { 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000 }, { 1, 5, 10, 50, 100 }}, // SP_PC
- {PX_PER_PX, { 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000 }, { 1, 5, 10, 50, 100 }}, // SP_PX
- {PX_PER_M, { 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000 }, { 1, 5, 10, 50, 100 }}, // SP_M
+ {{ 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000 }, { 1, 5, 10, 50, 100 }}, // SP_NONE
+ {{ 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000 }, { 1, 5, 10, 50, 100 }}, // SP_MM
+ {{ 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000 }, { 1, 5, 10, 50, 100 }}, // SP_CM
+ {{ 1, 2, 4, 8, 16, 32, 64, 128, 256, 512 }, { 1, 2, 4, 8, 16 }}, // SP_IN
+ {{ 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000 }, { 1, 5, 10, 50, 100 }}, // SP_FT
+ {{ 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000 }, { 1, 5, 10, 50, 100 }}, // SP_PT
+ {{ 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000 }, { 1, 5, 10, 50, 100 }}, // SP_PC
+ {{ 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000 }, { 1, 5, 10, 50, 100 }}, // SP_PX
+ {{ 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000 }, { 1, 5, 10, 50, 100 }}, // SP_M
};
@@ -1252,11 +1252,6 @@ sp_ruler_draw_ticks (SPRuler *ruler)
sp_ruler_get_range (ruler, &lower, &upper, &max_size);
- upper /= priv->metric->pixels_per_unit; // upper and lower are expressed in ruler units
- lower /= priv->metric->pixels_per_unit;
- /* "pixels_per_unit" should be "points_per_unit". This is the size of the unit
- * in 1/72nd's of an inch and has nothing to do with screen pixels */
-
if ((upper - lower) == 0)
goto out;
@@ -1272,7 +1267,7 @@ sp_ruler_draw_ticks (SPRuler *ruler)
* actually measuring the text width, so that the result for the
* scale looks consistent with an accompanying vruler
*/
- scale = (gint)(ceil(priv->max_size / priv->metric->pixels_per_unit));
+ scale = ceil (priv->max_size);
sprintf (unit_str, "%d", scale);
text_size = strlen (unit_str) * digit_height + 1;
diff --git a/src/widgets/ruler.h b/src/widgets/ruler.h
index c21cf0fa8..7fa3d334c 100644
--- a/src/widgets/ruler.h
+++ b/src/widgets/ruler.h
@@ -18,6 +18,8 @@
#include <iostream>
#include <glib.h>
+G_BEGIN_DECLS
+
#define SP_TYPE_RULER (sp_ruler_get_type ())
#define SP_RULER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SP_TYPE_RULER, SPRuler))
#define SP_RULER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SP_TYPE_RULER, SPRulerClass))
@@ -30,12 +32,9 @@ typedef struct _SPRuler SPRuler;
typedef struct _SPRulerClass SPRulerClass;
typedef struct _SPRulerMetric SPRulerMetric;
-/* All distances below are in 1/72nd's of an inch. (According to
- * Adobe that's a point, but points are really 1/72.27 in.)
- */
struct _SPRuler
{
- GtkWidget widget;
+ GtkWidget parent_instance;
};
struct _SPRulerClass
@@ -45,9 +44,6 @@ struct _SPRulerClass
struct _SPRulerMetric
{
- /* This should be points_per_unit. This is the size of the unit
- * in 1/72nd's of an inch and has nothing to do with screen pixels */
- gdouble pixels_per_unit;
gdouble ruler_scale[10];
gint subdivide[5]; /* five possible modes of subdivision */
};
@@ -77,6 +73,8 @@ void sp_ruler_set_metric (SPRuler *ruler,
SPMetric metric);
SPMetric sp_ruler_get_metric (SPRuler *ruler);
+G_END_DECLS
+
#endif /* __SP_RULER_H__ */
/*