libgimpwidgets/Makefile.am libgimpwidgets/gimpwidgets.h
2008-08-29 Michael Natterer <mitch@gimp.org> * libgimpwidgets/Makefile.am * libgimpwidgets/gimpwidgets.h * libgimpwidgets/gimphruler.[ch] * libgimpwidgets/gimpvruler.[ch]: remove separate H/VRuler classes. * libgimpwidgets/gimpruler.[ch]: add an "orientation" property instead. Add gimp_ruler_new(). * libgimpwidgets/gimpwidgets.def: changed accordingly. * app/dialogs/resolution-calibrate-dialog.c * app/display/gimpdisplayshell.c * plug-ins/gfig/gfig-preview.c * plug-ins/imagemap/imap_preview.c: ditto. svn path=/trunk/; revision=26810
This commit is contained in:

committed by
Michael Natterer

parent
ee9d10f70a
commit
edcd1e7810
17
ChangeLog
17
ChangeLog
@ -1,3 +1,20 @@
|
|||||||
|
2008-08-29 Michael Natterer <mitch@gimp.org>
|
||||||
|
|
||||||
|
* libgimpwidgets/Makefile.am
|
||||||
|
* libgimpwidgets/gimpwidgets.h
|
||||||
|
* libgimpwidgets/gimphruler.[ch]
|
||||||
|
* libgimpwidgets/gimpvruler.[ch]: remove separate H/VRuler classes.
|
||||||
|
|
||||||
|
* libgimpwidgets/gimpruler.[ch]: add an "orientation" property
|
||||||
|
instead. Add gimp_ruler_new().
|
||||||
|
|
||||||
|
* libgimpwidgets/gimpwidgets.def: changed accordingly.
|
||||||
|
|
||||||
|
* app/dialogs/resolution-calibrate-dialog.c
|
||||||
|
* app/display/gimpdisplayshell.c
|
||||||
|
* plug-ins/gfig/gfig-preview.c
|
||||||
|
* plug-ins/imagemap/imap_preview.c: ditto.
|
||||||
|
|
||||||
2008-08-29 Lars-Peter Clausen <lars@metafoo.de>
|
2008-08-29 Lars-Peter Clausen <lars@metafoo.de>
|
||||||
|
|
||||||
* plug-ins/pygimp/gimpui.defs
|
* plug-ins/pygimp/gimpui.defs
|
||||||
|
@ -105,14 +105,14 @@ resolution_calibrate_dialog (GtkWidget *resolution_entry,
|
|||||||
gtk_widget_show (image);
|
gtk_widget_show (image);
|
||||||
}
|
}
|
||||||
|
|
||||||
ruler = gimp_hruler_new ();
|
ruler = gimp_ruler_new (GTK_ORIENTATION_HORIZONTAL);
|
||||||
gtk_widget_set_size_request (ruler, ruler_width, 32);
|
gtk_widget_set_size_request (ruler, ruler_width, 32);
|
||||||
gimp_ruler_set_range (GIMP_RULER (ruler), 0, ruler_width, ruler_width);
|
gimp_ruler_set_range (GIMP_RULER (ruler), 0, ruler_width, ruler_width);
|
||||||
gtk_table_attach (GTK_TABLE (table), ruler, 1, 3, 0, 1,
|
gtk_table_attach (GTK_TABLE (table), ruler, 1, 3, 0, 1,
|
||||||
GTK_SHRINK, GTK_SHRINK, 0, 0);
|
GTK_SHRINK, GTK_SHRINK, 0, 0);
|
||||||
gtk_widget_show (ruler);
|
gtk_widget_show (ruler);
|
||||||
|
|
||||||
ruler = gimp_vruler_new ();
|
ruler = gimp_ruler_new (GTK_ORIENTATION_VERTICAL);
|
||||||
gtk_widget_set_size_request (ruler, 32, ruler_height);
|
gtk_widget_set_size_request (ruler, 32, ruler_height);
|
||||||
gimp_ruler_set_range (GIMP_RULER (ruler), 0, ruler_height, ruler_height);
|
gimp_ruler_set_range (GIMP_RULER (ruler), 0, ruler_height, ruler_height);
|
||||||
gtk_table_attach (GTK_TABLE (table), ruler, 0, 1, 1, 3,
|
gtk_table_attach (GTK_TABLE (table), ruler, 0, 1, 1, 3,
|
||||||
|
@ -1026,7 +1026,7 @@ gimp_display_shell_new (GimpDisplay *display,
|
|||||||
gimp_display_shell_selection_init (shell);
|
gimp_display_shell_selection_init (shell);
|
||||||
|
|
||||||
/* the horizontal ruler */
|
/* the horizontal ruler */
|
||||||
shell->hrule = gimp_hruler_new ();
|
shell->hrule = gimp_ruler_new (GTK_ORIENTATION_HORIZONTAL);
|
||||||
gtk_widget_set_events (GTK_WIDGET (shell->hrule),
|
gtk_widget_set_events (GTK_WIDGET (shell->hrule),
|
||||||
GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
|
GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
|
||||||
|
|
||||||
@ -1040,7 +1040,7 @@ gimp_display_shell_new (GimpDisplay *display,
|
|||||||
gimp_help_set_help_data (shell->hrule, NULL, GIMP_HELP_IMAGE_WINDOW_RULER);
|
gimp_help_set_help_data (shell->hrule, NULL, GIMP_HELP_IMAGE_WINDOW_RULER);
|
||||||
|
|
||||||
/* the vertical ruler */
|
/* the vertical ruler */
|
||||||
shell->vrule = gimp_vruler_new ();
|
shell->vrule = gimp_ruler_new (GTK_ORIENTATION_VERTICAL);
|
||||||
gtk_widget_set_events (GTK_WIDGET (shell->vrule),
|
gtk_widget_set_events (GTK_WIDGET (shell->vrule),
|
||||||
GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
|
GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
|
||||||
|
|
||||||
|
@ -122,8 +122,6 @@ libgimpwidgets_2_0_la_sources = \
|
|||||||
gimphelpui.h \
|
gimphelpui.h \
|
||||||
gimphintbox.c \
|
gimphintbox.c \
|
||||||
gimphintbox.h \
|
gimphintbox.h \
|
||||||
gimphruler.c \
|
|
||||||
gimphruler.h \
|
|
||||||
gimpintcombobox.c \
|
gimpintcombobox.c \
|
||||||
gimpintcombobox.h \
|
gimpintcombobox.h \
|
||||||
gimpintstore.c \
|
gimpintstore.c \
|
||||||
@ -166,8 +164,6 @@ libgimpwidgets_2_0_la_sources = \
|
|||||||
gimpstringcombobox.h \
|
gimpstringcombobox.h \
|
||||||
gimpunitmenu.c \
|
gimpunitmenu.c \
|
||||||
gimpunitmenu.h \
|
gimpunitmenu.h \
|
||||||
gimpvruler.c \
|
|
||||||
gimpvruler.h \
|
|
||||||
gimpzoommodel.c \
|
gimpzoommodel.c \
|
||||||
gimpzoommodel.h \
|
gimpzoommodel.h \
|
||||||
gimpwidgets-private.c \
|
gimpwidgets-private.c \
|
||||||
@ -218,7 +214,6 @@ libgimpwidgetsinclude_HEADERS = \
|
|||||||
gimpframe.h \
|
gimpframe.h \
|
||||||
gimphelpui.h \
|
gimphelpui.h \
|
||||||
gimphintbox.h \
|
gimphintbox.h \
|
||||||
gimphruler.h \
|
|
||||||
gimpintcombobox.h \
|
gimpintcombobox.h \
|
||||||
gimpintstore.h \
|
gimpintstore.h \
|
||||||
gimpmemsizeentry.h \
|
gimpmemsizeentry.h \
|
||||||
@ -240,7 +235,6 @@ libgimpwidgetsinclude_HEADERS = \
|
|||||||
gimpstock.h \
|
gimpstock.h \
|
||||||
gimpstringcombobox.h \
|
gimpstringcombobox.h \
|
||||||
gimpunitmenu.h \
|
gimpunitmenu.h \
|
||||||
gimpvruler.h \
|
|
||||||
gimpzoommodel.h
|
gimpzoommodel.h
|
||||||
|
|
||||||
libgimpwidgets_2_0_la_LDFLAGS = \
|
libgimpwidgets_2_0_la_LDFLAGS = \
|
||||||
|
@ -1,347 +0,0 @@
|
|||||||
/* LIBGIMP - The GIMP Library
|
|
||||||
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
|
|
||||||
*
|
|
||||||
* This library is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
|
||||||
* License as published by the Free Software Foundation; either
|
|
||||||
* version 2 of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
* License along with this library; if not, write to the
|
|
||||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
||||||
* Boston, MA 02111-1307, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include <gtk/gtk.h>
|
|
||||||
|
|
||||||
#include "libgimpmath/gimpmath.h"
|
|
||||||
|
|
||||||
#include "gimpwidgetstypes.h"
|
|
||||||
|
|
||||||
#include "gimphruler.h"
|
|
||||||
|
|
||||||
|
|
||||||
#define RULER_HEIGHT 13
|
|
||||||
#define MINIMUM_INCR 5
|
|
||||||
|
|
||||||
|
|
||||||
static const struct
|
|
||||||
{
|
|
||||||
gdouble ruler_scale[16];
|
|
||||||
gint subdivide[5];
|
|
||||||
} ruler_metric =
|
|
||||||
{
|
|
||||||
{ 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000, 10000, 25000, 50000, 100000 },
|
|
||||||
{ 1, 5, 10, 50, 100 }
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
gint xsrc;
|
|
||||||
gint ysrc;
|
|
||||||
} GimpHRulerPrivate;
|
|
||||||
|
|
||||||
|
|
||||||
static gint gimp_hruler_motion_notify (GtkWidget *widget,
|
|
||||||
GdkEventMotion *event);
|
|
||||||
static void gimp_hruler_draw_ticks (GimpRuler *ruler);
|
|
||||||
static void gimp_hruler_draw_pos (GimpRuler *ruler);
|
|
||||||
|
|
||||||
G_DEFINE_TYPE (GimpHRuler, gimp_hruler, GIMP_TYPE_RULER)
|
|
||||||
|
|
||||||
#define GIMP_HRULER_GET_PRIVATE(ruler) \
|
|
||||||
G_TYPE_INSTANCE_GET_PRIVATE (ruler, GIMP_TYPE_HRULER, GimpHRulerPrivate)
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
gimp_hruler_class_init (GimpHRulerClass *klass)
|
|
||||||
{
|
|
||||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
||||||
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
||||||
GimpRulerClass *ruler_class = GIMP_RULER_CLASS (klass);
|
|
||||||
|
|
||||||
widget_class->motion_notify_event = gimp_hruler_motion_notify;
|
|
||||||
|
|
||||||
ruler_class->draw_ticks = gimp_hruler_draw_ticks;
|
|
||||||
ruler_class->draw_pos = gimp_hruler_draw_pos;
|
|
||||||
|
|
||||||
g_type_class_add_private (object_class, sizeof (GimpHRulerPrivate));
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gimp_hruler_init (GimpHRuler *hruler)
|
|
||||||
{
|
|
||||||
GtkWidget *widget = GTK_WIDGET (hruler);
|
|
||||||
|
|
||||||
widget->requisition.width = widget->style->xthickness * 2 + 1;
|
|
||||||
widget->requisition.height = widget->style->ythickness * 2 + RULER_HEIGHT;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* gimp_hruler_new:
|
|
||||||
*
|
|
||||||
* Creates a new horizontal ruler.
|
|
||||||
*
|
|
||||||
* Return value: a new #GimpHRuler widget.
|
|
||||||
*
|
|
||||||
* Since: GIMP 2.8
|
|
||||||
**/
|
|
||||||
GtkWidget*
|
|
||||||
gimp_hruler_new (void)
|
|
||||||
{
|
|
||||||
return g_object_new (GIMP_TYPE_HRULER, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
static gint
|
|
||||||
gimp_hruler_motion_notify (GtkWidget *widget,
|
|
||||||
GdkEventMotion *event)
|
|
||||||
{
|
|
||||||
GimpRuler *ruler = GIMP_RULER (widget);
|
|
||||||
gdouble lower;
|
|
||||||
gdouble upper;
|
|
||||||
gint x;
|
|
||||||
|
|
||||||
gdk_event_request_motions (event);
|
|
||||||
x = event->x;
|
|
||||||
|
|
||||||
gimp_ruler_get_range (ruler, &lower, &upper, NULL);
|
|
||||||
|
|
||||||
gimp_ruler_set_position (ruler,
|
|
||||||
lower +
|
|
||||||
((upper - lower) * x) / widget->allocation.width);
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gimp_hruler_draw_ticks (GimpRuler *ruler)
|
|
||||||
{
|
|
||||||
GtkWidget *widget = GTK_WIDGET (ruler);
|
|
||||||
GdkDrawable *backing_store;
|
|
||||||
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_width;
|
|
||||||
gint pos;
|
|
||||||
gdouble max_size;
|
|
||||||
GimpUnit unit;
|
|
||||||
PangoLayout *layout;
|
|
||||||
PangoRectangle logical_rect, ink_rect;
|
|
||||||
|
|
||||||
if (! GTK_WIDGET_DRAWABLE (widget))
|
|
||||||
return;
|
|
||||||
|
|
||||||
backing_store = _gimp_ruler_get_backing_store (ruler);
|
|
||||||
|
|
||||||
xthickness = widget->style->xthickness;
|
|
||||||
ythickness = widget->style->ythickness;
|
|
||||||
|
|
||||||
layout = _gimp_ruler_create_pango_layout (widget, "012456789");
|
|
||||||
pango_layout_get_extents (layout, &ink_rect, &logical_rect);
|
|
||||||
|
|
||||||
digit_height = PANGO_PIXELS (ink_rect.height) + 2;
|
|
||||||
digit_offset = ink_rect.y;
|
|
||||||
|
|
||||||
width = widget->allocation.width;
|
|
||||||
height = widget->allocation.height - ythickness * 2;
|
|
||||||
|
|
||||||
gtk_paint_box (widget->style, backing_store,
|
|
||||||
GTK_STATE_NORMAL, GTK_SHADOW_OUT,
|
|
||||||
NULL, widget, "hruler",
|
|
||||||
0, 0,
|
|
||||||
widget->allocation.width, widget->allocation.height);
|
|
||||||
|
|
||||||
cr = gdk_cairo_create (backing_store);
|
|
||||||
gdk_cairo_set_source_color (cr, &widget->style->fg[widget->state]);
|
|
||||||
|
|
||||||
cairo_rectangle (cr,
|
|
||||||
xthickness,
|
|
||||||
height + ythickness,
|
|
||||||
widget->allocation.width - 2 * xthickness,
|
|
||||||
1);
|
|
||||||
|
|
||||||
gimp_ruler_get_range (ruler, &lower, &upper, &max_size);
|
|
||||||
|
|
||||||
if ((upper - lower) == 0)
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
increment = (gdouble) width / (upper - lower);
|
|
||||||
|
|
||||||
/* determine the scale
|
|
||||||
* We calculate the text size as for the vruler instead of using
|
|
||||||
* text_width = 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_width = 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_width)
|
|
||||||
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);
|
|
||||||
|
|
||||||
cairo_rectangle (cr,
|
|
||||||
pos, height + ythickness - length,
|
|
||||||
1, length);
|
|
||||||
|
|
||||||
/* draw label */
|
|
||||||
if (i == 0)
|
|
||||||
{
|
|
||||||
g_snprintf (unit_str, sizeof (unit_str), "%d", (int) cur);
|
|
||||||
|
|
||||||
pango_layout_set_text (layout, unit_str, -1);
|
|
||||||
pango_layout_get_extents (layout, &logical_rect, NULL);
|
|
||||||
|
|
||||||
gtk_paint_layout (widget->style,
|
|
||||||
backing_store,
|
|
||||||
GTK_WIDGET_STATE (widget),
|
|
||||||
FALSE,
|
|
||||||
NULL,
|
|
||||||
widget,
|
|
||||||
"hruler",
|
|
||||||
pos + 2,
|
|
||||||
ythickness + PANGO_PIXELS (logical_rect.y - digit_offset),
|
|
||||||
layout);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cairo_fill (cr);
|
|
||||||
out:
|
|
||||||
cairo_destroy (cr);
|
|
||||||
|
|
||||||
g_object_unref (layout);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gimp_hruler_draw_pos (GimpRuler *ruler)
|
|
||||||
{
|
|
||||||
GtkWidget *widget = GTK_WIDGET (ruler);
|
|
||||||
|
|
||||||
if (GTK_WIDGET_DRAWABLE (ruler))
|
|
||||||
{
|
|
||||||
GimpHRulerPrivate *priv = GIMP_HRULER_GET_PRIVATE (ruler);
|
|
||||||
gint x, y;
|
|
||||||
gint width, height;
|
|
||||||
gint bs_width, bs_height;
|
|
||||||
gint xthickness;
|
|
||||||
gint ythickness;
|
|
||||||
|
|
||||||
xthickness = widget->style->xthickness;
|
|
||||||
ythickness = widget->style->ythickness;
|
|
||||||
width = widget->allocation.width;
|
|
||||||
height = widget->allocation.height - ythickness * 2;
|
|
||||||
|
|
||||||
bs_width = height / 2 + 2;
|
|
||||||
bs_width |= 1; /* make sure it's odd */
|
|
||||||
bs_height = bs_width / 2 + 1;
|
|
||||||
|
|
||||||
if ((bs_width > 0) && (bs_height > 0))
|
|
||||||
{
|
|
||||||
GdkDrawable *backing_store = _gimp_ruler_get_backing_store (ruler);
|
|
||||||
cairo_t *cr = gdk_cairo_create (widget->window);
|
|
||||||
gdouble lower;
|
|
||||||
gdouble upper;
|
|
||||||
gdouble position;
|
|
||||||
gdouble increment;
|
|
||||||
|
|
||||||
/* If a backing store exists, restore the ruler */
|
|
||||||
if (backing_store)
|
|
||||||
gdk_draw_drawable (widget->window,
|
|
||||||
widget->style->black_gc,
|
|
||||||
backing_store,
|
|
||||||
priv->xsrc, priv->ysrc,
|
|
||||||
priv->xsrc, priv->ysrc,
|
|
||||||
bs_width, bs_height);
|
|
||||||
|
|
||||||
position = gimp_ruler_get_position (ruler);
|
|
||||||
|
|
||||||
gimp_ruler_get_range (ruler, &lower, &upper, NULL);
|
|
||||||
|
|
||||||
increment = (gdouble) width / (upper - lower);
|
|
||||||
|
|
||||||
x = ROUND ((position - lower) * increment) + (xthickness - bs_width) / 2 - 1;
|
|
||||||
y = (height + bs_height) / 2 + ythickness;
|
|
||||||
|
|
||||||
gdk_cairo_set_source_color (cr, &widget->style->fg[widget->state]);
|
|
||||||
|
|
||||||
cairo_move_to (cr, x, y);
|
|
||||||
cairo_line_to (cr, x + bs_width / 2., y + bs_height);
|
|
||||||
cairo_line_to (cr, x + bs_width, y);
|
|
||||||
cairo_fill (cr);
|
|
||||||
|
|
||||||
cairo_destroy (cr);
|
|
||||||
|
|
||||||
priv->xsrc = x;
|
|
||||||
priv->ysrc = y;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,55 +0,0 @@
|
|||||||
/* GTK - The GIMP Toolkit
|
|
||||||
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
|
||||||
*
|
|
||||||
* This library is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
|
||||||
* License as published by the Free Software Foundation; either
|
|
||||||
* version 2 of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
* License along with this library; if not, write to the
|
|
||||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
||||||
* Boston, MA 02111-1307, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
|
|
||||||
* file for a list of people on the GTK+ Team. See the ChangeLog
|
|
||||||
* files for a list of changes. These files are distributed with
|
|
||||||
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __GIMP_HRULER_H__
|
|
||||||
#define __GIMP_HRULER_H__
|
|
||||||
|
|
||||||
#include "gimpruler.h"
|
|
||||||
|
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
|
||||||
|
|
||||||
|
|
||||||
#define GIMP_TYPE_HRULER (gimp_hruler_get_type ())
|
|
||||||
#define GIMP_HRULER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_HRULER, GimpHRuler))
|
|
||||||
#define GIMP_HRULER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_HRULER, GimpHRulerClass))
|
|
||||||
#define GIMP_IS_HRULER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_HRULER))
|
|
||||||
#define GIMP_IS_HRULER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_HRULER))
|
|
||||||
#define GIMP_HRULER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_HRULER, GimpHRulerClass))
|
|
||||||
|
|
||||||
|
|
||||||
typedef GimpRulerClass GimpHRulerClass;
|
|
||||||
typedef GimpRuler GimpHRuler;
|
|
||||||
|
|
||||||
|
|
||||||
GType gimp_hruler_get_type (void) G_GNUC_CONST;
|
|
||||||
GtkWidget* gimp_hruler_new (void);
|
|
||||||
|
|
||||||
|
|
||||||
G_END_DECLS
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* __GIMP_HRULER_H__ */
|
|
@ -19,33 +19,26 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
#include "libgimpbase/gimpbase.h"
|
#include "libgimpbase/gimpbase.h"
|
||||||
|
#include "libgimpmath/gimpmath.h"
|
||||||
|
|
||||||
#include "gimpwidgetstypes.h"
|
#include "gimpwidgetstypes.h"
|
||||||
|
|
||||||
#include "gimpruler.h"
|
#include "gimpruler.h"
|
||||||
|
|
||||||
|
|
||||||
/* All distances below are in 1/72nd's of an inch. (According to
|
#define RULER_WIDTH 13
|
||||||
* Adobe that's a point, but points are really 1/72.27 in.)
|
#define MINIMUM_INCR 5
|
||||||
*/
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
GimpUnit unit;
|
|
||||||
gdouble lower;
|
|
||||||
gdouble upper;
|
|
||||||
gdouble position;
|
|
||||||
gdouble max_size;
|
|
||||||
|
|
||||||
GdkPixmap *backing_store;
|
|
||||||
GdkGC *non_gr_exp_gc;
|
|
||||||
} GimpRulerPrivate;
|
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
PROP_0,
|
PROP_0,
|
||||||
|
PROP_ORIENTATION,
|
||||||
PROP_UNIT,
|
PROP_UNIT,
|
||||||
PROP_LOWER,
|
PROP_LOWER,
|
||||||
PROP_UPPER,
|
PROP_UPPER,
|
||||||
@ -53,23 +46,62 @@ enum
|
|||||||
PROP_MAX_SIZE
|
PROP_MAX_SIZE
|
||||||
};
|
};
|
||||||
|
|
||||||
static void gimp_ruler_realize (GtkWidget *widget);
|
|
||||||
static void gimp_ruler_unrealize (GtkWidget *widget);
|
/* All distances below are in 1/72nd's of an inch. (According to
|
||||||
static void gimp_ruler_size_allocate (GtkWidget *widget,
|
* Adobe that's a point, but points are really 1/72.27 in.)
|
||||||
GtkAllocation *allocation);
|
*/
|
||||||
static gint gimp_ruler_expose (GtkWidget *widget,
|
typedef struct
|
||||||
GdkEventExpose *event);
|
{
|
||||||
static void gimp_ruler_draw_ticks (GimpRuler *ruler);
|
GtkOrientation orientation;
|
||||||
static void gimp_ruler_draw_pos (GimpRuler *ruler);
|
GimpUnit unit;
|
||||||
static void gimp_ruler_make_pixmap (GimpRuler *ruler);
|
gdouble lower;
|
||||||
static void gimp_ruler_set_property (GObject *object,
|
gdouble upper;
|
||||||
guint prop_id,
|
gdouble position;
|
||||||
const GValue *value,
|
gdouble max_size;
|
||||||
GParamSpec *pspec);
|
|
||||||
static void gimp_ruler_get_property (GObject *object,
|
GdkPixmap *backing_store;
|
||||||
guint prop_id,
|
GdkGC *non_gr_exp_gc;
|
||||||
GValue *value,
|
|
||||||
GParamSpec *pspec);
|
gint xsrc;
|
||||||
|
gint ysrc;
|
||||||
|
} GimpRulerPrivate;
|
||||||
|
|
||||||
|
|
||||||
|
static const struct
|
||||||
|
{
|
||||||
|
gdouble ruler_scale[16];
|
||||||
|
gint subdivide[5];
|
||||||
|
} 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);
|
||||||
|
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);
|
||||||
|
static PangoLayout * gimp_ruler_create_layout (GtkWidget *widget,
|
||||||
|
const gchar *text);
|
||||||
|
|
||||||
|
|
||||||
G_DEFINE_TYPE (GimpRuler, gimp_ruler, GTK_TYPE_WIDGET)
|
G_DEFINE_TYPE (GimpRuler, gimp_ruler, GTK_TYPE_WIDGET)
|
||||||
|
|
||||||
@ -83,19 +115,26 @@ gimp_ruler_class_init (GimpRulerClass *klass)
|
|||||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||||
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
||||||
|
|
||||||
object_class->set_property = gimp_ruler_set_property;
|
object_class->set_property = gimp_ruler_set_property;
|
||||||
object_class->get_property = gimp_ruler_get_property;
|
object_class->get_property = gimp_ruler_get_property;
|
||||||
|
|
||||||
widget_class->realize = gimp_ruler_realize;
|
widget_class->realize = gimp_ruler_realize;
|
||||||
widget_class->unrealize = gimp_ruler_unrealize;
|
widget_class->unrealize = gimp_ruler_unrealize;
|
||||||
widget_class->size_allocate = gimp_ruler_size_allocate;
|
widget_class->size_allocate = gimp_ruler_size_allocate;
|
||||||
widget_class->expose_event = gimp_ruler_expose;
|
widget_class->motion_notify_event = gimp_ruler_motion_notify;
|
||||||
|
widget_class->expose_event = gimp_ruler_expose;
|
||||||
klass->draw_ticks = NULL;
|
|
||||||
klass->draw_pos = NULL;
|
|
||||||
|
|
||||||
g_type_class_add_private (object_class, sizeof (GimpRulerPrivate));
|
g_type_class_add_private (object_class, sizeof (GimpRulerPrivate));
|
||||||
|
|
||||||
|
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));
|
||||||
|
|
||||||
g_object_class_install_property (object_class,
|
g_object_class_install_property (object_class,
|
||||||
PROP_LOWER,
|
PROP_LOWER,
|
||||||
gimp_param_spec_unit ("unit",
|
gimp_param_spec_unit ("unit",
|
||||||
@ -151,6 +190,10 @@ gimp_ruler_init (GimpRuler *ruler)
|
|||||||
{
|
{
|
||||||
GimpRulerPrivate *priv = GIMP_RULER_GET_PRIVATE (ruler);
|
GimpRulerPrivate *priv = GIMP_RULER_GET_PRIVATE (ruler);
|
||||||
|
|
||||||
|
widget->requisition.width = widget->style->xthickness * 2 + 1;
|
||||||
|
widget->requisition.height = widget->style->ythickness * 2 + RULER_WIDTH;
|
||||||
|
|
||||||
|
priv->orientation = GTK_ORIENTATION_HORIZONTAL;
|
||||||
priv->unit = GIMP_PIXELS;
|
priv->unit = GIMP_PIXELS;
|
||||||
priv->lower = 0;
|
priv->lower = 0;
|
||||||
priv->upper = 0;
|
priv->upper = 0;
|
||||||
@ -171,6 +214,24 @@ gimp_ruler_set_property (GObject *object,
|
|||||||
|
|
||||||
switch (prop_id)
|
switch (prop_id)
|
||||||
{
|
{
|
||||||
|
case PROP_ORIENTATION:
|
||||||
|
{
|
||||||
|
GtkWidget *widget = GTK_WIDGET (ruler);
|
||||||
|
|
||||||
|
priv->orientation = g_value_get_enum (value);
|
||||||
|
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
|
||||||
|
{
|
||||||
|
widget->requisition.width = widget->style->xthickness * 2 + 1;
|
||||||
|
widget->requisition.height = widget->style->ythickness * 2 + RULER_WIDTH;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
widget->requisition.width = widget->style->xthickness * 2 + RULER_WIDTH;
|
||||||
|
widget->requisition.height = widget->style->ythickness * 2 + 1;
|
||||||
|
}
|
||||||
|
gtk_widget_queue_resize (widget);
|
||||||
|
}
|
||||||
|
break;
|
||||||
case PROP_UNIT:
|
case PROP_UNIT:
|
||||||
gimp_ruler_set_unit (ruler, g_value_get_int (value));
|
gimp_ruler_set_unit (ruler, g_value_get_int (value));
|
||||||
break;
|
break;
|
||||||
@ -195,6 +256,7 @@ gimp_ruler_set_property (GObject *object,
|
|||||||
priv->upper,
|
priv->upper,
|
||||||
g_value_get_double (value));
|
g_value_get_double (value));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
break;
|
break;
|
||||||
@ -212,6 +274,9 @@ gimp_ruler_get_property (GObject *object,
|
|||||||
|
|
||||||
switch (prop_id)
|
switch (prop_id)
|
||||||
{
|
{
|
||||||
|
case PROP_ORIENTATION:
|
||||||
|
g_value_set_enum (value, priv->orientation);
|
||||||
|
break;
|
||||||
case PROP_UNIT:
|
case PROP_UNIT:
|
||||||
g_value_set_int (value, priv->unit);
|
g_value_set_int (value, priv->unit);
|
||||||
break;
|
break;
|
||||||
@ -227,12 +292,31 @@ gimp_ruler_get_property (GObject *object,
|
|||||||
case PROP_MAX_SIZE:
|
case PROP_MAX_SIZE:
|
||||||
g_value_set_double (value, priv->max_size);
|
g_value_set_double (value, priv->max_size);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gimp_vruler_new:
|
||||||
|
* @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);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gimp_ruler_set_position:
|
* gimp_ruler_set_position:
|
||||||
* @ruler: a #GimpRuler
|
* @ruler: a #GimpRuler
|
||||||
@ -399,35 +483,6 @@ gimp_ruler_get_range (GimpRuler *ruler,
|
|||||||
*max_size = priv->max_size;
|
*max_size = priv->max_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
GdkDrawable *
|
|
||||||
_gimp_ruler_get_backing_store (GimpRuler *ruler)
|
|
||||||
{
|
|
||||||
return GIMP_RULER_GET_PRIVATE (ruler)->backing_store;
|
|
||||||
}
|
|
||||||
|
|
||||||
PangoLayout *
|
|
||||||
_gimp_ruler_create_pango_layout (GtkWidget *widget,
|
|
||||||
const gchar *text)
|
|
||||||
{
|
|
||||||
PangoLayout *layout;
|
|
||||||
PangoAttrList *attrs;
|
|
||||||
PangoAttribute *attr;
|
|
||||||
|
|
||||||
layout = gtk_widget_create_pango_layout (widget, text);
|
|
||||||
|
|
||||||
attrs = pango_attr_list_new ();
|
|
||||||
|
|
||||||
attr = pango_attr_scale_new (PANGO_SCALE_X_SMALL);
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gimp_ruler_realize (GtkWidget *widget)
|
gimp_ruler_realize (GtkWidget *widget)
|
||||||
{
|
{
|
||||||
@ -445,9 +500,9 @@ gimp_ruler_realize (GtkWidget *widget)
|
|||||||
attributes.wclass = GDK_INPUT_OUTPUT;
|
attributes.wclass = GDK_INPUT_OUTPUT;
|
||||||
attributes.visual = gtk_widget_get_visual (widget);
|
attributes.visual = gtk_widget_get_visual (widget);
|
||||||
attributes.colormap = gtk_widget_get_colormap (widget);
|
attributes.colormap = gtk_widget_get_colormap (widget);
|
||||||
attributes.event_mask = gtk_widget_get_events (widget);
|
attributes.event_mask = (gtk_widget_get_events (widget) |
|
||||||
attributes.event_mask |= (GDK_EXPOSURE_MASK |
|
GDK_EXPOSURE_MASK |
|
||||||
GDK_POINTER_MOTION_MASK |
|
GDK_POINTER_MOTION_MASK |
|
||||||
GDK_POINTER_MOTION_HINT_MASK);
|
GDK_POINTER_MOTION_HINT_MASK);
|
||||||
|
|
||||||
attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
|
attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
|
||||||
@ -480,8 +535,7 @@ gimp_ruler_unrealize (GtkWidget *widget)
|
|||||||
priv->non_gr_exp_gc = NULL;
|
priv->non_gr_exp_gc = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GTK_WIDGET_CLASS (gimp_ruler_parent_class)->unrealize)
|
GTK_WIDGET_CLASS (gimp_ruler_parent_class)->unrealize (widget);
|
||||||
(* GTK_WIDGET_CLASS (gimp_ruler_parent_class)->unrealize) (widget);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -502,7 +556,38 @@ gimp_ruler_size_allocate (GtkWidget *widget,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static gint
|
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
|
||||||
gimp_ruler_expose (GtkWidget *widget,
|
gimp_ruler_expose (GtkWidget *widget,
|
||||||
GdkEventExpose *event)
|
GdkEventExpose *event)
|
||||||
{
|
{
|
||||||
@ -529,19 +614,312 @@ gimp_ruler_expose (GtkWidget *widget,
|
|||||||
static void
|
static void
|
||||||
gimp_ruler_draw_ticks (GimpRuler *ruler)
|
gimp_ruler_draw_ticks (GimpRuler *ruler)
|
||||||
{
|
{
|
||||||
g_return_if_fail (GIMP_IS_RULER (ruler));
|
GtkWidget *widget = GTK_WIDGET (ruler);
|
||||||
|
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 (GIMP_RULER_GET_CLASS (ruler)->draw_ticks)
|
if (! GTK_WIDGET_DRAWABLE (widget))
|
||||||
GIMP_RULER_GET_CLASS (ruler)->draw_ticks (ruler);
|
return;
|
||||||
|
|
||||||
|
xthickness = widget->style->xthickness;
|
||||||
|
ythickness = widget->style->ythickness;
|
||||||
|
|
||||||
|
layout = gimp_ruler_create_layout (widget, "012456789");
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
width = widget->allocation.width;
|
||||||
|
height = widget->allocation.height - ythickness * 2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
width = widget->allocation.height;
|
||||||
|
height = widget->allocation.width - ythickness * 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
gtk_paint_box (widget->style, priv->backing_store,
|
||||||
|
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);
|
||||||
|
gdk_cairo_set_source_color (cr, &widget->style->fg[widget->state]);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
gtk_paint_layout (widget->style,
|
||||||
|
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);
|
||||||
|
|
||||||
|
gtk_paint_layout (widget->style,
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cairo_fill (cr);
|
||||||
|
out:
|
||||||
|
cairo_destroy (cr);
|
||||||
|
|
||||||
|
g_object_unref (layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gimp_ruler_draw_pos (GimpRuler *ruler)
|
gimp_ruler_draw_pos (GimpRuler *ruler)
|
||||||
{
|
{
|
||||||
g_return_if_fail (GIMP_IS_RULER (ruler));
|
GtkWidget *widget = GTK_WIDGET (ruler);
|
||||||
|
|
||||||
if (GIMP_RULER_GET_CLASS (ruler)->draw_pos)
|
if (GTK_WIDGET_DRAWABLE (ruler))
|
||||||
GIMP_RULER_GET_CLASS (ruler)->draw_pos (ruler);
|
{
|
||||||
|
GimpRulerPrivate *priv = GIMP_RULER_GET_PRIVATE (ruler);
|
||||||
|
gint x, y;
|
||||||
|
gint width, height;
|
||||||
|
gint bs_width, bs_height;
|
||||||
|
gint xthickness;
|
||||||
|
gint ythickness;
|
||||||
|
|
||||||
|
xthickness = widget->style->xthickness;
|
||||||
|
ythickness = widget->style->ythickness;
|
||||||
|
|
||||||
|
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
|
||||||
|
{
|
||||||
|
width = widget->allocation.width;
|
||||||
|
height = widget->allocation.height - ythickness * 2;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
bs_height = width / 2 + 2;
|
||||||
|
bs_height |= 1; /* make sure it's odd */
|
||||||
|
bs_width = bs_height / 2 + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((bs_width > 0) && (bs_height > 0))
|
||||||
|
{
|
||||||
|
cairo_t *cr = gdk_cairo_create (widget->window);
|
||||||
|
gdouble lower;
|
||||||
|
gdouble upper;
|
||||||
|
gdouble position;
|
||||||
|
gdouble increment;
|
||||||
|
|
||||||
|
/* If a backing store exists, restore the ruler */
|
||||||
|
if (priv->backing_store)
|
||||||
|
gdk_draw_drawable (widget->window,
|
||||||
|
widget->style->black_gc,
|
||||||
|
priv->backing_store,
|
||||||
|
priv->xsrc, priv->ysrc,
|
||||||
|
priv->xsrc, priv->ysrc,
|
||||||
|
bs_width, bs_height);
|
||||||
|
|
||||||
|
position = gimp_ruler_get_position (ruler);
|
||||||
|
|
||||||
|
gimp_ruler_get_range (ruler, &lower, &upper, NULL);
|
||||||
|
|
||||||
|
if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
|
||||||
|
{
|
||||||
|
increment = (gdouble) width / (upper - lower);
|
||||||
|
|
||||||
|
x = ROUND ((position - lower) * increment) + (xthickness - bs_width) / 2 - 1;
|
||||||
|
y = (height + bs_height) / 2 + ythickness;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
increment = (gdouble) height / (upper - lower);
|
||||||
|
|
||||||
|
x = (width + bs_width) / 2 + xthickness;
|
||||||
|
y = ROUND ((position - lower) * increment) + (ythickness - bs_height) / 2 - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
gdk_cairo_set_source_color (cr, &widget->style->fg[widget->state]);
|
||||||
|
|
||||||
|
cairo_move_to (cr, x, y);
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
cairo_fill (cr);
|
||||||
|
|
||||||
|
cairo_destroy (cr);
|
||||||
|
|
||||||
|
priv->xsrc = x;
|
||||||
|
priv->ysrc = y;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -552,7 +930,6 @@ gimp_ruler_make_pixmap (GimpRuler *ruler)
|
|||||||
gint width;
|
gint width;
|
||||||
gint height;
|
gint height;
|
||||||
|
|
||||||
|
|
||||||
if (priv->backing_store)
|
if (priv->backing_store)
|
||||||
{
|
{
|
||||||
gdk_drawable_get_size (priv->backing_store, &width, &height);
|
gdk_drawable_get_size (priv->backing_store, &width, &height);
|
||||||
@ -574,3 +951,26 @@ gimp_ruler_make_pixmap (GimpRuler *ruler)
|
|||||||
gdk_gc_set_exposures (priv->non_gr_exp_gc, FALSE);
|
gdk_gc_set_exposures (priv->non_gr_exp_gc, FALSE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static PangoLayout *
|
||||||
|
gimp_ruler_create_layout (GtkWidget *widget,
|
||||||
|
const gchar *text)
|
||||||
|
{
|
||||||
|
PangoLayout *layout;
|
||||||
|
PangoAttrList *attrs;
|
||||||
|
PangoAttribute *attr;
|
||||||
|
|
||||||
|
layout = gtk_widget_create_pango_layout (widget, text);
|
||||||
|
|
||||||
|
attrs = pango_attr_list_new ();
|
||||||
|
|
||||||
|
attr = pango_attr_scale_new (PANGO_SCALE_X_SMALL);
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
@ -20,7 +20,6 @@
|
|||||||
#ifndef __GIMP_RULER_H__
|
#ifndef __GIMP_RULER_H__
|
||||||
#define __GIMP_RULER_H__
|
#define __GIMP_RULER_H__
|
||||||
|
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
#define GIMP_TYPE_RULER (gimp_ruler_get_type ())
|
#define GIMP_TYPE_RULER (gimp_ruler_get_type ())
|
||||||
@ -35,15 +34,12 @@ typedef struct _GimpRulerClass GimpRulerClass;
|
|||||||
|
|
||||||
struct _GimpRuler
|
struct _GimpRuler
|
||||||
{
|
{
|
||||||
GtkWidget parent_instance;
|
GtkWidget parent_instance;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GimpRulerClass
|
struct _GimpRulerClass
|
||||||
{
|
{
|
||||||
GtkWidgetClass parent_class;
|
GtkWidgetClass parent_class;
|
||||||
|
|
||||||
void (* draw_ticks) (GimpRuler *ruler);
|
|
||||||
void (* draw_pos) (GimpRuler *ruler);
|
|
||||||
|
|
||||||
/* Padding for future expansion */
|
/* Padding for future expansion */
|
||||||
void (*_gimp_reserved1) (void);
|
void (*_gimp_reserved1) (void);
|
||||||
@ -53,28 +49,23 @@ struct _GimpRulerClass
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
GType gimp_ruler_get_type (void) G_GNUC_CONST;
|
GType gimp_ruler_get_type (void) G_GNUC_CONST;
|
||||||
|
|
||||||
void gimp_ruler_set_unit (GimpRuler *ruler,
|
|
||||||
GimpUnit unit);
|
|
||||||
GimpUnit gimp_ruler_get_unit (GimpRuler *ruler);
|
|
||||||
void gimp_ruler_set_position (GimpRuler *ruler,
|
|
||||||
gdouble position);
|
|
||||||
gdouble gimp_ruler_get_position (GimpRuler *ruler);
|
|
||||||
void gimp_ruler_set_range (GimpRuler *ruler,
|
|
||||||
gdouble lower,
|
|
||||||
gdouble upper,
|
|
||||||
gdouble max_size);
|
|
||||||
void gimp_ruler_get_range (GimpRuler *ruler,
|
|
||||||
gdouble *lower,
|
|
||||||
gdouble *upper,
|
|
||||||
gdouble *max_size);
|
|
||||||
|
|
||||||
|
|
||||||
GdkDrawable * _gimp_ruler_get_backing_store (GimpRuler *ruler) G_GNUC_INTERNAL;
|
|
||||||
PangoLayout * _gimp_ruler_create_pango_layout (GtkWidget *widget,
|
|
||||||
const gchar *text) G_GNUC_INTERNAL;
|
|
||||||
|
|
||||||
|
GtkWidget * gimp_ruler_new (GtkOrientation orientation);
|
||||||
|
void gimp_ruler_set_unit (GimpRuler *ruler,
|
||||||
|
GimpUnit unit);
|
||||||
|
GimpUnit gimp_ruler_get_unit (GimpRuler *ruler);
|
||||||
|
void gimp_ruler_set_position (GimpRuler *ruler,
|
||||||
|
gdouble position);
|
||||||
|
gdouble gimp_ruler_get_position (GimpRuler *ruler);
|
||||||
|
void gimp_ruler_set_range (GimpRuler *ruler,
|
||||||
|
gdouble lower,
|
||||||
|
gdouble upper,
|
||||||
|
gdouble max_size);
|
||||||
|
void gimp_ruler_get_range (GimpRuler *ruler,
|
||||||
|
gdouble *lower,
|
||||||
|
gdouble *upper,
|
||||||
|
gdouble *max_size);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
@ -1,351 +0,0 @@
|
|||||||
/* LIBGIMP - The GIMP Library
|
|
||||||
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
|
|
||||||
*
|
|
||||||
* This library is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
|
||||||
* License as published by the Free Software Foundation; either
|
|
||||||
* version 2 of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
* License along with this library; if not, write to the
|
|
||||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
||||||
* Boston, MA 02111-1307, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include <gtk/gtk.h>
|
|
||||||
|
|
||||||
#include "libgimpmath/gimpmath.h"
|
|
||||||
|
|
||||||
#include "gimpwidgetstypes.h"
|
|
||||||
|
|
||||||
#include "gimpvruler.h"
|
|
||||||
|
|
||||||
|
|
||||||
#define RULER_WIDTH 13
|
|
||||||
#define MINIMUM_INCR 5
|
|
||||||
|
|
||||||
static const struct
|
|
||||||
{
|
|
||||||
gdouble ruler_scale[16];
|
|
||||||
gint subdivide[5];
|
|
||||||
} ruler_metric =
|
|
||||||
{
|
|
||||||
{ 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000, 10000, 25000, 50000, 100000 },
|
|
||||||
{ 1, 5, 10, 50, 100 }
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
gint xsrc;
|
|
||||||
gint ysrc;
|
|
||||||
} GimpVRulerPrivate;
|
|
||||||
|
|
||||||
|
|
||||||
static gint gimp_vruler_motion_notify (GtkWidget *widget,
|
|
||||||
GdkEventMotion *event);
|
|
||||||
static void gimp_vruler_draw_ticks (GimpRuler *ruler);
|
|
||||||
static void gimp_vruler_draw_pos (GimpRuler *ruler);
|
|
||||||
|
|
||||||
G_DEFINE_TYPE (GimpVRuler, gimp_vruler, GIMP_TYPE_RULER)
|
|
||||||
|
|
||||||
#define GIMP_VRULER_GET_PRIVATE(ruler) \
|
|
||||||
G_TYPE_INSTANCE_GET_PRIVATE (ruler, GIMP_TYPE_VRULER, GimpVRulerPrivate)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
gimp_vruler_class_init (GimpVRulerClass *klass)
|
|
||||||
{
|
|
||||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
||||||
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
||||||
GimpRulerClass *ruler_class = GIMP_RULER_CLASS (klass);
|
|
||||||
|
|
||||||
widget_class->motion_notify_event = gimp_vruler_motion_notify;
|
|
||||||
|
|
||||||
ruler_class->draw_ticks = gimp_vruler_draw_ticks;
|
|
||||||
ruler_class->draw_pos = gimp_vruler_draw_pos;
|
|
||||||
|
|
||||||
g_type_class_add_private (object_class, sizeof (GimpVRulerPrivate));
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gimp_vruler_init (GimpVRuler *vruler)
|
|
||||||
{
|
|
||||||
GtkWidget *widget = GTK_WIDGET (vruler);
|
|
||||||
|
|
||||||
widget->requisition.width = widget->style->xthickness * 2 + RULER_WIDTH;
|
|
||||||
widget->requisition.height = widget->style->ythickness * 2 + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* gimp_vruler_new:
|
|
||||||
*
|
|
||||||
* Creates a new vertical ruler.
|
|
||||||
*
|
|
||||||
* Return value: a new #GimpVRuler widget.
|
|
||||||
*
|
|
||||||
* Since: GIMP 2.8
|
|
||||||
**/
|
|
||||||
GtkWidget*
|
|
||||||
gimp_vruler_new (void)
|
|
||||||
{
|
|
||||||
return g_object_new (GIMP_TYPE_VRULER, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
static gint
|
|
||||||
gimp_vruler_motion_notify (GtkWidget *widget,
|
|
||||||
GdkEventMotion *event)
|
|
||||||
{
|
|
||||||
GimpRuler *ruler = GIMP_RULER (widget);
|
|
||||||
gdouble lower;
|
|
||||||
gdouble upper;
|
|
||||||
gint y;
|
|
||||||
|
|
||||||
gdk_event_request_motions (event);
|
|
||||||
y = event->y;
|
|
||||||
|
|
||||||
gimp_ruler_get_range (ruler, &lower, &upper, NULL);
|
|
||||||
|
|
||||||
gimp_ruler_set_position (ruler,
|
|
||||||
lower +
|
|
||||||
((upper - lower) * y) / widget->allocation.height);
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gimp_vruler_draw_ticks (GimpRuler *ruler)
|
|
||||||
{
|
|
||||||
GtkWidget *widget = GTK_WIDGET (ruler);
|
|
||||||
GdkDrawable *backing_store;
|
|
||||||
cairo_t *cr;
|
|
||||||
gint i, j;
|
|
||||||
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_height;
|
|
||||||
gint pos;
|
|
||||||
gdouble max_size;
|
|
||||||
GimpUnit unit;
|
|
||||||
PangoLayout *layout;
|
|
||||||
PangoRectangle logical_rect, ink_rect;
|
|
||||||
|
|
||||||
if (! GTK_WIDGET_DRAWABLE (widget))
|
|
||||||
return;
|
|
||||||
|
|
||||||
backing_store = _gimp_ruler_get_backing_store (ruler);
|
|
||||||
|
|
||||||
xthickness = widget->style->xthickness;
|
|
||||||
ythickness = widget->style->ythickness;
|
|
||||||
|
|
||||||
layout = _gimp_ruler_create_pango_layout (widget, "012456789");
|
|
||||||
pango_layout_get_extents (layout, &ink_rect, &logical_rect);
|
|
||||||
|
|
||||||
digit_height = PANGO_PIXELS (ink_rect.height) + 2;
|
|
||||||
digit_offset = ink_rect.y;
|
|
||||||
|
|
||||||
width = widget->allocation.height;
|
|
||||||
height = widget->allocation.width - ythickness * 2;
|
|
||||||
|
|
||||||
gtk_paint_box (widget->style, backing_store,
|
|
||||||
GTK_STATE_NORMAL, GTK_SHADOW_OUT,
|
|
||||||
NULL, widget, "vruler",
|
|
||||||
0, 0,
|
|
||||||
widget->allocation.width, widget->allocation.height);
|
|
||||||
|
|
||||||
cr = gdk_cairo_create (backing_store);
|
|
||||||
gdk_cairo_set_source_color (cr, &widget->style->fg[widget->state]);
|
|
||||||
|
|
||||||
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.
|
|
||||||
*/
|
|
||||||
scale = ceil (max_size);
|
|
||||||
g_snprintf (unit_str, sizeof (unit_str), "%d", scale);
|
|
||||||
text_height = 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_height)
|
|
||||||
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)
|
|
||||||
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);
|
|
||||||
|
|
||||||
cairo_rectangle (cr,
|
|
||||||
height + xthickness - length, pos,
|
|
||||||
length, 1);
|
|
||||||
|
|
||||||
/* draw label */
|
|
||||||
if (i == 0)
|
|
||||||
{
|
|
||||||
g_snprintf (unit_str, sizeof (unit_str), "%d", (int) cur);
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
gtk_paint_layout (widget->style,
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cairo_fill (cr);
|
|
||||||
out:
|
|
||||||
cairo_destroy (cr);
|
|
||||||
|
|
||||||
g_object_unref (layout);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
gimp_vruler_draw_pos (GimpRuler *ruler)
|
|
||||||
{
|
|
||||||
GtkWidget *widget = GTK_WIDGET (ruler);
|
|
||||||
|
|
||||||
if (GTK_WIDGET_DRAWABLE (ruler))
|
|
||||||
{
|
|
||||||
GimpVRulerPrivate *priv = GIMP_VRULER_GET_PRIVATE (ruler);
|
|
||||||
gint x, y;
|
|
||||||
gint width, height;
|
|
||||||
gint bs_width, bs_height;
|
|
||||||
gint xthickness;
|
|
||||||
gint ythickness;
|
|
||||||
|
|
||||||
xthickness = widget->style->xthickness;
|
|
||||||
ythickness = widget->style->ythickness;
|
|
||||||
width = widget->allocation.width - xthickness * 2;
|
|
||||||
height = widget->allocation.height;
|
|
||||||
|
|
||||||
bs_height = width / 2 + 2;
|
|
||||||
bs_height |= 1; /* make sure it's odd */
|
|
||||||
bs_width = bs_height / 2 + 1;
|
|
||||||
|
|
||||||
if ((bs_width > 0) && (bs_height > 0))
|
|
||||||
{
|
|
||||||
GdkDrawable *backing_store = _gimp_ruler_get_backing_store (ruler);
|
|
||||||
cairo_t *cr = gdk_cairo_create (widget->window);
|
|
||||||
gdouble lower;
|
|
||||||
gdouble upper;
|
|
||||||
gdouble position;
|
|
||||||
gdouble increment;
|
|
||||||
|
|
||||||
/* If a backing store exists, restore the ruler */
|
|
||||||
if (backing_store)
|
|
||||||
gdk_draw_drawable (widget->window,
|
|
||||||
widget->style->black_gc,
|
|
||||||
backing_store,
|
|
||||||
priv->xsrc, priv->ysrc,
|
|
||||||
priv->xsrc, priv->ysrc,
|
|
||||||
bs_width, bs_height);
|
|
||||||
|
|
||||||
position = gimp_ruler_get_position (ruler);
|
|
||||||
|
|
||||||
gimp_ruler_get_range (ruler, &lower, &upper, NULL);
|
|
||||||
|
|
||||||
increment = (gdouble) height / (upper - lower);
|
|
||||||
|
|
||||||
x = (width + bs_width) / 2 + xthickness;
|
|
||||||
y = ROUND ((position - lower) * increment) + (ythickness - bs_height) / 2 - 1;
|
|
||||||
|
|
||||||
gdk_cairo_set_source_color (cr, &widget->style->fg[widget->state]);
|
|
||||||
|
|
||||||
cairo_move_to (cr, x, y);
|
|
||||||
cairo_line_to (cr, x + bs_width, y + bs_height / 2.);
|
|
||||||
cairo_line_to (cr, x, y + bs_height);
|
|
||||||
cairo_fill (cr);
|
|
||||||
|
|
||||||
cairo_destroy (cr);
|
|
||||||
|
|
||||||
priv->xsrc = x;
|
|
||||||
priv->ysrc = y;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,49 +0,0 @@
|
|||||||
/* LIBGIMP - The GIMP Library
|
|
||||||
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
|
|
||||||
*
|
|
||||||
* This library is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
|
||||||
* License as published by the Free Software Foundation; either
|
|
||||||
* version 2 of the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
* License along with this library; if not, write to the
|
|
||||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
||||||
* Boston, MA 02111-1307, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __GIMP_VRULER_H__
|
|
||||||
#define __GIMP_VRULER_H__
|
|
||||||
|
|
||||||
#include "gimpruler.h"
|
|
||||||
|
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
|
||||||
|
|
||||||
|
|
||||||
#define GIMP_TYPE_VRULER (gimp_vruler_get_type ())
|
|
||||||
#define GIMP_VRULER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_VRULER, GimpVRuler))
|
|
||||||
#define GIMP_VRULER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_VRULER, GimpVRulerClass))
|
|
||||||
#define GIMP_IS_VRULER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_VRULER))
|
|
||||||
#define GIMP_IS_VRULER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_VRULER))
|
|
||||||
#define GIMP_VRULER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_VRULER, GimpVRulerClass))
|
|
||||||
|
|
||||||
|
|
||||||
typedef GimpRulerClass GimpVRulerClass;
|
|
||||||
typedef GimpRuler GimpVRuler;
|
|
||||||
|
|
||||||
|
|
||||||
GType gimp_vruler_get_type (void) G_GNUC_CONST;
|
|
||||||
GtkWidget* gimp_vruler_new (void);
|
|
||||||
|
|
||||||
|
|
||||||
G_END_DECLS
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* __GIMP_VRULER_H__ */
|
|
||||||
|
|
@ -157,8 +157,6 @@ EXPORTS
|
|||||||
gimp_help_set_help_data_with_markup
|
gimp_help_set_help_data_with_markup
|
||||||
gimp_hint_box_get_type
|
gimp_hint_box_get_type
|
||||||
gimp_hint_box_new
|
gimp_hint_box_new
|
||||||
gimp_hruler_get_type
|
|
||||||
gimp_hruler_new
|
|
||||||
gimp_int_adjustment_update
|
gimp_int_adjustment_update
|
||||||
gimp_int_combo_box_append
|
gimp_int_combo_box_append
|
||||||
gimp_int_combo_box_connect
|
gimp_int_combo_box_connect
|
||||||
@ -307,6 +305,7 @@ EXPORTS
|
|||||||
gimp_ruler_get_range
|
gimp_ruler_get_range
|
||||||
gimp_ruler_get_type
|
gimp_ruler_get_type
|
||||||
gimp_ruler_get_unit
|
gimp_ruler_get_unit
|
||||||
|
gimp_ruler_new
|
||||||
gimp_ruler_set_position
|
gimp_ruler_set_position
|
||||||
gimp_ruler_set_range
|
gimp_ruler_set_range
|
||||||
gimp_ruler_set_unit
|
gimp_ruler_set_unit
|
||||||
@ -358,8 +357,6 @@ EXPORTS
|
|||||||
gimp_unit_menu_set_pixel_digits
|
gimp_unit_menu_set_pixel_digits
|
||||||
gimp_unit_menu_set_unit
|
gimp_unit_menu_set_unit
|
||||||
gimp_unit_menu_update
|
gimp_unit_menu_update
|
||||||
gimp_vruler_get_type
|
|
||||||
gimp_vruler_new
|
|
||||||
gimp_widgets_init
|
gimp_widgets_init
|
||||||
gimp_zoom_button_new
|
gimp_zoom_button_new
|
||||||
gimp_zoom_model_get_factor
|
gimp_zoom_model_get_factor
|
||||||
|
@ -54,7 +54,6 @@
|
|||||||
#include <libgimpwidgets/gimpframe.h>
|
#include <libgimpwidgets/gimpframe.h>
|
||||||
#include <libgimpwidgets/gimphelpui.h>
|
#include <libgimpwidgets/gimphelpui.h>
|
||||||
#include <libgimpwidgets/gimphintbox.h>
|
#include <libgimpwidgets/gimphintbox.h>
|
||||||
#include <libgimpwidgets/gimphruler.h>
|
|
||||||
#include <libgimpwidgets/gimpintcombobox.h>
|
#include <libgimpwidgets/gimpintcombobox.h>
|
||||||
#include <libgimpwidgets/gimpintstore.h>
|
#include <libgimpwidgets/gimpintstore.h>
|
||||||
#include <libgimpwidgets/gimpmemsizeentry.h>
|
#include <libgimpwidgets/gimpmemsizeentry.h>
|
||||||
@ -75,7 +74,6 @@
|
|||||||
#include <libgimpwidgets/gimpstock.h>
|
#include <libgimpwidgets/gimpstock.h>
|
||||||
#include <libgimpwidgets/gimpstringcombobox.h>
|
#include <libgimpwidgets/gimpstringcombobox.h>
|
||||||
#include <libgimpwidgets/gimpunitmenu.h>
|
#include <libgimpwidgets/gimpunitmenu.h>
|
||||||
#include <libgimpwidgets/gimpvruler.h>
|
|
||||||
#include <libgimpwidgets/gimpzoommodel.h>
|
#include <libgimpwidgets/gimpzoommodel.h>
|
||||||
|
|
||||||
#include <libgimpwidgets/gimpoldwidgets.h>
|
#include <libgimpwidgets/gimpoldwidgets.h>
|
||||||
|
@ -99,7 +99,7 @@ make_preview (void)
|
|||||||
GTK_FILL , GTK_FILL , 0, 0);
|
GTK_FILL , GTK_FILL , 0, 0);
|
||||||
gtk_container_add (GTK_CONTAINER (frame), table);
|
gtk_container_add (GTK_CONTAINER (frame), table);
|
||||||
|
|
||||||
ruler = gimp_hruler_new ();
|
ruler = gimp_ruler_new (GTK_ORIENTATION_HORIZONTAL);
|
||||||
gimp_ruler_set_range (GIMP_RULER (ruler), 0, preview_width, PREVIEW_SIZE);
|
gimp_ruler_set_range (GIMP_RULER (ruler), 0, preview_width, PREVIEW_SIZE);
|
||||||
g_signal_connect_swapped (gfig_context->preview, "motion-notify-event",
|
g_signal_connect_swapped (gfig_context->preview, "motion-notify-event",
|
||||||
G_CALLBACK (GTK_WIDGET_CLASS (G_OBJECT_GET_CLASS (ruler))->motion_notify_event),
|
G_CALLBACK (GTK_WIDGET_CLASS (G_OBJECT_GET_CLASS (ruler))->motion_notify_event),
|
||||||
@ -108,7 +108,7 @@ make_preview (void)
|
|||||||
GTK_FILL, GTK_FILL, 0, 0);
|
GTK_FILL, GTK_FILL, 0, 0);
|
||||||
gtk_widget_show (ruler);
|
gtk_widget_show (ruler);
|
||||||
|
|
||||||
ruler = gimp_vruler_new ();
|
ruler = gimp_ruler_new (GTK_ORIENTATION_VERTICAL);
|
||||||
gimp_ruler_set_range (GIMP_RULER (ruler), 0, preview_height, PREVIEW_SIZE);
|
gimp_ruler_set_range (GIMP_RULER (ruler), 0, preview_height, PREVIEW_SIZE);
|
||||||
g_signal_connect_swapped (gfig_context->preview, "motion-notify-event",
|
g_signal_connect_swapped (gfig_context->preview, "motion-notify-event",
|
||||||
G_CALLBACK (GTK_WIDGET_CLASS (G_OBJECT_GET_CLASS (ruler))->motion_notify_event),
|
G_CALLBACK (GTK_WIDGET_CLASS (G_OBJECT_GET_CLASS (ruler))->motion_notify_event),
|
||||||
|
@ -473,7 +473,7 @@ make_preview (GimpDrawable *drawable)
|
|||||||
gtk_widget_show(arrow);
|
gtk_widget_show(arrow);
|
||||||
|
|
||||||
/* Create horizontal ruler */
|
/* Create horizontal ruler */
|
||||||
data->hruler = ruler = gimp_hruler_new();
|
data->hruler = ruler = gimp_ruler_new (GTK_ORIENTATION_HORIZONTAL);
|
||||||
g_signal_connect_swapped(preview, "motion-notify-event",
|
g_signal_connect_swapped(preview, "motion-notify-event",
|
||||||
G_CALLBACK(GTK_WIDGET_GET_CLASS(ruler)->motion_notify_event),
|
G_CALLBACK(GTK_WIDGET_GET_CLASS(ruler)->motion_notify_event),
|
||||||
ruler);
|
ruler);
|
||||||
@ -483,7 +483,7 @@ make_preview (GimpDrawable *drawable)
|
|||||||
gtk_widget_show(ruler);
|
gtk_widget_show(ruler);
|
||||||
|
|
||||||
/* Create vertical ruler */
|
/* Create vertical ruler */
|
||||||
data->vruler = ruler = gimp_vruler_new();
|
data->vruler = ruler = gimp_ruler_new (GTK_ORIENTATION_VERTICAL);
|
||||||
g_signal_connect_swapped(preview, "motion-notify-event",
|
g_signal_connect_swapped(preview, "motion-notify-event",
|
||||||
G_CALLBACK(GTK_WIDGET_GET_CLASS(ruler)->motion_notify_event),
|
G_CALLBACK(GTK_WIDGET_GET_CLASS(ruler)->motion_notify_event),
|
||||||
ruler);
|
ruler);
|
||||||
|
Reference in New Issue
Block a user