summaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
authorAlex Valavanis <valavanisalex@gmail.com>2012-12-24 12:36:29 +0000
committerAlex Valavanis <valavanisalex@gmail.com>2012-12-24 12:36:29 +0000
commitc7843b31ce20afbc5cf12de77dc082477d5ce174 (patch)
treea0be47b7ca47ee1c7b3a89f8eadf27eed6e10d3f /src/widgets
parentruler: (Merge from GIMP) Cache PangoLayout (diff)
downloadinkscape-c7843b31ce20afbc5cf12de77dc082477d5ce174.tar.gz
inkscape-c7843b31ce20afbc5cf12de77dc082477d5ce174.zip
ruler: (Merge from GIMP) private update_position function
(bzr r11980)
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/ruler.cpp73
1 files changed, 50 insertions, 23 deletions
diff --git a/src/widgets/ruler.cpp b/src/widgets/ruler.cpp
index 2db84339e..b7d8e8eb1 100644
--- a/src/widgets/ruler.cpp
+++ b/src/widgets/ruler.cpp
@@ -44,7 +44,6 @@ struct _SPRulerPrivate
SPRulerMetric *metric;
- gint slider_size;
gint xsrc;
gint ysrc;
};
@@ -784,13 +783,48 @@ sp_ruler_draw_pos (SPRuler *ruler)
#define UNUSED_PIXELS 2 // There appear to be two pixels that are not being used at each end of the ruler
-GtkWidget* sp_ruler_new(GtkOrientation orientation)
+/**
+ * sp_ruler_new:
+ * @orientation: the ruler's orientation
+ *
+ * Creates a new ruler.
+ *
+ * Return value: a new #SPRuler widget.
+ */
+GtkWidget *
+sp_ruler_new (GtkOrientation orientation)
{
- return GTK_WIDGET(g_object_new(SP_TYPE_RULER,
- "orientation", orientation,
- NULL));
+ return GTK_WIDGET (g_object_new (SP_TYPE_RULER,
+ "orientation", orientation,
+ NULL));
}
+static void
+sp_ruler_update_position (SPRuler *ruler,
+ gdouble x,
+ gdouble y)
+{
+ SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler);
+ GtkAllocation allocation;
+ gdouble lower;
+ gdouble upper;
+
+ gtk_widget_get_allocation (GTK_WIDGET (ruler), &allocation);
+ sp_ruler_get_range (ruler, &lower, &upper, NULL);
+
+ if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
+ {
+ sp_ruler_set_position (ruler,
+ lower +
+ (upper - lower) * x / allocation.width);
+ }
+ else
+ {
+ sp_ruler_set_position (ruler,
+ lower +
+ (upper - lower) * y / allocation.height);
+ }
+}
/**
* sp_ruler_set_position:
@@ -836,24 +870,9 @@ static gboolean
sp_ruler_motion_notify (GtkWidget *widget,
GdkEventMotion *event)
{
- GtkAllocation allocation;
SPRuler *ruler = SP_RULER(widget);
- SPRulerPrivate *priv = SP_RULER_GET_PRIVATE (ruler);
-
- gdk_event_request_motions(event);
- gint x = event->x;
- gint y = event->y;
-
- gtk_widget_get_allocation(widget, &allocation);
-
- if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
- priv->position = priv->lower + (priv->upper - priv->lower) * (x + UNUSED_PIXELS) / (allocation.width + 2*UNUSED_PIXELS);
- else
- priv->position = priv->lower + (priv->upper - priv->lower) * (y + UNUSED_PIXELS) / (allocation.height + 2*UNUSED_PIXELS);
- g_object_notify(G_OBJECT(ruler), "position");
-
- gtk_widget_queue_draw(widget);
+ sp_ruler_update_position (ruler, event->x, event->y);
return FALSE;
}
@@ -915,12 +934,20 @@ sp_ruler_draw_ticks (SPRuler *ruler)
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
{
width = allocation.width; // in pixels; is apparently 2 pixels shorter than the canvas at each end
- height = allocation.height;
+#if GTK_CHECK_VERSION(3,0,0)
+ height = allocation.height - (border.top + border.bottom);
+#else
+ height = allocation.height - ythickness * 2;
+#endif
}
else
{
width = allocation.height;
- height = allocation.width;
+#if GTK_CHECK_VERSION(3,0,0)
+ height = allocation.width - (border.top + border.bottom);
+#else
+ height = allocation.width - ythickness * 2;
+#endif
}
cr = cairo_create (priv->backing_store);