ruler.cpp revision 6688c01ec1a01f023a66cbd510a9f781238ce3d3
/*
* Customized ruler class for inkscape. Note that this is a fork of
* the GimpRuler widget from GIMP: libgimpwidgets/gimpruler.c.
* The GIMP code is released under the GPL 3. The GIMP code itself
* is a fork of the now-obsolete GtkRuler widget from GTK+ 2.
*
* Major differences between implementations in Inkscape and GIMP are
* as follows:
* - We use a 1,2,4,8... scale for inches and 1,2,5,10... for everything
* else. GIMP uses 1,2,5,10... for everything.
*
* - We use a default font size of PANGO_SCALE_X_SMALL for labels,
* GIMP uses PANGO_SCALE_SMALL (i.e., a bit larger than ours).
*
* - We abbreviate large numbers in tick-labels (e.g., 10000 -> 10k)
*
* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
* Frank Felfe <innerspace@iname.com>
* bulia byak <buliabyak@users.sf.net>
* Diederik van Lierop <mail@diedenrezi.nl>
* Jon A. Cruz <jon@joncruz.org>
* Alex Valavanis <valavanisalex@gmail.com>
*
* Copyright (C) 1999-2011 authors
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include <cstring>
#include <cmath>
#include <cstdio>
#include "widget-sizes.h"
#include "ruler.h"
#include "round.h"
#define ROUND(x) ((int) ((x) + 0.5))
#define GTK_PARAM_READWRITE G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB
#define MINIMUM_INCR 5
#define IMMEDIATE_REDRAW_THRESHOLD 20
enum {
};
/* 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.)
*/
typedef struct
{
#define SP_RULER_GET_PRIVATE(ruler) \
struct SPRulerMetric
{
};
// Ruler metric for general use.
static SPRulerMetric const ruler_metric_general = {
{ 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000, 10000, 25000, 50000, 100000 },
{ 1, 5, 10, 50, 100 }
};
// Ruler metric for inch scales.
static SPRulerMetric const ruler_metric_inches = {
{ 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768 },
{ 1, 2, 4, 8, 16 }
};
GParamSpec *pspec);
GParamSpec *pspec);
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
#if !GTK_CHECK_VERSION(3,0,0)
#endif
#define parent_class sp_ruler_parent_class
static void
{
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
g_param_spec_enum ("orientation",
_("Orientation"),
_("The orientation of the ruler"),
static_cast<GParamFlags>(GTK_PARAM_READWRITE)));
/* FIXME: Should probably use g_param_spec_enum */
g_param_spec_string ("unit",
_("Unit"),
_("Unit of the ruler"),
"px",
static_cast<GParamFlags>(GTK_PARAM_READWRITE)));
g_param_spec_double ("lower",
_("Lower"),
_("Lower limit of ruler"),
0.0,
static_cast<GParamFlags>(GTK_PARAM_READWRITE)));
g_param_spec_double ("upper",
_("Upper"),
_("Upper limit of ruler"),
0.0,
static_cast<GParamFlags>(GTK_PARAM_READWRITE)));
g_param_spec_double ("position",
_("Position"),
_("Position of mark on the ruler"),
0.0,
static_cast<GParamFlags>(GTK_PARAM_READWRITE)));
g_param_spec_double ("max-size",
_("Max Size"),
_("Maximum size of the ruler"),
0.0,
static_cast<GParamFlags>(GTK_PARAM_READWRITE)));
g_param_spec_double ("font-scale",
0.0,
}
static void
{
priv->last_pos_rect.x = 0;
priv->last_pos_rect.y = 0;
priv->pos_redraw_idle_id = 0;
#if GTK_CHECK_VERSION(3,0,0)
"SPRuler {\n"
" background-color: @bg_color;\n"
"}\n";
#endif
}
static void
{
while (priv->track_widgets)
if (priv->pos_redraw_idle_id)
{
priv->pos_redraw_idle_id = 0;
}
}
/**
* sp_ruler_set_range:
* @ruler: the SPRuler
* @lower: the lower limit of the ruler
* @upper: the upper limit of the ruler
* @max_size: the maximum size of the ruler used when calculating the space to
* leave for the text
*
* This sets the range of the ruler.
*/
void
{
{
}
{
}
{
}
}
/**
* sp_ruler_get_range:
* @ruler: a #SPRuler
* @lower: (allow-none): location to store lower limit of the ruler, or %NULL
* @upper: (allow-none): location to store upper limit of the ruler, or %NULL
* @max_size: location to store the maximum size of the ruler used when calculating
* the space to leave for the text, or %NULL.
*
* Retrieves values indicating the range and current position of a #SPRuler.
* See sp_ruler_set_range().
**/
void
{
if (lower)
if (upper)
if (max_size)
}
static void
{
switch (prop_id)
{
case PROP_ORIENTATION:
break;
case PROP_UNIT:
break;
case PROP_LOWER:
break;
case PROP_UPPER:
break;
case PROP_POSITION:
break;
case PROP_MAX_SIZE:
break;
default:
break;
}
}
static void
{
switch (prop_id)
{
case PROP_ORIENTATION:
break;
case PROP_UNIT:
break;
case PROP_LOWER:
break;
case PROP_UPPER:
break;
case PROP_POSITION:
break;
case PROP_MAX_SIZE:
break;
default:
break;
}
}
static void
{
attributes.x = allocation.x;
attributes.y = allocation.y;
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
}
static void
{
if (priv->backing_store)
{
}
{
}
if (priv->input_window)
{
}
}
static void
{
if (priv->input_window)
}
static void
{
if (priv->input_window)
}
static void
{
if (gtk_widget_get_realized (widget))
{
allocation->x, allocation->y,
if (resized)
}
}
static void
{
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
{
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
}
else
{
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
}
}
static void
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
{
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
NULL);
{
}
}
#if GTK_CHECK_VERSION(3,0,0)
static void
{
}
static void
{
}
#else
static gboolean
{
cairo_clip (cr);
cairo_destroy (cr);
return result;
}
#endif
static gboolean
{
return FALSE;
}
static void
{
if (priv->backing_store)
}
static void
{
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
if (! gtk_widget_is_drawable (widget))
return;
{
#if GTK_CHECK_VERSION(3,0,0)
&color);
#else
#endif
{
pos_rect.y);
}
else
{
}
cairo_fill (cr);
}
}
/**
* sp_ruler_new:
* @orientation: the ruler's orientation
*
* Creates a new ruler.
*
* Return value: a new #SPRuler widget.
*/
{
"orientation", orientation,
NULL));
}
static void
gdouble x,
gdouble y)
{
{
lower +
}
else
{
lower +
}
}
/* Returns TRUE if a translation should be done */
static gboolean
int *x,
int *y)
{
GdkWindow *w, *widget_window;
if (! gtk_widget_get_has_window (widget))
{
*x = -allocation.x;
*y = -allocation.y;
}
else
{
*x = 0;
*y = 0;
}
for (w = window;
w && w != widget_window;
w = gdk_window_get_effective_parent (w))
{
*x += px;
*y += px;
}
if (w == NULL)
{
*x = 0;
*y = 0;
return FALSE;
}
return TRUE;
}
static void
{
{
}
}
static gboolean
{
{
}
return FALSE;
}
void
{
ruler);
ruler);
}
/**
* sp_ruler_remove_track_widget:
* @ruler: an #SPRuler
* @widget: the track widget to remove
*
* Removes a previously added track widget from the ruler. See
* sp_ruler_add_track_widget().
*/
void
{
ruler);
ruler);
}
/**
* sp_ruler_set_unit:
* @ruler: a #SPRuler
* @unit: the #SPMetric to set the ruler to
*
* This sets the unit of the ruler.
*/
void
{
{
}
}
/**
* sp_ruler_get_unit:
* @ruler: a #SPRuler
*
* Return value: the unit currently used in the @ruler widget.
**/
{
}
/**
* sp_ruler_set_position:
* @ruler: a #SPRuler
* @position: the position to set the ruler to
*
* This sets the position of the ruler.
*/
void
{
{
/*
* If the position has changed far enough, queue a redraw immediately.
* Otherwise, we only queue a redraw in a low priority idle handler, to
* allow for other things (like updating the canvas) to run.
*
* TODO: This might not be necessary any more in GTK3 with the frame
* clock. Investigate this more after the port to GTK3.
*/
{
}
else if (! priv->pos_redraw_idle_id)
{
}
}
}
/**
* sp_ruler_get_position:
* @ruler: a #SPRuler
*
* Return value: the current position of the @ruler widget.
*/
{
}
static gboolean
{
return FALSE;
}
static void
{
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
gint i;
if (! gtk_widget_is_drawable (widget))
return;
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
digit_offset = ink_rect.y;
{
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
}
else
{
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
}
#if GTK_CHECK_VERSION(3,0,0)
&color);
{
1);
}
else
{
1,
}
#else
cairo_paint (cr);
{
height + ythickness,
1);
}
else
{
height + xthickness,
1,
}
#endif
goto out;
/* determine the scale
* Use the maximum extents of the ruler to determine the largest
* possible number to be displayed. Calculate the height in pixels
* of this displayed text. Use this height to find a scale which
* leaves sufficient room for drawing the ruler.
*
* We calculate the text size as for the vruler instead of
* actually measuring the text width, so that the result for the
* scale looks consistent with an accompanying vruler
*/
/* Inkscape change to ruler: Use a 1,2,4,8... scale for inches
* or a 1,2,5,10... scale for everything else */
break;
/* drawing starts here */
length = 0;
{
/* hack to get proper subdivisions at full pixels */
subd_incr = 1.0;
else
continue;
/* Calculate the length of the tickmarks. Make sure that
* this length increases for each set of ticks
*/
if (ideal_length > ++length)
{
}
else
{
}
gint tick_index = 0;
{
// due to the typical values for cur, lower and increment, pos will often end up to
// be e.g. 641.50000000000; rounding behaviour is not defined in such a case (see round.h)
// and jitter will be apparent (upon redrawing some of the lines on the ruler might jump a
// by a pixel, and jump back on the next redraw). This is suppressed by adding 1e-9 (that's only one nanopixel ;-))
#if GTK_CHECK_VERSION(3,0,0)
{
1, length);
}
else
{
length, 1);
}
#else
{
1, length);
}
else
{
length, 1);
}
#endif
/* draw label */
double label_spacing_px = fabs(increment*(double)ruler_metric.ruler_scale[scale]/ruler_metric.subdivide[i]);
if (i == 0 &&
{
else
{
#if GTK_CHECK_VERSION(3,0,0)
pos + 2,
#else
pos + 2,
#endif
}
else
{
gint j;
{
#if GTK_CHECK_VERSION(3,0,0)
#else
xthickness + 1,
#endif
}
}
}
++tick_index;
}
}
cairo_fill (cr);
out:
cairo_destroy (cr);
}
static GdkRectangle
{
GdkRectangle rect = { 0, 0, 0, 0 };
if (! gtk_widget_is_drawable (widget))
return rect;
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
{
}
else
{
}
{
}
else
{
}
rect.x += allocation.x;
rect.y += allocation.y;
return rect;
}
static gboolean
{
priv->pos_redraw_idle_id = 0;
return ret;
}
static void
{
rect.x,
rect.y,
{
priv->last_pos_rect.x,
priv->last_pos_rect.y,
priv->last_pos_rect.x = 0;
priv->last_pos_rect.y = 0;
}
}
static PangoLayout*
{
attrs = pango_attr_list_new ();
attr->start_index = 0;
return layout;
}
static PangoLayout *
{
{
}
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :