mirror of https://github.com/GNOME/gimp.git
minor tweaks and constification
svn path=/trunk/; revision=25830
This commit is contained in:
parent
89cd2d483d
commit
7efbde7f85
|
@ -30,7 +30,7 @@
|
|||
#include "gimphruler.h"
|
||||
|
||||
|
||||
#define RULER_HEIGHT 14
|
||||
#define RULER_HEIGHT 13
|
||||
#define MINIMUM_INCR 5
|
||||
#define MAXIMUM_SUBDIVIDE 5
|
||||
#define MAXIMUM_SCALES 10
|
||||
|
@ -112,28 +112,27 @@ gimp_hruler_motion_notify (GtkWidget *widget,
|
|||
static void
|
||||
gimp_hruler_draw_ticks (GimpRuler *ruler)
|
||||
{
|
||||
GtkWidget *widget = GTK_WIDGET (ruler);
|
||||
GimpRulerMetric *metric;
|
||||
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 subd_incr;
|
||||
gdouble start, end, cur;
|
||||
gchar unit_str[32];
|
||||
gint digit_height;
|
||||
gint digit_offset;
|
||||
gint text_width;
|
||||
gint pos;
|
||||
gdouble max_size;
|
||||
PangoLayout *layout;
|
||||
PangoRectangle logical_rect, ink_rect;
|
||||
GtkWidget *widget = GTK_WIDGET (ruler);
|
||||
const GimpRulerMetric *metric;
|
||||
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;
|
||||
PangoLayout *layout;
|
||||
PangoRectangle logical_rect, ink_rect;
|
||||
|
||||
if (! GTK_WIDGET_DRAWABLE (widget))
|
||||
return;
|
||||
|
@ -153,19 +152,19 @@ gimp_hruler_draw_ticks (GimpRuler *ruler)
|
|||
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);
|
||||
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);
|
||||
xthickness,
|
||||
height + ythickness,
|
||||
widget->allocation.width - 2 * xthickness,
|
||||
1);
|
||||
|
||||
gimp_ruler_get_range (ruler, &lower, &upper, NULL, &max_size);
|
||||
|
||||
|
@ -189,7 +188,7 @@ gimp_hruler_draw_ticks (GimpRuler *ruler)
|
|||
text_width = strlen (unit_str) * digit_height + 1;
|
||||
|
||||
for (scale = 0; scale < MAXIMUM_SCALES; scale++)
|
||||
if (metric->ruler_scale[scale] * fabs(increment) > 2 * text_width)
|
||||
if (metric->ruler_scale[scale] * fabs (increment) > 2 * text_width)
|
||||
break;
|
||||
|
||||
if (scale == MAXIMUM_SCALES)
|
||||
|
@ -199,58 +198,59 @@ gimp_hruler_draw_ticks (GimpRuler *ruler)
|
|||
length = 0;
|
||||
for (i = MAXIMUM_SUBDIVIDE - 1; i >= 0; i--)
|
||||
{
|
||||
subd_incr = (gdouble) metric->ruler_scale[scale] /
|
||||
(gdouble) metric->subdivide[i];
|
||||
if (subd_incr * fabs(increment) <= MINIMUM_INCR)
|
||||
continue;
|
||||
gdouble subd_incr = ((gdouble) metric->ruler_scale[scale] /
|
||||
(gdouble) metric->subdivide[i]);
|
||||
|
||||
if (subd_incr * fabs (increment) <= MINIMUM_INCR)
|
||||
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;
|
||||
length = ideal_length;
|
||||
|
||||
if (lower < upper)
|
||||
{
|
||||
start = floor (lower / subd_incr) * subd_incr;
|
||||
end = ceil (upper / subd_incr) * subd_incr;
|
||||
}
|
||||
{
|
||||
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;
|
||||
}
|
||||
{
|
||||
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);
|
||||
{
|
||||
pos = ROUND ((cur - lower) * increment);
|
||||
|
||||
cairo_rectangle (cr,
|
||||
pos, height + ythickness - length,
|
||||
1, length);
|
||||
cairo_rectangle (cr,
|
||||
pos, height + ythickness - length,
|
||||
1, length);
|
||||
|
||||
/* draw label */
|
||||
if (i == 0)
|
||||
{
|
||||
g_snprintf (unit_str, sizeof (unit_str), "%d", (int) cur);
|
||||
/* 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);
|
||||
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,
|
||||
FALSE,
|
||||
NULL,
|
||||
widget,
|
||||
"hruler",
|
||||
pos + 2,
|
||||
ythickness + PANGO_PIXELS (logical_rect.y - digit_offset),
|
||||
layout);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cairo_fill (cr);
|
||||
|
@ -284,41 +284,41 @@ gimp_hruler_draw_pos (GimpRuler *ruler)
|
|||
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);
|
||||
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,
|
||||
/* 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,
|
||||
priv->xsrc, priv->ysrc,
|
||||
bs_width, bs_height);
|
||||
|
||||
gimp_ruler_get_range (ruler, &lower, &upper, &position, NULL);
|
||||
|
||||
increment = (gdouble) width / (upper - lower);
|
||||
increment = (gdouble) width / (upper - lower);
|
||||
|
||||
x = ROUND ((position - lower) * increment) + (xthickness - bs_width) / 2 - 1;
|
||||
y = (height + bs_height) / 2 + ythickness;
|
||||
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]);
|
||||
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_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);
|
||||
cairo_destroy (cr);
|
||||
|
||||
priv->xsrc = x;
|
||||
priv->ysrc = y;
|
||||
}
|
||||
priv->xsrc = x;
|
||||
priv->ysrc = y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,11 +71,20 @@ static void gimp_ruler_get_property (GObject *object,
|
|||
GValue *value,
|
||||
GParamSpec *pspec);
|
||||
|
||||
static const GimpRulerMetric ruler_metrics[] =
|
||||
static const GimpRulerMetric const ruler_metrics[] =
|
||||
{
|
||||
{ "Pixel", "Pi", 1.0, { 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000 }, { 1, 5, 10, 50, 100 }},
|
||||
{ "Inches", "In", 72.0, { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512 }, { 1, 2, 4, 8, 16 }},
|
||||
{ "Centimeters", "Cn", 28.35, { 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000 }, { 1, 5, 10, 50, 100 }},
|
||||
{
|
||||
"Pixel", "Pi", 1.0,
|
||||
{ 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000 }, { 1, 5, 10, 50, 100 }
|
||||
},
|
||||
{
|
||||
"Inches", "In", 72.0,
|
||||
{ 1, 2, 4, 8, 16, 32, 64, 128, 256, 512 }, { 1, 2, 4, 8, 16 }
|
||||
},
|
||||
{
|
||||
"Centimeters", "Cn", 28.35,
|
||||
{ 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000 }, { 1, 5, 10, 50, 100 }
|
||||
}
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (GimpRuler, gimp_ruler, GTK_TYPE_WIDGET)
|
||||
|
@ -106,50 +115,50 @@ gimp_ruler_class_init (GimpRulerClass *klass)
|
|||
g_object_class_install_property (object_class,
|
||||
PROP_LOWER,
|
||||
g_param_spec_double ("lower",
|
||||
"Lower",
|
||||
"Lower limit of ruler",
|
||||
-G_MAXDOUBLE,
|
||||
G_MAXDOUBLE,
|
||||
0.0,
|
||||
GIMP_PARAM_READWRITE));
|
||||
"Lower",
|
||||
"Lower limit of ruler",
|
||||
-G_MAXDOUBLE,
|
||||
G_MAXDOUBLE,
|
||||
0.0,
|
||||
GIMP_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_UPPER,
|
||||
g_param_spec_double ("upper",
|
||||
"Upper",
|
||||
"Upper limit of ruler",
|
||||
-G_MAXDOUBLE,
|
||||
G_MAXDOUBLE,
|
||||
0.0,
|
||||
GIMP_PARAM_READWRITE));
|
||||
"Upper",
|
||||
"Upper limit of ruler",
|
||||
-G_MAXDOUBLE,
|
||||
G_MAXDOUBLE,
|
||||
0.0,
|
||||
GIMP_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_POSITION,
|
||||
g_param_spec_double ("position",
|
||||
"Position",
|
||||
"Position of mark on the ruler",
|
||||
-G_MAXDOUBLE,
|
||||
G_MAXDOUBLE,
|
||||
0.0,
|
||||
GIMP_PARAM_READWRITE));
|
||||
"Position of mark on the ruler",
|
||||
-G_MAXDOUBLE,
|
||||
G_MAXDOUBLE,
|
||||
0.0,
|
||||
GIMP_PARAM_READWRITE));
|
||||
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_MAX_SIZE,
|
||||
g_param_spec_double ("max-size",
|
||||
"Max Size",
|
||||
"Maximum size of the ruler",
|
||||
-G_MAXDOUBLE,
|
||||
G_MAXDOUBLE,
|
||||
0.0,
|
||||
GIMP_PARAM_READWRITE));
|
||||
"Max Size",
|
||||
"Maximum size of the ruler",
|
||||
-G_MAXDOUBLE,
|
||||
G_MAXDOUBLE,
|
||||
0.0,
|
||||
GIMP_PARAM_READWRITE));
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_METRIC,
|
||||
g_param_spec_enum ("metric",
|
||||
"Metric",
|
||||
"The metric used for the ruler",
|
||||
GTK_TYPE_METRIC_TYPE,
|
||||
GTK_PIXELS,
|
||||
GIMP_PARAM_READWRITE));
|
||||
"Metric",
|
||||
"The metric used for the ruler",
|
||||
GTK_TYPE_METRIC_TYPE,
|
||||
GTK_PIXELS,
|
||||
GIMP_PARAM_READWRITE));
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -396,7 +405,7 @@ _gimp_ruler_get_backing_store (GimpRuler *ruler)
|
|||
return GIMP_RULER_GET_PRIVATE (ruler)->backing_store;
|
||||
}
|
||||
|
||||
GimpRulerMetric *
|
||||
const GimpRulerMetric *
|
||||
_gimp_ruler_get_metric (GimpRuler *ruler)
|
||||
{
|
||||
return GIMP_RULER_GET_PRIVATE (ruler)->metric;
|
||||
|
@ -444,8 +453,8 @@ gimp_ruler_realize (GtkWidget *widget)
|
|||
attributes.colormap = gtk_widget_get_colormap (widget);
|
||||
attributes.event_mask = gtk_widget_get_events (widget);
|
||||
attributes.event_mask |= (GDK_EXPOSURE_MASK |
|
||||
GDK_POINTER_MOTION_MASK |
|
||||
GDK_POINTER_MOTION_HINT_MASK);
|
||||
GDK_POINTER_MOTION_MASK |
|
||||
GDK_POINTER_MOTION_HINT_MASK);
|
||||
|
||||
attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
|
||||
|
||||
|
@ -492,8 +501,8 @@ gimp_ruler_size_allocate (GtkWidget *widget,
|
|||
if (GTK_WIDGET_REALIZED (widget))
|
||||
{
|
||||
gdk_window_move_resize (widget->window,
|
||||
allocation->x, allocation->y,
|
||||
allocation->width, allocation->height);
|
||||
allocation->x, allocation->y,
|
||||
allocation->width, allocation->height);
|
||||
|
||||
gimp_ruler_make_pixmap (ruler);
|
||||
}
|
||||
|
@ -511,11 +520,11 @@ gimp_ruler_expose (GtkWidget *widget,
|
|||
gimp_ruler_draw_ticks (ruler);
|
||||
|
||||
gdk_draw_drawable (widget->window,
|
||||
priv->non_gr_exp_gc,
|
||||
priv->backing_store,
|
||||
0, 0, 0, 0,
|
||||
widget->allocation.width,
|
||||
widget->allocation.height);
|
||||
priv->non_gr_exp_gc,
|
||||
priv->backing_store,
|
||||
0, 0, 0, 0,
|
||||
widget->allocation.width,
|
||||
widget->allocation.height);
|
||||
|
||||
gimp_ruler_draw_pos (ruler);
|
||||
}
|
||||
|
@ -536,8 +545,8 @@ gimp_ruler_make_pixmap (GimpRuler *ruler)
|
|||
{
|
||||
gdk_drawable_get_size (priv->backing_store, &width, &height);
|
||||
if ((width == widget->allocation.width) &&
|
||||
(height == widget->allocation.height))
|
||||
return;
|
||||
(height == widget->allocation.height))
|
||||
return;
|
||||
|
||||
g_object_unref (priv->backing_store);
|
||||
}
|
||||
|
|
|
@ -55,13 +55,13 @@ struct _GimpRulerClass
|
|||
|
||||
struct _GimpRulerMetric
|
||||
{
|
||||
gchar *metric_name;
|
||||
gchar *abbrev;
|
||||
const gchar *metric_name;
|
||||
const gchar *abbrev;
|
||||
/* This should be points_per_unit. This is the size of the unit
|
||||
* in 1/72nd's of an inch and has nothing to do with screen pixels */
|
||||
gdouble pixels_per_unit;
|
||||
gdouble ruler_scale[10];
|
||||
gint subdivide[5]; /* five possible modes of subdivision */
|
||||
gdouble pixels_per_unit;
|
||||
gdouble ruler_scale[10];
|
||||
gint subdivide[5]; /* five possible modes of subdivision */
|
||||
};
|
||||
|
||||
|
||||
|
@ -83,10 +83,10 @@ void gimp_ruler_get_range (GimpRuler *ruler,
|
|||
gdouble *position,
|
||||
gdouble *max_size);
|
||||
|
||||
GdkDrawable * _gimp_ruler_get_backing_store (GimpRuler *ruler) G_GNUC_INTERNAL;
|
||||
GimpRulerMetric * _gimp_ruler_get_metric (GimpRuler *ruler) G_GNUC_INTERNAL;
|
||||
PangoLayout * _gimp_ruler_create_pango_layout (GtkWidget *widget,
|
||||
const gchar *text) G_GNUC_INTERNAL;
|
||||
GdkDrawable * _gimp_ruler_get_backing_store (GimpRuler *ruler) G_GNUC_INTERNAL;
|
||||
const GimpRulerMetric * _gimp_ruler_get_metric (GimpRuler *ruler) G_GNUC_INTERNAL;
|
||||
PangoLayout * _gimp_ruler_create_pango_layout (GtkWidget *widget,
|
||||
const gchar *text) G_GNUC_INTERNAL;
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
#include "gimpvruler.h"
|
||||
|
||||
|
||||
#define RULER_WIDTH 14
|
||||
#define RULER_WIDTH 13
|
||||
#define MINIMUM_INCR 5
|
||||
#define MAXIMUM_SUBDIVIDE 5
|
||||
#define MAXIMUM_SCALES 10
|
||||
|
@ -88,7 +88,7 @@ gimp_vruler_new (void)
|
|||
|
||||
static gint
|
||||
gimp_vruler_motion_notify (GtkWidget *widget,
|
||||
GdkEventMotion *event)
|
||||
GdkEventMotion *event)
|
||||
{
|
||||
GimpRuler *ruler = GIMP_RULER (widget);
|
||||
gdouble lower;
|
||||
|
@ -112,28 +112,27 @@ gimp_vruler_motion_notify (GtkWidget *widget,
|
|||
static void
|
||||
gimp_vruler_draw_ticks (GimpRuler *ruler)
|
||||
{
|
||||
GtkWidget *widget = GTK_WIDGET (ruler);
|
||||
GimpRulerMetric *metric;
|
||||
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 subd_incr;
|
||||
gdouble start, end, cur;
|
||||
gchar unit_str[32];
|
||||
gint digit_height;
|
||||
gint digit_offset;
|
||||
gint text_height;
|
||||
gint pos;
|
||||
gdouble max_size;
|
||||
PangoLayout *layout;
|
||||
PangoRectangle logical_rect, ink_rect;
|
||||
GtkWidget *widget = GTK_WIDGET (ruler);
|
||||
const GimpRulerMetric *metric;
|
||||
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;
|
||||
PangoLayout *layout;
|
||||
PangoRectangle logical_rect, ink_rect;
|
||||
|
||||
if (! GTK_WIDGET_DRAWABLE (widget))
|
||||
return;
|
||||
|
@ -149,23 +148,23 @@ gimp_vruler_draw_ticks (GimpRuler *ruler)
|
|||
digit_height = PANGO_PIXELS (ink_rect.height) + 2;
|
||||
digit_offset = ink_rect.y;
|
||||
|
||||
width = widget->allocation.height;
|
||||
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);
|
||||
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);
|
||||
height + xthickness,
|
||||
ythickness,
|
||||
1,
|
||||
widget->allocation.height - 2 * ythickness);
|
||||
|
||||
gimp_ruler_get_range (ruler, &lower, &upper, NULL, &max_size);
|
||||
|
||||
|
@ -190,7 +189,7 @@ gimp_vruler_draw_ticks (GimpRuler *ruler)
|
|||
text_height = strlen (unit_str) * digit_height + 1;
|
||||
|
||||
for (scale = 0; scale < MAXIMUM_SCALES; scale++)
|
||||
if (metric->ruler_scale[scale] * fabs(increment) > 2 * text_height)
|
||||
if (metric->ruler_scale[scale] * fabs (increment) > 2 * text_height)
|
||||
break;
|
||||
|
||||
if (scale == MAXIMUM_SCALES)
|
||||
|
@ -200,60 +199,61 @@ gimp_vruler_draw_ticks (GimpRuler *ruler)
|
|||
length = 0;
|
||||
for (i = MAXIMUM_SUBDIVIDE - 1; i >= 0; i--)
|
||||
{
|
||||
subd_incr = (gdouble) metric->ruler_scale[scale] /
|
||||
(gdouble) metric->subdivide[i];
|
||||
if (subd_incr * fabs(increment) <= MINIMUM_INCR)
|
||||
continue;
|
||||
gdouble subd_incr = ((gdouble) metric->ruler_scale[scale] /
|
||||
(gdouble) metric->subdivide[i]);
|
||||
|
||||
if (subd_incr * fabs (increment) <= MINIMUM_INCR)
|
||||
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;
|
||||
length = ideal_length;
|
||||
|
||||
if (lower < upper)
|
||||
{
|
||||
start = floor (lower / subd_incr) * subd_incr;
|
||||
end = ceil (upper / subd_incr) * subd_incr;
|
||||
}
|
||||
{
|
||||
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;
|
||||
}
|
||||
{
|
||||
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);
|
||||
{
|
||||
pos = ROUND ((cur - lower) * increment);
|
||||
|
||||
cairo_rectangle (cr,
|
||||
height + xthickness - length, pos,
|
||||
length, 1);
|
||||
cairo_rectangle (cr,
|
||||
height + xthickness - length, pos,
|
||||
length, 1);
|
||||
|
||||
/* draw label */
|
||||
if (i == 0)
|
||||
{
|
||||
g_snprintf (unit_str, sizeof (unit_str), "%d", (int) cur);
|
||||
/* 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);
|
||||
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,
|
||||
FALSE,
|
||||
NULL,
|
||||
widget,
|
||||
"vruler",
|
||||
xthickness + 1,
|
||||
pos + digit_height * j + 2 + PANGO_PIXELS (logical_rect.y - digit_offset),
|
||||
layout);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cairo_fill (cr);
|
||||
|
@ -288,41 +288,41 @@ gimp_vruler_draw_pos (GimpRuler *ruler)
|
|||
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);
|
||||
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,
|
||||
/* 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,
|
||||
priv->xsrc, priv->ysrc,
|
||||
bs_width, bs_height);
|
||||
|
||||
gimp_ruler_get_range (ruler, &lower, &upper, &position, NULL);
|
||||
|
||||
increment = (gdouble) height / (upper - lower);
|
||||
increment = (gdouble) height / (upper - lower);
|
||||
|
||||
x = (width + bs_width) / 2 + xthickness;
|
||||
y = ROUND ((position - lower) * increment) + (ythickness - bs_height) / 2 - 1;
|
||||
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]);
|
||||
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_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);
|
||||
cairo_destroy (cr);
|
||||
|
||||
priv->xsrc = x;
|
||||
priv->ysrc = y;
|
||||
}
|
||||
priv->xsrc = x;
|
||||
priv->ysrc = y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue