ruler.cpp revision 9bcabeae6022ee91934738a05a4256d777352248
1549N/A#include "widget-sizes.h"
1549N/A#include "desktop-widget.h"
1549N/A#include "unit-constants.h"
1549N/A#define GTK_PARAM_READWRITE G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB
1549N/Astruct _SPRulerPrivate
1549N/A#define SP_RULER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), SP_TYPE_RULER, SPRulerPrivate))
1549N/A// Note: const casts are due to SPRuler being const-broken and not scheduled for any more fixes.
1549N/A {const_cast<gchar*>("NONE"), const_cast<gchar*>(""), 1, { 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000 }, { 1, 5, 10, 50, 100 }},
1549N/A {const_cast<gchar*>("millimeters"), const_cast<gchar*>("mm"), PX_PER_MM, { 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000 }, { 1, 5, 10, 50, 100 }},
1549N/A {const_cast<gchar*>("centimeters"), const_cast<gchar*>("cm"), PX_PER_CM, { 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000 }, { 1, 5, 10, 50, 100 }},
1549N/A {const_cast<gchar*>("inches"), const_cast<gchar*>("in"), PX_PER_IN, { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512 }, { 1, 2, 4, 8, 16 }},
1549N/A {const_cast<gchar*>("feet"), const_cast<gchar*>("ft"), PX_PER_FT, { 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000 }, { 1, 5, 10, 50, 100 }},
1549N/A {const_cast<gchar*>("points"), const_cast<gchar*>("pt"), PX_PER_PT, { 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000 }, { 1, 5, 10, 50, 100 }},
1549N/A {const_cast<gchar*>("picas"), const_cast<gchar*>("pc"), PX_PER_PC, { 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000 }, { 1, 5, 10, 50, 100 }},
1549N/A {const_cast<gchar*>("pixels"), const_cast<gchar*>("px"), PX_PER_PX, { 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000 }, { 1, 5, 10, 50, 100 }},
1549N/A {const_cast<gchar*>("meters"), const_cast<gchar*>("m"), PX_PER_M, { 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000 }, { 1, 5, 10, 50, 100 }},
1549N/A * @position: (allow-none): location to store the current position of the mark on the ruler, or %NULL
1549N/A case PROP_ORIENTATION:
1549N/A case PROP_LOWER:
1549N/A case PROP_UPPER:
1549N/A case PROP_POSITION:
1549N/A case PROP_MAX_SIZE:
1549N/A case PROP_METRIC:
1549N/A case PROP_ORIENTATION:
1549N/A case PROP_LOWER:
1549N/A case PROP_UPPER:
1549N/A case PROP_POSITION:
1549N/A case PROP_MAX_SIZE:
1549N/A case PROP_METRIC:
static void sp_ruler_get_preferred_width(GtkWidget *widget, gint *minimal_width, gint *natural_width)
static void sp_ruler_get_preferred_height(GtkWidget *widget, gint *minimal_height, gint *natural_height)
if(resized)
static gboolean
return FALSE;
gint x, y;
#define UNUSED_PIXELS 2 // There appear to be two pixels that are not being used at each end of the ruler
NULL));
priv->position = priv->lower + (priv->upper - priv->lower) * (x + UNUSED_PIXELS) / (allocation.width + 2*UNUSED_PIXELS);
priv->position = priv->lower + (priv->upper - priv->lower) * (y + UNUSED_PIXELS) / (allocation.height + 2*UNUSED_PIXELS);
return FALSE;
gint digit_height = (int) floor (RULER_FONT_SIZE * RULER_FONT_VERTICAL_SPACING / PANGO_SCALE + 0.5);
gdouble upper = priv->upper / priv->metric->pixels_per_unit; // upper and lower are expressed in ruler units
double increment = (double) (width + 2*UNUSED_PIXELS) / (upper - lower); // screen pixels per ruler unit
gdouble cur = start; // location (in ruler units) of the first invisible tick at the left side of the canvas
// be e.g. 641.50000000000; rounding behaviour is not defined in such a case (see round.h)
// by a pixel, and jump back on the next redraw). This is suppressed by adding 1e-9 (that's only one nanopixel ;-))
double label_spacing_px = fabs((increment*(double)priv->metric->ruler_scale[scale])/priv->metric->subdivide[i]);
++tick_index;
if (metric == 0)