2008-05-27 05:20:16 +08:00
|
|
|
/* LIBGIMP - The GIMP Library
|
|
|
|
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This library is free software: you can redistribute it and/or
|
2008-05-27 05:20:16 +08:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2009-01-18 06:28:01 +08:00
|
|
|
* version 3 of the License, or (at your option) any later version.
|
2008-05-27 05:20:16 +08:00
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2009-01-18 06:28:01 +08:00
|
|
|
* License along with this library. If not, see
|
|
|
|
* <http://www.gnu.org/licenses/>.
|
2008-05-27 05:20:16 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2008-08-29 18:25:29 +08:00
|
|
|
#include <string.h>
|
|
|
|
|
2008-05-27 05:20:16 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2008-05-28 19:49:24 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
2008-08-29 18:25:29 +08:00
|
|
|
#include "libgimpmath/gimpmath.h"
|
2008-05-28 19:49:24 +08:00
|
|
|
|
2008-05-27 05:20:16 +08:00
|
|
|
#include "gimpwidgetstypes.h"
|
|
|
|
|
|
|
|
#include "gimpruler.h"
|
|
|
|
|
|
|
|
|
2008-10-05 05:47:53 +08:00
|
|
|
#define DEFAULT_RULER_FONT_SCALE PANGO_SCALE_SMALL
|
2008-10-04 06:11:15 +08:00
|
|
|
#define MINIMUM_INCR 5
|
2008-08-29 18:25:29 +08:00
|
|
|
|
2008-05-27 05:20:16 +08:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
2008-08-29 18:25:29 +08:00
|
|
|
PROP_ORIENTATION,
|
2008-05-28 19:49:24 +08:00
|
|
|
PROP_UNIT,
|
2008-05-27 05:20:16 +08:00
|
|
|
PROP_LOWER,
|
|
|
|
PROP_UPPER,
|
|
|
|
PROP_POSITION,
|
2008-05-28 18:18:43 +08:00
|
|
|
PROP_MAX_SIZE
|
2008-05-27 05:20:16 +08:00
|
|
|
};
|
|
|
|
|
2008-08-29 18:25:29 +08:00
|
|
|
|
|
|
|
/* 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
|
|
|
|
{
|
|
|
|
GtkOrientation orientation;
|
|
|
|
GimpUnit unit;
|
|
|
|
gdouble lower;
|
|
|
|
gdouble upper;
|
|
|
|
gdouble position;
|
|
|
|
gdouble max_size;
|
|
|
|
|
|
|
|
GdkPixmap *backing_store;
|
|
|
|
GdkGC *non_gr_exp_gc;
|
2008-10-05 07:32:41 +08:00
|
|
|
PangoLayout *layout;
|
2008-10-04 06:11:15 +08:00
|
|
|
gdouble font_scale;
|
2008-08-29 18:25:29 +08:00
|
|
|
|
|
|
|
gint xsrc;
|
|
|
|
gint ysrc;
|
|
|
|
} GimpRulerPrivate;
|
|
|
|
|
|
|
|
|
|
|
|
static const struct
|
|
|
|
{
|
2008-10-04 06:11:15 +08:00
|
|
|
const gdouble ruler_scale[16];
|
|
|
|
const gint subdivide[5];
|
2008-08-29 18:25:29 +08:00
|
|
|
} ruler_metric =
|
|
|
|
{
|
|
|
|
{ 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000, 10000, 25000, 50000, 100000 },
|
|
|
|
{ 1, 5, 10, 50, 100 }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void gimp_ruler_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gimp_ruler_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
|
|
|
|
static void gimp_ruler_realize (GtkWidget *widget);
|
|
|
|
static void gimp_ruler_unrealize (GtkWidget *widget);
|
|
|
|
static void gimp_ruler_size_allocate (GtkWidget *widget,
|
|
|
|
GtkAllocation *allocation);
|
2008-10-05 07:13:44 +08:00
|
|
|
static void gimp_ruler_size_request (GtkWidget *widget,
|
|
|
|
GtkRequisition *requisition);
|
2008-10-04 06:11:15 +08:00
|
|
|
static void gimp_ruler_style_set (GtkWidget *widget,
|
|
|
|
GtkStyle *prev_style);
|
2008-08-29 18:25:29 +08:00
|
|
|
static gboolean gimp_ruler_motion_notify (GtkWidget *widget,
|
|
|
|
GdkEventMotion *event);
|
|
|
|
static gboolean gimp_ruler_expose (GtkWidget *widget,
|
|
|
|
GdkEventExpose *event);
|
|
|
|
|
|
|
|
static void gimp_ruler_draw_ticks (GimpRuler *ruler);
|
|
|
|
static void gimp_ruler_draw_pos (GimpRuler *ruler);
|
|
|
|
static void gimp_ruler_make_pixmap (GimpRuler *ruler);
|
2008-10-05 07:32:41 +08:00
|
|
|
|
|
|
|
static PangoLayout * gimp_ruler_get_layout (GtkWidget *widget,
|
2008-08-29 18:25:29 +08:00
|
|
|
const gchar *text);
|
|
|
|
|
2008-05-27 05:20:16 +08:00
|
|
|
|
|
|
|
G_DEFINE_TYPE (GimpRuler, gimp_ruler, GTK_TYPE_WIDGET)
|
|
|
|
|
|
|
|
#define GIMP_RULER_GET_PRIVATE(ruler) \
|
|
|
|
G_TYPE_INSTANCE_GET_PRIVATE (ruler, GIMP_TYPE_RULER, GimpRulerPrivate)
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_ruler_class_init (GimpRulerClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
|
2008-08-29 18:25:29 +08:00
|
|
|
object_class->set_property = gimp_ruler_set_property;
|
|
|
|
object_class->get_property = gimp_ruler_get_property;
|
2008-05-27 05:20:16 +08:00
|
|
|
|
2008-08-29 18:25:29 +08:00
|
|
|
widget_class->realize = gimp_ruler_realize;
|
|
|
|
widget_class->unrealize = gimp_ruler_unrealize;
|
|
|
|
widget_class->size_allocate = gimp_ruler_size_allocate;
|
2008-10-05 07:13:44 +08:00
|
|
|
widget_class->size_request = gimp_ruler_size_request;
|
2008-10-04 06:11:15 +08:00
|
|
|
widget_class->style_set = gimp_ruler_style_set;
|
2008-08-29 18:25:29 +08:00
|
|
|
widget_class->motion_notify_event = gimp_ruler_motion_notify;
|
|
|
|
widget_class->expose_event = gimp_ruler_expose;
|
2008-05-27 05:20:16 +08:00
|
|
|
|
|
|
|
g_type_class_add_private (object_class, sizeof (GimpRulerPrivate));
|
|
|
|
|
2008-08-29 18:25:29 +08:00
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_ORIENTATION,
|
|
|
|
g_param_spec_enum ("orientation",
|
|
|
|
"Orientation",
|
|
|
|
"The orientation of the ruler",
|
|
|
|
GTK_TYPE_ORIENTATION,
|
|
|
|
GTK_ORIENTATION_HORIZONTAL,
|
|
|
|
GIMP_PARAM_READWRITE));
|
|
|
|
|
2008-05-28 19:49:24 +08:00
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_LOWER,
|
|
|
|
gimp_param_spec_unit ("unit",
|
|
|
|
"Unit",
|
|
|
|
"Unit of ruler",
|
|
|
|
TRUE, TRUE,
|
|
|
|
GIMP_UNIT_PIXEL,
|
|
|
|
GIMP_PARAM_READWRITE));
|
|
|
|
|
2008-05-27 05:20:16 +08:00
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_LOWER,
|
|
|
|
g_param_spec_double ("lower",
|
2008-05-27 21:41:48 +08:00
|
|
|
"Lower",
|
|
|
|
"Lower limit of ruler",
|
|
|
|
-G_MAXDOUBLE,
|
|
|
|
G_MAXDOUBLE,
|
|
|
|
0.0,
|
|
|
|
GIMP_PARAM_READWRITE));
|
2008-05-27 05:20:16 +08:00
|
|
|
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_UPPER,
|
|
|
|
g_param_spec_double ("upper",
|
2008-05-27 21:41:48 +08:00
|
|
|
"Upper",
|
|
|
|
"Upper limit of ruler",
|
|
|
|
-G_MAXDOUBLE,
|
|
|
|
G_MAXDOUBLE,
|
|
|
|
0.0,
|
|
|
|
GIMP_PARAM_READWRITE));
|
2008-05-27 05:20:16 +08:00
|
|
|
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_POSITION,
|
|
|
|
g_param_spec_double ("position",
|
|
|
|
"Position",
|
2008-05-27 21:41:48 +08:00
|
|
|
"Position of mark on the ruler",
|
|
|
|
-G_MAXDOUBLE,
|
|
|
|
G_MAXDOUBLE,
|
|
|
|
0.0,
|
|
|
|
GIMP_PARAM_READWRITE));
|
2008-05-27 05:20:16 +08:00
|
|
|
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_MAX_SIZE,
|
|
|
|
g_param_spec_double ("max-size",
|
2008-05-27 21:41:48 +08:00
|
|
|
"Max Size",
|
|
|
|
"Maximum size of the ruler",
|
|
|
|
-G_MAXDOUBLE,
|
|
|
|
G_MAXDOUBLE,
|
|
|
|
0.0,
|
|
|
|
GIMP_PARAM_READWRITE));
|
2008-10-04 06:11:15 +08:00
|
|
|
|
|
|
|
gtk_widget_class_install_style_property (widget_class,
|
|
|
|
g_param_spec_double ("font-scale",
|
|
|
|
NULL, NULL,
|
|
|
|
0.0,
|
|
|
|
G_MAXDOUBLE,
|
|
|
|
DEFAULT_RULER_FONT_SCALE,
|
|
|
|
GIMP_PARAM_READABLE));
|
2008-05-27 05:20:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_ruler_init (GimpRuler *ruler)
|
|
|
|
{
|
2008-10-05 07:13:44 +08:00
|
|
|
GimpRulerPrivate *priv = GIMP_RULER_GET_PRIVATE (ruler);
|
2008-08-29 18:25:29 +08:00
|
|
|
|
|
|
|
priv->orientation = GTK_ORIENTATION_HORIZONTAL;
|
2008-05-28 19:49:24 +08:00
|
|
|
priv->unit = GIMP_PIXELS;
|
2008-05-27 05:20:16 +08:00
|
|
|
priv->lower = 0;
|
|
|
|
priv->upper = 0;
|
|
|
|
priv->position = 0;
|
|
|
|
priv->max_size = 0;
|
2008-05-28 19:49:24 +08:00
|
|
|
priv->backing_store = NULL;
|
|
|
|
priv->non_gr_exp_gc = NULL;
|
2008-10-04 06:11:15 +08:00
|
|
|
priv->font_scale = DEFAULT_RULER_FONT_SCALE;
|
2008-05-27 05:20:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_ruler_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GimpRuler *ruler = GIMP_RULER (object);
|
|
|
|
GimpRulerPrivate *priv = GIMP_RULER_GET_PRIVATE (ruler);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
2008-08-29 18:25:29 +08:00
|
|
|
case PROP_ORIENTATION:
|
2008-10-09 02:47:13 +08:00
|
|
|
priv->orientation = g_value_get_enum (value);
|
|
|
|
gtk_widget_queue_resize (GTK_WIDGET (ruler));
|
2008-08-29 18:25:29 +08:00
|
|
|
break;
|
2008-10-05 07:13:44 +08:00
|
|
|
|
2008-05-28 19:49:24 +08:00
|
|
|
case PROP_UNIT:
|
|
|
|
gimp_ruler_set_unit (ruler, g_value_get_int (value));
|
|
|
|
break;
|
2008-10-05 07:13:44 +08:00
|
|
|
|
2008-05-27 05:20:16 +08:00
|
|
|
case PROP_LOWER:
|
2008-05-28 18:18:43 +08:00
|
|
|
gimp_ruler_set_range (ruler,
|
|
|
|
g_value_get_double (value),
|
|
|
|
priv->upper,
|
|
|
|
priv->max_size);
|
2008-05-27 05:20:16 +08:00
|
|
|
break;
|
|
|
|
case PROP_UPPER:
|
2008-05-28 18:18:43 +08:00
|
|
|
gimp_ruler_set_range (ruler,
|
|
|
|
priv->lower,
|
|
|
|
g_value_get_double (value),
|
|
|
|
priv->max_size);
|
2008-05-27 05:20:16 +08:00
|
|
|
break;
|
2008-10-05 07:13:44 +08:00
|
|
|
|
2008-05-27 05:20:16 +08:00
|
|
|
case PROP_POSITION:
|
2008-05-28 18:18:43 +08:00
|
|
|
gimp_ruler_set_position (ruler, g_value_get_double (value));
|
2008-05-27 05:20:16 +08:00
|
|
|
break;
|
2008-10-05 07:13:44 +08:00
|
|
|
|
2008-05-27 05:20:16 +08:00
|
|
|
case PROP_MAX_SIZE:
|
2008-05-28 18:18:43 +08:00
|
|
|
gimp_ruler_set_range (ruler,
|
|
|
|
priv->lower,
|
|
|
|
priv->upper,
|
|
|
|
g_value_get_double (value));
|
2008-05-27 05:20:16 +08:00
|
|
|
break;
|
2008-08-29 18:25:29 +08:00
|
|
|
|
2008-05-27 05:20:16 +08:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2008-10-09 02:47:13 +08:00
|
|
|
gimp_ruler_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2008-05-27 05:20:16 +08:00
|
|
|
{
|
|
|
|
GimpRuler *ruler = GIMP_RULER (object);
|
|
|
|
GimpRulerPrivate *priv = GIMP_RULER_GET_PRIVATE (ruler);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
2008-08-29 18:25:29 +08:00
|
|
|
case PROP_ORIENTATION:
|
|
|
|
g_value_set_enum (value, priv->orientation);
|
|
|
|
break;
|
2008-10-05 07:13:44 +08:00
|
|
|
|
2008-05-28 19:49:24 +08:00
|
|
|
case PROP_UNIT:
|
|
|
|
g_value_set_int (value, priv->unit);
|
|
|
|
break;
|
2008-10-05 07:13:44 +08:00
|
|
|
|
2008-05-27 05:20:16 +08:00
|
|
|
case PROP_LOWER:
|
|
|
|
g_value_set_double (value, priv->lower);
|
|
|
|
break;
|
2008-10-05 07:13:44 +08:00
|
|
|
|
2008-05-27 05:20:16 +08:00
|
|
|
case PROP_UPPER:
|
|
|
|
g_value_set_double (value, priv->upper);
|
|
|
|
break;
|
2008-10-05 07:13:44 +08:00
|
|
|
|
2008-05-27 05:20:16 +08:00
|
|
|
case PROP_POSITION:
|
|
|
|
g_value_set_double (value, priv->position);
|
|
|
|
break;
|
2008-10-05 07:13:44 +08:00
|
|
|
|
2008-05-27 05:20:16 +08:00
|
|
|
case PROP_MAX_SIZE:
|
|
|
|
g_value_set_double (value, priv->max_size);
|
|
|
|
break;
|
2008-08-29 18:25:29 +08:00
|
|
|
|
2008-05-27 05:20:16 +08:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-29 18:25:29 +08:00
|
|
|
/**
|
2008-08-29 18:43:21 +08:00
|
|
|
* gimp_ruler_new:
|
2008-08-29 18:25:29 +08:00
|
|
|
* @orientation: the ruler's orientation.
|
|
|
|
*
|
|
|
|
* Creates a new ruler.
|
|
|
|
*
|
|
|
|
* Return value: a new #GimpRuler widget.
|
|
|
|
*
|
|
|
|
* Since: GIMP 2.8
|
|
|
|
**/
|
|
|
|
GtkWidget *
|
|
|
|
gimp_ruler_new (GtkOrientation orientation)
|
|
|
|
{
|
|
|
|
return g_object_new (GIMP_TYPE_RULER,
|
|
|
|
"orientation", orientation,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2008-05-28 19:49:24 +08:00
|
|
|
/**
|
|
|
|
* gimp_ruler_set_position:
|
|
|
|
* @ruler: a #GimpRuler
|
|
|
|
* @unit: the #GimpUnit to set the ruler to
|
|
|
|
*
|
|
|
|
* This sets the unit of the ruler.
|
|
|
|
*
|
|
|
|
* Since: GIMP 2.8
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gimp_ruler_set_unit (GimpRuler *ruler,
|
|
|
|
GimpUnit unit)
|
|
|
|
{
|
|
|
|
GimpRulerPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_RULER (ruler));
|
|
|
|
|
|
|
|
priv = GIMP_RULER_GET_PRIVATE (ruler);
|
|
|
|
|
|
|
|
if (priv->unit != unit)
|
|
|
|
{
|
|
|
|
priv->unit = unit;
|
|
|
|
g_object_notify (G_OBJECT (ruler), "unit");
|
|
|
|
|
|
|
|
gtk_widget_queue_draw (GTK_WIDGET (ruler));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_ruler_get_unit:
|
|
|
|
* @ruler: a #GimpRuler
|
|
|
|
*
|
|
|
|
* Return value: the unit currently used in the @ruler widget.
|
|
|
|
*
|
|
|
|
* Since: GIMP 2.8
|
|
|
|
**/
|
|
|
|
GimpUnit
|
|
|
|
gimp_ruler_get_unit (GimpRuler *ruler)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_RULER (ruler), 0);
|
|
|
|
|
|
|
|
return GIMP_RULER_GET_PRIVATE (ruler)->unit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_ruler_set_position:
|
|
|
|
* @ruler: a #GimpRuler
|
|
|
|
* @position: the position to set the ruler to
|
|
|
|
*
|
|
|
|
* This sets the position of the ruler.
|
|
|
|
*
|
|
|
|
* Since: GIMP 2.8
|
|
|
|
*/
|
2008-05-27 05:20:16 +08:00
|
|
|
void
|
2008-05-28 18:18:43 +08:00
|
|
|
gimp_ruler_set_position (GimpRuler *ruler,
|
|
|
|
gdouble position)
|
2008-05-27 05:20:16 +08:00
|
|
|
{
|
|
|
|
GimpRulerPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_RULER (ruler));
|
|
|
|
|
|
|
|
priv = GIMP_RULER_GET_PRIVATE (ruler);
|
|
|
|
|
2008-05-28 18:18:43 +08:00
|
|
|
if (priv->position != position)
|
|
|
|
{
|
|
|
|
priv->position = position;
|
|
|
|
g_object_notify (G_OBJECT (ruler), "position");
|
2008-05-27 05:20:16 +08:00
|
|
|
|
2008-05-28 19:49:24 +08:00
|
|
|
gimp_ruler_draw_pos (ruler);
|
|
|
|
}
|
2008-05-27 05:20:16 +08:00
|
|
|
}
|
|
|
|
|
2008-05-28 19:49:24 +08:00
|
|
|
/**
|
|
|
|
* gimp_ruler_get_position:
|
|
|
|
* @ruler: a #GimpRuler
|
|
|
|
*
|
|
|
|
* Return value: the current position of the @ruler widget.
|
|
|
|
*
|
|
|
|
* Since: GIMP 2.8
|
|
|
|
**/
|
2008-05-28 18:18:43 +08:00
|
|
|
gdouble
|
|
|
|
gimp_ruler_get_position (GimpRuler *ruler)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_RULER (ruler), 0.0);
|
2008-05-27 05:20:16 +08:00
|
|
|
|
2008-05-28 18:18:43 +08:00
|
|
|
return GIMP_RULER_GET_PRIVATE (ruler)->position;
|
2008-05-27 05:20:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_ruler_set_range:
|
2008-05-28 19:49:24 +08:00
|
|
|
* @ruler: a #GimpRuler
|
2008-05-27 05:20:16 +08:00
|
|
|
* @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.
|
|
|
|
*
|
|
|
|
* Since: GIMP 2.8
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gimp_ruler_set_range (GimpRuler *ruler,
|
|
|
|
gdouble lower,
|
|
|
|
gdouble upper,
|
|
|
|
gdouble max_size)
|
|
|
|
{
|
|
|
|
GimpRulerPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_RULER (ruler));
|
|
|
|
|
|
|
|
priv = GIMP_RULER_GET_PRIVATE (ruler);
|
|
|
|
|
|
|
|
g_object_freeze_notify (G_OBJECT (ruler));
|
|
|
|
if (priv->lower != lower)
|
|
|
|
{
|
|
|
|
priv->lower = lower;
|
|
|
|
g_object_notify (G_OBJECT (ruler), "lower");
|
|
|
|
}
|
|
|
|
if (priv->upper != upper)
|
|
|
|
{
|
|
|
|
priv->upper = upper;
|
|
|
|
g_object_notify (G_OBJECT (ruler), "upper");
|
|
|
|
}
|
|
|
|
if (priv->max_size != max_size)
|
|
|
|
{
|
|
|
|
priv->max_size = max_size;
|
|
|
|
g_object_notify (G_OBJECT (ruler), "max-size");
|
|
|
|
}
|
|
|
|
g_object_thaw_notify (G_OBJECT (ruler));
|
|
|
|
|
2008-05-28 19:49:24 +08:00
|
|
|
gtk_widget_queue_draw (GTK_WIDGET (ruler));
|
2008-05-27 05:20:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_ruler_get_range:
|
|
|
|
* @ruler: a #GimpRuler
|
|
|
|
* @lower: location to store lower limit of the ruler, or %NULL
|
|
|
|
* @upper: location to store upper limit of the ruler, or %NULL
|
2008-05-28 19:49:24 +08:00
|
|
|
* @max_size: location to store the maximum size of the ruler used when
|
|
|
|
* calculating the space to leave for the text, or %NULL.
|
2008-05-27 05:20:16 +08:00
|
|
|
*
|
|
|
|
* Retrieves values indicating the range and current position of a #GimpRuler.
|
|
|
|
* See gimp_ruler_set_range().
|
|
|
|
*
|
|
|
|
* Since: GIMP 2.8
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gimp_ruler_get_range (GimpRuler *ruler,
|
|
|
|
gdouble *lower,
|
|
|
|
gdouble *upper,
|
|
|
|
gdouble *max_size)
|
|
|
|
{
|
|
|
|
GimpRulerPrivate *priv;
|
|
|
|
|
|
|
|
g_return_if_fail (GIMP_IS_RULER (ruler));
|
|
|
|
|
|
|
|
priv = GIMP_RULER_GET_PRIVATE (ruler);
|
|
|
|
|
|
|
|
if (lower)
|
|
|
|
*lower = priv->lower;
|
|
|
|
if (upper)
|
|
|
|
*upper = priv->upper;
|
|
|
|
if (max_size)
|
|
|
|
*max_size = priv->max_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_ruler_realize (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GimpRuler *ruler = GIMP_RULER (widget);
|
|
|
|
GdkWindowAttr attributes;
|
|
|
|
gint attributes_mask;
|
|
|
|
|
|
|
|
GTK_WIDGET_SET_FLAGS (ruler, GTK_REALIZED);
|
|
|
|
|
|
|
|
attributes.window_type = GDK_WINDOW_CHILD;
|
|
|
|
attributes.x = widget->allocation.x;
|
|
|
|
attributes.y = widget->allocation.y;
|
|
|
|
attributes.width = widget->allocation.width;
|
|
|
|
attributes.height = widget->allocation.height;
|
|
|
|
attributes.wclass = GDK_INPUT_OUTPUT;
|
|
|
|
attributes.visual = gtk_widget_get_visual (widget);
|
|
|
|
attributes.colormap = gtk_widget_get_colormap (widget);
|
2008-08-29 18:25:29 +08:00
|
|
|
attributes.event_mask = (gtk_widget_get_events (widget) |
|
|
|
|
GDK_EXPOSURE_MASK |
|
|
|
|
GDK_POINTER_MOTION_MASK |
|
2008-05-27 21:41:48 +08:00
|
|
|
GDK_POINTER_MOTION_HINT_MASK);
|
2008-05-27 05:20:16 +08:00
|
|
|
|
|
|
|
attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
|
|
|
|
|
|
|
|
widget->window = gdk_window_new (gtk_widget_get_parent_window (widget),
|
|
|
|
&attributes, attributes_mask);
|
|
|
|
gdk_window_set_user_data (widget->window, ruler);
|
|
|
|
|
|
|
|
widget->style = gtk_style_attach (widget->style, widget->window);
|
2008-09-02 20:30:53 +08:00
|
|
|
gtk_style_set_background (gtk_widget_get_style (widget), widget->window,
|
|
|
|
GTK_STATE_ACTIVE);
|
2008-05-27 05:20:16 +08:00
|
|
|
|
|
|
|
gimp_ruler_make_pixmap (ruler);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_ruler_unrealize (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GimpRuler *ruler = GIMP_RULER (widget);
|
|
|
|
GimpRulerPrivate *priv = GIMP_RULER_GET_PRIVATE (ruler);
|
|
|
|
|
|
|
|
if (priv->backing_store)
|
|
|
|
{
|
|
|
|
g_object_unref (priv->backing_store);
|
|
|
|
priv->backing_store = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->non_gr_exp_gc)
|
|
|
|
{
|
|
|
|
g_object_unref (priv->non_gr_exp_gc);
|
|
|
|
priv->non_gr_exp_gc = NULL;
|
|
|
|
}
|
|
|
|
|
2008-10-05 07:32:41 +08:00
|
|
|
if (priv->layout)
|
|
|
|
{
|
|
|
|
g_object_unref (priv->layout);
|
|
|
|
priv->layout = NULL;
|
|
|
|
}
|
|
|
|
|
2008-08-29 18:25:29 +08:00
|
|
|
GTK_WIDGET_CLASS (gimp_ruler_parent_class)->unrealize (widget);
|
2008-05-27 05:20:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_ruler_size_allocate (GtkWidget *widget,
|
|
|
|
GtkAllocation *allocation)
|
|
|
|
{
|
|
|
|
GimpRuler *ruler = GIMP_RULER (widget);
|
|
|
|
|
|
|
|
widget->allocation = *allocation;
|
|
|
|
|
|
|
|
if (GTK_WIDGET_REALIZED (widget))
|
|
|
|
{
|
2009-03-22 23:42:42 +08:00
|
|
|
gdk_window_move_resize (gtk_widget_get_window (widget),
|
2008-05-27 21:41:48 +08:00
|
|
|
allocation->x, allocation->y,
|
|
|
|
allocation->width, allocation->height);
|
2008-05-27 05:20:16 +08:00
|
|
|
|
|
|
|
gimp_ruler_make_pixmap (ruler);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-05 07:13:44 +08:00
|
|
|
static void
|
|
|
|
gimp_ruler_size_request (GtkWidget *widget,
|
|
|
|
GtkRequisition *requisition)
|
|
|
|
{
|
|
|
|
GimpRulerPrivate *priv = GIMP_RULER_GET_PRIVATE (widget);
|
|
|
|
GtkStyle *style = gtk_widget_get_style (widget);
|
2008-10-05 07:32:41 +08:00
|
|
|
PangoLayout *layout;
|
|
|
|
PangoRectangle ink_rect;
|
2008-10-05 07:13:44 +08:00
|
|
|
gint size;
|
|
|
|
|
2008-10-05 07:32:41 +08:00
|
|
|
layout = gimp_ruler_get_layout (widget, "0123456789");
|
|
|
|
pango_layout_get_pixel_extents (layout, &ink_rect, NULL);
|
|
|
|
|
|
|
|
size = 2 + ink_rect.height * 1.7;
|
2008-10-05 07:13:44 +08:00
|
|
|
|
|
|
|
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
|
|
|
|
{
|
|
|
|
widget->requisition.width = style->xthickness * 2 + 1;
|
|
|
|
widget->requisition.height = style->ythickness * 2 + size;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
widget->requisition.width = style->xthickness * 2 + size;
|
|
|
|
widget->requisition.height = style->ythickness * 2 + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-04 06:11:15 +08:00
|
|
|
static void
|
|
|
|
gimp_ruler_style_set (GtkWidget *widget,
|
|
|
|
GtkStyle *prev_style)
|
|
|
|
{
|
2008-10-05 07:13:44 +08:00
|
|
|
GimpRulerPrivate *priv = GIMP_RULER_GET_PRIVATE (widget);
|
2008-10-04 06:11:15 +08:00
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gimp_ruler_parent_class)->style_set (widget, prev_style);
|
|
|
|
|
|
|
|
gtk_widget_style_get (widget,
|
|
|
|
"font-scale", &priv->font_scale,
|
|
|
|
NULL);
|
2008-10-05 07:32:41 +08:00
|
|
|
|
|
|
|
if (priv->layout)
|
|
|
|
{
|
|
|
|
g_object_unref (priv->layout);
|
|
|
|
priv->layout = NULL;
|
|
|
|
}
|
2008-10-04 06:11:15 +08:00
|
|
|
}
|
|
|
|
|
2008-08-29 18:25:29 +08:00
|
|
|
static gboolean
|
|
|
|
gimp_ruler_motion_notify (GtkWidget *widget,
|
|
|
|
GdkEventMotion *event)
|
|
|
|
{
|
|
|
|
GimpRuler *ruler = GIMP_RULER (widget);
|
|
|
|
GimpRulerPrivate *priv = GIMP_RULER_GET_PRIVATE (ruler);
|
|
|
|
gdouble lower;
|
|
|
|
gdouble upper;
|
|
|
|
|
|
|
|
gdk_event_request_motions (event);
|
|
|
|
|
|
|
|
gimp_ruler_get_range (ruler, &lower, &upper, NULL);
|
|
|
|
|
|
|
|
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
|
|
|
|
{
|
|
|
|
gimp_ruler_set_position (ruler,
|
|
|
|
lower +
|
|
|
|
(upper - lower) * event->x /
|
|
|
|
widget->allocation.width);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gimp_ruler_set_position (ruler,
|
|
|
|
lower +
|
|
|
|
(upper - lower) * event->y /
|
|
|
|
widget->allocation.height);
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2008-05-27 05:20:16 +08:00
|
|
|
gimp_ruler_expose (GtkWidget *widget,
|
|
|
|
GdkEventExpose *event)
|
|
|
|
{
|
|
|
|
if (GTK_WIDGET_DRAWABLE (widget))
|
|
|
|
{
|
|
|
|
GimpRuler *ruler = GIMP_RULER (widget);
|
|
|
|
GimpRulerPrivate *priv = GIMP_RULER_GET_PRIVATE (ruler);
|
|
|
|
|
|
|
|
gimp_ruler_draw_ticks (ruler);
|
|
|
|
|
2009-03-22 23:42:42 +08:00
|
|
|
gdk_draw_drawable (gtk_widget_get_window (widget),
|
2008-05-27 21:41:48 +08:00
|
|
|
priv->non_gr_exp_gc,
|
|
|
|
priv->backing_store,
|
|
|
|
0, 0, 0, 0,
|
|
|
|
widget->allocation.width,
|
|
|
|
widget->allocation.height);
|
2008-05-27 05:20:16 +08:00
|
|
|
|
|
|
|
gimp_ruler_draw_pos (ruler);
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-05-28 19:49:24 +08:00
|
|
|
static void
|
|
|
|
gimp_ruler_draw_ticks (GimpRuler *ruler)
|
|
|
|
{
|
2008-08-29 18:25:29 +08:00
|
|
|
GtkWidget *widget = GTK_WIDGET (ruler);
|
2008-09-02 20:30:53 +08:00
|
|
|
GtkStyle *style = gtk_widget_get_style (widget);
|
2008-08-29 18:25:29 +08:00
|
|
|
GimpRulerPrivate *priv = GIMP_RULER_GET_PRIVATE (ruler);
|
|
|
|
cairo_t *cr;
|
|
|
|
gint i;
|
|
|
|
gint width, height;
|
|
|
|
gint xthickness;
|
|
|
|
gint ythickness;
|
|
|
|
gint length, ideal_length;
|
|
|
|
gdouble lower, upper; /* Upper and lower limits, in ruler units */
|
|
|
|
gdouble increment; /* Number of pixels per unit */
|
|
|
|
gint scale; /* Number of units per major unit */
|
|
|
|
gdouble start, end, cur;
|
|
|
|
gchar unit_str[32];
|
|
|
|
gint digit_height;
|
|
|
|
gint digit_offset;
|
|
|
|
gint text_size;
|
|
|
|
gint pos;
|
|
|
|
gdouble max_size;
|
|
|
|
GimpUnit unit;
|
|
|
|
PangoLayout *layout;
|
|
|
|
PangoRectangle logical_rect, ink_rect;
|
|
|
|
|
|
|
|
if (! GTK_WIDGET_DRAWABLE (widget))
|
|
|
|
return;
|
|
|
|
|
2008-09-02 20:30:53 +08:00
|
|
|
xthickness = style->xthickness;
|
|
|
|
ythickness = style->ythickness;
|
2008-08-29 18:25:29 +08:00
|
|
|
|
2008-10-05 07:32:41 +08:00
|
|
|
layout = gimp_ruler_get_layout (widget, "0123456789");
|
2008-08-29 18:25:29 +08:00
|
|
|
pango_layout_get_extents (layout, &ink_rect, &logical_rect);
|
|
|
|
|
|
|
|
digit_height = PANGO_PIXELS (ink_rect.height) + 2;
|
|
|
|
digit_offset = ink_rect.y;
|
|
|
|
|
|
|
|
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
|
|
|
|
{
|
2008-09-02 20:30:53 +08:00
|
|
|
width = widget->allocation.width;
|
2008-08-29 18:25:29 +08:00
|
|
|
height = widget->allocation.height - ythickness * 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
width = widget->allocation.height;
|
|
|
|
height = widget->allocation.width - ythickness * 2;
|
|
|
|
}
|
|
|
|
|
2008-09-02 20:30:53 +08:00
|
|
|
gtk_paint_box (style, priv->backing_store,
|
2008-08-29 18:25:29 +08:00
|
|
|
GTK_STATE_NORMAL, GTK_SHADOW_OUT,
|
|
|
|
NULL, widget,
|
|
|
|
priv->orientation == GTK_ORIENTATION_HORIZONTAL ?
|
|
|
|
"hruler" : "vruler",
|
|
|
|
0, 0,
|
|
|
|
widget->allocation.width, widget->allocation.height);
|
|
|
|
|
|
|
|
cr = gdk_cairo_create (priv->backing_store);
|
2008-09-02 20:30:53 +08:00
|
|
|
gdk_cairo_set_source_color (cr, &style->fg[widget->state]);
|
2008-08-29 18:25:29 +08:00
|
|
|
|
|
|
|
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
|
|
|
|
{
|
|
|
|
cairo_rectangle (cr,
|
|
|
|
xthickness,
|
|
|
|
height + ythickness,
|
|
|
|
widget->allocation.width - 2 * xthickness,
|
|
|
|
1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cairo_rectangle (cr,
|
|
|
|
height + xthickness,
|
|
|
|
ythickness,
|
|
|
|
1,
|
|
|
|
widget->allocation.height - 2 * ythickness);
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_ruler_get_range (ruler, &lower, &upper, &max_size);
|
|
|
|
|
|
|
|
if ((upper - lower) == 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
increment = (gdouble) width / (upper - lower);
|
|
|
|
|
|
|
|
/* 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 using
|
|
|
|
* text_size = gdk_string_width(font, unit_str), so that the result
|
|
|
|
* for the scale looks consistent with an accompanying vruler
|
|
|
|
*/
|
|
|
|
scale = ceil (max_size);
|
|
|
|
g_snprintf (unit_str, sizeof (unit_str), "%d", scale);
|
|
|
|
text_size = strlen (unit_str) * digit_height + 1;
|
|
|
|
|
|
|
|
for (scale = 0; scale < G_N_ELEMENTS (ruler_metric.ruler_scale); scale++)
|
|
|
|
if (ruler_metric.ruler_scale[scale] * fabs (increment) > 2 * text_size)
|
|
|
|
break;
|
|
|
|
|
|
|
|
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 = G_N_ELEMENTS (ruler_metric.subdivide) - 1; i >= 0; 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
|
|
|
|
*/
|
|
|
|
ideal_length = height / (i + 1) - 1;
|
|
|
|
if (ideal_length > ++length)
|
|
|
|
length = ideal_length;
|
|
|
|
|
|
|
|
if (lower < upper)
|
|
|
|
{
|
|
|
|
start = floor (lower / subd_incr) * subd_incr;
|
|
|
|
end = ceil (upper / subd_incr) * subd_incr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
start = floor (upper / subd_incr) * subd_incr;
|
|
|
|
end = ceil (lower / subd_incr) * subd_incr;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (cur = start; cur <= end; cur += subd_incr)
|
|
|
|
{
|
|
|
|
pos = ROUND ((cur - lower) * increment);
|
|
|
|
|
|
|
|
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
|
|
|
|
{
|
|
|
|
cairo_rectangle (cr,
|
|
|
|
pos, height + ythickness - length,
|
|
|
|
1, length);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cairo_rectangle (cr,
|
|
|
|
height + xthickness - length, pos,
|
|
|
|
length, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* draw label */
|
|
|
|
if (i == 0)
|
|
|
|
{
|
|
|
|
g_snprintf (unit_str, sizeof (unit_str), "%d", (int) cur);
|
|
|
|
|
|
|
|
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
|
|
|
|
{
|
|
|
|
pango_layout_set_text (layout, unit_str, -1);
|
|
|
|
pango_layout_get_extents (layout, &logical_rect, NULL);
|
|
|
|
|
2008-09-02 20:30:53 +08:00
|
|
|
gtk_paint_layout (style,
|
2008-08-29 18:25:29 +08:00
|
|
|
priv->backing_store,
|
|
|
|
GTK_WIDGET_STATE (widget),
|
|
|
|
FALSE,
|
|
|
|
NULL,
|
|
|
|
widget,
|
|
|
|
"hruler",
|
|
|
|
pos + 2,
|
|
|
|
ythickness + PANGO_PIXELS (logical_rect.y - digit_offset),
|
|
|
|
layout);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gint j;
|
|
|
|
|
|
|
|
for (j = 0; j < (int) strlen (unit_str); j++)
|
|
|
|
{
|
|
|
|
pango_layout_set_text (layout, unit_str + j, 1);
|
|
|
|
pango_layout_get_extents (layout, NULL, &logical_rect);
|
|
|
|
|
2008-09-02 20:30:53 +08:00
|
|
|
gtk_paint_layout (style,
|
2008-08-29 18:25:29 +08:00
|
|
|
priv->backing_store,
|
|
|
|
GTK_WIDGET_STATE (widget),
|
|
|
|
FALSE,
|
|
|
|
NULL,
|
|
|
|
widget,
|
|
|
|
"vruler",
|
|
|
|
xthickness + 1,
|
|
|
|
pos + digit_height * j + 2 + PANGO_PIXELS (logical_rect.y - digit_offset),
|
|
|
|
layout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-05-28 19:49:24 +08:00
|
|
|
|
2008-08-29 18:25:29 +08:00
|
|
|
cairo_fill (cr);
|
|
|
|
out:
|
|
|
|
cairo_destroy (cr);
|
2008-05-28 19:49:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_ruler_draw_pos (GimpRuler *ruler)
|
|
|
|
{
|
2008-09-02 20:30:53 +08:00
|
|
|
GtkWidget *widget = GTK_WIDGET (ruler);
|
|
|
|
GtkStyle *style = gtk_widget_get_style (widget);
|
|
|
|
GimpRulerPrivate *priv = GIMP_RULER_GET_PRIVATE (ruler);
|
|
|
|
gint x, y;
|
|
|
|
gint width, height;
|
|
|
|
gint bs_width, bs_height;
|
|
|
|
gint xthickness;
|
|
|
|
gint ythickness;
|
2008-05-28 19:49:24 +08:00
|
|
|
|
2008-09-02 20:30:53 +08:00
|
|
|
if (! GTK_WIDGET_DRAWABLE (ruler))
|
|
|
|
return;
|
2008-08-29 18:25:29 +08:00
|
|
|
|
2008-09-02 20:30:53 +08:00
|
|
|
xthickness = style->xthickness;
|
|
|
|
ythickness = style->ythickness;
|
2008-08-29 18:25:29 +08:00
|
|
|
|
2008-09-02 20:30:53 +08:00
|
|
|
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
|
|
|
|
{
|
|
|
|
width = widget->allocation.width;
|
|
|
|
height = widget->allocation.height - ythickness * 2;
|
2008-08-29 18:25:29 +08:00
|
|
|
|
2008-09-02 20:30:53 +08:00
|
|
|
bs_width = height / 2 + 2;
|
|
|
|
bs_width |= 1; /* make sure it's odd */
|
|
|
|
bs_height = bs_width / 2 + 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
width = widget->allocation.width - xthickness * 2;
|
|
|
|
height = widget->allocation.height;
|
2008-08-29 18:25:29 +08:00
|
|
|
|
2008-09-02 20:30:53 +08:00
|
|
|
bs_height = width / 2 + 2;
|
|
|
|
bs_height |= 1; /* make sure it's odd */
|
|
|
|
bs_width = bs_height / 2 + 1;
|
|
|
|
}
|
2008-08-29 18:25:29 +08:00
|
|
|
|
2008-09-02 20:30:53 +08:00
|
|
|
if ((bs_width > 0) && (bs_height > 0))
|
|
|
|
{
|
2009-03-22 23:42:42 +08:00
|
|
|
cairo_t *cr = gdk_cairo_create (gtk_widget_get_window (widget));
|
2008-09-02 20:30:53 +08:00
|
|
|
gdouble lower;
|
|
|
|
gdouble upper;
|
|
|
|
gdouble position;
|
|
|
|
gdouble increment;
|
2008-08-29 18:25:29 +08:00
|
|
|
|
2008-09-02 20:30:53 +08:00
|
|
|
/* If a backing store exists, restore the ruler */
|
|
|
|
if (priv->backing_store)
|
2009-03-22 23:42:42 +08:00
|
|
|
gdk_draw_drawable (gtk_widget_get_window (widget),
|
2008-09-02 20:30:53 +08:00
|
|
|
style->black_gc,
|
|
|
|
priv->backing_store,
|
|
|
|
priv->xsrc, priv->ysrc,
|
|
|
|
priv->xsrc, priv->ysrc,
|
|
|
|
bs_width, bs_height);
|
2008-08-29 18:25:29 +08:00
|
|
|
|
2008-09-02 20:30:53 +08:00
|
|
|
position = gimp_ruler_get_position (ruler);
|
2008-08-29 18:25:29 +08:00
|
|
|
|
2008-09-02 20:30:53 +08:00
|
|
|
gimp_ruler_get_range (ruler, &lower, &upper, NULL);
|
2008-08-29 18:25:29 +08:00
|
|
|
|
2008-09-02 20:30:53 +08:00
|
|
|
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
|
|
|
|
{
|
|
|
|
increment = (gdouble) width / (upper - lower);
|
2008-08-29 18:25:29 +08:00
|
|
|
|
2008-09-02 20:30:53 +08:00
|
|
|
x = ROUND ((position - lower) * increment) + (xthickness - bs_width) / 2 - 1;
|
|
|
|
y = (height + bs_height) / 2 + ythickness;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
increment = (gdouble) height / (upper - lower);
|
2008-08-29 18:25:29 +08:00
|
|
|
|
2008-09-02 20:30:53 +08:00
|
|
|
x = (width + bs_width) / 2 + xthickness;
|
|
|
|
y = ROUND ((position - lower) * increment) + (ythickness - bs_height) / 2 - 1;
|
|
|
|
}
|
2008-08-29 18:25:29 +08:00
|
|
|
|
2008-09-02 20:30:53 +08:00
|
|
|
gdk_cairo_set_source_color (cr, &style->fg[widget->state]);
|
2008-08-29 18:25:29 +08:00
|
|
|
|
2008-09-02 20:30:53 +08:00
|
|
|
cairo_move_to (cr, x, y);
|
2008-08-29 18:25:29 +08:00
|
|
|
|
2008-09-02 20:30:53 +08:00
|
|
|
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
|
|
|
|
{
|
|
|
|
cairo_line_to (cr, x + bs_width / 2.0, y + bs_height);
|
|
|
|
cairo_line_to (cr, x + bs_width, y);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cairo_line_to (cr, x + bs_width, y + bs_height / 2.0);
|
|
|
|
cairo_line_to (cr, x, y + bs_height);
|
|
|
|
}
|
2008-08-29 18:25:29 +08:00
|
|
|
|
2008-09-02 20:30:53 +08:00
|
|
|
cairo_fill (cr);
|
2008-08-29 18:25:29 +08:00
|
|
|
|
2008-09-02 20:30:53 +08:00
|
|
|
cairo_destroy (cr);
|
2008-08-29 18:25:29 +08:00
|
|
|
|
2008-09-02 20:30:53 +08:00
|
|
|
priv->xsrc = x;
|
|
|
|
priv->ysrc = y;
|
2008-08-29 18:25:29 +08:00
|
|
|
}
|
2008-05-28 19:49:24 +08:00
|
|
|
}
|
|
|
|
|
2008-05-27 05:20:16 +08:00
|
|
|
static void
|
|
|
|
gimp_ruler_make_pixmap (GimpRuler *ruler)
|
|
|
|
{
|
|
|
|
GtkWidget *widget = GTK_WIDGET (ruler);
|
2008-09-02 20:30:53 +08:00
|
|
|
GimpRulerPrivate *priv = GIMP_RULER_GET_PRIVATE (ruler);
|
2008-05-27 05:20:16 +08:00
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
|
|
|
|
if (priv->backing_store)
|
|
|
|
{
|
|
|
|
gdk_drawable_get_size (priv->backing_store, &width, &height);
|
|
|
|
if ((width == widget->allocation.width) &&
|
2008-05-27 21:41:48 +08:00
|
|
|
(height == widget->allocation.height))
|
|
|
|
return;
|
2008-05-27 05:20:16 +08:00
|
|
|
|
|
|
|
g_object_unref (priv->backing_store);
|
|
|
|
}
|
|
|
|
|
2009-03-22 23:42:42 +08:00
|
|
|
priv->backing_store = gdk_pixmap_new (gtk_widget_get_window (widget),
|
2008-05-27 05:20:16 +08:00
|
|
|
widget->allocation.width,
|
|
|
|
widget->allocation.height,
|
|
|
|
-1);
|
|
|
|
|
|
|
|
if (!priv->non_gr_exp_gc)
|
|
|
|
{
|
2009-03-22 23:42:42 +08:00
|
|
|
priv->non_gr_exp_gc = gdk_gc_new (gtk_widget_get_window (widget));
|
2008-05-27 05:20:16 +08:00
|
|
|
gdk_gc_set_exposures (priv->non_gr_exp_gc, FALSE);
|
|
|
|
}
|
|
|
|
}
|
2008-08-29 18:25:29 +08:00
|
|
|
|
2008-10-05 07:32:41 +08:00
|
|
|
|
2008-08-29 18:25:29 +08:00
|
|
|
static PangoLayout *
|
|
|
|
gimp_ruler_create_layout (GtkWidget *widget,
|
|
|
|
const gchar *text)
|
|
|
|
{
|
2008-10-04 06:11:15 +08:00
|
|
|
GimpRulerPrivate *priv = GIMP_RULER_GET_PRIVATE (widget);
|
|
|
|
PangoLayout *layout;
|
|
|
|
PangoAttrList *attrs;
|
|
|
|
PangoAttribute *attr;
|
2008-08-29 18:25:29 +08:00
|
|
|
|
|
|
|
layout = gtk_widget_create_pango_layout (widget, text);
|
|
|
|
|
|
|
|
attrs = pango_attr_list_new ();
|
|
|
|
|
2008-10-04 06:11:15 +08:00
|
|
|
attr = pango_attr_scale_new (priv->font_scale);
|
2008-08-29 18:25:29 +08:00
|
|
|
attr->start_index = 0;
|
|
|
|
attr->end_index = -1;
|
|
|
|
pango_attr_list_insert (attrs, attr);
|
|
|
|
|
|
|
|
pango_layout_set_attributes (layout, attrs);
|
|
|
|
pango_attr_list_unref (attrs);
|
|
|
|
|
|
|
|
return layout;
|
|
|
|
}
|
2008-10-05 07:32:41 +08:00
|
|
|
|
|
|
|
static PangoLayout *
|
|
|
|
gimp_ruler_get_layout (GtkWidget *widget,
|
|
|
|
const gchar *text)
|
|
|
|
{
|
|
|
|
GimpRulerPrivate *priv = GIMP_RULER_GET_PRIVATE (widget);
|
|
|
|
|
|
|
|
if (priv->layout)
|
|
|
|
{
|
|
|
|
pango_layout_set_text (priv->layout, text, -1);
|
|
|
|
return priv->layout;
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->layout = gimp_ruler_create_layout (widget, text);
|
|
|
|
|
|
|
|
return priv->layout;
|
|
|
|
}
|